43namespace incompressibleAdjoint
45namespace adjointRASModels
126 auto tzeroFirstCell =
146 const fvPatch& patch = omegab.patch();
147 if (isA<omegaWallFunctionFvPatchScalarField>(omegab))
149 const label patchi = patch.index();
166 return tzeroFirstCell;
174 word scheme(
"coeffsDiff");
189 if (isA<nutkWallFunctionFvPatchScalarField>(nutb))
192 const scalarField kSnGrad(
k().boundaryField()[pI].snGrad());
195 omega().boundaryField()[pI].snGrad()
199 const vectorField USnGrad(
U.boundaryField()[pI].snGrad());
207 -
ka()[cI]*akb[fI]*kSnGrad[fI]
208 - (Ua[cI] & (USnGrad[fI] + (
dev2(gradUb[fI]) & nf[fI])));
250 - scalar(2)*arg2*(1 -
F2_*
F2_)*
302 word scheme(
"coeffsDiff");
315 typedef fixedValueFvPatchScalarField fixedValue;
316 typedef zeroGradientFvPatchScalarField zeroGrad;
326 && (isA<zeroGrad>(omegab) || isA<omegaWF>(omegab))
331 else if (isA<fixedValue>(
kb) && isA<fixedValue>(omegab)
356 && (isA<zeroGrad>(omegab) || isA<omegaWF>(omegab))
361 else if (isA<fixedValue>(
kb) && isA<fixedValue>(omegab))
367 dRdF1 += dR_dF1_coeffs;
425 interpolationScheme<vector>(
"div(dR_dGradOmega)")().
451 isA<zeroGradientFvPatchScalarField>(omegab)
452 || isA<omegaWallFunctionFvPatchScalarField>(omegab)
457 else if (isA<fixedValueFvPatchScalarField>(omegab))
465 interpolationScheme<vector>(
"sourceAdjontkOmegaSST")().
491 if (isA<zeroGradientFvPatchScalarField>(
kb))
495 else if (isA<fixedValueFvPatchScalarField>(
kb))
504 interpolationScheme<vector>(
"sourceAdjontkOmegaSST")().
562 interpolationScheme<vector>(
"div(dR_dGradK)")().
578 const word& schemeName
582 (interpolationScheme<scalar>(schemeName));
589 if (isA<zeroGradientFvPatchScalarField>(primalbf))
595 else if (isA<fixedValueFvPatchScalarField>(primalbf))
613 const word& schemeName
617 (interpolationScheme<scalar>(schemeName));
624 if (isA<zeroGradientFvPatchScalarField>(bc))
632 else if (isA<fixedValueFvPatchScalarField>(bc))
648 const word& schemeName
652 (interpolationScheme<vector>(schemeName));
660 if (isA<zeroGradientFvPatchScalarField>(bc))
664 else if (isA<fixedValueFvPatchScalarField>(bc))
680 if (!isA<coupledFvPatchVectorField>(Ub))
692 if (isA<zeroGradientFvPatchScalarField>(bc))
704 M[celli] -= ((Uai[fI] & dev2GradU[fI]) & Sfb[fI])/V[celli];
708 M.correctBoundaryConditions();
766 if (isA<zeroGradientFvPatchVectorField>(bc))
770 else if (isA<fixedValueFvPatchVectorField>(bc))
795 if (isA<zeroGradientFvPatchVectorField>(bc))
799 else if (isA<fixedValueFvPatchVectorField>(bc))
801 flux.boundaryFieldRef()[pI] =
803 & GbyNuMult().boundaryField()[pI].patchInternalField();
825 if (isA<zeroGradientFvPatchVectorField>(bc))
829 else if (isA<fixedValueFvPatchVectorField>(bc))
831 flux.boundaryFieldRef()[pI] =
833 *divUMult().boundaryField()[pI].patchInternalField();
861 if (!isA<coupledFvPatchVectorField>(bc))
880 M.correctBoundaryConditions();
892 if (isA<zeroGradientFvPatchVectorField>(bc))
896 else if (isA<fixedValueFvPatchVectorField>(bc))
900 &
M.boundaryField()[pI].patchInternalField();
927 if (isA<nutkWallFunctionFvPatchScalarField>(nutWall))
940 refCast<nutWallFunctionFvPatchScalarField>(nutWall);
942 const scalar Cmu = wallCoeffs.
Cmu();
943 const scalar kappa = wallCoeffs.
kappa();
944 const scalar E = wallCoeffs.
E();
945 const scalar yPlusLam = wallCoeffs.
yPlusLam();
947 const scalar Cmu25 =
pow025(Cmu);
951 dR_dnut.boundaryField()[patchi];
953 bool addTermsFromOmegaWallFuction
954 (isA<omegaWallFunctionFvPatchScalarField>(omegaw));
963 const scalar sqrtkCell(
sqrt(
k[celli]));
964 const scalar
yPlus = Cmu25*
y[facei]*sqrtkCell/nuw[facei];
965 const scalar logEyPlus =
log(E*
yPlus);
966 const scalar dnut_dyPlus =
967 nuw[facei]*kappa*(logEyPlus - 1)/
sqr(logEyPlus);
968 const scalar dyPlus_dk =
969 Cmu25*
y[facei]/(2*nuw[facei]*sqrtkCell);
970 const scalar
dnut_dk = dnut_dyPlus*dyPlus_dk;
972 if (yPlusLam <
yPlus)
975 source[celli] -= dR_dnutw[facei]*
dnut_dk*magSf[facei];
977 if (addTermsFromOmegaWallFuction)
979 const scalar denom(Cmu25*kappa*
y[facei]);
980 const scalar omegaLog(sqrtkCell/denom);
983 wa[celli]*omegaLog/
omega[celli]
984 /(2*sqrtkCell*denom);
990 (nutWall[facei] + nuw[facei])
993 /(2.0*sqrtkCell*kappa*
y[facei])
996 if (yPlusLam <
yPlus)
1016 Info<<
"Updating primal-based fields of the adjoint turbulence "
1017 <<
"model ..." <<
endl;
1160 word divEntry(
"div(" + phiInst.
name() +
',' + varName +
')');
1164 word discarded(divScheme);
1165 if (discarded ==
"bounded")
1167 discarded =
word(divScheme);
1180 const word& adjointTurbulenceModelName,
1181 const word& modelName
1190 adjointTurbulenceModelName
1312 Switch::lookupOrAddToDict
1320 y_(primalVars_.RASModelVariables()().d()),
1340 "rasModel::gradOmega",
1393 "adjointRASModel::GbyNu0",
1668 zeroFirstCell_(zeroFirstCell()),
1884 "adjointMeanFlowSource" +
type(),
1912 twoSymmGradU.
clear();
1942 if (isA<omegaWallFunctionFvPatchScalarField>(omegaWall))
1954 refCast<nutWallFunctionFvPatchScalarField>
1955 (
nutRef().boundaryFieldRef()[patchi]);
1957 const scalar Cmu = wallCoeffs.
Cmu();
1958 const scalar kappa = wallCoeffs.
kappa();
1959 const scalar Cmu25 =
pow025(Cmu);
1966 const scalarField& deltaCoeffs = patch.deltaCoeffs();
1971 meanFlowSource[celli] +=
1973 *(nutw[facei] + nuw[facei])
1974 *snGradUw[facei].normalise()
1975 *Cmu25*
sqrt(
k()[celli])
1981 return tmeanFlowSource;
2002 +
nu()().boundaryField()[patchI]
2012 +
nu()().boundaryField()[patchI]
2053 waEqn.
ref().boundaryManipulate(
wa().boundaryFieldRef());
2054 waEqn.
ref().relax();
2059 waEqn.
ref().solve();
2076 kaEqn.
ref().relax();
2077 kaEqn.
ref().boundaryManipulate(
ka().boundaryFieldRef());
2082 kaEqn.
ref().solve();
2088 Info<<
"Max mag of adjoint dissipation = " << maxwa.
value() <<
endl;
2089 Info<<
"Max mag of adjoint kinetic energy = " << maxka.
value() <<
endl;
2108 wallShapeSens[patchi] = nf & FITerm.
boundaryField()[patchi];
2110 return wallShapeSens;
2126 "adjointEikonalSource" +
type(),
2170 type() +
"FISensTerm",
2178 zeroGradientFvPatchTensorField::typeName
2227 const word& designVarsName
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic GeometricBoundaryField class.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
void correctBoundaryConditions()
Correct boundary field.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & name() const noexcept
Return the object name.
An input stream of tokens.
void setSize(const label n)
Alias for resize()
void resize(const label len)
Adjust allocated size of list.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
bool readIfPresent(const word &key, const dictionary &dict)
Update the value of the Switch if it is found in the dictionary.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
static word timeName(const scalar t, const int precision=precision_)
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const Type & value() const
Return const reference to value.
bool readIfPresent(const dictionary &dict)
Abstract base class for finite area calculus convection schemes.
Smooth ATC in cells next to a set of patches supplied by type.
UPtrList< const labelUList > faceCells() const
Return a list of faceCells for each patch.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Field< Type > & source() noexcept
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
const Time & time() const
Return the top-level database.
const surfaceVectorField & Sf() const
Return cell face area vectors.
const surfaceScalarField & magSf() const
Return cell face area magnitudes.
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch as patch field.
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Manages the adjoint mean flow fields and their mean values.
const volVectorField & UaInst() const
Return const reference to velocity.
const solverControl & getSolverControl() const
Return const reference to solverControl.
Abstract base class for incompressible turbulence models.
autoPtr< boundaryVectorField > wallShapeSensitivitiesPtr_
Wall sensitivity term for shape optimisation.
virtual void correct()
Solve the adjoint turbulence equations.
Switch adjointTurbulence_
Turbulence on/off flag.
bool changedPrimalSolution_
Has the primal solution changed?
autoPtr< boundaryVectorField > adjMomentumBCSourcePtr_
const nearWallDist & y() const
Return the near wall distances.
autoPtr< volScalarField > adjointTMVariable1Ptr_
Adjoint turbulence model variable 1.
autoPtr< volScalarField > adjointTMVariable2Ptr_
Adjoint turbulence model variable 2.
objectiveManager & objectiveManager_
Reference to the objectiveManager.
wordList adjointTMVariablesBaseNames_
Base names of the adjoint fields.
autoPtr< boundaryVectorField > wallFloCoSensitivitiesPtr_
Wall sensitivity term for flow control optimisation.
const dictionary & coeffDict() const
Const access to the coefficients dictionary.
void setMeanFields()
Set mean fields.
virtual bool read()
Read adjointRASProperties dictionary.
Continuous adjoint to the kOmegaSST turbulence model for incompressible flows.
virtual tmp< fvVectorMatrix > divDevReff(volVectorField &U) const
Return the transpose part of the adjoint momentum stresses.
virtual tmp< scalarField > diffusionCoeffVar1(label patchI) const
Diffusion coeff at the boundary for k.
virtual tmp< volScalarField > nutJacobianTMVar2() const
Jacobian of nut wrt to omega.
tmp< volScalarField > dGPrime_domega() const
GbyNu Jacobian wrt omega.
tmp< volVectorField > GMeanFlowSource(tmp< volSymmTensorField > &GbyNuMult) const
Contributions from the G.
virtual tmp< volTensorField > FISensitivityTerm()
Sensitivity derivative contributions when using the FI approach.
tmp< volVectorField > dF1_dGradK(const volScalarField &arg1) const
F1 Jacobian wrt grad(k)
volScalarField case_1_F1_
tmp< volScalarField > dR_dF1() const
Derivative of the primal equations wrt F1.
tmp< volScalarField > dF1_dk(const volScalarField &arg1) const
F1 Jacobian wrt k (no contributions from grad(k))
tmp< volScalarField > dnut_dk() const
Nut Jacobian wrt k.
tmp< volScalarField > dGPrime_dk() const
GbyNu Jacobian wrt k.
tmp< volVectorField > convectionMeanFlowSource(const volScalarField &primalField, const volScalarField &adjointField) const
Contributions from the turbulence model convection terms.
Switch F3_
Flag to include the F3 term.
dimensionedScalar alphaOmega2_
virtual void correct()
Solve the adjoint turbulence equations.
volScalarField DkEff_
Diffusivity of the k equation.
virtual tmp< volScalarField > F2() const
dimensionedScalar gamma2_
volScalarField S2_
Primal cached fields involved in the solution of the.
tmp< volScalarField > dNutdbMult(const volScalarField &primalField, const volScalarField &adjointField, const volScalarField &coeffField, const volScalarField &bcField, const word &schemeName) const
Term multiplying dnut/db, coming from the turbulence model.
volScalarField case_2_nut_
tmp< fvScalarMatrix > waEqnSourceFromCDkOmega() const
Source to waEqn from the differentiation of CDkOmega.
volScalarField alphaOmega_
tmp< volScalarField > kaEqnSourceFromF1() const
Source to kaEqn from the differentiation of F1.
tmp< volScalarField > dR_dnut()
Derivative of the primal equations wrt nut.
virtual tmp< volScalarField > F1() const
void updatePrimalRelatedFields()
Update of the primal cached fields.
tmp< volScalarField > dF2_dk() const
F2 Jacobian wrt k.
virtual const boundaryVectorField & adjointMomentumBCSource() const
tmp< surfaceInterpolationScheme< scalar > > convectionScheme(const word &varName) const
virtual tmp< volSymmTensorField > devReff() const
Return the effective stress tensor including the laminar stress.
volScalarField case_3_nut_
virtual void nullify()
Nullify all adjoint turbulence model fields and their old times.
volScalarField CDkOmegaPlus_
volScalarField zeroFirstCell_
virtual tmp< volScalarField > nutJacobianTMVar1() const
Jacobian of nut wrt to k.
tmp< volVectorField > nutMeanFlowSource(tmp< volScalarField > &mult) const
Contributions from nut(U)
tmp< volScalarField > zeroFirstCell()
volTensorField gradU_
Cached primal gradient fields.
volScalarField case_3_F1_
volScalarField DOmegaEff_
Diffusivity of the omega equation.
virtual tmp< volScalarField > GbyNu(const volScalarField &GbyNu0, const volScalarField &F2, const volScalarField &S2) const
const volScalarField & k() const
tmp< volScalarField > alphaK(const volScalarField &F1) const
tmp< volScalarField > diffusionNutMeanFlowMult(const volScalarField &primalField, const volScalarField &adjointField, const volScalarField &coeffField) const
virtual const boundaryVectorField & wallShapeSensitivities()
Sensitivity derivative contributions when using the (E)SI approach.
dimensionedScalar alphaK2_
const volScalarField & y_
Wall distance.
tmp< volScalarField > DomegaEff(const volScalarField &F1) const
Return the effective diffusivity for omega.
volScalarField case_2_F1_
tmp< volScalarField > alphaOmega(const volScalarField &F1) const
void addWallFunctionTerms(fvScalarMatrix &kaEqn, const volScalarField &dR_dnut)
tmp< volScalarField > waEqnSourceFromF1() const
Source to waEqn from the differentiation of F1.
volScalarField case_1_GPrime_
virtual tmp< volVectorField > adjointMeanFlowSource()
volScalarField case_1_Pk_
Switch fields for the production in the k Eqn.
tmp< volScalarField::Internal > beta(const volScalarField::Internal &F1) const
virtual const boundaryVectorField & wallFloCoSensitivities()
Sensitivity terms for flow control, emerging from the.
virtual tmp< volVectorField > nonConservativeMomentumSource() const
Non-conservative part of the terms added to the mean flow equations.
volScalarField case_2_Pk_
dimensionedScalar alphaK1_
volScalarField dnut_domega_
Nut Jacobian w.r.t. omega.
tmp< volScalarField > kaEqnSourceFromCDkOmega() const
Source to kaEqn from the differentiation of CDkOmega.
tmp< volScalarField > coeffsDifferentiation(const volScalarField &primalField, const volScalarField &adjointField, const word &schemeName) const
Differentiation of the turbulence model diffusion coefficients.
virtual tmp< volScalarField > distanceSensitivities()
Contributions to the adjoint eikonal equation (zero for now)
volScalarField case_4_F1_
dimensionedScalar alphaOmega1_
const volScalarField & nutRef() const
virtual tmp< scalarField > diffusionCoeffVar2(label patchI) const
Diffusion coeff at the boundary for omega.
volScalarField dnut_dk_
Nut Jacobian w.r.t. k.
tmp< volVectorField > divUMeanFlowSource(tmp< volScalarField > &divUMult) const
Contributions from the divU.
dimensionedScalar gamma1_
volScalarField case_2_GPrime_
tmp< volVectorField > dF1_dGradOmega(const volScalarField &arg1) const
F1 Jacobian wrt grad(omega)
volScalarField case_3_Pk_
virtual tmp< scalarField > topologySensitivities(const word &designVarsName) const
volVectorField gradOmega_
tmp< volScalarField > dnut_domega() const
Nut Jacobian wrt omega.
volScalarField case_1_nut_
tmp< volScalarField > DkEff(const volScalarField &F1) const
Return the effective diffusivity for k.
dimensionedScalar betaStar_
tmp< volScalarField > dF1_domega(const volScalarField &arg1) const
F1 Jacobian wrt omega (no contributions from grad(omega))
virtual bool read()
Read adjointRASProperties dictionary.
const volScalarField & omega() const
tmp< volScalarField > dF2_domega() const
F2 Jacobian wrt omega.
virtual tmp< volScalarField > nuEff() const
Return the effective viscosity.
incompressibleAdjointMeanFlowVars & adjointVars_
tmp< volScalarField > nu() const
Return the laminar viscosity.
virtual const volScalarField & nut() const
Return the turbulence viscosity.
incompressibleVars & primalVars_
Base class for solution control classes.
const volVectorField & U() const
Return const reference to velocity.
const surfaceScalarField & phi() const
Return const reference to volume flux.
const surfaceScalarField & phiInst() const
Return const reference to volume flux.
const autoPtr< incompressible::turbulenceModel > & turbulence() const
Return const reference to the turbulence model.
const autoPtr< incompressible::RASModelVariables > & RASModelVariables() const
Return const reference to the turbulence model variables.
Central-differencing interpolation scheme class.
The class nutWallFunction is an abstract base class that hosts calculation methods and common functi...
const wallFunctionCoefficients & wallCoeffs() const noexcept
Return wallFunctionCoefficients.
class for managing incompressible objective functions.
virtual void addTMEqn2Source(fvScalarMatrix &adjTMEqn2)=0
Add contribution to second adjoint turbulence model PDE.
virtual void addTMEqn1Source(fvScalarMatrix &adjTMEqn1)=0
Add contribution to first adjoint turbulence model PDE.
This boundary condition provides a wall function for the specific dissipation rate (i....
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
label nCells() const noexcept
Number of mesh cells.
Inversed weight central-differencing interpolation scheme class.
ITstream & divScheme(const word &name) const
Get div scheme for given name, or default.
bool printMaxMags() const
Print max mags of solver fields.
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &, const tmp< surfaceScalarField > &, const tmp< surfaceScalarField > &)
Return the face-interpolate of the given cell field.
A class for managing temporary objects.
void clear() const noexcept
static void setField(autoPtr< GeometricField< Type, fvPatchField, volMesh > > &fieldPtr, const fvMesh &mesh, const word &baseName, const word &solverName, const bool useSolverNameForFields)
Read vol fields.
const word & solverName() const
Return solver name.
bool useSolverNameForFields() const
Append solver name to fields?
static void nullifyField(GeometricField< Type, PatchField, GeoMesh > &fieldPtr)
Nullify field and old times, if present.
Class to host the wall-function coefficients being used in the wall function boundary conditions.
scalar kappa() const noexcept
Return the object: kappa.
scalar E() const noexcept
Return the object: E.
scalar yPlusLam() const noexcept
Return the object: yPlusLam.
scalar Cmu() const noexcept
Return the object: Cmu.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
tmp< surfaceScalarField > absolute(const tmp< surfaceScalarField > &tphi, const volVectorField &U)
Return the given relative flux in absolute form.
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
zeroField SuSp(const Foam::zero, const GeometricField< Type, fvPatchField, volMesh > &)
A no-op source.
zeroField Sp(const Foam::zero, const GeometricField< Type, fvPatchField, volMesh > &)
A no-op source.
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
dimensionedSymmTensor dev(const dimensionedSymmTensor &dt)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensionedScalar pos(const dimensionedScalar &ds)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
const dimensionSet dimless
Dimensionless.
dimensionedScalar pos0(const dimensionedScalar &ds)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
dimensionedScalar pow3(const dimensionedScalar &ds)
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
const dimensionSet dimArea(sqr(dimLength))
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
const dimensionSet dimVelocity
dimensionedScalar tanh(const dimensionedScalar &ds)
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
dimensionedScalar log(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
dimensionedScalar pow4(const dimensionedScalar &ds)
dimensionedScalar neg(const dimensionedScalar &ds)
static constexpr const zero Zero
Global zero (0)
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
dimensionedScalar neg0(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
dimensionedScalar pow025(const dimensionedScalar &ds)
#define forAll(list, i)
Loop across all elements in list.