67 bool (objective::*hasFunction)()
const
71 const PtrList<objective>& objectives =
72 adjointSolver_.getObjectiveManager().getObjectiveFunctions();
73 for (
const objective& func : objectives)
75 hasMult = hasMult || (func.*hasFunction)();
84 if (wallFaceSensNormalPtr_)
86 constructAndWriteSensitivityField<scalar>
88 wallFaceSensNormalPtr_,
89 "faceSensNormal" + suffix_
93 if (writeAllSurfaceFiles_)
96 if (wallFaceSensVecPtr_)
98 constructAndWriteSensitivityField<vector>
101 "faceSensVec" + suffix_
106 if (wallFaceSensNormalVecPtr_)
108 constructAndWriteSensitivityField<vector>
110 wallFaceSensNormalVecPtr_,
121 if (wallPointSensNormalPtr_)
123 constructAndWriteSensitivtyPointField<scalar>
125 wallPointSensNormalPtr_,
126 "pointSensNormal" + suffix_
133 if (writeAllSurfaceFiles_)
136 if (wallPointSensVecPtr_)
138 constructAndWriteSensitivtyPointField<vector>
140 wallPointSensVecPtr_,
141 "pointSensVec" + suffix_
146 if (wallPointSensNormalVecPtr_)
148 constructAndWriteSensitivtyPointField<vector>
150 wallPointSensNormalVecPtr_,
161 if (wallFaceSensVecPtr_)
165 if (wallFaceSensNormalVecPtr_)
169 if (wallFaceSensNormalPtr_)
171 wallFaceSensNormalPtr_() = scalar(0);
175 if (wallPointSensVecPtr_)
177 for (
vectorField& patchSens : wallPointSensVecPtr_())
182 if (wallPointSensNormalVecPtr_)
184 for (
vectorField& patchSens : wallPointSensNormalVecPtr_())
189 if (wallPointSensNormalPtr_)
191 for (
scalarField& patchSens : wallPointSensNormalPtr_())
193 patchSens = scalar(0);
208 mesh_.time().timeName(),
240 gradDxDbMult_() =
Zero;
243 divDxDbMult_() =
Zero;
247 eikonalSolver_->reset();
263 dxdbDirectMult_() =
Zero;
265 if (pointDxDbDirectMult_)
279Foam::ShapeSensitivitiesBase::ShapeSensitivitiesBase
295 writeAllSurfaceFiles_
297 dict.getOrDefault<bool>(
"writeAllSurfaceFiles", false)
299 wallFaceSensVecPtr_(nullptr),
300 wallFaceSensNormalPtr_(nullptr),
301 wallFaceSensNormalVecPtr_(nullptr),
303 wallPointSensVecPtr_(nullptr),
304 wallPointSensNormalPtr_(nullptr),
305 wallPointSensNormalVecPtr_(nullptr)
318 sensitivityPatchIDs_ =
319 mesh_.boundaryMesh().patchSet
321 dict_.optionalSubDict(mesh_.name()).
324 writeAllSurfaceFiles_ =
325 dict_.getOrDefault<
bool>(
"writeAllSurfaceFiles",
false);
327 if (includeDistance_)
331 eikonalSolver_().readDict(
dict);
335 allocateEikonalSolver();
356 adjointSolver_.accumulateGradDxDbMultiplier(gradDxDbMult_(), dt);
359 adjointSolver_.accumulateDivDxDbMultiplier(divDxDbMult_, dt);
362 adjointSolver_.accumulateOptionsDxDbMultiplier(optionsDxDbMult_(), dt);
367 eikonalSolver_->accumulateIntegrand(dt);
371 adjointSolver_.accumulateGeometryVariationsMultipliers
376 pointDxDbDirectMult_,
377 geometryVariationIntegrationPatches(),
406 if (wallFaceSensVecPtr_)
409 constructVolSensitivtyField<vector>
412 "faceSensVec" + suffix_
418 <<
" no faceSensVec boundary field. Returning zero" <<
endl;
426 "faceSensVec" + suffix_,
437 if (wallFaceSensNormalPtr_)
440 constructVolSensitivtyField<scalar>
442 wallFaceSensNormalPtr_,
443 "faceSensNormal" + suffix_
449 <<
" no wallFaceSensNormal boundary field. Returning zero" <<
endl;
457 "faceSensNormal" + suffix_,
dimless
467 if (wallFaceSensNormalVecPtr_)
470 constructVolSensitivtyField<vector>
472 wallFaceSensNormalVecPtr_,
473 "faceSensNormalVec" + suffix_
479 <<
" no wallFaceSensNormalVec boundary field. Returning zero"
488 "faceSensNormalVec" + suffix_,
499 tmp<volVectorField> tWallFaceSensVec = getWallFaceSensVec();
502 return (volPointInter.interpolate(tWallFaceSensVec));
512 return (volPointInter.interpolate(tWallFaceSensNormal));
522 return (volPointInter.interpolate(tWallFaceSensNormalVec));
543 return wallFaceSensNormalVecPtr_();
Macros for easy insertion into run-time selection tables.
@ 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,...
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Base class supporting Shape sensitivity derivatives.
tmp< volVectorField > getWallFaceSensVec()
Get wall face sensitivity vectors field.
autoPtr< pointBoundaryVectorField > wallPointSensNormalVecPtr_
Normal sens as vectors.
void clearSensitivities()
Zero sensitivity fields and their constituents.
bool hasMultiplier(bool(objective::*hasFunction)() const)
Check if any of the available objective has a certain multiplier, provided through a function object.
bool writeAllSurfaceFiles_
Whether to write all surface sensitivity fields.
tmp< volVectorField > getWallFaceSensNormalVec()
Get wall face normal sens as vectors field.
autoPtr< boundaryVectorField > wallFaceSensVecPtr_
Wall face sens w.r.t. (x,y.z).
labelHashSet sensitivityPatchIDs_
Patches on which to compute shape sensitivities.
virtual const boundaryScalarField & getWallFaceSensNormalBoundary() const
Get wall face sensitivity projected to normal field.
virtual const boundaryVectorField & getWallFaceSensNormalVecBoundary() const
Get wall face normal sens as vectors field.
void writeFaceBasedSens() const
Write face-based sensitivities, if present.
void writePointBasedSens() const
Write point-based sensitivities, if present.
virtual const boundaryVectorField & getWallFaceSensVecBoundary() const
Get wall face sensitivity vectors field.
autoPtr< pointBoundaryVectorField > wallPointSensVecPtr_
Wall point sens w.r.t. (x,y.z).
tmp< pointVectorField > getWallPointSensVec()
Get wall point sensitivity vectors field.
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
virtual bool readDict(const dictionary &dict)
Read dict if changed.
tmp< pointScalarField > getWallPointSensNormal()
Get wall point sensitivity projected to normal field.
void allocateEikonalSolver()
Allocate the adjoint eikonal solver.
void clearSurfaceFields()
Clear surface/point fields.
tmp< GeometricField< Type, fvPatchField, volMesh > > constructVolSensitivtyField(const autoPtr< typename GeometricField< Type, fvPatchField, volMesh >::Boundary > &sensFieldPtr, const word &name) const
Constructs volField based on boundaryField and writes it.
void allocateMultipliers()
Allocate multiplier fields.
tmp< pointVectorField > getWallPointSensNormalVec()
Get wall point sens as vectors field.
autoPtr< pointBoundaryScalarField > wallPointSensNormalPtr_
Wall point sens projected to normal.
tmp< volScalarField > getWallFaceSensNormal()
Get wall face sensitivity projected to normal field.
void constructAndWriteSensitivityField(const autoPtr< typename GeometricField< Type, fvPatchField, volMesh >::Boundary > &sensFieldPtr, const word &name) const
Constructs volField based on boundaryField and writes it.
autoPtr< boundaryScalarField > wallFaceSensNormalPtr_
Wall face sens projected to normal.
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
void constructAndWriteSensitivtyPointField(const autoPtr< List< Field< Type > > > &sensFieldPtr, const word &name) const
Constructs pointField based on boundaryField and writes it.
autoPtr< boundaryVectorField > wallFaceSensNormalVecPtr_
Normal sens as vectors.
virtual const labelHashSet & geometryVariationIntegrationPatches() const
Return set of patches on which to compute direct sensitivities.
void clearMultipliers()
Clear multipliers.
Solver of the adjoint to the eikonal PDE.
Abstract base class for adjoint-based sensitivities.
autoPtr< scalarField > divDxDbMult_
Multiplier of div(dx/db).
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
bool includeDistance_
Include distance variation in sensitivity computations.
autoPtr< boundaryVectorField > dxdbDirectMult_
Multiplier of dCf/db, found in the objective function.
autoPtr< pointBoundaryVectorField > pointDxDbDirectMult_
Multiplier of dx/db computed at points, found in the objective function.
autoPtr< adjointEikonalSolver > eikonalSolver_
Adjoint eikonal equation solver.
autoPtr< boundaryVectorField > bcDxDbMult_
Multiplier of dx/db, coming from boundary conditions that depend on the geometry, like rotatingWallVe...
adjointSolver & adjointSolver_
Reference to the underlaying adjoint solver.
autoPtr< vectorField > optionsDxDbMult_
dx/db multiplier coming from fvOptions
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
autoPtr< boundaryVectorField > dxdbMult_
Multiplier of face dx/db.
autoPtr< boundaryVectorField > dnfdbMult_
Multiplier of dnf/db.
autoPtr< boundaryVectorField > dSfdbMult_
Multiplier of dSf/db.
autoPtr< volTensorField > gradDxDbMult_
Multiplier of grad(dx/b).
word suffix_
Append this word to files related to the sensitivities.
Base class for adjoint solvers.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Mesh data needed to do the Finite Volume discretisation.
A class for handling keywords in dictionaries.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
bool hasdSdbMult() const noexcept
bool hasdndbMult() const noexcept
bool hasDivDxDbMult() const noexcept
bool hasdxdbDirectMult() const noexcept
const fvMesh & mesh() const
Return reference to mesh.
const dictionary & dict() const
Return the construction dictionary.
A class for managing temporary objects.
Interpolate from cell centres to points (vertices) using inverse distance weighting.
tmp< GeometricField< Type, pointPatchField, pointMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &) const
Interpolate volField using inverse distance weighting.
A List of wordRe with additional matching capabilities.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define WarningInFunction
Report a warning using Foam::Warning.
volScalarField::Boundary boundaryScalarField
volFields
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)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
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)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
autoPtr< typename GeometricField< Type, fvPatchField, volMesh >::Boundary > createZeroBoundaryPtr(const fvMesh &mesh, bool printAllocation=false)
volVectorField::Boundary boundaryVectorField
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.