void NSContravarientMetricTensor<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { /** The allocated size of the Field Containers must currently * match the full workset size of the allocated PHX Fields, * this is the size that is used in the computation. There is * wasted effort computing on zeroes for the padding on the * final workset. Ideally, these are size numCells. //int containerSize = workset.numCells; */ Intrepid2::CellTools<MeshScalarT>::setJacobian(jacobian, refPoints, coordVec, *cellType); Intrepid2::CellTools<MeshScalarT>::setJacobianInv(jacobian_inv, jacobian); for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { for (std::size_t i=0; i < numDims; ++i) { for (std::size_t j=0; j < numDims; ++j) { Gc(cell,qp,i,j) = 0.0; for (std::size_t alpha=0; alpha < numDims; ++alpha) { Gc(cell,qp,i,j) += jacobian_inv(cell,qp,alpha,i)*jacobian_inv(cell,qp,alpha,j); } } } } } }
bool test(accelerator_view &rv) { const int size = 100; vector<int> A(size); vector<c2> Gc(size); for(int i = 0; i < size; i++) { A[i] = INIT_VALUE; Gc[i].i = 1; Gc[i].d = 1; Gc[i].ul = 1; Gc[i].f = 1; } extent<1> e(size); array<int, 1> aA(e, A.begin(), rv); array<c2, 1> aGc(e, Gc.begin(), rv); parallel_for_each(aA.get_extent(), [&](index<1>idx) __GPU { int *pi = NULL; void *pv1 = pi; if (pv1 != NULL) aA[idx] = 1; c1 *p = &aGc[idx]; if (!Equal(p->i, (int)1) || !Equal(p->d, (double)1) || !Equal(p->f, (float)1) || !Equal(p->ul, (unsigned long)1)) aA[idx] = 1; });
static num pw91c(const densvars<num> &d) { const parameter pa = 1.0; const parameter Aa = 0.016887; // ok const parameter a1a = 0.11125; // ok const parameter b1a = 10.357; // ok const parameter b2a = 3.6231; // ok const parameter b3a = 0.88026; // ok const parameter b4a = 0.49671; // ok const parameter pe = 1; const parameter c0p = 0.031091; // ok const parameter a1p = 0.21370; // ok const parameter b1p = 7.5957; // ok const parameter b2p = 3.5876; // ok const parameter b3p = 1.6382; // ok const parameter b4p = 0.49294; // ok const parameter c0f = 0.015545; // ok const parameter a1f = 0.20548; // ok const parameter b1f = 14.1189; // ok const parameter b2f = 6.1977; // ok const parameter b3f = 3.3662; // ok const parameter b4f = 0.62517; // ok const parameter d2fz0 = 1.709921; // ok num fz = (uf(d,4.0/3.0)-2)/(2*pow(2,1.0/3.0)-2); num Ac = Gc(d.r_s, Aa, a1a, b1a, b2a, b3a, b4a, pa); num EcP = Gc(d.r_s, c0p, a1p, b1p, b2p, b3p, b4p, pe); num EcF = Gc(d.r_s, c0f, a1f, b1f, b2f, b3f, b4f, pe); num Ec = EcP - Ac*fz*(1-pow(d.zeta,4))/d2fz0 + (EcF - EcP)*fz*pow(d.zeta,4); num kF = cbrt(3*M_PI*M_PI*d.n); num ks = sqrt(4)*sqrt(kF/M_PI); num gs = 0.5*uf(d,2.0/3.0); num T2 = 0.25*d.gnn/pow(gs*ks*d.n,2); const parameter alpha = 0.09; const parameter Cc0 = 0.004235; const parameter Cx = -0.001667; const parameter nu = 16*cbrt(3*M_PI*M_PI)/M_PI; const parameter beta = nu*Cc0; num A = 2*alpha/beta/expm1(-2*(alpha*Ec)/(pow(gs,3)*beta*beta)); num Cc = 1.0/1000*((2.568 + d.r_s*(23.266 + 0.007389*d.r_s))/ (1 + d.r_s*(8.723 + d.r_s*(0.472 + d.r_s*0.073890)))) - Cx; num H0 = 0.5*pow(gs,3)*beta*beta/alpha*log((1 + 2*(alpha*(T2+A*T2*T2))/(beta*(1 + A*T2*(1 + A*T2))))); num H1 = nu*(Cc - Cc0 - 3.0/7.0*Cx)*pow(gs,3)*T2*exp(-100*pow(gs,4)*pow(ks,2)*T2/pow(kF,2)); return d.n*(Ec + H0 + H1); }
void NSTauT<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { for (std::size_t cell=0; cell < workset.numCells; ++cell) { for (std::size_t qp=0; qp < numQPs; ++qp) { TauT(cell,qp) = 0.0; normGc(cell,qp) = 0.0; for (std::size_t i=0; i < numDims; ++i) { for (std::size_t j=0; j < numDims; ++j) { TauT(cell,qp) += rho(cell,qp) * Cp(cell,qp) * rho(cell,qp) * Cp(cell,qp)* V(cell,qp,i)*Gc(cell,qp,i,j)*V(cell,qp,j); normGc(cell,qp) += Gc(cell,qp,i,j)*Gc(cell,qp,i,j); } } TauT(cell,qp) += 12.*ThermalCond(cell,qp)*ThermalCond(cell,qp)*std::sqrt(normGc(cell,qp)); TauT(cell,qp) = 1./std::sqrt(TauT(cell,qp)); } } }
void CCustomStep::InitialiseL() { CAnimationTestStep::InitialiseL(); ANIM_INFO1(_L("Begin test SYNCH")); TInt winborder = 2; iWinSize = Screen()->SizeInPixels(); iWinSize.iWidth /= 2; iWinPosition = TPoint(iWinSize.iWidth + winborder, winborder); iWinSize.iWidth -= winborder * 2; iWinSize.iHeight -= winborder * 2; iWinRect = TRect(iWinPosition, iWinSize); iWin = new (ELeave) CCustomStepAnimationWindow(Ws(), *GroupWin(), *Gc()); iWin->Window()->SetRequiredDisplayMode(EColor256); iWin->Window()->SetExtent(iWinPosition, iWinSize); iWin->Window()->SetBackgroundColor(iBackgroundColor1); iWin->Window()->SetVisible(ETrue); iWin->Window()->Activate(); }
bool test_vertex_on_face_iterator(G const& g, ::std::ostream & out, GT) { typedef grid_types<G> gt; typedef typename gt::FaceIterator FaceIterator; typedef typename gt::VertexOnFaceIterator VertexOnFaceIterator; for(FaceIterator c(g); ! c.IsDone(); ++c) { int v_cnt = 0; for(VertexOnFaceIterator vc(*c); ! vc.IsDone(); ++vc, ++v_cnt) { ; } REQUIRE_ALWAYS(v_cnt == (int)(*c).NumOfVertices(), "v_cnt = " << v_cnt << " != c.NumOfVertices() = " << (*c).NumOfVertices() << '\n',1); VertexOnFaceIterator v; v = (*c).FirstVertex(); VertexOnFaceIterator w = v; for( ; !v.IsDone(); ++v, ++w) { ref_ptr<G const> Gv(v.TheGrid()); ref_ptr<G const> Gc(c.TheGrid()); REQUIRE_ALWAYS( &(*Gv) == &(*Gc), "",1); // REQUIRE_ALWAYS( &(v.TheGrid()) == &(c.TheGrid()), "",1); REQUIRE_ALWAYS( ( v == w), "Iterators differ!\n",1); REQUIRE_ALWAYS( (*v == *w), "Iterator values differ!\n",1); } REQUIRE_ALWAYS( (w.IsDone()), "", 1); REQUIRE_ALWAYS( (v == w), "Past-the-end iterators differ!\n", 1); if((*c).NumOfVertices() > 0) { v = (*c).FirstVertex(); w = v; ++v; for( ; !v.IsDone(); ++v, ++w) REQUIRE_ALWAYS( (*v != *w), "Iterators point to same vertex!\n",1); } } return true; }
__DEBUG_OUT } void QBlitterWidget::startDSA() { __DEBUG_IN if(!iDSA) { iDSBitmap = CDirectScreenBitmap::NewL(); iDSA = CDirectScreenAccess::NewL(CEikonEnv::Static()->WsSession(), *CEikonEnv::Static()->ScreenDevice(), *winId()->DrawableWindow(), *this); CEikonEnv::Static()->WsSession().Flush(); iDSA->StartL(); CFbsBitGc *gc = iDSA->Gc(); //gc->SetOrientation(CFbsBitGc::EGraphicsOrientationRotated90); RRegion *region = iDSA->DrawingRegion(); gc->SetClippingRegion(region); createScreenBuffer(); } __DEBUG_OUT } void QBlitterWidget::setScreenMode( int mode, bool keepaspectratio ) { screenmode = mode; keepratio = keepaspectratio; }
void omxComputeNumericDeriv::computeImpl(FitContext *fc) { if (fc->fitUnits == FIT_UNITS_SQUARED_RESIDUAL || fc->fitUnits == FIT_UNITS_SQUARED_RESIDUAL_CHISQ) { // refactor TODO numParams = 0; if (verbose >= 1) mxLog("%s: derivatives %s units are meaningless", name, fitUnitsToName(fc->fitUnits)); return; //Possible TODO: calculate Hessian anyway? } int newWanted = fc->wanted | FF_COMPUTE_GRADIENT; if (wantHessian) newWanted |= FF_COMPUTE_HESSIAN; int nf = fc->calcNumFree(); if (numParams != 0 && numParams != nf) { mxThrow("%s: number of parameters changed from %d to %d", name, numParams, nf); } numParams = nf; if (numParams <= 0) { complainNoFreeParam(); return; } optima.resize(numParams); fc->copyEstToOptimizer(optima); paramMap.resize(numParams); for (int px=0,ex=0; px < numParams; ++ex) { if (fc->profiledOut[ex]) continue; paramMap[px++] = ex; } omxAlgebraPreeval(fitMat, fc); fc->createChildren(fitMat); // allow FIML rowwiseParallel even when parallel=false fc->state->countNonlinearConstraints(fc->state->numEqC, fc->state->numIneqC, false); int c_n = fc->state->numEqC + fc->state->numIneqC; fc->constraintFunVals.resize(c_n); fc->constraintJacobian.resize(c_n, numParams); if(c_n){ omxCalcFinalConstraintJacobian(fc, numParams); } // TODO: Allow more than one hessian value for calculation int numChildren = 1; if (parallel && !fc->openmpUser && fc->childList.size()) numChildren = fc->childList.size(); if (!fc->haveReferenceFit(fitMat)) return; minimum = fc->fit; hessWorkVector = new hess_struct[numChildren]; if (numChildren == 1) { omxPopulateHessianWork(hessWorkVector, fc); } else { for(int i = 0; i < numChildren; i++) { omxPopulateHessianWork(hessWorkVector + i, fc->childList[i]); } } if(verbose >= 1) mxLog("Numerical Hessian approximation (%d children, ref fit %.2f)", numChildren, minimum); hessian = NULL; if (wantHessian) { hessian = fc->getDenseHessUninitialized(); Eigen::Map< Eigen::MatrixXd > eH(hessian, numParams, numParams); eH.setConstant(NA_REAL); if (knownHessian) { int khSize = int(khMap.size()); Eigen::Map< Eigen::MatrixXd > kh(knownHessian, khSize, khMap.size()); for (int rx=0; rx < khSize; ++rx) { for (int cx=0; cx < khSize; ++cx) { if (khMap[rx] < 0 || khMap[cx] < 0) continue; eH(khMap[rx], khMap[cx]) = kh(rx, cx); } } } } if (detail) { recordDetail = false; // already done it once } else { Rf_protect(detail = Rf_allocVector(VECSXP, 4)); SET_VECTOR_ELT(detail, 0, Rf_allocVector(LGLSXP, numParams)); for (int gx=0; gx < 3; ++gx) { SET_VECTOR_ELT(detail, 1+gx, Rf_allocVector(REALSXP, numParams)); } SEXP detailCols; Rf_protect(detailCols = Rf_allocVector(STRSXP, 4)); Rf_setAttrib(detail, R_NamesSymbol, detailCols); SET_STRING_ELT(detailCols, 0, Rf_mkChar("symmetric")); SET_STRING_ELT(detailCols, 1, Rf_mkChar("forward")); SET_STRING_ELT(detailCols, 2, Rf_mkChar("central")); SET_STRING_ELT(detailCols, 3, Rf_mkChar("backward")); SEXP detailRowNames; Rf_protect(detailRowNames = Rf_allocVector(STRSXP, numParams)); Rf_setAttrib(detail, R_RowNamesSymbol, detailRowNames); for (int nx=0; nx < int(numParams); ++nx) { SET_STRING_ELT(detailRowNames, nx, Rf_mkChar(fc->varGroup->vars[nx]->name)); } markAsDataFrame(detail); } gforward = REAL(VECTOR_ELT(detail, 1)); gcentral = REAL(VECTOR_ELT(detail, 2)); gbackward = REAL(VECTOR_ELT(detail, 3)); Eigen::Map< Eigen::ArrayXd > Gf(gforward, numParams); Eigen::Map< Eigen::ArrayXd > Gc(gcentral, numParams); Eigen::Map< Eigen::ArrayXd > Gb(gbackward, numParams); Gf.setConstant(NA_REAL); Gc.setConstant(NA_REAL); Gb.setConstant(NA_REAL); calcHessianEntry che(this); CovEntrywiseParallel(numChildren, che); for(int i = 0; i < numChildren; i++) { struct hess_struct *hw = hessWorkVector + i; totalProbeCount += hw->probeCount; } delete [] hessWorkVector; if (isErrorRaised()) return; Eigen::Map< Eigen::ArrayXi > Gsymmetric(LOGICAL(VECTOR_ELT(detail, 0)), numParams); double gradNorm = 0.0; double feasibilityTolerance = Global->feasibilityTolerance; for (int px=0; px < numParams; ++px) { // factor out simliar code in ComputeNR omxFreeVar &fv = *fc->varGroup->vars[ paramMap[px] ]; if ((fabs(optima[px] - fv.lbound) < feasibilityTolerance && Gc[px] > 0) || (fabs(optima[px] - fv.ubound) < feasibilityTolerance && Gc[px] < 0)) { Gsymmetric[px] = false; continue; } gradNorm += Gc[px] * Gc[px]; double relsym = 2 * fabs(Gf[px] + Gb[px]) / (Gb[px] - Gf[px]); Gsymmetric[px] = (Gf[px] < 0 && 0 < Gb[px] && relsym < 1.5); if (checkGradient && verbose >= 2 && !Gsymmetric[px]) { mxLog("%s: param[%d] %d %f", name, px, Gsymmetric[px], relsym); } } fc->grad.resize(fc->numParam); fc->grad.setZero(); fc->copyGradFromOptimizer(Gc); if(c_n){ fc->inequality.resize(fc->state->numIneqC); fc->analyticIneqJacTmp.resize(fc->state->numIneqC, numParams); fc->myineqFun(true, verbose, omxConstraint::LESS_THAN, false); } gradNorm = sqrt(gradNorm); double gradThresh = Global->getGradientThreshold(minimum); //The gradient will generally not be near zero at a local minimum if there are equality constraints //or active inequality constraints: if ( checkGradient && gradNorm > gradThresh && !(fc->state->numEqC || fc->inequality.array().sum()) ) { if (verbose >= 1) { mxLog("Some gradient entries are too large, norm %f", gradNorm); } if (fc->getInform() < INFORM_NOT_AT_OPTIMUM) fc->setInform(INFORM_NOT_AT_OPTIMUM); } fc->setEstFromOptimizer(optima); // auxillary information like per-row likelihoods need a refresh ComputeFit(name, fitMat, FF_COMPUTE_FIT, fc); fc->wanted = newWanted; }
void mixtureKEpsilon<BasicTurbulenceModel>::correct() { const transportModel& gas = this->transport(); const twoPhaseSystem& fluid = gas.fluid(); // Only solve the mixture turbulence for the gas-phase if (&gas != &fluid.phase1()) { // This is the liquid phase but check the model for the gas-phase // is consistent this->liquidTurbulence(); return; } if (!this->turbulence_) { return; } // Initialise the mixture fields if they have not yet been constructed initMixtureFields(); // Local references to gas-phase properties const surfaceScalarField& phig = this->phi_; const volVectorField& Ug = this->U_; const volScalarField& alphag = this->alpha_; volScalarField& kg = this->k_; volScalarField& epsilong = this->epsilon_; volScalarField& nutg = this->nut_; // Local references to liquid-phase properties mixtureKEpsilon<BasicTurbulenceModel>& liquidTurbulence = this->liquidTurbulence(); const surfaceScalarField& phil = liquidTurbulence.phi_; const volVectorField& Ul = liquidTurbulence.U_; const volScalarField& alphal = liquidTurbulence.alpha_; volScalarField& kl = liquidTurbulence.k_; volScalarField& epsilonl = liquidTurbulence.epsilon_; volScalarField& nutl = liquidTurbulence.nut_; // Local references to mixture properties volScalarField& rhom = rhom_(); volScalarField& km = km_(); volScalarField& epsilonm = epsilonm_(); eddyViscosity<RASModel<BasicTurbulenceModel> >::correct(); // Update the effective mixture density rhom = this->rhom(); // Mixture flux surfaceScalarField phim("phim", mixFlux(phil, phig)); // Mixture velocity divergence volScalarField divUm ( mixU ( fvc::div(fvc::absolute(phil, Ul)), fvc::div(fvc::absolute(phig, Ug)) ) ); tmp<volScalarField> Gc; { tmp<volTensorField> tgradUl = fvc::grad(Ul); Gc = tmp<volScalarField> ( new volScalarField ( this->GName(), nutl*(tgradUl() && dev(twoSymm(tgradUl()))) ) ); tgradUl.clear(); // Update k, epsilon and G at the wall kl.boundaryField().updateCoeffs(); epsilonl.boundaryField().updateCoeffs(); Gc().checkOut(); } tmp<volScalarField> Gd; { tmp<volTensorField> tgradUg = fvc::grad(Ug); Gd = tmp<volScalarField> ( new volScalarField ( this->GName(), nutg*(tgradUg() && dev(twoSymm(tgradUg()))) ) ); tgradUg.clear(); // Update k, epsilon and G at the wall kg.boundaryField().updateCoeffs(); epsilong.boundaryField().updateCoeffs(); Gd().checkOut(); } // Mixture turbulence generation volScalarField Gm(mix(Gc, Gd)); // Mixture turbulence viscosity volScalarField nutm(mixU(nutl, nutg)); // Update the mixture k and epsilon boundary conditions km == mix(kl, kg); bound(km, this->kMin_); epsilonm == mix(epsilonl, epsilong); bound(epsilonm, this->epsilonMin_); // Dissipation equation tmp<fvScalarMatrix> epsEqn ( fvm::ddt(rhom, epsilonm) + fvm::div(phim, epsilonm) - fvm::Sp(fvc::ddt(rhom) + fvc::div(phim), epsilonm) - fvm::laplacian(DepsilonEff(rhom*nutm), epsilonm) == C1_*rhom*Gm*epsilonm/km - fvm::SuSp(((2.0/3.0)*C1_)*rhom*divUm, epsilonm) - fvm::Sp(C2_*rhom*epsilonm/km, epsilonm) + epsilonSource() ); epsEqn().relax(); epsEqn().boundaryManipulate(epsilonm.boundaryField()); solve(epsEqn); bound(epsilonm, this->epsilonMin_); // Turbulent kinetic energy equation tmp<fvScalarMatrix> kmEqn ( fvm::ddt(rhom, km) + fvm::div(phim, km) - fvm::Sp(fvc::ddt(rhom) + fvc::div(phim), km) - fvm::laplacian(DkEff(rhom*nutm), km) == rhom*Gm - fvm::SuSp((2.0/3.0)*rhom*divUm, km) - fvm::Sp(rhom*epsilonm/km, km) + kSource() ); kmEqn().relax(); solve(kmEqn); bound(km, this->kMin_); km.correctBoundaryConditions(); volScalarField Cc2(rhom/(alphal*rholEff() + alphag*rhogEff()*Ct2_())); kl = Cc2*km; kl.correctBoundaryConditions(); epsilonl = Cc2*epsilonm; epsilonl.correctBoundaryConditions(); liquidTurbulence.correctNut(); Ct2_() = Ct2(); kg = Ct2_()*kl; kg.correctBoundaryConditions(); epsilong = Ct2_()*epsilonl; epsilong.correctBoundaryConditions(); nutg = Ct2_()*(liquidTurbulence.nu()/this->nu())*nutl; }