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);
146 dxdbSurfSens_ =
Zero;
149 dxdbDirectSens_ =
Zero;
151 distanceSens_ =
Zero;
159Foam::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* ctorPtr = dictionaryConstructorTable(modelType);
222 *dictionaryConstructorTablePtr_
236 parametertisedPatches_ =
237 mesh_.boundaryMesh().patchSet(
dict.get<
wordRes>(
"patches"));
238 displMethodPtr_->setPatchIDs(parametertisedPatches_.toc());
241 dict.getOrDefault<
bool>(
"writeEachMesh",
true);
258 pointsInit_() = mesh_.points();
272 displMethodPtr_->update();
276 Info<<
" Writing new mesh points for mesh region "
277 << mesh_.name() <<
endl;
283 mesh_.pointsInstance(),
296 mesh_.checkMesh(
true);
302 adjointSensitivity& adjointSens
310 allocateSensFields();
314 const autoPtr<volTensorField>& gradDxDbMult = adjointSens.gradDxDbMult();
315 const autoPtr<scalarField>& divDxDbMult = adjointSens.divDxDbMult();
316 const autoPtr<boundaryVectorField>& dxdbMult = adjointSens.dxdbMult();
317 const autoPtr<boundaryVectorField>& dSdbMult = adjointSens.dSfdbMult();
318 const autoPtr<boundaryVectorField>& dndbMult = adjointSens.dnfdbMult();
319 const autoPtr<boundaryVectorField>& dxdbDirectMult =
320 adjointSens.dxdbDirectMult();
321 const autoPtr<boundaryVectorField>& bcDxDbmult = adjointSens.bcDxDbMult();
322 const autoPtr<vectorField>& optionsDxDbMult = adjointSens.optionsDxDbMult();
324 autoPtr<adjointEikonalSolver>& eikonalSolver =
325 adjointSens.getAdjointEikonalSolver();
327 autoPtr<volTensorField> distanceSens(
nullptr);
328 if (adjointSens.includeDistance())
337 for (
const label varI : activeSensitivities())
341 if (adjointSens.computeDxDbInternalField())
349 dxdbVolSens_[varI] =
gSum((gradDxDbMult() && gradDxDb())*V);
352 if (adjointSens.includeDistance())
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_)
376 dSdbSens_[varI] +=
gSum(dSdbMult()[patchI] & pdSdb);
382 dndbSens_[varI] +=
gSum((dndbMult()[patchI] & pdndb));
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_;
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] <<
" "
Istream and Ostream manipulators taking arguments.
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
DimensionedField< scalar, volMesh > Internal
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
label size() const noexcept
The number of elements in table.
@ NO_REGISTER
Do not request registration (bool: false).
@ 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,...
static unsigned int defaultPrecision() noexcept
Return the default precision.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
bool get(const label i) const
label size() const noexcept
Abstract base class for adjoint-based sensitivities.
autoPtr< adjointEikonalSolver > & getAdjointEikonalSolver()
Return the adjoint eikonal solver.
const autoPtr< volTensorField > & gradDxDbMult() const
const autoPtr< vectorField > & optionsDxDbMult() const
bool includeDistance() const
Should the adjoint eikonal PDE should be solved.
const autoPtr< boundaryVectorField > & dxdbDirectMult() const
const adjointSolver & getAdjointSolver() const
Const access to adjoint solver.
const autoPtr< boundaryVectorField > & dnfdbMult() const
virtual bool computeDxDbInternalField() const
Should the parameterization compute the internalField of dxdb.
const autoPtr< boundaryVectorField > & dxdbMult() const
const autoPtr< scalarField > & divDxDbMult() const
const autoPtr< boundaryVectorField > & dSfdbMult() const
const word & getSuffix() const
Get suffix.
const autoPtr< boundaryVectorField > & bcDxDbMult() const
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Abstract base class for defining design variables.
virtual void resetDesignVariables()
Reset to the starting point of line search.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
labelList activeDesignVariables_
Which of the design variables will be updated.
virtual void storeDesignVariables()
Store design variables, as the starting point for line search.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
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.
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...
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Abstract base class for displacement methods, which are a set or wrapper classes allowing to change t...
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
Mesh data needed to do the Finite Volume discretisation.
Mesh consisting of general polyhedral cells.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh").
Abstract base class for defining design variables for shape optimisation.
bool writeEachMesh_
Write the mesh points irrespective of whether this is a write time.
scalarField dSdbSens_
Term depending on delta(n dS)/delta b.
virtual tmp< vectorField > dSdb(const label patchI, const label varID) const
Get dSdb for a given design variable and patch.
virtual void resetDesignVariables()
Reset to starting point of line search.
scalarField dVdbSens_
Term depending on delta(V)/delta b.
void zeroSensFields()
Zero the fields assosiated with the computation of sensitivities.
scalarField optionsSens_
Term depending on fvOptions.
fileName derivativesFolder_
Name of the sensitivity derivatives folder.
virtual void moveMesh()
Move mesh based on displacementMethod.
virtual tmp< volVectorField > solveMeshMovementEqn(const label patchI, const label varID) const
Compute dxdb at the mesh cell centers by solving a Laplace PDE.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
autoPtr< displacementMethod > displMethodPtr_
Mesh movement mechanism.
void allocateSensFields()
Allocate the fields assosiated with the computation of sensitivities.
virtual void writeSensitivities(const scalarField &sens, const adjointSensitivity &adjointSens)
Write final sensitivity derivatives to files.
scalarField dxdbDirectSens_
Term depending on delta(x)/delta b for objectives that directly depend on x.
autoPtr< pointField > pointsInit_
Store old points. Useful for line search.
static autoPtr< shapeDesignVariables > New(fvMesh &mesh, const dictionary &dict)
Construct and return the selected shapeDesignVariables.
scalarField dxdbSurfSens_
Flow related term.
scalarField distanceSens_
Term depending on distance differentiation.
labelHashSet parametertisedPatches_
Patches to be moved by the design variables.
scalarField dxdbVolSens_
Flow related term.
scalarField bcSens_
Term depending on the differenation of boundary conditions.
virtual void storeDesignVariables()
Store design variables, as the starting point for line search.
virtual tmp< vectorField > dxdbVol(const label varID) const
Get dxdb for all mesh points.
virtual const labelList & activeSensitivities() const
Active variables for which to compute sensitivities.
virtual label sensSize() const
Size of the sensitivity derivatives.
virtual tmp< vectorField > dxdbFace(const label patchI, const label varID) const
Get dxdb for a given design variable and patch.
virtual tmp< vectorField > dndb(const label patchI, const label varID) const
Get dndb for a given design variable and patch.
virtual tmp< volVectorField > dCdb(const label varID) const
Get dCdb for a given design variable.
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &adjointSens)
Add part of sensitivity derivatives related to geometry variations.
scalarField dndbSens_
Term depending on delta(n)/delta b.
const word & solverName() const
Return the solver name.
A class for managing temporary objects.
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.
static tmp< volVectorField > autoCreateMeshMovementField(const fvMesh &mesh, const word &name, const dimensionSet &dims)
Auto create variable for mesh movement.
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 FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
#define DebugInfo
Report an information message using Foam::Info.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
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.
Type gSum(const FieldField< Field, Type > &f)
GeometricField< vector, fvPatchField, volMesh > volVectorField
List< label > labelList
A List of labels.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
messageStream Info
Information stream (stdout output on master, null elsewhere).
vectorIOField pointIOField
pointIOField is a vectorIOField.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Omanip< int > setw(const int i)
Ostream & endl(Ostream &os)
Add newline and flush stream.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
fvMatrix< vector > fvVectorMatrix
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Type gMax(const FieldField< Field, Type > &f)
loopControl iters(runTime, aMesh.solutionDict(), "solution")
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
Forwards and collection of common volume field types.