44objectiveManager::objectiveManager
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,
264 <<
setw(4) <<
mesh_.time().timeName() <<
" "
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);
Istream and Ostream manipulators taking arguments.
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing 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.
static unsigned int defaultPrecision() noexcept
Return the default precision.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
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.
void size(const label n)
Older name for setAddressableSize.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
wordList toc() const
Return the table of contents.
Mesh data needed to do the Finite Volume discretisation.
const Time & time() const
Return the top-level database.
Class for managing objective functions.
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
void updateAndWrite()
Call all functions required prior to the solution of the adjoint equations.
const word & adjointSolverName() const
Return name of the adjointSolver.
virtual void addSource(fvVectorMatrix &matrix)
Add contribution to adjoint momentum PDEs.
virtual bool readDict(const dictionary &dict)
void setWrite(const bool shouldWrite)
Should the objectives be written to file upon calling write()?
virtual bool writeObjectives()
Write objective function history.
scalar print(bool negate=false)
Print to screen.
void checkIntegrationTimes() const
Check integration times for unsteady runs.
PtrList< objective > objectives_
void updateOrNullify()
Update contributions to adjoint if true, otherwise return nulls.
void incrementIntegrationTimes(const scalar timeSpan)
Increment integration times by the optimisation cycle time-span.
void update()
Update objective function related values.
const word primalSolverName_
void updateNormalizationFactor()
Update objective function related values.
const word adjointSolverName_
autoPtr< OFstream > weightedObjectiveFile_
const word & primalSolverName() const
Return name of the primalSolver.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
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.
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
List< word > wordList
List of word.
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
fvMatrix< scalar > fvScalarMatrix
messageStream Info
Information stream (stdout output on master, null elsewhere).
Omanip< int > setw(const int i)
Ostream & endl(Ostream &os)
Add newline and flush stream.
fvMatrix< vector > fvVectorMatrix
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 nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.