64 for (
const label patchI : sensitivityPatchIDs)
87Foam::incompressibleAdjointSolver::incompressibleAdjointSolver
90 const word& managerType,
92 const word& primalSolverName,
93 const word& solverName
96 adjointSolver(
mesh, managerType,
dict, primalSolverName, solverName),
99 mesh.lookupObjectRef<incompressiblePrimalSolver>(primalSolverName).
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)
198 return getAdjointVars().adjointTurbulence()->distanceSensitivities();
220 ATCModel_().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];
268 tmp<vectorField> tnf = mesh_.boundary()[patchI].nf();
269 gradUbf[patchI] = tnf*
U.boundaryField()[patchI].snGrad();
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());
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;
364 for (
const label patchI : sensitivityPatchIDs)
366 const scalarField magSfDt(mesh_.boundary()[patchI].magSf()*dt);
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;
395 if (!hasBCdxdbMult(sensitivityPatchIDs))
403 getAdjointVars().adjointTurbulence();
407 turbVars = primalVars_.RASModelVariables();
415 auto& UaBoundary = getAdjointVars().Ua().boundaryFieldRef(
false);
416 auto& nuEffBoundary = nuEff.boundaryField();
418 for (
const label patchI : sensitivityPatchIDs)
432 nuEffBoundary[patchI]
433 *(Uab.snGrad() + (gradUabf[patchI] & tnf))
435 + adjointTurbulence().adjointMomentumBCSource()[patchI];
436 bcDxDbMult()[patchI] += (DvDbMult & dxdbMult())*magSf*dt;
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(),
506 (adjointTurbulence->topologySensitivities(designVariablesName))*dt;
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())
521 betaMult += weight*betaSens*dt;
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
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())
tmp< GeometricField< Type, PatchField, GeoMesh > > T() const
Return transpose (only if it is a tensor field).
Internal & ref(const bool updateAccessTime=true)
Same as internalFieldRef().
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
GeometricBoundaryField< tensor, fvPatchField, volMesh > Boundary
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
void correctBoundaryConditions()
Correct boundary field.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & name() const noexcept
Return the object name.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
SubField is a Field obtained as a section of another Field, without its own allocation....
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
bool bad() const noexcept
True if the Switch does not represent a valid enumeration.
virtual tmp< Field< typename Foam::outerProduct< Foam::vector, Type >::type > > dxdbMult() const
Return contribution to sensitivity derivatives.
Base class for adjoint solvers.
objectiveManager objectiveManager_
Object to manage objective functions.
const word & primalSolverName() const
Return the primal solver name.
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,...
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Mesh data needed to do the Finite Volume discretisation.
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
void postProcessSens(Field< Type > &sensField, const word &fieldName=word::null, const word &designVariablesName=word::null)
Post process sensitivity field related to the fvOption.
Finite-volume options, which is an IOdictionary of values and a fv::optionList.
static options & New(const fvMesh &mesh)
Construct fvOptions and register to database if not present otherwise lookup and return.
const volVectorField & Ua() const
Return const reference to velocity.
const volVectorField & UaInst() const
Return const reference to velocity.
const volScalarField & paInst() const
Return const reference to pressure.
Base class for incompressibleAdjoint solvers.
autoPtr< ATCModel > ATCModel_
Adjoint Transpose Convection options.
bool hasBCdxdbMult(const labelHashSet &sensitivityPatchIDs)
Compute, if necessary, and return the hasBCdxdbMult_ bool.
virtual tmp< volScalarField > yWall() const
Return the distance field, to be used in the solution of the adjoint eikonal PDE.
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.
const incompressibleVars & getPrimalVars() const
Access to the incompressible primal variables set.
virtual tmp< volScalarField > adjointEikonalSource()
Return the source the adjoint eikonal equation.
const autoPtr< ATCModel > & getATCModel() const
Access to the ATC model.
virtual dimensionSet daDimensions() const
Return the dimensions of the adjoint distance field.
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...
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 bool includeDistance() const
Should the adjoint to the eikonal equation be solved.
virtual void updatePrimalBasedQuantities()
Update primal based quantities, e.g. the primal fields in adjoint turbulence models.
virtual void accumulateGradDxDbMultiplier(volTensorField &gradDxDbMult, const scalar dt)
Compute the multiplier for grad(dxdb).
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...
virtual void topOSensMultiplier(scalarField &betaMult, const word &designVariablesName, const scalar dt)
Compute the multiplier of beta.
Switch hasBCdxdbMult_
Auxiliary bool to avoid a potentially expensive part of the sensitivity computation.
virtual void accumulateOptionsDxDbMultiplier(vectorField &optionsDxDbMult, const scalar dt)
Contributions from fvOptions that inlcude geometric aspects in them and change when the geometry is d...
virtual dimensionSet maDimensions() const
Return the dimensions of the adjoint grid displacement variable.
incompressibleVars & primalVars_
Primal variable set.
Class including all adjoint fields for incompressible flows.
const autoPtr< incompressibleAdjoint::adjointRASModel > & adjointTurbulence() const
Return const reference to the adjointRASModel.
Base class for primal incompressible solvers.
Base class for solution control classes.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
static void postProcessSens(scalarField &sens, scalarField &auxSens, fv::options &fvOptions, const word &fieldName, const word &designVariablesName)
Add part of the sensitivities coming from fvOptions.
A simple single-phase transport model based on viscosityModel.
virtual tmp< volScalarField > nu() const
Return the laminar viscosity.
autoPtr< variablesSet > vars_
Base variableSet pointer.
const word & managerType() const
Return the manager type.
const dictionary & dict() const
Return the solver dictionary.
const fvMesh & mesh() const
Return the solver mesh.
const word & solverName() const
Return the solver name.
fvMesh & mesh_
Reference to the mesh database.
A class for managing temporary objects.
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Base class for creating a set of variables.
const word & solverName() const
Return solver name.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Namespace for handling debugging switches.
const std::string patch
OpenFOAM patch number as a std::string.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
GeometricField< vector, fvPatchField, volMesh > volVectorField
const dimensionSet dimless
Dimensionless.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
dimensionedScalar pow3(const dimensionedScalar &ds)
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Field< vector > vectorField
Specialisation of Field<T> for vector.
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).
adjointBoundaryCondition< vector > adjointVectorBoundaryCondition
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
errorManipArg< error, int > exit(error &err, const int errNo=1)
fvPatchField< vector > fvPatchVectorField
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
Calculation of adjoint based sensitivities for topology optimisation. This returns just the field par...
#define forAll(list, i)
Loop across all elements in list.