Go to the documentation of this file.
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;
77 wordList objectiveNames(objectiveNamesDict.toc());
78 objectives_.
setSize(objectiveNames.size());
80 forAll(objectiveNames, objectivei)
82 const word& objectiveName = objectiveNames[objectivei];
90 objectiveNamesDict.subDict(objectiveName),
98 if (objectives_.empty())
101 <<
"No objectives have been set - cannot perform an optimisation"
107 if (objectives_.size() > 1)
110 weigthedObjectiveFile_.reset
115 /time.
timeName()/
"weightedObjective"+adjointSolverName_
120 weigthedObjectiveFile_()
121 <<
setw(4) <<
"#" <<
" "
122 <<
setw(width) <<
"weightedObjective" <<
" ";
125 weigthedObjectiveFile_()
126 <<
setw(width) << objI.objectiveName() <<
" ";
128 weigthedObjectiveFile_()
141 const word& adjointSolverName,
142 const word& primalSolverName
147 const word managerType(
"objectiveManager" & objectiveType);
149 auto* ctorPtr = dictionaryConstructorTable(managerType);
156 "objectiveManagerType",
158 *dictionaryConstructorTablePtr_
164 ctorPtr(
mesh,
dict, adjointSolverName, primalSolverName)
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;
249 Info<<
"Weighted objective : " << objValue <<
nl <<
endl;
257 const scalar weightedObjective,
265 obj.writeMeanValue();
268 if (weigthedObjectiveFile_.valid())
271 weigthedObjectiveFile_()
272 <<
setw(4) << mesh_.time().timeName() <<
" "
273 <<
setw(width) << weightedObjective <<
" ";
277 weigthedObjectiveFile_()
278 <<
setw(width) << objI.JCycle() <<
" ";
280 weigthedObjectiveFile_() <<
endl;
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 "
void updateNormalizationFactor()
Update objective function related values.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const word & primalSolverName() const
Return name of the primalSolver.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for handling words, derived from Foam::string.
static autoPtr< dictionary > New(Istream &is)
Construct top-level dictionary on freestore from Istream.
scalar print()
Print to screen.
static constexpr const zero Zero
Global zero (0)
PtrList< objective > objectives_
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
static word timeName(const scalar t, const int precision=precision_)
virtual bool readDict(const dictionary &dict)
void update()
Update objective function related values.
static bool master(const label communicator=worldComm)
Am I the master process.
Ostream & endl(Ostream &os)
Add newline and flush stream.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
#define forAll(list, i)
Loop across all elements in list.
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
void incrementIntegrationTimes(const scalar timeSpan)
Increment integration times by the optimisation cycle time-span.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool writeObjectives(const scalar weightedObjective, const bool valid=true)
Write objective function history.
void setSize(const label n)
Alias for resize()
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Istream and Ostream manipulators taking arguments.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const word primalSolverName_
Mesh data needed to do the Finite Volume discretisation.
Omanip< int > setw(const int i)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Output to file stream, using an OSstream.
const word adjointSolverName_
static unsigned int defaultPrecision() noexcept
Return the default precision.
void checkIntegrationTimes() const
Check integration times for unsteady runs.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
const word & system() const
Return system name.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static autoPtr< objectiveManager > New(const fvMesh &mesh, const dictionary &dict, const word &adjointSolverName, const word &primalSolverName)
Return a reference to the selected turbulence model.
fileName globalPath() const
Return global path for the case.
const Time & time() const
Return the top-level database.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
void updateOrNullify()
Update contributions to adjoint if true, otherwise return nulls.
const word & adjointSolverName() const
Return name of the adjointSolver.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
defineTypeNameAndDebug(combustionModel, 0)
const Time & time() const noexcept
Return time registry.
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.