44 objectiveManager::objectiveManager
48 const word& adjointSolverName,
49 const word& primalSolverName
56 "objectiveManager" + adjointSolverName,
66 adjointSolverName_(adjointSolverName),
67 primalSolverName_(primalSolverName),
69 weightedObjectiveFile_(nullptr)
73 Info <<
"Constructing objective functions " <<
nl <<
endl;
75 const dictionary& objectiveNamesDict(
dict.subDict(
"objectiveNames"));
76 wordList objectiveNames(objectiveNamesDict.toc());
79 forAll(objectiveNames, objectivei)
81 const word& objectiveName = objectiveNames[objectivei];
89 objectiveNamesDict.
subDict(objectiveName),
100 <<
"No objectives have been set - cannot perform an optimisation" 120 <<
setw(4) <<
"#" <<
" " 121 <<
setw(width) <<
"weightedObjective" <<
" ";
125 <<
setw(width) << objI.objectiveName() <<
" ";
143 dict.subDict(
"objectiveNames").subDict(obj.objectiveName())
158 obj.updateNormalizationFactor();
179 if (obj.isWithinIntegrationTime())
197 obj.incrementIntegrationTimes(timeSpan);
204 scalar objValue(
Zero);
213 obj.setComputed(
false);
214 const scalar cost = obj.JCycle(
negate);
217 Info<< obj.objectiveName() <<
" : " << cost <<
endl;
220 Info<<
"Weighted objective : " << objValue <<
nl <<
endl;
230 obj.setWrite(shouldWrite);
240 if (obj.shouldWrite())
243 obj.writeMeanValue();
253 const scalar weightedObjective,
265 <<
setw(width) << weightedObjective <<
" ";
269 os <<
setw(width) << objI.JCycle() <<
" ";
282 scalar weightedObjective =
print();
315 if (!obj.hasIntegrationStartTime() || !obj.hasIntegrationEndTime())
318 <<
"Objective function " << obj.objectiveName()
319 <<
" does not have a defined integration start or end time " 330 obj.addSource(matrix);
339 obj.addSource(matrix);
void setWrite(const bool shouldWrite)
Should the objectives be written to file upon calling write()?
fvMatrix< scalar > fvScalarMatrix
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.
const word adjointSolverName_
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
constexpr char nl
The newline '\n' character (0x0a)
Class for managing objective functions.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static unsigned int defaultPrecision() noexcept
Return the default precision.
void incrementIntegrationTimes(const scalar timeSpan)
Increment integration times by the optimisation cycle time-span.
const Time & time() const
Return the top-level database.
void updateAndWrite()
Call all functions required prior to the solution of the adjoint equations.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
PtrList< objective > objectives_
#define forAll(list, i)
Loop across all elements in list.
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.
void updateNormalizationFactor()
Update objective function related values.
fileName globalPath() const
Return global path for the case = rootPath/globalCaseName. Same as TimePaths::globalPath() ...
A class for handling words, derived from Foam::string.
virtual bool writeObjectives()
Write objective function history.
void negate(DimensionedField< Type, GeoMesh > &result, const DimensionedField< Type, GeoMesh > &f1)
const word & primalSolverName() const
Return name of the primalSolver.
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Istream and Ostream manipulators taking arguments.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
scalar print(bool negate=false)
Print to screen.
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.
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
void update()
Update objective function related values.
virtual void addSource(fvVectorMatrix &matrix)
Add contribution to adjoint momentum PDEs.
const word & adjointSolverName() const
Return name of the adjointSolver.
virtual bool readDict(const dictionary &dict)
void updateOrNullify()
Update contributions to adjoint if true, otherwise return nulls.
autoPtr< OFstream > weightedObjectiveFile_
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Mesh data needed to do the Finite Volume discretisation.
fvMatrix< vector > fvVectorMatrix
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
const word primalSolverName_
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
messageStream Info
Information stream (stdout output on master, null elsewhere)
Omanip< int > setw(const int i)
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
void checkIntegrationTimes() const
Check integration times for unsteady runs.
Defines the attributes of an object for which implicit objectRegistry management is supported...
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)