49 alphaPorosityPtr_(nullptr),
50 laminarTransportPtr_(nullptr),
51 turbulencePtr_(nullptr),
52 daTurbulenceModelPtr_(nullptr),
53 daFvSourcePtr_(nullptr),
54 fvSourcePtr_(nullptr),
58 const fvSolution& myFvSolution =
meshPtr_->thisDb().lookupObject<fvSolution>(
"fvSolution");
59 if (myFvSolution.found(
"relaxationFactors"))
61 if (myFvSolution.subDict(
"relaxationFactors").found(
"equations"))
63 if (myFvSolution.subDict(
"relaxationFactors").subDict(
"equations").found(
"U"))
65 relaxUEqn_ = myFvSolution.subDict(
"relaxationFactors").subDict(
"equations").getScalar(
"U");
69 solverDictU_ = myFvSolution.subDict(
"solvers").subDict(
"U");
70 solverDictP_ = myFvSolution.subDict(
"solvers").subDict(
"p");
81 Info <<
"Initializing fields for DASimpleFoam" << endl;
96 if (
allOptions.subDict(
"fvSource").toc().size() != 0)
99 Info <<
"Initializing DASource" << endl;
100 word sourceName =
allOptions.subDict(
"fvSource").toc()[0];
101 word fvSourceType =
allOptions.subDict(
"fvSource").subDict(sourceName).getWord(
"type");
123 #include "createFvOptions.H"
126 daOptionPtr_->setOption<word>(
"runStatus",
"solvePrimal");
131 Info <<
"\nStarting time loop\n"
149 word divUScheme =
"div(phi,U)";
150 if (
daOptionPtr_->getSubDictOption<label>(
"runLowOrderPrimal4PC",
"active"))
152 if (
daOptionPtr_->getSubDictOption<label>(
"runLowOrderPrimal4PC",
"isPC"))
154 Info <<
"Using low order div scheme for primal solution .... " << endl;
155 divUScheme =
"div(pc)";
160 label printInterval =
daOptionPtr_->getOption<label>(
"printInterval");
161 label printToScreen = 0;
169 Info <<
"Time = " <<
runTime.timeName() << nl << endl;
189 Info <<
"ExecutionTime = " <<
runTime.elapsedCpuTime() <<
" s"
190 <<
" ClockTime = " <<
runTime.elapsedClockTime() <<
" s"
225 #ifdef CODI_AD_REVERSE
246 label printInterval =
daOptionPtr_->getOption<label>(
"printInterval");
248 word adjEqnSolMethod =
daOptionPtr_->getOption<word>(
"adjEqnSolMethod");
250 if (adjEqnSolMethod ==
"fixedPoint")
252 Info <<
"Solving the adjoint using consistent fixed-point iteration method..."
253 <<
" Execution Time: " <<
meshPtr_->time().elapsedCpuTime() <<
" s" << endl;
255 label fpMaxIters =
daOptionPtr_->getSubDictOption<label>(
"adjEqnOption",
"fpMaxIters");
256 scalar fpRelTol =
daOptionPtr_->getSubDictOption<scalar>(
"adjEqnOption",
"fpRelTol");
257 scalar fpMinResTolDiff =
daOptionPtr_->getSubDictOption<scalar>(
"adjEqnOption",
"fpMinResTolDiff");
259 const objectRegistry& db =
meshPtr_->thisDb();
260 volVectorField&
U =
const_cast<volVectorField&
>(db.lookupObject<volVectorField>(
"U"));
261 volScalarField&
p =
const_cast<volScalarField&
>(db.lookupObject<volScalarField>(
"p"));
262 surfaceScalarField&
phi =
const_cast<surfaceScalarField&
>(db.lookupObject<surfaceScalarField>(
"phi"));
263 volScalarField& nuTilda =
const_cast<volScalarField&
>(db.lookupObject<volScalarField>(
"nuTilda"));
277 volVectorField URes(
"URes", 0.0 *
U);
278 volScalarField pRes(
"pRes", 0.0 *
p);
279 surfaceScalarField phiRes(
"phiRes", 0.0 *
phi);
280 volScalarField nuTildaRes(
"nuTildaRes", 0.0 * nuTilda);
296 volVectorField UPsi(
"UPsi", 0.0 *
U);
297 volScalarField pPsi(
"pPsi", 0.0 *
p);
298 surfaceScalarField phiPsi(
"phiPsi", 0.0 *
phi);
299 volScalarField nuTildaPsi(
"nuTildaPsi", 0.0 * nuTilda);
335 volVectorField adjURes(
"adjURes", 0.0 *
U);
336 volScalarField adjPRes(
"adjPRes", 0.0 *
p);
337 surfaceScalarField adjPhiRes(
"adjPhiRes", 0.0 *
phi);
338 volScalarField adjNuTildaRes(
"adjNuTildaRes", 0.0 * nuTilda);
341 vector initNormAdjURes = vector::zero;
342 scalar initNormAdjPRes = 0.0;
343 scalar initNormAdjPhiRes = 0.0;
344 scalar initNormAdjNuTildaRes = 0.0;
372 volScalarField p1(
"p1",
p);
373 volScalarField p2(
"p2",
p);
374 this->
meshPtr_->setFluxRequired(p2.name());
375 surfaceScalarField phi1(
"phi1",
phi);
376 volVectorField U1(
"U1",
U);
379 volVectorField gradP(
"gradP", fvc::grad(
p));
380 surfaceScalarField pEqnFlux(
"pEqnFlux", 0.0 *
phi);
381 volScalarField divPhi(
"divPhi", fvc::div(
phi));
382 surfaceScalarField fluxU(
"fluxU", 0.0 *
phi);
397 while (cnt < fpMaxIters)
399 if (cnt % printInterval == 0)
401 Info <<
"Step = " << cnt <<
" Execution Time: " <<
meshPtr_->time().elapsedCpuTime() <<
" s" << endl;
410 this->
calcAdjointResidual(URes, pRes, phiRes, nuTildaRes, dFdW, UPsi, pPsi, phiPsi, nuTildaPsi, adjURes, adjPRes, adjPhiRes, adjNuTildaRes, cnt);
449 vector normAdjURes =
L2norm(adjURes);
450 scalar normAdjPRes =
L2norm(adjPRes);
451 scalar normAdjPhiRes =
L2norm(adjPhiRes);
452 scalar normAdjNuTildaRes =
L2norm(adjNuTildaRes);
456 initNormAdjURes = normAdjURes;
457 initNormAdjPRes = normAdjPRes;
458 initNormAdjPhiRes = normAdjPhiRes;
459 initNormAdjNuTildaRes = normAdjNuTildaRes;
463 normAdjURes[0] /= initNormAdjURes[0];
464 normAdjURes[1] /= initNormAdjURes[1];
465 normAdjURes[2] /= initNormAdjURes[2];
466 normAdjPRes /= initNormAdjPRes;
467 normAdjPhiRes /= initNormAdjPhiRes;
468 normAdjNuTildaRes /= initNormAdjNuTildaRes;
470 if (cnt % printInterval == 0)
472 Info <<
"Normalized L2 norm of adjURes: " << normAdjURes[0] <<
" " << normAdjURes[1] <<
" " << normAdjURes[2] << endl;
473 Info <<
"Normalized L2 norm of adjPRes: " << normAdjPRes << endl;
474 Info <<
"Normalized L2 norm of adjPhiRes: " << normAdjPhiRes << endl;
475 Info <<
"Normalized L2 norm of adjNuTildaRes: " << normAdjNuTildaRes << endl;
479 if (normAdjURes[0] < fpRelTol && normAdjURes[1] < fpRelTol && normAdjURes[2] < fpRelTol && normAdjPRes < fpRelTol && normAdjPhiRes < fpRelTol && normAdjNuTildaRes < fpRelTol)
481 Info <<
"Residual drop of " << fpRelTol <<
" has been achieved after " << cnt <<
" steps! Execution Time: " <<
meshPtr_->time().elapsedCpuTime() <<
" s" << endl;
482 Info <<
"Adjoint is converged and succussful.." << endl;
483 Info <<
"Normalized L2 norm of adjURes: " << normAdjURes[0] <<
" " << normAdjURes[1] <<
" " << normAdjURes[2] << endl;
484 Info <<
"Normalized L2 norm of adjPRes: " << normAdjPRes << endl;
485 Info <<
"Normalized L2 norm of adjPhiRes: " << normAdjPhiRes << endl;
486 Info <<
"Normalized L2 norm of adjNuTildaRes: " << normAdjNuTildaRes << endl;
500 adjURes[cellI] /=
UDiag[cellI];
511 volScalarField& step_2 = adjPRes;
519 this->globalADTape_.setActive();
524 this->globalADTape_.registerInput(p1[cellI]);
528 gradPStart_ = this->globalADTape_.getPosition();
531 p1.correctBoundaryConditions();
532 U.correctBoundaryConditions();
535 gradP = fvc::grad(p1);
538 gradP.primitiveFieldRef()[cellI] *=
U.mesh().V()[cellI];
542 gradPEnd_ = this->globalADTape_.getPosition();
545 this->globalADTape_.setPassive();
552 gradP[cellI][0].setGradient(adjURes[cellI][0].getValue());
553 gradP[cellI][1].setGradient(adjURes[cellI][1].getValue());
554 gradP[cellI][2].setGradient(adjURes[cellI][2].getValue());
558 this->globalADTape_.evaluate(gradPEnd_, gradPStart_);
561 step_2[cellI] += p1[cellI].getGradient();
565 this->globalADTape_.clearAdjoints();
569 scalar alphaP =
p.mesh().fieldRelaxationFactor(
p.name());
581 fvScalarMatrix pEqn1(
582 fvm::laplacian(
rAU, p2));
586 this->globalADTape_.setActive();
591 this->globalADTape_.registerInput(p2[cellI]);
595 pEqnFluxStart_ = this->globalADTape_.getPosition();
598 p2.correctBoundaryConditions();
599 U.correctBoundaryConditions();
602 pEqnFlux = pEqn1.flux();
605 pEqnFluxEnd_ = this->globalADTape_.getPosition();
608 this->globalADTape_.setPassive();
614 forAll(pEqnFlux.primitiveFieldRef(), faceI)
616 pEqnFlux.primitiveFieldRef()[faceI].setGradient(adjPhiRes.primitiveFieldRef()[faceI].getValue());
619 forAll(pEqnFlux.boundaryFieldRef(), patchI)
621 forAll(pEqnFlux.boundaryFieldRef()[patchI], faceI)
623 pEqnFlux.boundaryFieldRef()[patchI][faceI].setGradient(adjPhiRes.boundaryFieldRef()[patchI][faceI].getValue());
628 this->globalADTape_.evaluate(pEqnFluxEnd_, pEqnFluxStart_);
631 step_2[cellI] += p2[cellI].getGradient();
635 this->globalADTape_.clearAdjoints();
653 volScalarField& pSource = step_2;
658 volScalarField& step_3 =
pseudoP;
678 surfaceScalarField& phiTemp = adjPhiRes;
684 this->globalADTape_.setActive();
689 forAll(phi1.primitiveFieldRef(), faceI)
691 this->globalADTape_.registerInput(phi1.primitiveFieldRef()[faceI]);
694 forAll(phi1.boundaryFieldRef(), patchI)
696 forAll(phi1.boundaryFieldRef()[patchI], faceI)
698 this->globalADTape_.registerInput(phi1.boundaryFieldRef()[patchI][faceI]);
703 divPhiStart_ = this->globalADTape_.getPosition();
711 divPhi = fvc::div(phi1);
714 divPhi.primitiveFieldRef()[cellI] *=
p.mesh().V()[cellI];
718 divPhiEnd_ = this->globalADTape_.getPosition();
721 this->globalADTape_.setPassive();
728 divPhi[cellI].setGradient(step_3[cellI].getValue());
732 this->globalADTape_.evaluate(divPhiEnd_, divPhiStart_);
733 forAll(phi1.primitiveFieldRef(), faceI)
735 phiTemp.primitiveFieldRef()[faceI] += phi1.primitiveFieldRef()[faceI].getGradient();
737 forAll(phi1.boundaryFieldRef(), patchI)
739 forAll(phi1.boundaryFieldRef()[patchI], faceI)
741 phiTemp.boundaryFieldRef()[patchI][faceI] += phi1.boundaryFieldRef()[patchI][faceI].getGradient();
746 this->globalADTape_.clearAdjoints();
763 UPsi[cellI] -= adjURes[cellI];
769 volVectorField& step_4 = adjURes;
774 this->globalADTape_.setActive();
779 this->globalADTape_.registerInput(U1[cellI][0]);
780 this->globalADTape_.registerInput(U1[cellI][1]);
781 this->globalADTape_.registerInput(U1[cellI][2]);
785 fluxUStart_ = this->globalADTape_.getPosition();
788 U1.correctBoundaryConditions();
789 p.correctBoundaryConditions();
792 fluxU = fvc::flux(U1);
795 fluxUEnd_ = this->globalADTape_.getPosition();
798 this->globalADTape_.setPassive();
804 forAll(fluxU.primitiveFieldRef(), faceI)
806 fluxU.primitiveFieldRef()[faceI].setGradient(phiTemp.primitiveFieldRef()[faceI].getValue());
809 forAll(fluxU.boundaryFieldRef(), patchI)
811 forAll(fluxU.boundaryFieldRef()[patchI], faceI)
813 fluxU.boundaryFieldRef()[patchI][faceI].setGradient(phiTemp.boundaryFieldRef()[patchI][faceI].getValue());
818 this->globalADTape_.evaluate(fluxUEnd_, fluxUStart_);
821 for (label cmpt = 0; cmpt < 3; cmpt++)
823 step_4[cellI][cmpt] -= U1[cellI][cmpt].getGradient() /
UDiag[cellI];
828 this->globalADTape_.clearAdjoints();
837 step_4.primitiveFieldRef() = -
pseudoUEqn.lduMatrix::H(step_4);
851 volVectorField& USource = step_4;
856 volVectorField& step_5 =
pseudoU;
862 UPsi[cellI] += step_5[cellI];
877 volScalarField& nuTildaSource = adjNuTildaRes;
895 Info <<
"Prescribed adjoint convergence of " << fpRelTol <<
" has not been met after " << cnt <<
" steps! Execution Time: " <<
meshPtr_->time().elapsedCpuTime() <<
" s" << endl;
896 Info <<
"Now checking if the relaxed convergence is met..." << endl;
897 this->
calcAdjointResidual(URes, pRes, phiRes, nuTildaRes, dFdW, UPsi, pPsi, phiPsi, nuTildaPsi, adjURes, adjPRes, adjPhiRes, adjNuTildaRes, cnt);
899 vector normAdjURes =
L2norm(adjURes);
900 scalar normAdjPRes =
L2norm(adjPRes);
901 scalar normAdjPhiRes =
L2norm(adjPhiRes);
902 scalar normAdjNuTildaRes =
L2norm(adjNuTildaRes);
905 normAdjURes[0] /= initNormAdjURes[0];
906 normAdjURes[1] /= initNormAdjURes[1];
907 normAdjURes[2] /= initNormAdjURes[2];
908 normAdjPRes /= initNormAdjPRes;
909 normAdjPhiRes /= initNormAdjPhiRes;
910 normAdjNuTildaRes /= initNormAdjNuTildaRes;
912 scalar relaxedFpRelTol = fpRelTol * fpMinResTolDiff;
913 if (normAdjURes[0] < relaxedFpRelTol && normAdjURes[1] < relaxedFpRelTol && normAdjURes[2] < relaxedFpRelTol && normAdjPRes < relaxedFpRelTol && normAdjPhiRes < relaxedFpRelTol && normAdjNuTildaRes < relaxedFpRelTol)
915 Info <<
"Relaxed residual drop of " << relaxedFpRelTol <<
" has been achieved! Execution Time: " <<
meshPtr_->time().elapsedCpuTime() <<
" s" << endl;
916 Info <<
"Adjoint is still considered succussful.." << endl;
921 Info <<
"Relaxed residual drop of " << relaxedFpRelTol <<
" has not been met! Execution Time: " <<
meshPtr_->time().elapsedCpuTime() <<
" s" << endl;
922 Info <<
"Adjoint has failed to converge.." << endl;
924 Info <<
"Normalized L2 norm of adjURes: " << normAdjURes[0] <<
" " << normAdjURes[1] <<
" " << normAdjURes[2] << endl;
925 Info <<
"Normalized L2 norm of adjPRes: " << normAdjPRes << endl;
926 Info <<
"Normalized L2 norm of adjPhiRes: " << normAdjPhiRes << endl;
927 Info <<
"Normalized L2 norm of adjNuTildaRes: " << normAdjNuTildaRes << endl;
931 this->
vec2Fields(
"field2Vec", psi, UPsi, pPsi, phiPsi, nuTildaPsi);
935 FatalErrorIn(
"adjEqnSolMethod not valid") << exit(FatalError);
945 volVectorField& UField,
946 volScalarField& pField,
947 surfaceScalarField& phiField,
948 volScalarField& nuTildaField)
950 #ifdef CODI_AD_REVERSE
951 PetscScalar* cVecArray;
952 if (
mode ==
"vec2Field")
954 VecGetArray(cVec, &cVecArray);
959 for (label comp = 0; comp < 3; comp++)
961 label adjLocalIdx =
daIndexPtr_->getLocalAdjointStateIndex(
"U", cellI, comp);
962 UField[cellI][comp] = cVecArray[adjLocalIdx];
968 label adjLocalIdx =
daIndexPtr_->getLocalAdjointStateIndex(
"p", cellI);
969 pField[cellI] = cVecArray[adjLocalIdx];
974 label adjLocalIdx =
daIndexPtr_->getLocalAdjointStateIndex(
"phi", faceI);
976 if (faceI < daIndexPtr_->nLocalInternalFaces)
978 phiField[faceI] = cVecArray[adjLocalIdx];
982 label relIdx = faceI -
daIndexPtr_->nLocalInternalFaces;
985 phiField.boundaryFieldRef()[patchIdx][faceIdx] = cVecArray[adjLocalIdx];
991 label adjLocalIdx =
daIndexPtr_->getLocalAdjointStateIndex(
"nuTilda", cellI);
992 nuTildaField[cellI] = cVecArray[adjLocalIdx];
995 VecRestoreArray(cVec, &cVecArray);
997 else if (
mode ==
"field2Vec")
999 VecGetArray(cVec, &cVecArray);
1004 for (label comp = 0; comp < 3; comp++)
1006 label adjLocalIdx =
daIndexPtr_->getLocalAdjointStateIndex(
"U", cellI, comp);
1007 cVecArray[adjLocalIdx] = UField[cellI][comp].value();
1013 label adjLocalIdx =
daIndexPtr_->getLocalAdjointStateIndex(
"p", cellI);
1014 cVecArray[adjLocalIdx] = pField[cellI].value();
1019 label adjLocalIdx =
daIndexPtr_->getLocalAdjointStateIndex(
"phi", faceI);
1021 if (faceI < daIndexPtr_->nLocalInternalFaces)
1023 cVecArray[adjLocalIdx] = phiField[faceI].value();
1027 label relIdx = faceI -
daIndexPtr_->nLocalInternalFaces;
1028 label patchIdx =
daIndexPtr_->bFacePatchI[relIdx];
1030 cVecArray[adjLocalIdx] = phiField.boundaryFieldRef()[patchIdx][faceIdx].value();
1036 label adjLocalIdx =
daIndexPtr_->getLocalAdjointStateIndex(
"nuTilda", cellI);
1037 cVecArray[adjLocalIdx] = nuTildaField[cellI].value();
1040 VecRestoreArray(cVec, &cVecArray);
1044 FatalErrorIn(
"mode not valid") << exit(FatalError);
1050 const volVectorField& mySource,
1106 const volScalarField& mySource,
1173 volVectorField& URes,
1174 volScalarField& pRes,
1175 surfaceScalarField& phiRes)
1177 const objectRegistry& db =
meshPtr_->thisDb();
1178 const volVectorField&
U = db.lookupObject<volVectorField>(
"U");
1179 const volScalarField&
p = db.lookupObject<volScalarField>(
"p");
1180 const surfaceScalarField&
phi = db.lookupObject<surfaceScalarField>(
"phi");
1183 fvVectorMatrix
UEqn(
1185 - fvm::laplacian(nuEff,
U)
1186 - fvc::div(nuEff * dev2(
T(fvc::grad(
U)))));
1188 List<vector>& USource =
UEqn.source();
1194 volVectorField gradP(fvc::grad(
p));
1197 for (label i = 0; i <
U.size(); i++)
1199 URes[i] =
UDiag[i] *
U[i] - USource[i] +
U.mesh().V()[i] * gradP[i];
1201 URes.primitiveFieldRef() -=
UEqn.lduMatrix::H(
U);
1204 forAll(
U.boundaryField(), patchI)
1206 const fvPatch& pp =
U.boundaryField()[patchI].patch();
1211 label cellI = pp.faceCells()[faceI];
1214 for (label cmpt = 0; cmpt < 3; cmpt++)
1216 URes[cellI][cmpt] +=
UEqn.internalCoeffs()[patchI][faceI][cmpt] *
U[cellI][cmpt];
1219 URes[cellI] -=
UEqn.boundaryCoeffs()[patchI][faceI];
1224 URes.correctBoundaryConditions();
1228 volScalarField
rAU(1.0 /
UEqn.A());
1229 volVectorField
HbyA(
"HbyA",
U);
1231 surfaceScalarField
phiHbyA(
"phiHbyA", fvc::flux(
HbyA));
1233 fvScalarMatrix pEqn(
1236 List<scalar>& pSource = pEqn.source();
1237 List<scalar>& pDiag = pEqn.diag();
1240 for (label i = 0; i <
p.size(); i++)
1242 pRes[i] = pDiag[i] *
p[i] - pSource[i];
1244 pRes.primitiveFieldRef() -= pEqn.lduMatrix::H(
p);
1247 forAll(
p.boundaryField(), patchI)
1249 const fvPatch& pp =
p.boundaryField()[patchI].patch();
1254 label cellI = pp.faceCells()[faceI];
1258 pRes[cellI] += pEqn.internalCoeffs()[patchI][faceI] *
p[cellI];
1259 pRes[cellI] -= pEqn.boundaryCoeffs()[patchI][faceI];
1264 pRes.correctBoundaryConditions();
1272 volVectorField& URes,
1273 volScalarField& pRes,
1274 surfaceScalarField& phiRes,
1275 volScalarField& nuTildaRes,
1277 volVectorField& UPsi,
1278 volScalarField& pPsi,
1279 surfaceScalarField& phiPsi,
1280 volScalarField& nuTildaPsi,
1281 volVectorField& adjURes,
1282 volScalarField& adjPRes,
1283 surfaceScalarField& adjPhiRes,
1284 volScalarField& adjNuTildaRes,
1287 #ifdef CODI_AD_REVERSE
1288 volVectorField&
U =
const_cast<volVectorField&
>(
meshPtr_->thisDb().lookupObject<volVectorField>(
"U"));
1289 volScalarField&
p =
const_cast<volScalarField&
>(
meshPtr_->thisDb().lookupObject<volScalarField>(
"p"));
1290 volScalarField& nuTilda =
const_cast<volScalarField&
>(
meshPtr_->thisDb().lookupObject<volScalarField>(
"nuTilda"));
1291 surfaceScalarField&
phi =
const_cast<surfaceScalarField&
>(
meshPtr_->thisDb().lookupObject<surfaceScalarField>(
"phi"));
1294 this->
vec2Fields(
"vec2Field", dFdW, adjURes, adjPRes, adjPhiRes, adjNuTildaRes);
1297 adjPhiRes = -adjPhiRes;
1298 adjNuTildaRes = -adjNuTildaRes;
1302 this->globalADTape_.reset();
1303 this->globalADTape_.setActive();
1309 this->globalADTape_.registerInput(
U[cellI][0]);
1310 this->globalADTape_.registerInput(
U[cellI][1]);
1311 this->globalADTape_.registerInput(
U[cellI][2]);
1316 this->globalADTape_.registerInput(
p[cellI]);
1323 this->globalADTape_.registerInput(
phi.primitiveFieldRef()[faceI]);
1328 forAll(
phi.boundaryFieldRef()[patchI], faceI)
1330 this->globalADTape_.registerInput(
phi.boundaryFieldRef()[patchI][faceI]);
1336 this->globalADTape_.registerInput(nuTilda[cellI]);
1340 adjResStart_ = this->globalADTape_.getPosition();
1343 U.correctBoundaryConditions();
1344 p.correctBoundaryConditions();
1345 nuTilda.correctBoundaryConditions();
1386 adjResEnd_ = this->globalADTape_.getPosition();
1389 this->globalADTape_.setPassive();
1396 URes[cellI][0].setGradient(UPsi[cellI][0].getValue());
1397 URes[cellI][1].setGradient(UPsi[cellI][1].getValue());
1398 URes[cellI][2].setGradient(UPsi[cellI][2].getValue());
1403 pRes[cellI].setGradient(pPsi[cellI].getValue());
1407 forAll(phiRes.primitiveFieldRef(), faceI)
1409 phiRes.primitiveFieldRef()[faceI].setGradient(phiPsi.primitiveFieldRef()[faceI].getValue());
1412 forAll(phiRes.boundaryFieldRef(), patchI)
1414 forAll(phiRes.boundaryFieldRef()[patchI], faceI)
1416 phiRes.boundaryFieldRef()[patchI][faceI].setGradient(phiPsi.boundaryFieldRef()[patchI][faceI].getValue());
1420 forAll(nuTildaRes, cellI)
1422 nuTildaRes[cellI].setGradient(nuTildaPsi[cellI].getValue());
1426 this->globalADTape_.evaluate(adjResEnd_, adjResStart_);
1429 adjURes[cellI][0] +=
U[cellI][0].getGradient();
1430 adjURes[cellI][1] +=
U[cellI][1].getGradient();
1431 adjURes[cellI][2] +=
U[cellI][2].getGradient();
1435 adjPRes[cellI] +=
p[cellI].getGradient();
1439 adjPhiRes.primitiveFieldRef()[faceI] +=
phi.primitiveFieldRef()[faceI].getGradient();
1443 forAll(
phi.boundaryFieldRef()[patchI], faceI)
1445 adjPhiRes.boundaryFieldRef()[patchI][faceI] +=
phi.boundaryFieldRef()[patchI][faceI].getGradient();
1450 adjNuTildaRes[cellI] += nuTilda[cellI].getGradient();
1454 this->globalADTape_.clearAdjoints();
1462 scalar L2normV = 0.0;
1466 L2normV += sqr(v[cellI] /
meshPtr_->V()[cellI]);
1468 L2normV = sqrt(L2normV);
1476 vector L2normU = vector::zero;
1480 L2normU[0] += sqr(
U[cellI][0] /
meshPtr_->V()[cellI]);
1481 L2normU[1] += sqr(
U[cellI][1] /
meshPtr_->V()[cellI]);
1482 L2normU[2] += sqr(
U[cellI][2] /
meshPtr_->V()[cellI]);
1484 L2normU[0] = sqrt(L2normU[0]);
1485 L2normU[1] = sqrt(L2normU[1]);
1486 L2normU[2] = sqrt(L2normU[2]);
1494 scalar L2normPhi = 0.0;
1496 forAll(Phi.primitiveField(), faceI)
1498 L2normPhi += sqr(Phi.primitiveField()[faceI]);
1500 forAll(Phi.boundaryField(), patchI)
1502 forAll(Phi.boundaryField()[patchI], faceI)
1504 L2normPhi += sqr(Phi.boundaryField()[patchI][faceI]);
1507 L2normPhi = sqrt(L2normPhi);
1515 List<scalar> temp = a;