48 objectiveIncompressible,
54objectiveIncompressible::objectiveIncompressible
58 const word& adjointSolverName,
59 const word& primalSolverName
62 objective(
mesh,
dict, adjointSolverName, primalSolverName),
102 const word& adjointSolverName,
103 const word& primalSolverName
108 Info<<
"Creating objective function : " <<
dict.dictName()
109 <<
" of type " << modelType <<
endl;
111 auto* ctorPtr = dictionaryConstructorTable(modelType);
118 "objectiveIncompressible",
120 *dictionaryConstructorTablePtr_
124 return autoPtr<objectiveIncompressible>
126 ctorPtr(
mesh,
dict, adjointSolverName, primalSolverName)
141 dJdvPtr_().primitiveFieldRef() *= oneOverNorm;
145 dJdpPtr_().primitiveFieldRef() *= oneOverNorm;
149 dJdTPtr_().primitiveFieldRef() *= oneOverNorm;
309 const incompressiblePrimalSolver& primSolver =
311 const autoPtr<incompressible::RASModelVariables>& rasVars =
312 primSolver.getIncoVars().RASModelVariables();
314 if (rasVars().hasTMVar1())
316 const dimensionSet primalVarDims = rasVars->TMVar1Inst().dimensions();
328 if (rasVars().hasTMVar2())
330 const dimensionSet primalVarDims = rasVars->TMVar2Inst().dimensions();
355 reduce(nCells, sumOp<label>());
359 <<
"Provided cellZones include no cells"
367 autoPtr<volScalarField>& dJdTMvarPtr,
369 (incompressibleAdjoint::adjointRASModel::*JacobianFunc)()
const,
374 if (dJdTMvarPtr.good())
382 const incompressibleAdjointSolver& adjSolver =
385 const autoPtr<incompressibleAdjoint::adjointRASModel>& adjointRAS =
386 adjSolver.getAdjointVars().adjointTurbulence();
388 tmp<volScalarField> tnutJacobian = (adjointRAS->*JacobianFunc)();
393 for (
const label zI : zones)
396 for (
const label cellI : zoneI)
399 JacobianMultiplier[cellI]*nutJacobian[cellI];
406 <<
"Skipping the computation of nutJacobian until "
407 <<
"the adjoint solver is complete"
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
const word & name() const noexcept
Return the object name.
label size() const noexcept
The number of entries in the list.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
bool good() const noexcept
True if the managed pointer is non-null.
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...
const GeometricField< Type, fvPatchField, volMesh > & psi(const label i=0) const
Return psi.
Mesh data needed to do the Finite Volume discretisation.
Base class for incompressibleAdjoint solvers.
virtual const incompressibleAdjointVars & getAdjointVars() const
Access to the incompressible adjoint variables set.
const autoPtr< incompressibleAdjoint::adjointRASModel > & adjointTurbulence() const
Return const reference to the adjointRASModel.
Abstract base class for incompressible turbulence models.
Base class for primal incompressible solvers.
const incompressibleVars & getIncoVars() const
Access to the incompressible variables set.
const autoPtr< incompressible::RASModelVariables > & RASModelVariables() const
Return const reference to the turbulence model variables.
bool foundObject(const word &name, const bool recursive=false) const
Contains the named Type?
const Type & lookupObject(const word &name, const bool recursive=false) const
Lookup and return const reference to the object of the given Type. Fatal if not found or the wrong ty...
Abstract base class for objective functions in incompressible flows.
bool hasdJdp() const noexcept
autoPtr< volScalarField > dJdTMvar2Ptr_
Second turbulence model variable.
virtual void update_boundarydJdTMvar2()
static autoPtr< objectiveIncompressible > New(const fvMesh &mesh, const dictionary &dict, const word &adjointSolverName, const word &primalSolverName)
Return a reference to the selected turbulence model.
virtual void update_dJdTMvar1()
virtual bool write(const bool valid=true) const
Write objective function history.
bool hasdJdv() const noexcept
Inline functions for checking whether pointers are set or not.
bool hasdJdT() const noexcept
autoPtr< boundaryTensorField > bdJdGradUPtr_
Term multiplying gradU variations.
autoPtr< boundaryScalarField > bdJdTMvar2Ptr_
Adjoint outlet turbulence model var 2.
virtual void update_boundarydJdvt()
autoPtr< volScalarField > dJdpPtr_
bool hasBoundarydJdv() const noexcept
void update_dJdTMvar(autoPtr< volScalarField > &dJdTMvarPtr, tmp< volScalarField >(incompressibleAdjoint::adjointRASModel::*JacobianFunc)() const, const volScalarField &JacobianMultiplier, const labelList &zones)
Compute dJdTMVar{1,2}.
bool hasBoundarydJdvn() const noexcept
virtual void addSource(fvVectorMatrix &matrix)
Vector sources can be given only to the adjoint momentum equations. Implemented in base objectiveInco...
void allocatedJdTurbulence()
Allocate fields related to the differentiation of turbulence models, if necessary.
virtual void update_dJdTMvar2()
virtual void update_dJdv()
Update vol and boundary fields and derivatives.
virtual void nullify()
Update objective function derivatives.
const volVectorField & dJdv()
Contribution to field adjoint momentum eqs.
bool hasBoundarydJdT() const noexcept
virtual void update_boundarydJdp()
virtual void update_meanValues()
Some objectives need to store some auxiliary values. If averaging is enabled, update these mean value...
autoPtr< volScalarField > dJdTMvar1Ptr_
First turbulence model variable.
autoPtr< boundaryScalarField > bdJdTMvar1Ptr_
Adjoint outlet turbulence model var 1.
bool hasdJdTMVar1() const noexcept
virtual void update_boundarydJdTMvar1()
autoPtr< boundaryScalarField > bdJdnutPtr_
Jacobian wrt to nut.
autoPtr< boundaryScalarField > bdJdTPtr_
Adjoint outlet temperature.
autoPtr< boundaryScalarField > bdJdvnPtr_
Adjoint outlet pressure.
virtual void update_boundarydJdGradU()
bool hasdJdTMVar2() const noexcept
autoPtr< volScalarField > dJdTPtr_
autoPtr< boundaryVectorField > bdJdpPtr_
Adjoint (intlet,wall) velocity.
virtual void doNormalization()
Normalize all fields allocated by the objective.
virtual void update_boundarydJdnut()
virtual void update()
Update objective function derivatives.
virtual void update_boundarydJdv()
virtual void update_dJdT()
bool hasBoundarydJdTMVar2() const noexcept
autoPtr< boundaryVectorField > bdJdvtPtr_
Adjoint outlet velocity.
bool hasBoundarydJdTMVar1() const noexcept
const incompressibleVars & vars_
bool hasBoundarydJdGradU() const noexcept
virtual void update_boundarydJdvn()
autoPtr< boundaryVectorField > bdJdvPtr_
bool hasBoundarydJdnut() const noexcept
void checkCellZonesSize(const labelList &zoneIDs) const
Check if cellZones provided include at least one cell.
bool hasBoundarydJdp() const noexcept
virtual void update_boundarydJdT()
virtual void update_dJdp()
autoPtr< volVectorField > dJdvPtr_
bool hasBoundarydJdvt() const noexcept
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
virtual bool write(const bool valid=true) const
Write objective function history.
virtual void update()=0
Update objective function derivatives.
wordList fieldNames_
List of adjoint fields for which this objective will contribute sources to their equations.
virtual scalar weight() const
Return the objective function weight.
virtual void nullify()
Nullify adjoint contributions.
autoPtr< scalar > normFactor_
Normalization factor.
virtual void doNormalization()
Normalize all fields allocated by the objective.
const dictionary & dict() const
Return objective dictionary.
const word primalSolverName_
bool computed_
Whether the objective is computed or not.
const word adjointSolverName_
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
A class for managing temporary objects.
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.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const labelIOList & zoneIDs
#define WarningInFunction
Report a warning using Foam::Warning.
List< label > labelList
A List of labels.
dimensionedScalar pow3(const dimensionedScalar &ds)
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
const dimensionSet dimArea(sqr(dimLength))
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
fvMatrix< vector > fvVectorMatrix
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
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).
autoPtr< GeometricField< Type, fvPatchField, volMesh > > createZeroFieldPtr(const fvMesh &mesh, const word &name, const dimensionSet dims, bool printAllocation=false)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.