62 return activeDesignVariables_;
75 const scalar tolerance =
96 for (label iter = 0; iter <
iters; ++iter)
98 Info<<
"Mesh Movement Propagation for varID" << varID
99 <<
", Iteration : "<< iter <<
endl;
106 scalar residual =
mag(mEqn.solve().initialResidual());
111 mesh_.time().printExecutionTime(
Info);
114 if (residual < tolerance)
116 Info<<
"\n***Reached dxdb convergence limit, iteration " << iter
128 if (dxdbVolSens_.empty())
130 dxdbVolSens_.setSize(sensSize(),
Zero);
131 dxdbSurfSens_.setSize(sensSize(),
Zero);
132 dSdbSens_.setSize(sensSize(),
Zero);
133 dndbSens_.setSize(sensSize(),
Zero);
134 dxdbDirectSens_.setSize(sensSize(),
Zero);
135 dVdbSens_.setSize(sensSize(),
Zero);
136 distanceSens_.setSize(sensSize(),
Zero);
137 optionsSens_.setSize(sensSize(),
Zero);
138 bcSens_.setSize(sensSize(),
Zero);
146 dxdbSurfSens_ =
Zero;
149 dxdbDirectSens_ =
Zero;
151 distanceSens_ =
Zero;
159 Foam::shapeDesignVariables::shapeDesignVariables
166 parametertisedPatches_
174 pointsInit_(nullptr),
175 writeEachMesh_(
dict.getOrDefault<bool>(
"writeEachMesh", true)),
187 word(
"optimisation")/
word(
"derivatives")
194 <<
"None of the provided parameterised patches is valid" 212 Info<<
"shapeDesignVariables type : " << modelType <<
endl;
214 auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
216 if (!cstrIter.found())
222 *dictionaryConstructorTablePtr_
236 parametertisedPatches_ =
238 displMethodPtr_->setPatchIDs(parametertisedPatches_.toc());
258 pointsInit_() = mesh_.points();
265 mesh_.movePoints(pointsInit_());
272 displMethodPtr_->update();
276 Info<<
" Writing new mesh points for mesh region " 277 << mesh_.name() <<
endl;
283 mesh_.pointsInstance(),
296 mesh_.checkMesh(
true);
310 allocateSensFields();
337 for (
const label varI : activeSensitivities())
344 tmp<volVectorField> tvolDxDbI = dCdb(varI);
346 tmp<volTensorField> gradDxDb =
fvc::grad(volDxDbI);
349 dxdbVolSens_[varI] =
gSum((gradDxDbMult() && gradDxDb())*V);
354 distanceSens_[varI] =
gSum((distanceSens() && gradDxDb)*V);
360 gSum(divDxDbMult()*
fvc::div(volDxDbI)().primitiveField()*V);
364 optionsSens_[varI] +=
365 gSum((optionsDxDbMult() & volDxDbI.primitiveField())*V);
371 for (
const label patchI : parametertisedPatches_)
375 tmp<vectorField> pdSdb = dSdb(patchI, varI);
376 dSdbSens_[varI] +=
gSum(dSdbMult()[patchI] & pdSdb);
381 tmp<vectorField> pdndb = dndb(patchI, varI);
382 dndbSens_[varI] +=
gSum((dndbMult()[patchI] & pdndb));
385 tmp<vectorField> pdxdb = dxdbFace(patchI, varI);
389 dxdbSurfSens_[varI] +=
gSum(dxdbMult()[patchI] & pdxdb());
393 dxdbDirectSens_[varI] +=
394 gSum((dxdbDirectMult()[patchI] & pdxdb()));
398 bcSens_[varI] +=
gSum((bcDxDbmult()[patchI] & pdxdb()));
404 dxdbVolSens_ + dxdbSurfSens_ + dSdbSens_ + dndbSens_ + dxdbDirectSens_
405 + dVdbSens_ + distanceSens_ + optionsSens_ + bcSens_;
407 writeSensitivities(sens, adjointSens);
423 + adjointSens.
getSuffix() + mesh_.time().timeName()
425 unsigned int widthDV =
max(
int(
name(dxdbVolSens_.size()).size()),
int(6));
428 <<
setw(widthDV) <<
"#varID" <<
" " 429 <<
setw(width) <<
"total"<<
" " 430 <<
setw(width) <<
"dxdbVol" <<
" " 431 <<
setw(width) <<
"dxdbSurf" <<
" " 432 <<
setw(width) <<
"dSdb" <<
" " 433 <<
setw(width) <<
"dndb" <<
" " 434 <<
setw(width) <<
"dxdbDirect" <<
" " 435 <<
setw(width) <<
"dVdb" <<
" " 436 <<
setw(width) <<
"distance" <<
" " 437 <<
setw(width) <<
"options" <<
" " 440 for (
const label varI : activeSensitivities())
443 <<
setw(widthDV) << varI <<
" " 444 <<
setw(width) << sens[varI] <<
" " 445 <<
setw(width) << dxdbVolSens_[varI] <<
" " 446 <<
setw(width) << dxdbSurfSens_[varI] <<
" " 447 <<
setw(width) << dSdbSens_[varI] <<
" " 448 <<
setw(width) << dndbSens_[varI] <<
" " 449 <<
setw(width) << dxdbDirectSens_[varI] <<
" " 450 <<
setw(width) << dVdbSens_[varI] <<
" " 451 <<
setw(width) << distanceSens_[varI] <<
" " 452 <<
setw(width) << optionsSens_[varI] <<
" " 453 <<
setw(width) << bcSens_[varI] <<
" " List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
virtual const labelList & activeSensitivities() const
Active variables for which to compute sensitivities.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
virtual tmp< vectorField > dxdbFace(const label patchI, const label varID) const
Get dxdb for a given design variable and patch.
virtual void writeSensitivities(const scalarField &sens, const adjointSensitivity &adjointSens)
Write final sensitivity derivatives to files.
virtual void storeDesignVariables()
Store design variables, as the starting point for line search.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual tmp< volVectorField > dCdb(const label varID) const
Get dCdb for a given design variable.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Forwards and collection of common volume field types.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Abstract base class for adjoint-based sensitivities.
void zeroSensFields()
Zero the fields assosiated with the computation of sensitivities.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
virtual void resetDesignVariables()
Reset to starting point of line search.
Output to file stream, using an OSstream.
virtual void moveMesh()
Move mesh based on displacementMethod.
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.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
static unsigned int defaultPrecision() noexcept
Return the default precision.
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &adjointSens)
Add part of sensitivity derivatives related to geometry variations.
virtual label sensSize() const
Size of the sensitivity derivatives.
Ignore writing from objectRegistry::writeObject()
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.
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
const adjointSolver & getAdjointSolver() const
Const access to adjoint solver.
GeometricField< vector, fvPatchField, volMesh > volVectorField
virtual bool computeDxDbInternalField() const
Should the parameterization compute the internalField of dxdb.
virtual tmp< volVectorField > solveMeshMovementEqn(const label patchI, const label varID) const
Compute dxdb at the mesh cell centers by solving a Laplace PDE.
Macros for easy insertion into run-time selection tables.
const autoPtr< scalarField > & divDxDbMult() const
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
static autoPtr< shapeDesignVariables > New(fvMesh &mesh, const dictionary &dict)
Construct and return the selected shapeDesignVariables.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
const autoPtr< volTensorField > & gradDxDbMult() const
label size() const noexcept
The number of elements in table.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
vectorField pointField
pointField is a vectorField.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Type gSum(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A class for handling words, derived from Foam::string.
virtual tmp< vectorField > dndb(const label patchI, const label varID) const
Get dndb for a given design variable and patch.
tmp< volTensorField > getFISensitivityTerm() const
Return the volume-based sensitivity term depending on da.
const autoPtr< boundaryVectorField > & bcDxDbMult() const
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
A List of wordRe with additional matching capabilities.
const autoPtr< boundaryVectorField > & dxdbMult() const
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
virtual void resetDesignVariables()
Reset to the starting point of line search.
Abstract base class for displacement methods, which are a set or wrapper classes allowing to change t...
const autoPtr< boundaryVectorField > & dnfdbMult() const
#define DebugInfo
Report an information message using Foam::Info.
Istream and Ostream manipulators taking arguments.
label size() const noexcept
The number of elements in the container.
autoPtr< adjointEikonalSolver > & getAdjointEikonalSolver()
Return the adjoint eikonal solver.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Type gMax(const FieldField< Field, Type > &f)
defineTypeNameAndDebug(combustionModel, 0)
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Find and return a sub-dictionary as a copy, otherwise return an empty dictionary. ...
const word & getSuffix() const
Get suffix.
fileName derivativesFolder_
Name of the sensitivity derivatives folder.
virtual void storeDesignVariables()
Store design variables, as the starting point for line search.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
const autoPtr< vectorField > & optionsDxDbMult() const
Abstract base class for defining design variables.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
const word & solverName() const
Return the solver name.
Mesh data needed to do the Finite Volume discretisation.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
loopControl iters(runTime, aMesh.solutionDict(), "solution")
virtual tmp< vectorField > dSdb(const label patchI, const label varID) const
Get dSdb for a given design variable and patch.
const autoPtr< boundaryVectorField > & dxdbDirectMult() const
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Internal & ref(const bool updateAccessTime=true)
Same as internalFieldRef()
void allocateSensFields()
Allocate the fields assosiated with the computation of sensitivities.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
bool includeDistance() const
Should the adjoint eikonal PDE should be solved.
Mesh consisting of general polyhedral cells.
Omanip< int > setw(const int i)
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
A class for managing temporary objects.
const autoPtr< boundaryVectorField > & dSfdbMult() const
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Defines the attributes of an object for which implicit objectRegistry management is supported...
labelHashSet parametertisedPatches_
Patches to be moved by the design variables.
List< label > toc(const UList< bool > &bools)
Return the (sorted) values corresponding to 'true' entries.
A primitive field of type <T> with automated input and output.
virtual tmp< vectorField > dxdbVol(const label varID) const
Get dxdb for all mesh points.
static tmp< volVectorField > autoCreateMeshMovementField(const fvMesh &mesh, const word &name, const dimensionSet &dims)
Auto create variable for mesh movement.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)