46 void objective::makeFolder()
110 const word& adjointSolverName,
111 const word& primalSolverName
132 adjointSolverName_(adjointSolverName),
133 primalSolverName_(primalSolverName),
135 computeMeanFields_(false),
137 normalize_(
dict.getOrDefault<bool>(
"normalize", false)),
141 JMean_(this->getOrDefault<scalar>(
"JMean",
Zero)),
142 weight_(
dict.
get<scalar>(
"weight")),
144 normFactor_(nullptr),
157 integrationStartTimePtr_(nullptr),
158 integrationEndTimePtr_(nullptr),
166 dJdbFieldPtr_(nullptr),
168 bdSdbMultPtr_(nullptr),
169 bdndbMultPtr_(nullptr),
170 bdxdbMultPtr_(nullptr),
171 bdxdbDirectMultPtr_(nullptr),
172 bEdgeContribution_(nullptr),
173 divDxDbMultPtr_(nullptr),
174 gradDxDbMultPtr_(nullptr),
176 objFunctionFolder_(
"word"),
177 objFunctionFilePtr_(nullptr),
178 instantValueFilePtr_(nullptr),
179 meanValueFilePtr_(nullptr),
180 width_(
IOstream::defaultPrecision() + 5)
189 new scalar(
dict.
get<scalar>(
"integrationStartTime"))
196 new scalar(
dict.
get<scalar>(
"integrationEndTime"))
203 scalar normFactor(
Zero);
225 const word& objectiveType,
226 const word& adjointSolverName,
227 const word& primalSolverName
230 auto* ctorPtr = objectiveConstructorTable(objectiveType);
239 *objectiveConstructorTablePtr_
243 return autoPtr<objective>
308 <<
"objective " <<
name() <<
":: updating norm factor " 317 if (solverControl.doAverageIter())
319 const label iAverageIter = solverControl.averageIter();
320 if (iAverageIter == 0)
324 scalar avIter(iAverageIter);
325 scalar oneOverItP1 = 1./(avIter + 1);
326 scalar mult = avIter*oneOverItP1;
341 const scalar denom = elapsedTime + dt;
348 <<
"Unallocated integration start or end time" 374 dJdbPtr_().primitiveFieldRef() *= oneOverNorm;
430 <<
"Unallocated integration start or end time for objective '" 448 <<
"Unallocated integration start or end time" 511 field = vector::zero;
541 file.setf(std::ios_base::left);
559 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.
const Type & value() const noexcept
Return const reference to value.
void setInstantValueFilePtr() const
Set the output file ptr for the instantaneous value.
virtual void update_dSdbMultiplier()
Update d (normal dS) / db multiplier. Surface-based sensitivity term.
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.
virtual void incrementIntegrationTimes(const scalar timeSpan)
Increment integration times.
virtual void update_dJdb()
const word adjointSolverName_
const dictionary & dict() const
Return objective dictionary.
virtual void writeMeanValue() const
Write mean objective function history.
scalar deltaTValue() const noexcept
Return time step value.
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.
bool hasdxdbDirectMult() const noexcept
autoPtr< OFstream > objFunctionFilePtr_
File to keep the objective values after the end of the primal solver.
bool hasBoundarydJdb() const noexcept
bool hasdJdbField() const noexcept
autoPtr< scalar > normFactor_
Normalization factor.
virtual void update_dxdbMultiplier()
Update d (x) / db multiplier. Surface-based sensitivity term.
Output to file stream as an OSstream, normally using std::ofstream for the actual output...
autoPtr< scalar > targetLeft_
Target on the left hand-side of a double inequality, for double sided constraints.
bool hasdndbMult() const noexcept
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.
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.
constexpr char tab
The tab '\t' character(0x09)
virtual 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...
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.
const Time & time() const
Return the top-level database.
bool hasBoundaryEdgeContribution() const noexcept
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
const word objectiveName_
virtual void update_gradDxDbMultiplier()
Update grad( dx/db multiplier). Volume-based sensitivity term.
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
bool hasGradDxDbMult() const noexcept
virtual void update_divDxDbMultiplier()
Update div( dx/db multiplier). Volume-based sensitivity term.
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.
bool hasdSdbMult() const noexcept
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.
fileName globalPath() const
Return global path for the case = rootPath/globalCaseName. Same as TimePaths::globalPath() ...
A class for handling words, derived from Foam::string.
static word defaultRegion
Return the default region name.
void setMeanValueFilePtr() const
Set the output file ptr for the mean value.
virtual void addHeaderColumns() const
Write headers for additional columns.
virtual void update_dndbMultiplier()
Update d (normal) / db multiplier. Surface-based sensitivity term.
bool hasdJdb() const noexcept
virtual void update_boundarydJdb()
Update objective function derivative term.
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
scalar JMean_
Average objective value.
scalar J_
Objective function value and weight.
#define DebugInfo
Report an information message using Foam::Info.
const Time & time() const noexcept
Return Time associated with the objectRegistry.
virtual scalar weight() const
Return the objective function weight.
virtual void update_dJdbField()
virtual scalar JCycle(bool negate=false) const
Return the objective function of the optimisation cycle.
Istream and Ostream manipulators taking arguments.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value 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.
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
virtual 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.
unsigned int width_
Default width of entries when writing in the objective files.
virtual void update_boundaryEdgeContribution()
Update boundary edge contributions.
An IOstream is an abstract base class for all input/output systems; be they streams, files, token lists etc.
bool hasIntegrationStartTime() const noexcept
virtual void nullify()
Nullify adjoint contributions.
autoPtr< scalarField > dJdbFieldPtr_
Contribution to field sensitivity derivatives.
virtual void writeInstantaneousSeparator() const
Append a blank line after the end of optimisation cycle to the file holding the instantaneous objecti...
const word & name() const
Return reference to name.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
virtual bool normalize() const
Is the objective normalized.
scalar weight_
Objective weight.
Mesh data needed to do the Finite Volume discretisation.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
virtual void addHeaderInfo() const
Write any information that needs to go the header of the file.
virtual bool readDict(const dictionary &dict)
bool hasDivDxDbMult() const noexcept
bool hasdxdbMult() const noexcept
autoPtr< volTensorField > gradDxDbMultPtr_
Emerging from volume objectives that include spatial derivatives.
autoPtr< scalar > integrationStartTimePtr_
Objective integration start and end times (for unsteady flows)
virtual void update()=0
Update objective function derivatives.
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...
virtual void update_dxdbDirectMultiplier()
Update d (x) / db multiplier. Surface and volume-based sensitivity term.
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...
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
bool hasIntegrationEndTime() const noexcept
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)