Foam::tmp<Foam::volScalarField::Internal> Foam::fvMesh::Vsc() const { if (moving() && time().subCycling()) { const TimeState& ts = time(); const TimeState& ts0 = time().prevTimeState(); scalar tFrac = ( ts.value() - (ts0.value() - ts0.deltaTValue()) )/ts0.deltaTValue(); if (tFrac < (1 - SMALL)) { return V0() + tFrac*(V() - V0()); } else { return V(); } } else { return V(); } }
tmp<volScalarField::DimensionedInternalField> fvMesh::Vsc0() const { if (moving() && time().subCycling()) { const TimeState& ts = time(); const TimeState& ts0 = time().prevTimeState(); scalar t0Frac = ( (ts.value() - ts.deltaTValue()) - (ts0.value() - ts0.deltaTValue()) )/ts0.deltaTValue(); if (t0Frac > SMALL) { return V0() + t0Frac*(V() - V0()); } else { return V0(); } } else { return V0(); } }
void Box::create(Vector3 origin, float length, float depth, float width) { this->center = origin; this->sizeX = length; this->sizeY = depth; this->sizeZ = width; Vector3 V0(origin.x()-(length/2), origin.y()-(depth/2), origin.z()-(width/2)); Vector3 V1(origin.x()+(length/2), origin.y()-(depth/2), origin.z()-(width/2)); Vector3 V2(origin.x()+(length/2), origin.y()+(depth/2), origin.z()-(width/2)); Vector3 V3(origin.x()-(length/2), origin.y()+(depth/2), origin.z()-(width/2)); Vector3 V4(origin.x()-(length/2), origin.y()-(depth/2), origin.z()+(width/2)); Vector3 V5(origin.x()+(length/2), origin.y()-(depth/2), origin.z()+(width/2)); Vector3 V6(origin.x()+(length/2), origin.y()+(depth/2), origin.z()+(width/2)); Vector3 V7(origin.x()-(length/2), origin.y()+(depth/2), origin.z()+(width/2)); vector<Quadrilateral> Q; Q.push_back(Quadrilateral(V0,V1,V5,V4)); Q.push_back(Quadrilateral(V2,V3,V7,V6)); Q.push_back(Quadrilateral(V0,V4,V7,V3)); Q.push_back(Quadrilateral(V5,V1,V2,V6)); Q.push_back(Quadrilateral(V1,V0,V3,V2)); Q.push_back(Quadrilateral(V4,V5,V6,V7)); setFaces(Q); calculateMinMax(); }
ALenum InitEffectSlot(ALeffectslot *slot) { ALeffectStateFactory *factory; slot->Effect.Type = AL_EFFECT_NULL; factory = getFactoryByType(AL_EFFECT_NULL); if(!(slot->Effect.State=V0(factory,create)())) return AL_OUT_OF_MEMORY; slot->Gain = 1.0; slot->AuxSendAuto = AL_TRUE; InitRef(&slot->ref, 0); ATOMIC_INIT(&slot->Update, NULL); ATOMIC_INIT(&slot->FreeList, NULL); slot->Params.Gain = 1.0f; slot->Params.AuxSendAuto = AL_TRUE; slot->Params.EffectState = slot->Effect.State; slot->Params.RoomRolloff = 0.0f; slot->Params.DecayTime = 0.0f; slot->Params.AirAbsorptionGainHF = 1.0f; ATOMIC_INIT(&slot->next, NULL); return AL_NO_ERROR; }
const Foam::volScalarField::Internal& Foam::fvMesh::V00() const { if (!V00Ptr_) { if (debug) { InfoInFunction << "Constructing from V0" << endl; } V00Ptr_ = new DimensionedField<scalar, volMesh> ( IOobject ( "V00", time().timeName(), *this, IOobject::NO_READ, IOobject::NO_WRITE, false ), V0() ); // If V00 is used then V0 should be stored for restart V0Ptr_->writeOpt() = IOobject::AUTO_WRITE; } return *V00Ptr_; }
ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect) { ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL); ALeffectStateFactory *factory; if(newtype != EffectSlot->Effect.Type) { ALeffectState *State; FPUCtl oldMode; factory = getFactoryByType(newtype); if(!factory) { ERR("Failed to find factory for effect type 0x%04x\n", newtype); return AL_INVALID_ENUM; } State = V0(factory,create)(); if(!State) return AL_OUT_OF_MEMORY; SetMixerFPUMode(&oldMode); /* FIXME: This just needs to prevent the device from being reset during * the state's device update, so the list lock in ALc.c should do here. */ ALCdevice_Lock(Device); State->OutBuffer = Device->Dry.Buffer; State->OutChannels = Device->Dry.NumChannels; if(V(State,deviceUpdate)(Device) == AL_FALSE) { ALCdevice_Unlock(Device); RestoreFPUMode(&oldMode); DELETE_OBJ(State); return AL_OUT_OF_MEMORY; } ALCdevice_Unlock(Device); RestoreFPUMode(&oldMode); if(!effect) { EffectSlot->Effect.Type = AL_EFFECT_NULL; memset(&EffectSlot->Effect.Props, 0, sizeof(EffectSlot->Effect.Props)); } else { EffectSlot->Effect.Type = effect->type; memcpy(&EffectSlot->Effect.Props, &effect->Props, sizeof(EffectSlot->Effect.Props)); } EffectSlot->Effect.State = State; UpdateEffectSlotProps(EffectSlot, AL_TRUE); } else if(effect) { memcpy(&EffectSlot->Effect.Props, &effect->Props, sizeof(EffectSlot->Effect.Props)); UpdateEffectSlotProps(EffectSlot, AL_FALSE); } return AL_NO_ERROR; }
void CatmullRomCurveEvaluator::convertPoints(std::vector<Point>& pts, Point P0, Point P1, Point P2, Point P3) const { Point V0(P1); Point V1(Point(P1.x + cat / 3 * (P2.x - P0.x), P1.y + cat / 3 * (P2.y - P0.y))); Point V2(Point(P2.x - cat / 3 * (P3.x - P1.x), P2.y - cat / 3 * (P3.y - P1.y))); Point V3(P2); pts.push_back(V0); pts.push_back(V1); pts.push_back(V2); pts.push_back(V3); }
ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect) { ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL); ALeffectStateFactory *factory; if(newtype != EffectSlot->Effect.Type) { ALeffectState *State; FPUCtl oldMode; factory = getFactoryByType(newtype); if(!factory) { ERR("Failed to find factory for effect type 0x%04x\n", newtype); return AL_INVALID_ENUM; } State = V0(factory,create)(); if(!State) return AL_OUT_OF_MEMORY; SetMixerFPUMode(&oldMode); almtx_lock(&Device->BackendLock); State->OutBuffer = Device->Dry.Buffer; State->OutChannels = Device->Dry.NumChannels; if(V(State,deviceUpdate)(Device) == AL_FALSE) { almtx_unlock(&Device->BackendLock); RestoreFPUMode(&oldMode); DELETE_OBJ(State); return AL_OUT_OF_MEMORY; } almtx_unlock(&Device->BackendLock); RestoreFPUMode(&oldMode); if(!effect) { EffectSlot->Effect.Type = AL_EFFECT_NULL; memset(&EffectSlot->Effect.Props, 0, sizeof(EffectSlot->Effect.Props)); } else { EffectSlot->Effect.Type = effect->type; EffectSlot->Effect.Props = effect->Props; } EffectSlot->Effect.State = State; UpdateEffectSlotProps(EffectSlot); } else if(effect) { EffectSlot->Effect.Props = effect->Props; UpdateEffectSlotProps(EffectSlot); } return AL_NO_ERROR; }
CameraPinhole::CameraPinhole(const Vecteur3 & position, const Vecteur3 & visee, const Vecteur3 & verticale, reel fov) { // memorise la position et l'angle de vue _position = position; _fov = fov; // calcule les matrices de changement de repere Vecteur3 W(visee); W.normer(); Vecteur3 V0(-verticale); V0.normer(); Vecteur3 U(ProduitVectoriel(V0, W)); Vecteur3 V(ProduitVectoriel(W, U)); _mondeVersCamera.remplir(U, V, W); _cameraVersMonde = _mondeVersCamera.transposer(); }
AL_API void AL_APIENTRY alMidiResetSOFT(void) { ALCdevice *device; ALCcontext *context; MidiSynth *synth; context = GetContextRef(); if(!context) return; device = context->Device; synth = device->Synth; WriteLock(&synth->Lock); MidiSynth_setState(synth, AL_INITIAL); ALCdevice_Lock(device); V0(synth,reset)(); ALCdevice_Unlock(device); WriteUnlock(&synth->Lock); ALCcontext_DecRef(context); }
AL_API void AL_APIENTRY alMidiStopSOFT(void) { ALCdevice *device; ALCcontext *context; MidiSynth *synth; context = GetContextRef(); if(!context) return; device = context->Device; synth = device->Synth; WriteLock(&synth->Lock); V(synth,setState)(AL_STOPPED); ALCdevice_Lock(device); V0(synth,stop)(); ALCdevice_Unlock(device); WriteUnlock(&synth->Lock); ALCcontext_DecRef(context); }
const volScalarField::DimensionedInternalField& fvMesh::V00() const { if (!V00Ptr_) { V00Ptr_ = new DimensionedField<scalar, volMesh> ( IOobject ( "V00", time().timeName(), *this, IOobject::NO_READ, IOobject::NO_WRITE ), V0() ); // If V00 is used then V0 should be stored for restart V0Ptr_->writeOpt() = IOobject::AUTO_WRITE; } return *V00Ptr_; }
ALenum InitEffectSlot(ALeffectslot *slot) { ALeffectStateFactory *factory; ALuint i, c; slot->EffectType = AL_EFFECT_NULL; factory = getFactoryByType(AL_EFFECT_NULL); if(!(slot->EffectState=V0(factory,create)())) return AL_OUT_OF_MEMORY; slot->Gain = 1.0; slot->AuxSendAuto = AL_TRUE; ATOMIC_INIT(&slot->NeedsUpdate, AL_FALSE); for(c = 0;c < 1;c++) { for(i = 0;i < BUFFERSIZE;i++) slot->WetBuffer[c][i] = 0.0f; } InitRef(&slot->ref, 0); return AL_NO_ERROR; }
ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect) { ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL); ALeffectStateFactory *factory; if(newtype != EffectSlot->EffectType) { ALeffectState *State; FPUCtl oldMode; factory = getFactoryByType(newtype); if(!factory) { ERR("Failed to find factory for effect type 0x%04x\n", newtype); return AL_INVALID_ENUM; } State = V0(factory,create)(); if(!State) return AL_OUT_OF_MEMORY; SetMixerFPUMode(&oldMode); ALCdevice_Lock(Device); if(V(State,deviceUpdate)(Device) == AL_FALSE) { ALCdevice_Unlock(Device); RestoreFPUMode(&oldMode); DELETE_OBJ(State); return AL_OUT_OF_MEMORY; } State = ExchangePtr((XchgPtr*)&EffectSlot->EffectState, State); if(!effect) { memset(&EffectSlot->EffectProps, 0, sizeof(EffectSlot->EffectProps)); EffectSlot->EffectType = AL_EFFECT_NULL; } else { memcpy(&EffectSlot->EffectProps, &effect->Props, sizeof(effect->Props)); EffectSlot->EffectType = effect->type; } /* FIXME: This should be done asynchronously, but since the EffectState * object was changed, it needs an update before its Process method can * be called. */ ATOMIC_STORE(&EffectSlot->NeedsUpdate, AL_FALSE); V(EffectSlot->EffectState,update)(Device, EffectSlot); ALCdevice_Unlock(Device); RestoreFPUMode(&oldMode); DELETE_OBJ(State); State = NULL; } else { if(effect) { ALCdevice_Lock(Device); memcpy(&EffectSlot->EffectProps, &effect->Props, sizeof(effect->Props)); ALCdevice_Unlock(Device); ATOMIC_STORE(&EffectSlot->NeedsUpdate, AL_TRUE); } } return AL_NO_ERROR; }
vector<double> Plink::calcMantelHaenszel_IxJxK(vector<int> & X, vector<int> & Y, vector<int> & Z) { if (X.size() != Y.size() || Y.size() != Z.size() || X.size() != Z.size() ) error("Internal problem:\n problem in calcMantelHaenszel_IxJxK()...uneven input columns"); // Determine unique elements int nx=0, ny=0, nz=0; map<int,int> mx; map<int,int> my; map<int,int> mz; for (unsigned int i=0; i<X.size(); i++) { if (mx.find(X[i]) == mx.end()) mx.insert(make_pair(X[i],nx++)); if (my.find(Y[i]) == my.end()) my.insert(make_pair(Y[i],ny++)); if (mz.find(Z[i]) == mz.end()) mz.insert(make_pair(Z[i],nz++)); } // Generic function to calculate generalized IxJxK CMH // Assumes no missing data vector< vector<double> > N(nz); // observed counts vector< vector<double> > U(nz); // expected vector< vector< vector<double> > > V(nz); // variance matrix vector<vector<double> > Tx(nz); // marginal totals vector<vector<double> > Ty(nz); // .. vector<double> T(nz); // totals (per K) for (int k=0; k<nz; k++) { Tx[k].resize(nx); Ty[k].resize(ny); N[k].resize((nx-1)*(ny-1)); U[k].resize((nx-1)*(ny-1)); V[k].resize((nx-1)*(ny-1)); for (int k2=0; k2<(nx-1)*(ny-1); k2++) { N[k][k2] = U[k][k2] = 0; V[k][k2].resize((nx-1)*(ny-1)); for (int k3=0; k3<(nx-1)*(ny-1); k3++) V[k][k2][k3] = 0; } } // Consider each observation for (int i=0; i<X.size(); i++) { int vx = mx.find(X[i])->second; int vy = my.find(Y[i])->second; int vz = mz.find(Z[i])->second; // exclude nx + ny (upper limits) if (vx<nx-1 && vy<ny-1) N[vz][ vx + vy*(nx-1) ]++; Tx[vz][vx]++; Ty[vz][vy]++; T[vz]++; } // Determine valid clusters (at least 2 people) vector<bool> validK(nk,false); for (int k=0; k<nk; k++) if (T[k]>=2) validK[k]=true; // Calculate expecteds for (int k=0; k<nz; k++) { if (validK[k]) { for (int ix=0; ix<nx-1; ix++) for (int iy=0; iy<ny-1; iy++) { U[k][ix+iy*(nx-1)] = ( Tx[k][ix] * Ty[k][iy] ) / T[k]; for (int ix2=0; ix2<nx-1; ix2++) for (int iy2=0; iy2<ny-1; iy2++) { int dx=0; int dy=0; if (ix==ix2) dx=1; if (iy==iy2) dy=1; V[k][ix + iy*(nx-1)][ix2 + iy2*(nx-1)] = ( ( Tx[k][ix] * ( dx * T[k] - Tx[k][ix2] ) * Ty[k][iy] * ( dy *T[k] - Ty[k][iy2] ) ) / ( T[k]*T[k]*(T[k]-1) ) ); if (ix==ix2 && iy==iy2) V[k][ix + iy*(nx-1)][ix2 + iy2*(nx-1)] = abs(V[k][ix + iy*(nx-1)][ix2 + iy2*(nx-1)]); } } } } vector<vector<double> > V0((nx-1)*(ny-1)); for (int k2=0; k2<(nx-1)*(ny-1); k2++) V0[k2].resize((nx-1)*(ny-1)); vector<double> N0((nx-1)*(ny-1)); vector<double> U0((nx-1)*(ny-1)); // Sum N, U and V over K for (int k=0; k<nz; k++) { if (validK[k]) { for (int i=0; i<(nx-1)*(ny-1); i++) { N0[i] += N[k][i]; U0[i] += U[k][i]; for (int i2=0; i2<(nx-1)*(ny-1); i2++) V0[i][i2] += V[k][i][i2]; } } } bool flag = true; vector<double> tmp1((nx-1)*(ny-1),0); vector<double> tmp2((nx-1)*(ny-1),0); V0 = svd_inverse(V0,flag); for (int i=0; i<(nx-1)*(ny-1); i++) tmp1[i] = N0[i] - U0[i]; // Matrix mult -- rows by columns for (int i=0; i<(nx-1)*(ny-1); i++) for (int j=0; j<(nx-1)*(ny-1); j++) tmp2[j] += tmp1[i] * V0[i][j]; vector<double> result(2); // CMH Chi-square result[0]=0; for (int i=0; i<(nx-1)*(ny-1); i++) result[0] += tmp2[i] * tmp1[i]; // DF result[1] = (nx-1)*(ny-1); return result; }
CNWAligner::TScore CNWAligner::x_Align(SAlignInOut* data) { const size_t N1 = data->m_len1 + 1; const size_t N2 = data->m_len2 + 1; vector<TScore> stl_rowV (N2), stl_rowF(N2); TScore * rowV = &stl_rowV[0]; TScore * rowF = &stl_rowF[0]; TScore * pV = rowV - 1; const char * seq1 = m_Seq1 + data->m_offset1 - 1; const char * seq2 = m_Seq2 + data->m_offset2 - 1; const TNCBIScore (* sm) [NCBI_FSM_DIM] = m_ScoreMatrix.s; if(m_prg_callback) { m_prg_info.m_iter_total = N1*N2; m_prg_info.m_iter_done = 0; if( (m_terminate = m_prg_callback(&m_prg_info)) ) { return 0; } } bool bFreeGapLeft1 = data->m_esf_L1 && data->m_offset1 == 0; bool bFreeGapRight1 = data->m_esf_R1 && m_SeqLen1 == data->m_offset1 + data->m_len1; bool bFreeGapLeft2 = data->m_esf_L2 && data->m_offset2 == 0; bool bFreeGapRight2 = data->m_esf_R2 && m_SeqLen2 == data->m_offset2 + data->m_len2; TScore wgleft1 = bFreeGapLeft1? 0: m_Wg; TScore wsleft1 = bFreeGapLeft1? 0: m_Ws; TScore wg1 = m_Wg, ws1 = m_Ws; // index calculation: [i,j] = i*n2 + j CBacktraceMatrix4 backtrace_matrix (N1 * N2); backtrace_matrix.SetAt(0, 0); // first row size_t k; rowV[0] = wgleft1; for (k = 1; k < N2; ++k) { rowV[k] = pV[k] + wsleft1; rowF[k] = kInfMinus; backtrace_matrix.SetAt(k, kMaskE | kMaskEc); } backtrace_matrix.Purge(k); rowV[0] = 0; if(m_prg_callback) { m_prg_info.m_iter_done = k; m_terminate = m_prg_callback(&m_prg_info); } // recurrences TScore wgleft2 (bFreeGapLeft2? 0: m_Wg); TScore wsleft2 (bFreeGapLeft2? 0: m_Ws); TScore V (rowV[N2 - 1]); TScore V0 (wgleft2); TScore E, G, n0; unsigned char tracer; size_t i, j; for(i = 1; i < N1 && !m_terminate; ++i) { V = V0 += wsleft2; E = kInfMinus; backtrace_matrix.SetAt(k++, kMaskFc); unsigned char ci = seq1[i]; if(i == N1 - 1 && bFreeGapRight1) { wg1 = ws1 = 0; } TScore wg2 = m_Wg, ws2 = m_Ws; for (j = 1; j < N2; ++j, ++k) { G = pV[j] + sm[ci][(unsigned char)seq2[j]]; pV[j] = V; n0 = V + wg1; if(E >= n0) { E += ws1; // continue the gap tracer = kMaskEc; } else { E = n0 + ws1; // open a new gap tracer = 0; } if(j == N2 - 1 && bFreeGapRight2) { wg2 = ws2 = 0; } n0 = rowV[j] + wg2; if(rowF[j] >= n0) { rowF[j] += ws2; tracer |= kMaskFc; } else { rowF[j] = n0 + ws2; } if (E >= rowF[j]) { if(E >= G) { V = E; tracer |= kMaskE; } else { V = G; tracer |= kMaskD; } } else { if(rowF[j] >= G) { V = rowF[j]; } else { V = G; tracer |= kMaskD; } } backtrace_matrix.SetAt(k, tracer); } pV[j] = V; if(m_prg_callback) { m_prg_info.m_iter_done = k; if( (m_terminate = m_prg_callback(&m_prg_info)) ) { break; } } } backtrace_matrix.Purge(k); if(!m_terminate) { x_DoBackTrace(backtrace_matrix, data); } return V; }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::twoStrokeEngine::checkMotionFluxes() { /* //checking the motion fluxes for the cutFaceZone Info << "Checking the motion fluxes in the cut-face zone" << endl; const labelList& cutFaceZoneAddressing = faceZones()[faceZones().findZoneID("cutFaceZone")]; boolList calculatedMeshPhi(V().size(), false); scalarField sumMeshPhi(V().size(), 0.0); forAll(cutFaceZoneAddressing, i) { label facei = cutFaceZoneAddressing[i]; calculatedMeshPhi[owner()[facei]] = true; calculatedMeshPhi[neighbour()[facei]] = true; } Info << "Checking the motion fluxes in the liner zone" << endl; const labelList& linerAddressing = faceZones()[faceZones().findZoneID(scavInCylPatchName_ + "Zone")]; forAll(linerAddressing, i) { label facei = linerAddressing[i]; calculatedMeshPhi[owner()[facei]] = true; calculatedMeshPhi[neighbour()[facei]] = true; } const polyPatch& wallPatch = boundaryMesh()[boundaryMesh().findPatchID("wall")]; labelList wallLabels(wallPatch.size()); forAll (wallLabels, i) { wallLabels[i] = wallPatch.start() + i; } forAll(wallLabels, i) { label facei = wallLabels[i]; calculatedMeshPhi[owner()[facei]] = true; calculatedMeshPhi[neighbour()[facei]] = true; } forAll(owner(), facei) { sumMeshPhi[owner()[facei]] += phi()[facei]; sumMeshPhi[neighbour()[facei]] -= phi()[facei]; } forAll(boundary(), patchi) { const unallocLabelList& pFaceCells = boundary()[patchi].faceCells(); const fvsPatchField<scalar>& pssf = phi().boundaryField()[patchi]; forAll(boundary()[patchi], facei) { sumMeshPhi[pFaceCells[facei]] += pssf[facei]; } } sumMeshPhi /= V(); dynamicLabelList checkMeshPhi; label checkMeshPhiSize = 0; forAll(calculatedMeshPhi, i) { if(calculatedMeshPhi[i] == true) { checkMeshPhi.append(i); checkMeshPhiSize++; } } Info << "checkMeshPhiSize = " << checkMeshPhiSize << endl; checkMeshPhi.setSize(checkMeshPhiSize); scalarField dVdt(checkMeshPhiSize, 0.0); forAll(dVdt, i) { label celli = checkMeshPhi[i]; dVdt[i] = (1.0 - V0()[celli]/V()[celli])/engTime().deltaT().value(); } Info << "checking mesh flux in the cutFaces" << endl; label nOutCheck = 0; forAll(checkMeshPhi, i) { scalar sumCheck = dVdt[i] - sumMeshPhi[checkMeshPhi[i]]; if(mag(sumCheck) > 1) { Info<< "LOCAL sumCheck[" << checkMeshPhi[i] << "] = " << sumCheck << endl; nOutCheck++; } } Info<< "found " << nOutCheck << " cells with inconsistent motion fluxes" << endl; Info << "end " << endl; */ { scalarField dVdt = (1.0 - V0()/V())/engTime().deltaT(); scalarField sumMeshPhi(V().size(), 0.0); forAll(owner(), facei) { sumMeshPhi[owner()[facei]] += phi()[facei]; sumMeshPhi[neighbour()[facei]] -= phi()[facei]; } forAll(boundary(), patchi) { const unallocLabelList& pFaceCells = boundary()[patchi].faceCells(); const fvsPatchField<scalar>& pssf = phi().boundaryField()[patchi]; forAll(boundary()[patchi], facei) { sumMeshPhi[pFaceCells[facei]] += pssf[facei]; } } sumMeshPhi /= V(); scalarField sumCheck = dVdt - sumMeshPhi; label nOutCheck = 0; forAll(sumCheck, celli) { if(mag(sumCheck[celli]) > 1) { Info<< "sumCheck GLOBAL[" << celli << "] = " << sumCheck[celli] << endl; nOutCheck++; } } Info<< "found " << nOutCheck << " cells with inconsistent motion fluxes GLOBAL" << endl; }
static DWORD CALLBACK ALCmmdevProxy_messageHandler(void *ptr) { ThreadRequest *req = ptr; IMMDeviceEnumerator *Enumerator; ALuint deviceCount = 0; ALCmmdevProxy *proxy; HRESULT hr, cohr; MSG msg; TRACE("Starting message thread\n"); cohr = CoInitialize(NULL); if(FAILED(cohr)) { WARN("Failed to initialize COM: 0x%08lx\n", cohr); ReturnMsgResponse(req, cohr); return 0; } hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr); if(FAILED(hr)) { WARN("Failed to create IMMDeviceEnumerator instance: 0x%08lx\n", hr); CoUninitialize(); ReturnMsgResponse(req, hr); return 0; } Enumerator = ptr; IMMDeviceEnumerator_Release(Enumerator); Enumerator = NULL; CoUninitialize(); /* HACK: Force Windows to create a message queue for this thread before * returning success, otherwise PostThreadMessage may fail if it gets * called before GetMessage. */ PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); TRACE("Message thread initialization complete\n"); ReturnMsgResponse(req, S_OK); TRACE("Starting message loop\n"); while(GetMessage(&msg, NULL, WM_USER_First, WM_USER_Last)) { TRACE("Got message %u\n", msg.message); switch(msg.message) { case WM_USER_OpenDevice: req = (ThreadRequest*)msg.wParam; proxy = (ALCmmdevProxy*)msg.lParam; hr = cohr = S_OK; if(++deviceCount == 1) hr = cohr = CoInitialize(NULL); if(SUCCEEDED(hr)) hr = V0(proxy,openProxy)(); if(FAILED(hr)) { if(--deviceCount == 0 && SUCCEEDED(cohr)) CoUninitialize(); } ReturnMsgResponse(req, hr); continue; case WM_USER_ResetDevice: req = (ThreadRequest*)msg.wParam; proxy = (ALCmmdevProxy*)msg.lParam; hr = V0(proxy,resetProxy)(); ReturnMsgResponse(req, hr); continue; case WM_USER_StartDevice: req = (ThreadRequest*)msg.wParam; proxy = (ALCmmdevProxy*)msg.lParam; hr = V0(proxy,startProxy)(); ReturnMsgResponse(req, hr); continue; case WM_USER_StopDevice: req = (ThreadRequest*)msg.wParam; proxy = (ALCmmdevProxy*)msg.lParam; V0(proxy,stopProxy)(); ReturnMsgResponse(req, S_OK); continue; case WM_USER_CloseDevice: req = (ThreadRequest*)msg.wParam; proxy = (ALCmmdevProxy*)msg.lParam; V0(proxy,closeProxy)(); if(--deviceCount == 0) CoUninitialize(); ReturnMsgResponse(req, S_OK); continue; case WM_USER_Enumerate: req = (ThreadRequest*)msg.wParam; hr = cohr = S_OK; if(++deviceCount == 1) hr = cohr = CoInitialize(NULL); if(SUCCEEDED(hr)) hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr); if(SUCCEEDED(hr)) { Enumerator = ptr; if(msg.lParam == ALL_DEVICE_PROBE) hr = probe_devices(Enumerator, eRender, &PlaybackDevices); else if(msg.lParam == CAPTURE_DEVICE_PROBE) hr = probe_devices(Enumerator, eCapture, &CaptureDevices); IMMDeviceEnumerator_Release(Enumerator); Enumerator = NULL; } if(--deviceCount == 0 && SUCCEEDED(cohr)) CoUninitialize(); ReturnMsgResponse(req, hr); continue; default: ERR("Unexpected message: %u\n", msg.message); continue; } } TRACE("Message loop finished\n"); return 0; }
int main(int argc, char *argv[]) { std::cout << "///////////////////// POINT //////////////////////////////////" << std::endl; Point newPoint(0,1,2); std::cout << "x : " << newPoint.x() << std::endl; std::cout << "y : " << newPoint.y() << std::endl; std::cout << "z : " << newPoint.z() << std::endl; newPoint.setY(5); Point pointB; std::cout << "y : " << pointB.y() << std::endl; if (! newPoint.isNotEqual(pointB)) std::cout << "equal" << std::endl; else std::cout << "nonEqual" << std::endl; std::cout << "///////////////////// VECTOR //////////////////////////////////" << std::endl; Vector newVector, vect; newVector.setCoordonne(-8.0, 5.0, 6.0); Vector vec2(newPoint, pointB); Vector vec3(newVector, vec2); std::cout << "x2 : " << vec2.x() << std::endl; std::cout << "y2 : " << vec2.y() << std::endl; std::cout << "z2 : " << vec2.z() << std::endl; if (vect.vecteurNull()) std::cout << "vec Null" << std::endl; else std::cout << "vec Non NUll" << std::endl; if (newVector.vecteurNull()) std::cout << "newVector Null" << std::endl; else std::cout << "newVector Non NUll" << std::endl; std::cout << "dot => " << newVector.dot(vec2) << std::endl; std::cout << "x3 : " << vec3.x() << std::endl; std::cout << "y3 : " << vec3.y() << std::endl; std::cout << "z3 : " << vec3.z() << std::endl; std::cout << "///////////////////// RAY //////////////////////////////////" << std::endl; Ray newRay(pointB,newPoint); std::cout << "origine : " << newRay.P0().x() << ", " << newRay.P0().y() << ", " << newRay.P0().z()<< std::endl; std::cout << "direction : " << newRay.P1().x() << ", " << newRay.P1().y() << ", " << newRay.P1().z() << std::endl; std::cout << "///////////////////// Triangle //////////////////////////////////" << std::endl; Point pointC(6,8,5); Point V2(0,-1,-10); Point V0(5,-50,59); Point V1(9,0,-25); Triangle newTriangle(V0,V1,V2); std::cout << "coordonnee : " << newTriangle.V0().x() << ", " << newTriangle.V1().y() << ", "<< newTriangle.V2().z() << std::endl; std::cout << "///////////////////// Point/Triangle //////////////////////////////////" << std::endl; Point I; std::cout << newRay.P0().x() + 6 * newVector.x() << std::endl; std::cout << newRay.P0().y() + 6 * newVector.y() << std::endl; std::cout << newRay.P0().z() + 6 * newVector.z() << std::endl; I.setCoordonne(newRay.P0().x() + 6 * newVector.x(), newRay.P0().y() + 6 * newVector.y(), newRay.P0().z() + 6 * newVector.z()); std::cout << "coucou" << std::endl; std::cout << "///////////////////// test intersect //////////////////////////////////" << std::endl; int test; test = intersect3D_RayTriangle(newRay, newTriangle, I); std::cout << "I : " << I.x() << ", " << I.y() <<", "<< I.z() << "\n test : " << test << std::endl; std::cout << "///////////////////// VECTOR/Triangle //////////////////////////////////" << std::endl; Vector newVector2(newTriangle.V0(), newTriangle.V1()); std::cout << "x : " << newVector2.x() << std::endl; std::cout << "y : " << newVector2.y() << std::endl; std::cout << "z : " << newVector2.z() << std::endl; return 0; }
ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) { ALuint SamplesToDo; ALeffectslot **slot, **slot_end; ALvoice *voice, *voice_end; ALCcontext *ctx; FPUCtl oldMode; ALuint i, c; SetMixerFPUMode(&oldMode); while(size > 0) { ALfloat (*OutBuffer)[BUFFERSIZE]; ALuint OutChannels; IncrementRef(&device->MixCount); OutBuffer = device->DryBuffer; OutChannels = device->NumChannels; SamplesToDo = minu(size, BUFFERSIZE); for(c = 0;c < OutChannels;c++) memset(OutBuffer[c], 0, SamplesToDo*sizeof(ALfloat)); if(device->Hrtf) { /* Set OutBuffer/OutChannels to correspond to the actual output * with HRTF. Make sure to clear them too. */ OutBuffer += OutChannels; OutChannels = 2; for(c = 0;c < OutChannels;c++) memset(OutBuffer[c], 0, SamplesToDo*sizeof(ALfloat)); } V0(device->Backend,lock)(); V(device->Synth,process)(SamplesToDo, OutBuffer, OutChannels); ctx = ATOMIC_LOAD(&device->ContextList); while(ctx) { ALenum DeferUpdates = ctx->DeferUpdates; ALenum UpdateSources = AL_FALSE; if(!DeferUpdates) UpdateSources = ATOMIC_EXCHANGE(ALenum, &ctx->UpdateSources, AL_FALSE); if(UpdateSources) CalcListenerParams(ctx->Listener); /* source processing */ voice = ctx->Voices; voice_end = voice + ctx->VoiceCount; while(voice != voice_end) { ALsource *source = voice->Source; if(!source) goto next; if(source->state != AL_PLAYING && source->state != AL_PAUSED) { voice->Source = NULL; goto next; } if(!DeferUpdates && (ATOMIC_EXCHANGE(ALenum, &source->NeedsUpdate, AL_FALSE) || UpdateSources)) voice->Update(voice, source, ctx); if(source->state != AL_PAUSED) MixSource(voice, source, device, SamplesToDo); next: voice++; } /* effect slot processing */ slot = VECTOR_ITER_BEGIN(ctx->ActiveAuxSlots); slot_end = VECTOR_ITER_END(ctx->ActiveAuxSlots); while(slot != slot_end) { if(!DeferUpdates && ATOMIC_EXCHANGE(ALenum, &(*slot)->NeedsUpdate, AL_FALSE)) V((*slot)->EffectState,update)(device, *slot); V((*slot)->EffectState,process)(SamplesToDo, (*slot)->WetBuffer[0], device->DryBuffer, device->NumChannels); for(i = 0;i < SamplesToDo;i++) (*slot)->WetBuffer[0][i] = 0.0f; slot++; } ctx = ctx->next; } slot = &device->DefaultSlot; if(*slot != NULL) { if(ATOMIC_EXCHANGE(ALenum, &(*slot)->NeedsUpdate, AL_FALSE)) V((*slot)->EffectState,update)(device, *slot); V((*slot)->EffectState,process)(SamplesToDo, (*slot)->WetBuffer[0], device->DryBuffer, device->NumChannels); for(i = 0;i < SamplesToDo;i++) (*slot)->WetBuffer[0][i] = 0.0f; } /* Increment the clock time. Every second's worth of samples is * converted and added to clock base so that large sample counts don't * overflow during conversion. This also guarantees an exact, stable * conversion. */ device->SamplesDone += SamplesToDo; device->ClockBase += (device->SamplesDone/device->Frequency) * DEVICE_CLOCK_RES; device->SamplesDone %= device->Frequency; V0(device->Backend,unlock)(); if(device->Hrtf) { HrtfMixerFunc HrtfMix = SelectHrtfMixer(); ALuint irsize = GetHrtfIrSize(device->Hrtf); for(c = 0;c < device->NumChannels;c++) HrtfMix(OutBuffer, device->DryBuffer[c], 0, device->Hrtf_Offset, 0, irsize, &device->Hrtf_Params[c], &device->Hrtf_State[c], SamplesToDo ); device->Hrtf_Offset += SamplesToDo; } else if(device->Bs2b) { /* Apply binaural/crossfeed filter */ for(i = 0;i < SamplesToDo;i++) { float samples[2]; samples[0] = device->DryBuffer[0][i]; samples[1] = device->DryBuffer[1][i]; bs2b_cross_feed(device->Bs2b, samples); device->DryBuffer[0][i] = samples[0]; device->DryBuffer[1][i] = samples[1]; } } if(buffer) { #define WRITE(T, a, b, c, d) do { \ Write_##T((a), (b), (c), (d)); \ buffer = (T*)buffer + (c)*(d); \ } while(0) switch(device->FmtType) { case DevFmtByte: WRITE(ALbyte, OutBuffer, buffer, SamplesToDo, OutChannels); break; case DevFmtUByte: WRITE(ALubyte, OutBuffer, buffer, SamplesToDo, OutChannels); break; case DevFmtShort: WRITE(ALshort, OutBuffer, buffer, SamplesToDo, OutChannels); break; case DevFmtUShort: WRITE(ALushort, OutBuffer, buffer, SamplesToDo, OutChannels); break; case DevFmtInt: WRITE(ALint, OutBuffer, buffer, SamplesToDo, OutChannels); break; case DevFmtUInt: WRITE(ALuint, OutBuffer, buffer, SamplesToDo, OutChannels); break; case DevFmtFloat: WRITE(ALfloat, OutBuffer, buffer, SamplesToDo, OutChannels); break; } #undef WRITE } size -= SamplesToDo; IncrementRef(&device->MixCount); } RestoreFPUMode(&oldMode); }
void frameSolver2d::solve() { #if defined(HAVE_PETSC) linearSystemPETSc<double> *lsys = new linearSystemPETSc<double>; #elif defined(HAVE_GMM) linearSystemCSRGmm<double> *lsys = new linearSystemCSRGmm<double>; lsys->setGmres(1); lsys->setNoisy(1); #else linearSystemFull<double> *lsys = new linearSystemFull<double>; #endif if(pAssembler) delete pAssembler; pAssembler = new dofManager<double>(lsys); // fix dofs and create free ones createDofs(); // force vector std::vector<std::pair<GVertex *, std::vector<double> > >::iterator it = _nodalForces.begin(); for(; it != _nodalForces.end(); ++it) { MVertex *v = it->first->mesh_vertices[0]; const std::vector<double> &F = it->second; Dof DOFX(v->getNum(), 0); Dof DOFY(v->getNum(), 1); pAssembler->assemble(DOFX, F[0]); pAssembler->assemble(DOFY, F[1]); } // stifness matrix for(std::size_t i = 0; i < _beams.size(); i++) { fullMatrix<double> K(6, 6); computeStiffnessMatrix(i, K); _beams[i]._stiffness = K; MVertex *v0 = _beams[i]._element->getVertex(0); MVertex *v1 = _beams[i]._element->getVertex(1); Dof theta0(v0->getNum(), Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[0])); Dof theta1(v1->getNum(), Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[1])); Dof U0(v0->getNum(), 0); Dof U1(v1->getNum(), 0); Dof V0(v0->getNum(), 1); Dof V1(v1->getNum(), 1); Dof DOFS[6] = {U0, V0, theta0, U1, V1, theta1}; for(int j = 0; j < 6; j++) { for(int k = 0; k < 6; k++) { pAssembler->assemble(DOFS[j], DOFS[k], K(j, k)); } } } lsys->systemSolve(); // save the solution for(std::size_t i = 0; i < _beams.size(); i++) { MVertex *v0 = _beams[i]._element->getVertex(0); MVertex *v1 = _beams[i]._element->getVertex(1); Dof theta0(v0->getNum(), Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[0])); Dof theta1(v1->getNum(), Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[1])); Dof U0(v0->getNum(), 0); Dof U1(v1->getNum(), 0); Dof V0(v0->getNum(), 1); Dof V1(v1->getNum(), 1); Dof DOFS[6] = {U0, V0, theta0, U1, V1, theta1}; for(int j = 0; j < 6; j++) { pAssembler->getDofValue(DOFS[j], _beams[i]._displacement[j]); } } delete lsys; delete pAssembler; }
void Foam::MULES::limiter ( scalargpuField& allLambda, const RdeltaTType& rDeltaT, const RhoType& rho, const volScalarField& psi, const surfaceScalarField& phiBD, const surfaceScalarField& phiCorr, const SpType& Sp, const SuType& Su, const scalar psiMax, const scalar psiMin, const label nLimiterIter ) { const scalargpuField& psiIf = psi.getField(); const volScalarField::GeometricBoundaryField& psiBf = psi.boundaryField(); const scalargpuField& psi0 = psi.oldTime(); const fvMesh& mesh = psi.mesh(); const labelgpuList& owner = mesh.owner(); const labelgpuList& neighb = mesh.neighbour(); const labelgpuList& losort = mesh.lduAddr().losortAddr(); const labelgpuList& ownStart = mesh.lduAddr().ownerStartAddr(); const labelgpuList& losortStart = mesh.lduAddr().losortStartAddr(); tmp<volScalarField::DimensionedInternalField> tVsc = mesh.Vsc(); const scalargpuField& V = tVsc().getField(); const scalargpuField& phiBDIf = phiBD; const surfaceScalarField::GeometricBoundaryField& phiBDBf = phiBD.boundaryField(); const scalargpuField& phiCorrIf = phiCorr; const surfaceScalarField::GeometricBoundaryField& phiCorrBf = phiCorr.boundaryField(); slicedSurfaceScalarField lambda ( IOobject ( "lambda", mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE, false ), mesh, dimless, allLambda, false // Use slices for the couples ); scalargpuField& lambdaIf = lambda; surfaceScalarField::GeometricBoundaryField& lambdaBf = lambda.boundaryField(); scalargpuField psiMaxn(psiIf.size(), psiMin); scalargpuField psiMinn(psiIf.size(), psiMax); scalargpuField sumPhiBD(psiIf.size(), 0.0); scalargpuField sumPhip(psiIf.size(), VSMALL); scalargpuField mSumPhim(psiIf.size(), VSMALL); thrust::for_each ( thrust::make_counting_iterator(0), thrust::make_counting_iterator(0)+psiIf.size(), limiterMULESFunctor ( owner.data(), neighb.data(), ownStart.data(), losortStart.data(), losort.data(), psiIf.data(), phiBDIf.data(), phiCorrIf.data(), psiMaxn.data(), psiMinn.data(), sumPhiBD.data(), sumPhip.data(), mSumPhim.data() ) ); forAll(phiCorrBf, patchi) { const fvPatchScalarField& psiPf = psiBf[patchi]; const scalargpuField& phiBDPf = phiBDBf[patchi]; const scalargpuField& phiCorrPf = phiCorrBf[patchi]; const labelgpuList& pcells = mesh.lduAddr().patchSortCells(patchi); const labelgpuList& losort = mesh.lduAddr().patchSortAddr(patchi); const labelgpuList& losortStart = mesh.lduAddr().patchSortStartAddr(patchi); thrust::for_each ( thrust::make_counting_iterator(0), thrust::make_counting_iterator(0)+pcells.size(), patchMinMaxMULESFunctor ( losortStart.data(), losort.data(), pcells.data(), psiPf.coupled()?psiPf.patchNeighbourField()().data():psiPf.data(), phiBDPf.data(), phiCorrPf.data(), psiMaxn.data(), psiMinn.data(), sumPhiBD.data(), sumPhip.data(), mSumPhim.data() ) ); } psiMaxn = min(psiMaxn, psiMax); psiMinn = max(psiMinn, psiMin); //scalar smooth = 0.5; //psiMaxn = min((1.0 - smooth)*psiIf + smooth*psiMaxn, psiMax); //psiMinn = max((1.0 - smooth)*psiIf + smooth*psiMinn, psiMin); if (mesh.moving()) { tmp<volScalarField::DimensionedInternalField> V0 = mesh.Vsc0(); psiMaxn = V *( (rho.getField()*rDeltaT - Sp.getField())*psiMaxn - Su.getField() ) - (V0().getField()*rDeltaT)*rho.oldTime().getField()*psi0 + sumPhiBD; psiMinn = V *( Su.getField() - (rho.getField()*rDeltaT - Sp.getField())*psiMinn ) + (V0().getField()*rDeltaT)*rho.oldTime().getField()*psi0 - sumPhiBD; } else { psiMaxn = V *( (rho.getField()*rDeltaT - Sp.getField())*psiMaxn - Su.getField() - (rho.oldTime().getField()*rDeltaT)*psi0 ) + sumPhiBD; psiMinn = V *( Su.getField() - (rho.getField()*rDeltaT - Sp.getField())*psiMinn + (rho.oldTime().getField()*rDeltaT)*psi0 ) - sumPhiBD; } scalargpuField sumlPhip(psiIf.size()); scalargpuField mSumlPhim(psiIf.size()); for (int j=0; j<nLimiterIter; j++) { sumlPhip = 0.0; mSumlPhim = 0.0; thrust::for_each ( thrust::make_counting_iterator(0), thrust::make_counting_iterator(0)+sumlPhip.size(), sumlPhiMULESFunctor ( owner.data(), neighb.data(), ownStart.data(), losortStart.data(), losort.data(), lambdaIf.data(), phiCorrIf.data(), sumlPhip.data(), mSumlPhim.data() ) ); forAll(lambdaBf, patchi) { scalargpuField& lambdaPf = lambdaBf[patchi]; const scalargpuField& phiCorrfPf = phiCorrBf[patchi]; const labelgpuList& pcells = mesh.lduAddr().patchSortCells(patchi); const labelgpuList& losort = mesh.lduAddr().patchSortAddr(patchi); const labelgpuList& losortStart = mesh.lduAddr().patchSortStartAddr(patchi); thrust::for_each ( thrust::make_counting_iterator(0), thrust::make_counting_iterator(0)+pcells.size(), patchSumlPhiMULESFunctor ( losortStart.data(), losort.data(), pcells.data(), lambdaPf.data(), phiCorrfPf.data(), sumlPhip.data(), mSumlPhim.data() ) ); } thrust::transform ( sumlPhip.begin(), sumlPhip.end(), thrust::make_zip_iterator(thrust::make_tuple ( psiMaxn.begin(), mSumPhim.begin() )), sumlPhip.begin(), sumlPhipFinalMULESFunctor<false>() ); thrust::transform ( mSumlPhim.begin(), mSumlPhim.end(), thrust::make_zip_iterator(thrust::make_tuple ( psiMinn.begin(), sumPhip.begin() )), mSumlPhim.begin(), sumlPhipFinalMULESFunctor<true>() ); const scalargpuField& lambdam = sumlPhip; const scalargpuField& lambdap = mSumlPhim; thrust::transform ( phiCorrIf.begin(), phiCorrIf.end(), thrust::make_zip_iterator(thrust::make_tuple ( lambdaIf.begin(), thrust::make_permutation_iterator ( lambdap.begin(), owner.begin() ), thrust::make_permutation_iterator ( lambdam.begin(), neighb.begin() ), thrust::make_permutation_iterator ( lambdam.begin(), owner.begin() ), thrust::make_permutation_iterator ( lambdap.begin(), neighb.begin() ) )), lambdaIf.begin(), lambdaIfMULESFunctor() ); forAll(lambdaBf, patchi) { fvsPatchScalarField& lambdaPf = lambdaBf[patchi]; const scalargpuField& phiCorrfPf = phiCorrBf[patchi]; const fvPatchScalarField& psiPf = psiBf[patchi]; if (isA<wedgeFvPatch>(mesh.boundary()[patchi])) { lambdaPf = 0; } else if (psiPf.coupled()) { const labelgpuList& pFaceCells = mesh.boundary()[patchi].faceCells(); thrust::transform ( phiCorrfPf.begin(), phiCorrfPf.end(), thrust::make_zip_iterator(thrust::make_tuple ( lambdaPf.begin(), thrust::make_permutation_iterator ( lambdap.begin(), pFaceCells.begin() ), thrust::make_permutation_iterator ( lambdam.begin(), pFaceCells.begin() ) )), lambdaPf.begin(), coupledPatchLambdaPfMULESFunctor() ); } else { const labelgpuList& pFaceCells = mesh.boundary()[patchi].faceCells(); const scalargpuField& phiBDPf = phiBDBf[patchi]; const scalargpuField& phiCorrPf = phiCorrBf[patchi]; thrust::transform ( phiCorrfPf.begin(), phiCorrfPf.end(), thrust::make_zip_iterator(thrust::make_tuple ( lambdaPf.begin(), phiBDPf.begin(), phiCorrPf.begin(), thrust::make_permutation_iterator ( lambdap.begin(), pFaceCells.begin() ), thrust::make_permutation_iterator ( lambdam.begin(), pFaceCells.begin() ) )), lambdaPf.begin(), patchLambdaPfMULESFunctor() ); } }