47 incompressibleAdjointSolver,
64 for (
const label patchI : sensitivityPatchIDs)
67 if (isA<adjointVectorBoundaryCondition>(Uab))
70 refCast<adjointVectorBoundaryCondition>
87 Foam::incompressibleAdjointSolver::incompressibleAdjointSolver
90 const word& managerType,
92 const word& primalSolverName,
93 const word& solverName
103 hasBCdxdbMult_(
Switch::INVALID)
113 const word& managerType,
115 const word& primalSolverName,
116 const word& solverName
120 auto* ctorPtr = dictionaryConstructorTable(solverType);
127 "incompressibleAdjointSolver",
129 *dictionaryConstructorTablePtr_
134 autoPtr<incompressibleAdjointSolver>
136 ctorPtr(
mesh, managerType,
dict, primalSolverName, solverName)
155 refCast<incompressibleAdjointVars>(
const_cast<variablesSet&
>(vars_()));
164 refCast<incompressibleAdjointVars>(
const_cast<variablesSet&
>(vars_()));
179 return getAdjointVars().adjointTurbulence()->includeDistance();
198 return getAdjointVars().adjointTurbulence()->distanceSensitivities();
205 return getPrimalVars().RASModelVariables()->d();
219 getAdjointVars().adjointTurbulence()->setChangedPrimalSolution();
220 ATCModel_().updatePrimalBasedQuantities();
221 getAdjointVars().updatePrimalBasedQuantities();
239 autoPtr<incompressibleAdjoint::adjointRASModel>& adjointRAS
241 getAdjointVars().adjointTurbulence()
256 tmp<volTensorField> tgradU =
263 forAll(mesh_.boundary(), patchI)
265 const fvPatch&
patch = mesh_.boundary()[patchI];
266 if (isA<wallFvPatch>(
patch))
268 tmp<vectorField> tnf = mesh_.boundary()[patchI].nf();
269 gradUbf[patchI] = tnf*
U.boundaryField()[patchI].snGrad();
273 tmp<volScalarField> tnuEff = adjointRAS->nuEff();
274 tmp<volSymmTensorField> stress = tnuEff()*
twoSymm(gradU);
275 tmp<volTensorField> tgradUa =
fvc::grad(Ua);
285 mesh_.time().timeName(),
297 flowTerm = - tnuEff*(gradU &
twoSymm(tgradUa()));
299 flowTerm +=
fvc::grad(Ua & stress()) - (tgradUa & stress());
307 ATCModel_->getFISensitivityTerm()
312 flowTerm += pa*tgradU;
315 flowTerm +=
T(adjointRAS->FISensitivityTerm());
318 PtrList<objective>& functions = objectiveManager_.getObjectiveFunctions();
320 for (objective& objI : functions)
322 if (objI.hasGradDxDbMult())
324 flowTerm += objI.weight()*objI.gradDxDbMultiplier();
328 flowTerm.correctBoundaryConditions();
330 gradDxDbMult += flowTerm.T()*dt;
344 if (func.hasDivDxDbMult())
347 func.weight()*func.divDxDbMultiplier().primitiveField()*dt;
355 autoPtr<boundaryVectorField>& dSfdbMult,
356 autoPtr<boundaryVectorField>& dnfdbMult,
357 autoPtr<boundaryVectorField>& dxdbDirectMult,
358 autoPtr<pointBoundaryVectorField>& pointDxDbDirectMult,
363 PtrList<objective>& functions = objectiveManager_.getObjectiveFunctions();
364 for (
const label patchI : sensitivityPatchIDs)
366 const scalarField magSfDt(mesh_.boundary()[patchI].magSf()*dt);
367 for (objective& func : functions)
369 const scalar wei = func.weight();
370 if (func.hasdSdbMult())
372 dSfdbMult()[patchI] += wei*func.dSdbMultiplier(patchI)*dt;
374 if (func.hasdndbMult())
376 dnfdbMult()[patchI] += wei*func.dndbMultiplier(patchI)*magSfDt;
378 if (func.hasdxdbDirectMult())
380 dxdbDirectMult()[patchI] +=
381 wei*func.dxdbDirectMultiplier(patchI)*magSfDt;
390 autoPtr<boundaryVectorField>& bcDxDbMult,
395 if (!hasBCdxdbMult(sensitivityPatchIDs))
402 const autoPtr<incompressibleAdjoint::adjointRASModel>& adjointTurbulence =
403 getAdjointVars().adjointTurbulence();
406 const autoPtr<incompressible::RASModelVariables>&
407 turbVars = primalVars_.RASModelVariables();
408 const singlePhaseTransportModel& lamTransp = primalVars_.laminarTransport();
410 tmp<volTensorField> tgradUa =
fvc::grad(Ua);
415 auto& UaBoundary = getAdjointVars().Ua().boundaryFieldRef(
false);
416 auto& nuEffBoundary = nuEff.boundaryField();
418 for (
const label patchI : sensitivityPatchIDs)
421 if (isA<adjointVectorBoundaryCondition>(Uab))
423 tmp<tensorField> dxdbMult =
424 refCast<adjointVectorBoundaryCondition>(Uab).dxdbMult();
427 const fvPatch&
patch = mesh_.boundary()[patchI];
428 tmp<vectorField> tnf =
patch.nf();
431 tmp<vectorField> DvDbMult =
432 nuEffBoundary[patchI]
433 *(Uab.snGrad() + (gradUabf[patchI] & tnf))
435 + adjointTurbulence().adjointMomentumBCSource()[patchI];
436 bcDxDbMult()[patchI] += (DvDbMult & dxdbMult())*magSf*dt;
450 const incompressibleAdjointVars& av = getAdjointVars();
454 temp, av.UaInst().name(), av.solverName()
456 optionsDxDbMult += temp*dt;
460 temp, av.paInst().name(), av.solverName()
462 optionsDxDbMult += temp*dt;
469 const word& designVariablesName,
483 (betaMult, momSens,
fvOptions,
U.name(), designVariablesName);
490 "IvSens" + solverName(),
491 mesh_.time().timeName(),
509 PtrList<objective>& functions = objectiveManager_.getObjectiveFunctions();
510 for (objective& objI : functions)
512 const scalar weight(objI.weight());
515 betaMult += weight*objI.dJdb()*dt;
518 if (objI.hasdJdbField())
520 SubField<scalar> betaSens(objI.dJdbField(), mesh_.nCells(), 0);
521 betaMult += weight*betaSens*dt;
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
bool hasBCdxdbMult(const labelHashSet &sensitivityPatchIDs)
Compute, if necessary, and return the hasBCdxdbMult_ bool.
fvPatchField< vector > fvPatchVectorField
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool bad() const noexcept
True if the Switch does not represent a valid enumeration.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
virtual void accumulateDivDxDbMultiplier(autoPtr< scalarField > &divDxDbMult, const scalar dt)
Compute the multiplier for div(dxdb)
virtual const incompressibleAdjointVars & getAdjointVars() const
Access to the incompressible adjoint variables set.
virtual void accumulateGradDxDbMultiplier(volTensorField &gradDxDbMult, const scalar dt)
Compute the multiplier for grad(dxdb)
void postProcessSens(Field< Type > &sensField, const word &fieldName=word::null, const word &designVariablesName=word::null)
Post process sensitivity field related to the fvOption.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const incompressibleVars & getPrimalVars() const
Access to the incompressible primal variables set.
virtual void updatePrimalBasedQuantities()
Update primal based quantities, e.g. the primal fields in adjoint turbulence models.
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
Base class for adjoint solvers.
GeometricBoundaryField< tensor, fvPatchField, volMesh > Boundary
Type of boundary fields.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
virtual bool includeDistance() const
Should the adjoint to the eikonal equation be solved.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
GeometricField< vector, fvPatchField, volMesh > volVectorField
Macros for easy insertion into run-time selection tables.
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Class including all adjoint fields for incompressible flows.
#define forAll(list, i)
Loop across all elements in list.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Base class for solution control classes.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual void accumulateBCSensitivityIntegrand(autoPtr< boundaryVectorField > &bcDxDbMult, const labelHashSet &sensitivityPatchIDs, const scalar dt)
Contributions from boundary functions that inlcude geometric aspects in them and change when the geom...
static autoPtr< incompressibleAdjointSolver > New(fvMesh &mesh, const word &managerType, const dictionary &dict, const word &primalSolverName, const word &solverName)
Return a reference to the selected incompressible adjoint solver.
virtual dimensionSet maDimensions() const
Return the dimensions of the adjoint grid displacement variable.
const volVectorField & Ua() const
Return const reference to velocity.
Switch hasBCdxdbMult_
Auxiliary bool to avoid a potentially expensive part of the sensitivity computation.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
const autoPtr< incompressibleAdjoint::adjointRASModel > & adjointTurbulence() const
Return const reference to the adjointRASModel.
Calculation of adjoint based sensitivities for topology optimisation. This returns just the field par...
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
static tmp< GeometricField< tensor, fvPatchField, volMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=fvPatchField< tensor >::calculatedType())
Return tmp field (NO_READ, NO_WRITE) from name, mesh, dimensions and patch type. [Takes current timeN...
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const autoPtr< ATCModel > & getATCModel() const
Access to the ATC model.
static void postProcessSens(scalarField &sens, scalarField &auxSens, fv::options &fvOptions, const word &fieldName, const word &designVariablesName)
Add part of the sensitivities coming from fvOptions.
Base class for creating a set of variables.
dimensionedScalar pow3(const dimensionedScalar &ds)
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
virtual tmp< scalarField > topologySensitivities(const word &designVarsName) const =0
Term contributing to the computation of topology optimisation sensitivities.
virtual tmp< volScalarField > yWall() const
Return the distance field, to be used in the solution of the adjoint eikonal PDE. ...
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
virtual void topOSensMultiplier(scalarField &betaMult, const word &designVariablesName, const scalar dt)
Compute the multiplier of beta.
Base class for solution control classes.
virtual tmp< volScalarField > adjointEikonalSource()
Return the source the adjoint eikonal equation.
Mesh data needed to do the Finite Volume discretisation.
virtual dimensionSet daDimensions() const
Return the dimensions of the adjoint distance field.
const std::string patch
OpenFOAM patch number as a std::string.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Internal & ref(const bool updateAccessTime=true)
Same as internalFieldRef()
Field< vector > vectorField
Specialisation of Field<T> for vector.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
virtual void accumulateGeometryVariationsMultipliers(autoPtr< boundaryVectorField > &dSfdbMult, autoPtr< boundaryVectorField > &dnfdbMult, autoPtr< boundaryVectorField > &dxdbDirectMult, autoPtr< pointBoundaryVectorField > &pointDxDirectDbMult, const labelHashSet &sensitivityPatchIDs, const scalar dt)
Accumulate the multipliers of geometric quantities defined at the boundary, usually through an object...
Base class for primal incompressible solvers.
A class for managing temporary objects.
static options & New(const fvMesh &mesh)
Construct fvOptions and register to database if not present.
virtual void accumulateOptionsDxDbMultiplier(vectorField &optionsDxDbMult, const scalar dt)
Contributions from fvOptions that inlcude geometric aspects in them and change when the geometry is d...
Defines the attributes of an object for which implicit objectRegistry management is supported...
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0)