/** * @brief TIM3 IC2 ISR * @param : None * @retval : None */ bool _PUMP::Align(void) { _FIT *t,*p,*c; int _fpl=fpl, _fph=fph; if(tacho && pressure && current) { t=tacho; p=pressure; c=current; tacho=pressure=current=NULL; } else { t = new _FIT(4,FIT_POW); p = new _FIT(4,FIT_POW); c = new _FIT(4,FIT_POW); } printf("\rpump "); for(int i=_fpl; i<_fph; i+=5) { fpl=fph=i; _wait(1000,_thread_loop); t->Sample(i,Tau()); p->Sample(i,(double)adf.cooler); c->Sample(i,(double)adf.Ipump); printf("."); } for(int i=_fph; i>_fpl; i-=5) { fpl=fph=i; _wait(1000,_thread_loop); t->Sample(i,Tau()); p->Sample(i,(double)adf.cooler); c->Sample(i,(double)adf.Ipump); printf("\b \b"); } fpl=_fpl; fph=_fph; if(!t->Compute()) return false; else if(!p->Compute()) return false; else if(!c->Compute()) return false; else tacho=t; pressure=p; current=c; return true; }
BOOL CBulkDlg::OnInitDialog() { if (m_Type==N_TYPE) m_TypeStr = "n-type"; else m_TypeStr = "p-type"; double Tref = 300; double Vt = VT300; double taun = CPhysics::tau(1e-6*m_TauN,m_BkgndDoping,m_Nref,m_Nalpha,Tref,m_Talpha); double taup = CPhysics::tau(1e-6*m_TauP,m_BkgndDoping,m_Nref,m_Nalpha,Tref,m_Talpha); m_LLItau = (1e6 * CMath::round(Tau(taun,taup,Tref),4)); // s to us m_DiffLength = // cm to um (1e4 * CMath::round(sqrt(Mobility(m_BkgndDoping,Tref)*Vt*Tau(taun,taup,Tref)),4)); m_NeedUpdate = FALSE; CDialog::OnInitDialog(); return TRUE; }
void CBulkDlg::OnKillfocus() { UpdateData(TRUE); if (!m_NeedUpdate) return; double Tref = 300; double Vt = VT300; double taun = CPhysics::tau(1e-6*m_TauN,m_BkgndDoping,m_Nref,m_Nalpha,Tref,m_Talpha); double taup = CPhysics::tau(1e-6*m_TauP,m_BkgndDoping,m_Nref,m_Nalpha,Tref,m_Talpha); m_LLItau = (1e6 * CMath::round(Tau(taun,taup,Tref),4)); // s to us m_DiffLength = // cm to um (1e4 * CMath::round(sqrt(Mobility(m_BkgndDoping,Tref)*Vt*Tau(taun,taup,Tref)),4)); m_NeedUpdate = FALSE; UpdateData(FALSE); }
double CBulkDlg::MatchLLItau(double logtau) { double Tref = 300; double taun = CPhysics::tau(CMath::exp(logtau),m_BkgndDoping,m_Nref,m_Nalpha,Tref,m_Talpha); double taup = taun; return log(Tau(taun,taup,Tref)) - log(1e-6*m_LLItau); }
int _PUMP::Poll(void) { int e=0; if(timeout==INT_MAX) DAC_SetChannel1Data(DAC_Align_12b_R,0); else { DAC_SetChannel1Data(DAC_Align_12b_R,__ramp(Th2o(),ftl*100,fth*100,fpl*0xfff/100,fph*0xfff/100)); if(tacho && pressure && current && __time__ > timeout) { if(abs(tacho->Eval(Rpm()) - Tau()) > Tau()/10) _SET_BIT(e,pumpTacho); if(abs(pressure->Eval(Rpm()) - adf.cooler) > adf.cooler/10) _SET_BIT(e,pumpPressure); if(abs(current->Eval(Rpm()) - adf.Ipump) > adf.Ipump/10) _SET_BIT(e,pumpCurrent); } if(__time__ % (5*(Tau()/100)) == 0) _BLUE2(20); } return e; }
/** * @brief TIM3 IC2 ISR * @param : None * @retval : None */ bool _PUMP::Test(void) { int _fpl=fpl, _fph=fph; _FIT *t,*p,*c; if(!tacho || !pressure || !current) return false; t=tacho; p=pressure; c=current; tacho=pressure=current=NULL; do { for(int i=_fpl; i<_fph; i+=5) { fpl=fph=i; _wait(1000,_thread_loop); printf("\r\n%4.3lf,%4.3lf,%4.3lf,%4.3lf,%4.3lf,%4.3lf", t->Eval(Rpm()),(double)Tau(), p->Eval(Rpm()),(double)(adf.cooler), c->Eval(Rpm()),(double)(adf.Ipump)); } for(int i=_fph; i>_fpl; i-=5) { fpl=fph=i; fpl=fph=i; _wait(1000,_thread_loop); printf("\r\n%4.3lf,%4.3lf,%4.3lf,%4.3lf,%4.3lf,%4.3lf", t->Eval(Rpm()),(double)Tau(), p->Eval(Rpm()),(double)(adf.cooler), c->Eval(Rpm()),(double)(adf.Ipump)); } } while(getchar() == EOF); printf("\r\n:"); fpl=_fpl; fph=_fph; tacho=t; pressure=p; current=c; return true; }
CReal CTimeWiener::ModLinRegr(CComplexVector& veccCorrEst) { /* Modified linear regression to estimate the "sigma" of the Gaussian correlation function */ /* Get vector length */ int iVecLen = Size(veccCorrEst); /* Init vectors and variables */ CReal rSigmaRet; CRealVector Tau(iVecLen); CRealVector Z(iVecLen); CRealVector W(iVecLen); CRealVector Wmrem(iVecLen); CReal Wm, Zm; CReal A1; /* Generate the tau vector */ for (int i = 0; i < iVecLen; i++) Tau[i] = (CReal) (i * iScatPilTimeInt); /* Linearize acf equation: y = a * exp(-b * x^2) z = ln(y); w = x^2 -> z = a0 + a1 * w */ Z = Log(Abs(veccCorrEst)); W = Tau * Tau; Wm = Mean(W); Zm = Mean(Z); Wmrem = W - Wm; /* Remove mean of W */ A1 = Sum(Wmrem * (Z - Zm)) / Sum(Wmrem * Wmrem); /* Final sigma calculation from estimation and assumed Gaussian model */ rSigmaRet = (CReal) 0.5 / crPi * sqrt((CReal) -2.0 * A1) / Ts; /* Bound estimated sigma value */ if (rSigmaRet > rSigmaMax) rSigmaRet = rSigmaMax; if (rSigmaRet < LOW_BOUND_SIGMA) rSigmaRet = LOW_BOUND_SIGMA; return rSigmaRet; }
bool RGBVolume::Scatter(const Sample &sample, bool scatteredStart, const Ray &ray, float u, Intersection *isect, float *pdf, float *pdfBack, SWCSpectrum *L) const { // Determine scattering distance const float k = sigS.Filter(); const float d = logf(1 - u) / k; //the real distance is ray.mint-d bool scatter = d > ray.mint - ray.maxt; if (scatter) { // The ray is scattered ray.maxt = ray.mint - d; isect->dg.p = ray(ray.maxt); isect->dg.nn = Normal(-ray.d); isect->dg.scattered = true; CoordinateSystem(Vector(isect->dg.nn), &(isect->dg.dpdu), &(isect->dg.dpdv)); isect->ObjectToWorld = Transform(); isect->primitive = &primitive; isect->material = &material; isect->interior = this; isect->exterior = this; isect->arealight = NULL; // Update if volumetric emission if (L) *L *= SigmaT(sample.swl, isect->dg); } if (pdf) { *pdf = expf((ray.mint - ray.maxt) * k); if (isect->dg.scattered) *pdf *= k; } if (pdfBack) { *pdfBack = expf((ray.mint - ray.maxt) * k); if (scatteredStart) *pdfBack *= k; } if (L) *L *= Exp(-Tau(sample.swl, ray)); return scatter; }
void print_data(bodyptr btab, int nbody, real tnow, string *fields, string ifmt, string rfmt) { bodyptr bp; for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { if (set_member(fields, TimeTag)) printf(rfmt, tnow); if (set_member(fields, MassTag)) printf(rfmt, Mass(bp)); if (set_member(fields, PosTag)) { printf(rfmt, Pos(bp)[0]); printf(rfmt, Pos(bp)[1]); printf(rfmt, Pos(bp)[2]); } if (set_member(fields, VelTag)) { printf(rfmt, Vel(bp)[0]); printf(rfmt, Vel(bp)[1]); printf(rfmt, Vel(bp)[2]); } if (set_member(fields, AccTag)) { printf(rfmt, Acc(bp)[0]); printf(rfmt, Acc(bp)[1]); printf(rfmt, Acc(bp)[2]); } if (set_member(fields, PhiTag)) printf(rfmt, Phi(bp)); if (set_member(fields, SmoothTag)) printf(rfmt, Smooth(bp)); if (set_member(fields, RhoTag)) printf(rfmt, Rho(bp)); if (set_member(fields, EntFuncTag)) printf(rfmt, EntFunc(bp)); if (set_member(fields, UinternTag)) printf(rfmt, Uintern(bp)); if (set_member(fields, UdotIntTag)) printf(rfmt, UdotInt(bp)); if (set_member(fields, UdotRadTag)) printf(rfmt, UdotRad(bp)); if (set_member(fields, UdotVisTag)) printf(rfmt, UdotVis(bp)); if (set_member(fields, TauTag)) printf(rfmt, Tau(bp)); if (set_member(fields, BirthTag)) printf(rfmt, Birth(bp)); if (set_member(fields, DeathTag)) printf(rfmt, Death(bp)); if (set_member(fields, TypeTag)) printf(ifmt, (int) Type(bp)); if (set_member(fields, KeyTag)) printf(ifmt, Key(bp)); if (set_member(fields, AuxTag)) printf(rfmt, Aux(bp)); if (set_member(fields, AuxVecTag)) { printf(rfmt, AuxVec(bp)[0]); printf(rfmt, AuxVec(bp)[1]); printf(rfmt, AuxVec(bp)[2]); } printf("\n"); } }
STTwoElectronOperator(const string& name, const TwoElectronOperator<U>& X, const ExcitationOperator<U,N>& T, bool isHbar=false) : TwoElectronOperator<U>(name, X) { assert(N >= 2 && N <= 4); tensor::SpinorbitalTensor<U> Tau(T(2)); Tau["abij"] += 0.5*T(1)["ai"]*T(1)["bj"]; this->ia["me"] = this->ijab["mnef"]*T(1)["fn"]; this->ij["mi"] += 0.5*this->ijab["nmef"]*T(2)["efni"]; this->ij["mi"] += this->ia["me"]*T(1)["ei"]; this->ij["mi"] += this->ijak["nmfi"]*T(1)["fn"]; this->ijkl["mnij"] += 0.5*this->ijab["mnef"]*Tau["efij"]; this->ijkl["mnij"] += this->ijak["nmei"]*T(1)["ej"]; this->ijak["mnej"] += this->ijab["mnef"]*T(1)["fj"]; if (!isHbar) { this->ai["ai"] -= T(1)["em"]*this->aibj["amei"]; this->ai["ai"] += 0.5*this->aibc["amef"]*Tau["efim"]; this->ai["ai"] -= 0.5*this->ijak["mnei"]*T(2)["eamn"]; this->ai["ai"] += T(2)["aeim"]*this->ia["me"]; this->ai["ai"] += T(1)["ei"]*this->ab["ae"]; this->ai["ai"] -= T(1)["am"]*this->ij["mi"]; } else { this->ai = 0; } this->ab["ae"] -= 0.5*this->ijab["mnfe"]*T(2)["famn"]; this->ab["ae"] -= this->ia["me"]*T(1)["am"]; this->ab["ae"] += this->aibc["anef"]*T(1)["fn"]; this->aijk["amij"] += 0.5*this->aibc["amef"]*Tau["efij"]; this->aijk["amij"] += this->aibj["amej"]*T(1)["ei"]; this->aibj["amei"] -= 0.5*this->ijab["mnef"]*T(2)["afin"]; this->aibj["amei"] -= this->aibc["amfe"]*T(1)["fi"]; this->aibj["amei"] -= this->ijak["nmei"]*T(1)["an"]; if (!isHbar) { this->abij["abij"] += this->ab["af"]*T(2)["fbij"]; this->abij["abij"] -= this->ij["ni"]*T(2)["abnj"]; this->abij["abij"] += this->abci["abej"]*T(1)["ei"]; this->abij["abij"] -= this->aijk["amij"]*T(1)["bm"]; this->abij["abij"] += 0.5*this->abcd["abef"]*Tau["efij"]; this->abij["abij"] += 0.5*this->ijkl["mnij"]*Tau["abmn"]; this->abij["abij"] -= this->aibj["amei"]*T(2)["ebmj"]; } else { this->abij = 0; } this->aijk["amij"] += this->ijak["nmej"]*T(2)["aein"]; this->aijk["amij"] -= this->ijkl["nmij"]*T(1)["an"]; this->aijk["amij"] += this->ia["me"]*T(2)["aeij"]; this->aibj["amei"] -= 0.5*this->ijab["mnef"]*T(2)["afin"]; this->aibj["amei"] += 0.5*this->ijak["nmei"]*T(1)["an"]; this->abci["abej"] += 0.5*this->ijak["mnej"]*T(2)["abmn"]; this->abci["abej"] -= this->aibj["amej"]*T(1)["bm"]; this->abci["abej"] += this->aibc["amef"]*T(2)["fbmj"]; this->abci["abej"] += this->abcd["abef"]*T(1)["fj"]; this->abci["abej"] -= this->ia["me"]*T(2)["abmj"]; this->aibj["amei"] -= 0.5*this->ijak["nmei"]*T(1)["an"]; this->abcd["abef"] += 0.5*this->ijab["mnef"]*Tau["abmn"]; this->abcd["abef"] -= this->aibc["amef"]*T(1)["bm"]; this->aibc["amef"] -= this->ijab["nmef"]*T(1)["an"]; if (N > 2) { if (!isHbar) { this->ai["ai"] += 0.25*this->ijab["mnef"]*T(3)["aefimn"]; this->abij["abij"] += this->ia["me"]*T(3)["abeijm"]; this->abij["abij"] -= 0.5*this->ijak["mnej"]*T(3)["aebimn"]; this->abij["abij"] += 0.5*this->aibc["amef"]*T(3)["efbimj"]; } this->abci["abej"] -= 0.5*this->ijab["mnef"]*T(3)["abfmjn"]; this->aijk["amij"] += 0.5*this->ijab["mnef"]*T(3)["aefijn"]; } if (N > 3 && !isHbar) { this->abij["abij"] += 0.25*this->ijab["mnef"]*T(4)["abefijmn"]; } }
void TPZArtDiff::PrepareFastestDiff(TPZFMatrix<REAL> &jacinv, TPZVec<STATE> &sol, TPZFMatrix<STATE> &dsol, TPZFMatrix<REAL> &phi, TPZFMatrix<REAL> &dphi, TPZVec<TPZVec<STATE> > & TauDiv, TPZVec<TPZDiffMatrix<STATE> > & dTauDiv) { #ifdef _TFAD typedef TFad<dim+2, REAL> TFADREALdim; #endif #ifdef _FAD typedef Fad<REAL> TFADREALdim; #endif #ifdef _TINYFAD typedef TinyFad<dim+2, REAL> TFADREALdim; #endif const int nstate = sol.NElements(); const int nshape = phi.Rows(); TPZVec<TFADREALdim > FADsol(nstate); TPZVec<TPZDiffMatrix<TFADREALdim> > FADAi(dim); TPZVec<TPZDiffMatrix<REAL> > Ai(dim); TPZVec<TPZDiffMatrix<TFADREALdim> > FADTau(dim); TPZVec<TPZDiffMatrix<STATE> > Tau(dim); TPZVec<TPZVec<TFADREALdim> > FADTauDiv(dim); TFADREALdim temp; int i, j, k, l; for(i = 0; i < nstate; i++) { FADsol[i] = sol[i]; FADsol[i].diff(i, nstate); } TPZEulerConsLaw::JacobFlux(fGamma, dim, FADsol, FADAi); ComputeTau(dim, jacinv, FADsol, FADAi, FADTau); for( k = 0; k < dim; k++) { Tau[k].Redim(nstate, nstate); Ai [k].Redim(nstate, nstate); for(i = 0; i < nstate; i++) for( j = 0; j < nstate; j++) { Tau[k](i,j) = FADTau[k](i,j).val(); Ai [k](i,j) = FADAi [k](i,j).val(); } } TPZVec<STATE> Div; TPZDiffMatrix<STATE> dDiv; //Computing the divergent with derivatives Divergent(dsol, phi, dphi, FADAi, Div, &dDiv); TauDiv. Resize(dim); dTauDiv.Resize(dim); //Computing Tau * Div and DTau * Div for(k=0;k<dim;k++) { TauDiv [k].Resize(nstate); dTauDiv[k].Redim(nstate, nstate); //FADTau[k].Multiply(Div, FADTauDiv[k]); FADTauDiv[k].Resize(nstate); for(i = 0; i < nstate; i++) { temp = 0.; for(j = 0; j < nstate; j++) temp += FADTau[k](i,j) * ((REAL)Div[j]); FADTauDiv[k][i] = temp; }// // copying data using REAL dTauDiv[k].Redim(nstate, nstate * nshape); for(i = 0; i < nstate; i++) { TauDiv[k][i] = FADTauDiv[k][i].val(); for(j = 0; j < nstate; j++) { for(l = 0; l < nshape; l++) dTauDiv[k](i,l * nstate + j) = FADTauDiv[k][i].dx/*fastAccessDx*/(j) * phi(l,0); } } } TPZDiffMatrix<STATE> TaudDiv_k; // temporary storage for(k = 0; k < dim; k++) { Tau[k].Multiply(dDiv, TaudDiv_k); dTauDiv[k].Add(TaudDiv_k, 1.); } //Computing DTauDiv = DTau * Div + Tau * DDiv }