46 void objective::makeFolder()
106 const word& adjointSolverName,
107 const word& primalSolverName
128 adjointSolverName_(adjointSolverName),
129 primalSolverName_(primalSolverName),
131 computeMeanFields_(false),
133 normalize_(
dict.getOrDefault<bool>(
"normalize", false)),
136 JMean_(this->getOrDefault<scalar>(
"JMean",
Zero)),
138 normFactor_(nullptr),
145 integrationStartTimePtr_(nullptr),
146 integrationEndTimePtr_(nullptr),
154 bdSdbMultPtr_(nullptr),
155 bdndbMultPtr_(nullptr),
156 bdxdbMultPtr_(nullptr),
157 bdxdbDirectMultPtr_(nullptr),
158 bEdgeContribution_(nullptr),
159 divDxDbMultPtr_(nullptr),
160 gradDxDbMultPtr_(nullptr),
162 objFunctionFolder_(
"word"),
163 objFunctionFilePtr_(nullptr),
164 instantValueFilePtr_(nullptr),
165 meanValueFilePtr_(nullptr),
166 width_(
IOstream::defaultPrecision() + 5)
175 new scalar(
dict.
get<scalar>(
"integrationStartTime"))
182 new scalar(
dict.
get<scalar>(
"integrationEndTime"))
189 scalar normFactor(
Zero);
207 const dictionary&
dict,
208 const word& objectiveType,
209 const word& adjointSolverName,
210 const word& primalSolverName
213 auto* ctorPtr = objectiveConstructorTable(objectiveType);
222 *objectiveConstructorTablePtr_
226 return autoPtr<objective>
287 if (solverControl.doAverageIter())
289 const label iAverageIter = solverControl.averageIter();
290 if (iAverageIter == 0)
294 scalar avIter(iAverageIter);
295 scalar oneOverItP1 = 1./(avIter + 1);
296 scalar mult = avIter*oneOverItP1;
311 const scalar denom = elapsedTime + dt;
318 <<
"Unallocated integration start or end time" 344 dJdbPtr_().primitiveFieldRef() *= oneOverNorm;
396 <<
"Unallocated integration start or end time" 413 <<
"Unallocated integration start or end time" 426 createZeroFieldPtr<scalar>
430 dimensionSet(0, 5, -2, 0, 0, 0, 0)
498 <<
"Unallocated boundaryEdgeMultiplier field" 560 <<
"Unallocated boundaryEdgeMultiplier field" 575 createZeroFieldPtr<scalar>
596 createZeroFieldPtr<tensor>
641 field = vector::zero;
671 ios_base::fmtflags flags = file.flags();
672 flags |= std::cout.left;
685 file<<
setw(4) <<
"#" <<
" ";
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
bool hasGradDxDbMult() const
const Type & value() const noexcept
Return const reference to value.
void setInstantValueFilePtr() const
Set the output file ptr for the instantaneous value.
virtual void updateNormalizationFactor()
Update normalization factors, for objectives in which the factor is not known a priori.
autoPtr< boundaryVectorField > bdxdbMultPtr_
Term multiplying delta(x)/delta b at the boundary.
autoPtr< scalar > target_
Target value, in case the objective is used as a constraint.
A class for handling file names.
fvPatchField< vector > fvPatchVectorField
void incrementIntegrationTimes(const scalar timeSpan)
Increment integration times.
const word adjointSolverName_
const dictionary & dict() const
Return objective dictionary.
virtual void writeMeanValue() const
Write mean objective function history.
errorManipArg< error, int > exit(error &err, const int errNo=1)
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.
autoPtr< OFstream > objFunctionFilePtr_
File to keep the objective values after the end of the primal solver.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
autoPtr< scalar > normFactor_
Normalization factor.
Output to file stream, using an OSstream.
volVectorField::Boundary boundaryVectorField
virtual void doNormalization()
Normalize all fields allocated by the objective.
const word dictName("faMeshDefinition")
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual scalar J()=0
Return the instantaneous objective function value.
bool hasDivDxDbMult() const
constexpr char tab
The tab '\t' character(0x09)
void accumulateJMean()
Accumulate contribution for the mean objective value.
autoPtr< vectorField3 > bEdgeContribution_
Contribution located in specific parts of a patch. Mainly intended for patch boundary edges contribut...
const dimensionSet dimless
Dimensionless.
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.
autoPtr< boundaryVectorField > bdJdbPtr_
Term from material derivative.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
const Time & time() const
Return the top-level database.
const boundaryVectorField & dndbMultiplier()
Multiplier of delta(n dS)/delta b for all patches.
const volTensorField & gradDxDbMultiplier()
Multiplier of grad( delta(x)/delta b) for volume-based sensitivities.
const boundaryVectorField & dxdbDirectMultiplier()
Multiplier of delta(x)/delta b for all patches.
const boundaryVectorField & dxdbMultiplier()
Multiplier of delta(x)/delta b for all patches.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
const word objectiveName_
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
bool hasBoundarydJdb() const
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
virtual bool write(const bool valid=true) const
Write objective function history.
static autoPtr< objective > New(const fvMesh &mesh, const dictionary &dict, const word &objectiveType, const word &adjointSolverName, const word &primalSolverName)
Return a reference to the selected turbulence model.
autoPtr< scalar > integrationEndTimePtr_
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
void setObjectiveFilePtr() const
Set the output file ptr.
A class for handling words, derived from Foam::string.
void setMeanValueFilePtr() const
Set the output file ptr for the mean value.
virtual void addHeaderColumns() const
Write headers for additional columns.
scalar JCycle() const
Return the mean objective function value, if it exists, otherwise the mean one.
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
dimensionSet pow2(const dimensionSet &ds)
scalar JMean_
Average objective value.
scalar J_
Objective function value and weight.
const boundaryVectorField & dSdbMultiplier()
Multiplier of delta(n dS)/delta b for all patches.
bool valid() const noexcept
Identical to good(), or bool operator.
scalar weight() const
Return the objective function weight.
Istream and Ostream manipulators taking arguments.
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
autoPtr< boundaryVectorField > bdndbMultPtr_
Term multiplying delta(n)/delta b.
virtual bool writeData(Ostream &os) const
Write averaged objective for continuation.
virtual void writeInstantaneousValue() const
Write objective function history at each primal solver iteration.
const boundaryVectorField & boundarydJdb()
Contribution to surface sensitivities for all patches.
autoPtr< volScalarField > dJdbPtr_
Contribution to field sensitivity derivatives.
OBJstream os(runTime.globalPath()/outputName)
bool hasdxdbDirectMult() const
defineTypeNameAndDebug(combustionModel, 0)
bool hasIntegrationEndTime() const
bool hasIntegrationStartTime() const
bool isWithinIntegrationTime() const
Check whether this is an objective integration time.
autoPtr< volScalarField > divDxDbMultPtr_
Multiplier of d(Volume)/db.
virtual void addColumnValues() const
Write information to additional columns.
autoPtr< OFstream > meanValueFilePtr_
File to keep the average objective values after the end of the primal solver.
const volScalarField & dJdb()
Contribution to field sensitivities.
unsigned int width_
Default width of entries when writing in the objective files.
const volScalarField & divDxDbMultiplier()
Multiplier of grad( delta(x)/delta b) for volume-based sensitivities.
dimensionedScalar pow3(const dimensionedScalar &ds)
An IOstream is an abstract base class for all input/output systems; be they streams, files, token lists etc.
virtual void nullify()
Nullify adjoint contributions.
virtual void writeInstantaneousSeparator() const
Append a blank line after the end of optimisation cycle to the file holding the instantaneous objecti...
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const Time & time() const
Return Time associated with the objectRegistry.
bool normalize() const
Is the objective normalized.
Field< Field< vectorField > > vectorField3
scalar weight_
Objective weight.
Mesh data needed to do the Finite Volume discretisation.
const vectorField3 & boundaryEdgeMultiplier()
Multiplier located at patch boundary edges.
static bool master(const label communicator=worldComm)
Am I the master rank.
virtual void addHeaderInfo() const
Write any information that needs to go the header of the file.
virtual bool readDict(const dictionary &dict)
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
autoPtr< volTensorField > gradDxDbMultPtr_
Emerging from volume objectives that include spatial derivatives.
autoPtr< scalar > integrationStartTimePtr_
Objective integration start and end times (for unsteady flows)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Omanip< int > setw(const int i)
autoPtr< OFstream > instantValueFilePtr_
File to keep the objective values at each iteration of the primal solver.
autoPtr< boundaryVectorField > bdxdbDirectMultPtr_
Term multiplying delta(x)/delta b at the boundary for objectives that directly depend on x...
autoPtr< boundaryVectorField > bdSdbMultPtr_
Term multiplying delta(n dS)/delta b.
fileName objFunctionFolder_
Output file variables.
Defines the attributes of an object for which implicit objectRegistry management is supported...
bool hasBoundaryEdgeContribution() const
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
dimensionedScalar deltaT() const
Return time step.
fileName globalPath() const
Return global path for the case.
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)