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_,
111 "faceSensNormalVec" + suffix_
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_,
151 "pointSensNormalVec" + suffix_
161 if (wallFaceSensVecPtr_)
163 wallFaceSensVecPtr_() = vector::zero;
165 if (wallFaceSensNormalVecPtr_)
167 wallFaceSensNormalVecPtr_() = vector::zero;
169 if (wallFaceSensNormalPtr_)
171 wallFaceSensNormalPtr_() = scalar(0);
175 if (wallPointSensVecPtr_)
177 for (
vectorField& patchSens : wallPointSensVecPtr_())
179 patchSens = vector::zero;
182 if (wallPointSensNormalVecPtr_)
184 for (
vectorField& patchSens : wallPointSensNormalVecPtr_())
186 patchSens = vector::zero;
189 if (wallPointSensNormalPtr_)
191 for (
scalarField& patchSens : wallPointSensNormalPtr_())
193 patchSens = scalar(0);
208 mesh_.time().timeName(),
223 dSfdbMult_.reset(createZeroBoundaryPtr<vector>(mesh_));
227 dnfdbMult_.reset(createZeroBoundaryPtr<vector>(mesh_));
231 dxdbDirectMult_.reset(createZeroBoundaryPtr<vector>(mesh_));
233 bcDxDbMult_.reset(createZeroBoundaryPtr<vector>(mesh_));
243 divDxDbMult_() =
Zero;
247 eikonalSolver_->reset();
263 dxdbDirectMult_() =
Zero;
265 if (pointDxDbDirectMult_)
272 bcDxDbMult_() =
Zero;
279 Foam::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();
349 return sensitivityPatchIDs_;
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(),
382 adjointSolver_.accumulateBCSensitivityIntegrand
383 (bcDxDbMult_, geometryVariationIntegrationPatches(), dt);
390 clearSurfaceFields();
398 writeFaceBasedSens();
399 writePointBasedSens();
406 if (wallFaceSensVecPtr_)
409 constructVolSensitivtyField<vector>
412 "faceSensVec" + suffix_
418 <<
" no faceSensVec boundary field. Returning zero" <<
endl;
423 createZeroFieldPtr<vector>
426 "faceSensVec" + suffix_,
437 if (wallFaceSensNormalPtr_)
440 constructVolSensitivtyField<scalar>
442 wallFaceSensNormalPtr_,
443 "faceSensNormal" + suffix_
449 <<
" no wallFaceSensNormal boundary field. Returning zero" <<
endl;
454 createZeroFieldPtr<scalar>
457 "faceSensNormal" + suffix_,
dimless 467 if (wallFaceSensNormalVecPtr_)
470 constructVolSensitivtyField<vector>
472 wallFaceSensNormalVecPtr_,
473 "faceSensNormalVec" + suffix_
479 <<
" no wallFaceSensNormalVec boundary field. Returning zero" 485 createZeroFieldPtr<vector>
488 "faceSensNormalVec" + suffix_,
499 tmp<volVectorField> tWallFaceSensVec = getWallFaceSensVec();
502 return (volPointInter.interpolate(tWallFaceSensVec));
512 return (volPointInter.interpolate(tWallFaceSensNormal));
522 return (volPointInter.interpolate(tWallFaceSensNormalVec));
529 return wallFaceSensVecPtr_();
536 return wallFaceSensNormalPtr_();
543 return wallFaceSensNormalVecPtr_();
tmp< pointScalarField > getWallPointSensNormal()
Get wall point sensitivity projected to normal field.
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
A class for handling keywords in dictionaries.
void writeFaceBasedSens() const
Write face-based sensitivities, if present.
tmp< volVectorField > getWallFaceSensVec()
Get wall face sensitivity vectors field.
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
void allocateEikonalSolver()
Allocate the adjoint eikonal solver.
adjointSolver & adjointSolver_
Reference to the underlaying adjoint solver.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Abstract base class for adjoint-based sensitivities.
bool hasdxdbDirectMult() const noexcept
tmp< volVectorField > getWallFaceSensNormalVec()
Get wall face normal sens as vectors field.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
dimensionedSymmTensor sqr(const dimensionedVector &dv)
bool hasdndbMult() const noexcept
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
Base class for adjoint solvers.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
Macros for easy insertion into run-time selection tables.
void clearSurfaceFields()
Clear surface/point fields.
virtual const boundaryVectorField & getWallFaceSensNormalVecBoundary() const
Get wall face normal sens as vectors field.
virtual const boundaryVectorField & getWallFaceSensVecBoundary() const
Get wall face sensitivity vectors field.
bool hasdSdbMult() const noexcept
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
tmp< pointVectorField > getWallPointSensNormalVec()
Get wall point sens as vectors field.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual const boundaryScalarField & getWallFaceSensNormalBoundary() const
Get wall face sensitivity projected to normal field.
virtual bool readDict(const dictionary &dict)
Read dict if changed.
A List of wordRe with additional matching capabilities.
void writePointBasedSens() const
Write point-based sensitivities, if present.
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
virtual const labelHashSet & geometryVariationIntegrationPatches() const
Return set of patches on which to compute direct sensitivities.
Interpolate from cell centres to points (vertices) using inverse distance weighting.
tmp< volScalarField > getWallFaceSensNormal()
Get wall face sensitivity projected to normal field.
tmp< pointVectorField > getWallPointSensVec()
Get wall point sensitivity vectors field.
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
defineTypeNameAndDebug(combustionModel, 0)
Base class supporting Shape sensitivity derivatives.
const dictionary & dict() const
Return the construction dictionary.
dimensionedScalar pow3(const dimensionedScalar &ds)
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
bool includeDistance_
Include distance variation in sensitivity computations.
void clearSensitivities()
Zero sensitivity fields and their constituents.
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Mesh data needed to do the Finite Volume discretisation.
void clearMultipliers()
Clear multipliers.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
bool hasDivDxDbMult() const noexcept
autoPtr< adjointEikonalSolver > eikonalSolver_
Adjoint eikonal equation solver.
Field< vector > vectorField
Specialisation of Field<T> for vector.
A class for managing temporary objects.
Solver of the adjoint to the eikonal PDE.
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
bool hasMultiplier(bool(objective::*hasFunction)() const)
Check if any of the available objective has a certain multiplier, provided through a function object...
void allocateMultipliers()
Allocate multiplier fields.
static constexpr const zero Zero
Global zero (0)