46void objective::makeFolder()
110 const word& adjointSolverName,
111 const word& primalSolverName
132 adjointSolverName_(adjointSolverName),
133 primalSolverName_(primalSolverName),
135 computeMeanFields_(false),
139 dict.getOrDefaultCompat<bool>
141 "normalise", {{
"normalize", 2406}}, false
147 JMean_(this->getOrDefault<scalar>(
"JMean",
Zero)),
148 weight_(
dict.
get<scalar>(
"weight")),
150 normFactor_(
nullptr),
163 integrationStartTimePtr_(
nullptr),
164 integrationEndTimePtr_(
nullptr),
172 dJdbFieldPtr_(
nullptr),
174 bdSdbMultPtr_(
nullptr),
175 bdndbMultPtr_(
nullptr),
176 bdxdbMultPtr_(
nullptr),
177 bdxdbDirectMultPtr_(
nullptr),
178 bEdgeContribution_(
nullptr),
179 divDxDbMultPtr_(
nullptr),
180 gradDxDbMultPtr_(
nullptr),
182 objFunctionFolder_(
"word"),
183 objFunctionFilePtr_(
nullptr),
184 instantValueFilePtr_(
nullptr),
185 meanValueFilePtr_(
nullptr),
193 integrationStartTimePtr_.reset
195 new scalar(
dict.
get<scalar>(
"integrationStartTime"))
200 integrationEndTimePtr_.reset
202 new scalar(
dict.
get<scalar>(
"integrationEndTime"))
209 scalar normFactor(
Zero);
212 normFactor_.reset(
new scalar(normFactor));
216 normFactor_.reset(
new scalar(normFactor));
231 const word& objectiveType,
232 const word& adjointSolverName,
233 const word& primalSolverName
236 auto* ctorPtr = objectiveConstructorTable(objectiveType);
245 *objectiveConstructorTablePtr_
249 return autoPtr<objective>
314 <<
"objective " <<
name() <<
":: updating norm factor "
316 <<
" for time = " <<
mesh_.time().timeName() <<
endl;
323 if (solverControl.doAverageIter())
325 const label iAverageIter = solverControl.averageIter();
326 if (iAverageIter == 0)
330 scalar avIter(iAverageIter);
331 scalar oneOverItP1 = 1./(avIter + 1);
332 scalar mult = avIter*oneOverItP1;
347 const scalar denom = elapsedTime + dt;
354 <<
"Unallocated integration start or end time"
380 dJdbPtr_().primitiveFieldRef() *= oneOverNorm;
384 dJdbFieldPtr_() *= oneOverNorm;
426 const scalar
time =
mesh_.time().value();
436 <<
"Unallocated integration start or end time for objective '"
454 <<
"Unallocated integration start or end time"
491 dJdbFieldPtr_() =
Zero;
545 file.setf(std::ios_base::left);
563 file<<
setw(4) <<
"#" <<
" ";
575 file<<
setw(4) <<
mesh_.time().value() <<
" ";
Istream and Ostream manipulators taking arguments.
propsDict readIfPresent("fields", acceptFields)
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const Time & time() const noexcept
Return Time associated with the objectRegistry.
std::ios_base::fmtflags setf(std::ios_base::fmtflags f)
Set stream flag(s), return old stream flags.
static unsigned int defaultPrecision() noexcept
Return the default precision.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
scalar deltaTValue() const noexcept
Return time step value.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
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.
fileName globalPath() const
The global path for the case = rootPath/globalCaseName.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
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.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
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.
T getOrDefaultCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value using any compatibility names if needed.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
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...
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
word dictName() const
The local dictionary name (final part of scoped name).
const Type & value() const noexcept
Return const reference to value.
A class for handling file names.
Mesh data needed to do the Finite Volume discretisation.
const Time & time() const
Return the top-level database.
const word & name() const
Return reference to name.
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
localIOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
virtual void writeInstantaneousSeparator() const
Append a blank line after the end of optimisation cycle to the file holding the instantaneous objecti...
bool hasdSdbMult() const noexcept
virtual void writeInstantaneousValue() const
Write objective function history at each primal solver iteration.
virtual void update_dxdbMultiplier()
Update d (x) / db multiplier. Surface-based sensitivity term.
autoPtr< OFstream > instantValueFilePtr_
File to keep the objective values at each iteration of the primal solver.
virtual void update_gradDxDbMultiplier()
Update grad( dx/db multiplier). Volume-based sensitivity term.
bool hasIntegrationStartTime() const noexcept
autoPtr< boundaryVectorField > bdJdbPtr_
Contribution to field sensitivity derivatives.
virtual void update_dxdbDirectMultiplier()
Update d (x) / db multiplier. Surface and volume-based sensitivity term.
virtual bool write(const bool valid=true) const
Write objective function history.
virtual void accumulateJMean()
Accumulate contribution for the mean objective value.
virtual void update()=0
Update objective function derivatives.
scalar JMean_
Average objective value.
autoPtr< boundaryVectorField > bdSdbMultPtr_
Term multiplying delta(n dS)/delta b.
const word objectiveName_
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.
virtual void update_dJdbField()
void setMeanValueFilePtr() const
Set the output file ptr for the mean value.
virtual void writeMeanValue() const
Write mean objective function history.
autoPtr< OFstream > objFunctionFilePtr_
File to keep the objective values after the end of the primal solver.
autoPtr< OFstream > meanValueFilePtr_
File to keep the average objective values after the end of the primal solver.
virtual void update_divDxDbMultiplier()
Update div( dx/db multiplier). Volume-based sensitivity term.
virtual void addHeaderColumns() const
Write headers for additional columns.
bool hasGradDxDbMult() const noexcept
bool hasBoundarydJdb() const noexcept
bool hasdJdb() const noexcept
virtual scalar weight() const
Return the objective function weight.
virtual bool writeData(Ostream &os) const
Write averaged objective for continuation.
autoPtr< scalar > targetLeft_
Target on the left hand-side of a double inequality, for double sided constraints.
autoPtr< boundaryVectorField > bdxdbDirectMultPtr_
Term multiplying delta(x)/delta b at the boundary for objectives that directly depend on x,...
virtual void update_boundarydJdb()
Update objective function derivative term.
virtual void nullify()
Nullify adjoint contributions.
autoPtr< scalar > integrationStartTimePtr_
Objective integration start and end times (for unsteady flows).
bool hasIntegrationEndTime() const noexcept
bool hasdndbMult() const noexcept
void setObjectiveFilePtr() const
Set the output file ptr.
autoPtr< scalar > normFactor_
Normalization factor.
virtual scalar JCycle(bool negate=false) const
Return the objective function of the optimisation cycle.
scalar weight_
Objective weight.
virtual bool readDict(const dictionary &dict)
unsigned int width_
Default width of entries when writing in the objective files.
virtual scalar J()=0
Return the instantaneous objective function value.
autoPtr< scalar > integrationEndTimePtr_
virtual void update_dSdbMultiplier()
Update d (normal dS) / db multiplier. Surface-based sensitivity term.
virtual void addHeaderInfo() const
Write any information that needs to go the header of the file.
bool hasdJdbField() const noexcept
virtual void update_dndbMultiplier()
Update d (normal) / db multiplier. Surface-based sensitivity term.
autoPtr< volScalarField > divDxDbMultPtr_
Multiplier of d(Volume)/db.
bool hasDivDxDbMult() const noexcept
scalar J_
Objective function value and weight.
bool hasBoundaryEdgeContribution() const noexcept
void setInstantValueFilePtr() const
Set the output file ptr for the instantaneous value.
virtual void incrementIntegrationTimes(const scalar timeSpan)
Increment integration times.
virtual void doNormalization()
Normalize all fields allocated by the objective.
virtual bool normalize() const
Is the objective normalized.
const dictionary & dict() const
Return objective dictionary.
const word primalSolverName_
virtual void updateNormalizationFactor()
Update normalization factors, for objectives in which the factor is not known a priori.
virtual void update_dJdb()
fileName objFunctionFolder_
Output file variables.
autoPtr< scalar > target_
Target value, in case the objective is used as a constraint.
autoPtr< boundaryVectorField > bdndbMultPtr_
Term multiplying delta(n)/delta b.
virtual void update_boundaryEdgeContribution()
Update boundary edge contributions.
autoPtr< boundaryVectorField > bdxdbMultPtr_
Term multiplying delta(x)/delta b at the boundary.
const word adjointSolverName_
virtual void addColumnValues() const
Write information to additional columns.
bool hasdxdbDirectMult() const noexcept
virtual bool isWithinIntegrationTime() const
Check whether this is an objective integration time.
autoPtr< vectorField3 > bEdgeContribution_
Contribution located in specific parts of a patch. Mainly intended for patch boundary edges contribut...
bool hasdxdbMult() const noexcept
autoPtr< volTensorField > gradDxDbMultPtr_
Emerging from volume objectives that include spatial derivatives.
static word defaultRegion
Return the default region name.
Base class for solver control classes.
bool doAverageIter() const
Whether or not to add fields of the current iteration to the average fields.
label & averageIter()
Return average iteration index reference.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
const word dictName("faMeshDefinition")
#define DebugInfo
Report an information message using Foam::Info.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Omanip< int > setw(const int i)
Ostream & endl(Ostream &os)
Add newline and flush stream.
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).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char tab
The tab '\t' character(0x09).
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.