45 objectiveManager::objectiveManager
49 const word& adjointSolverName,
50 const word& primalSolverName
57 "objectiveManager" + adjointSolverName,
67 adjointSolverName_(adjointSolverName),
68 primalSolverName_(primalSolverName),
70 weigthedObjectiveFile_(nullptr)
74 Info <<
"Constructing objective functions " <<
nl <<
endl;
76 const dictionary& objectiveNamesDict(
dict.subDict(
"objectiveNames"));
77 wordList objectiveNames(objectiveNamesDict.toc());
80 forAll(objectiveNames, objectivei)
82 const word& objectiveName = objectiveNames[objectivei];
90 objectiveNamesDict.
subDict(objectiveName),
101 <<
"No objectives have been set - cannot perform an optimisation" 121 <<
setw(4) <<
"#" <<
" " 122 <<
setw(width) <<
"weightedObjective" <<
" ";
126 <<
setw(width) << objI.objectiveName() <<
" ";
140 const dictionary&
dict,
141 const word& adjointSolverName,
142 const word& primalSolverName
146 const word objectiveType(
dict.get<word>(
"type"));
147 const word managerType(
"objectiveManager" & objectiveType);
149 auto* ctorPtr = dictionaryConstructorTable(managerType);
156 "objectiveManagerType",
158 *dictionaryConstructorTablePtr_
162 return autoPtr<objectiveManager>
177 dict.subDict(
"objectiveNames").subDict(obj.objectiveName())
192 obj.updateNormalizationFactor();
213 if (obj.isWithinIntegrationTime())
231 obj.incrementIntegrationTimes(timeSpan);
238 scalar objValue(
Zero);
242 scalar cost = obj.JCycle();
243 scalar weight = obj.weight();
244 objValue += weight*cost;
246 Info<< obj.objectiveName() <<
" : " << cost <<
endl;
257 const scalar weightedObjective,
265 obj.writeMeanValue();
273 <<
setw(width) << weightedObjective <<
" ";
278 <<
setw(width) << objI.JCycle() <<
" ";
291 scalar weightedObjective =
print();
324 if (!obj.hasIntegrationStartTime() || !obj.hasIntegrationEndTime())
327 <<
"Objective function " << obj.objectiveName()
328 <<
" does not have a defined integration start or end time "
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 incompressible objective functions.
autoPtr< OFstream > weigthedObjectiveFile_
Ostream & endl(Ostream &os)
Add newline and flush stream.
static unsigned int defaultPrecision() noexcept
Return the default precision.
virtual bool writeObjectives(const scalar weightedObjective, const bool valid=true)
Write objective function history.
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.
A class for handling words, derived from Foam::string.
static autoPtr< objectiveManager > New(const fvMesh &mesh, const dictionary &dict, const word &adjointSolverName, const word &primalSolverName)
Return a reference to the selected turbulence model.
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...
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)
scalar print()
Print to screen.
defineTypeNameAndDebug(combustionModel, 0)
void update()
Update objective function related values.
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.
#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.
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...
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
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)