Go to the documentation of this file.
42 Foam::adjointSolverManager::adjointSolverManager
45 const word& managerType,
53 "adjointSolverManager" +
dict.dictName(),
63 managerName_(
dict.dictName()),
64 primalSolverName_(
dict.get<
word>(
"primalSolver")),
66 objectiveSolverIDs_(0),
67 constraintSolverIDs_(0),
70 dict.getOrDefault<scalar>(
"operatingPointWeight", 1)
73 const dictionary& adjointSolversDict =
dict.subDict(
"adjointSolvers");
75 const wordList adjSolverNames = adjointSolversDict.
toc();
76 adjointSolvers_.
setSize(adjSolverNames.size());
77 objectiveSolverIDs_.setSize(adjSolverNames.size());
78 constraintSolverIDs_.setSize(adjSolverNames.size());
80 label nConstraints(0);
81 forAll(adjSolverNames, namei)
90 adjointSolversDict.
subDict(adjSolverNames[namei]),
95 if (adjointSolvers_[namei].isConstraint())
97 constraintSolverIDs_[nConstraints++] = namei;
101 objectiveSolverIDs_[nObjectives++] = namei;
104 objectiveSolverIDs_.setSize(nObjectives);
105 constraintSolverIDs_.setSize(nConstraints);
107 Info<<
"Found " << nConstraints
108 <<
" adjoint solvers acting as constraints" <<
endl;
112 if (objectiveSolverIDs_.size() > 1)
115 <<
"Number of adjoint solvers corresponding to objectives "
116 <<
"is greater than 1 (" << objectiveSolverIDs_.size() <<
")" <<
nl
117 <<
"Consider aggregating your objectives to one" <<
endl;
148 return primalSolverName_;
161 return adjointSolvers_;
168 return adjointSolvers_;
174 return operatingPointWeight_;
180 return constraintSolverIDs_.size();
186 return objectiveSolverIDs_.size();
192 return nConstraints() + nObjectives();
214 for (
const label solveri : objectiveSolverIDs_)
218 adjointSolvers_[solveri].getObjectiveSensitivities();
235 forAll(constraintSens, cI)
237 label consI = constraintSolverIDs_[cI];
241 new scalarField(adjointSolvers_[consI].getObjectiveSensitivities())
245 return constraintSens;
253 adjSolver.computeObjectiveSensitivities();
262 adjSolver.clearSensitivities();
269 scalar objValue(
Zero);
270 for (
const label solveri : objectiveSolverIDs_)
273 adjointSolvers_[solveri].getObjectiveManager();
274 objValue += objManager.
print();
288 forAll(constraintValues, cI)
291 adjointSolvers_[constraintSolverIDs_[cI]].getObjectiveManager();
292 constraintValues[cI] = objManager.
print();
295 return tconstraintValues;
301 if (primalSolverName_ ==
name)
305 solver.updatePrimalBasedQuantities();
Base class for adjoint solvers.
PtrList< adjointSolver > adjointSolvers_
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
class for managing incompressible objective functions.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
label nConstraints() const
Number of adjoint solvers corresponding to constraints.
label nObjectives() const
Number of adjoint solvers corresponding to objectives.
virtual void solve()=0
Main control loop.
scalar operatingPointWeight() const
Const access to adjoint solvers.
A class for handling words, derived from Foam::string.
virtual PtrList< scalarField > constraintSensitivities()
Get constraint sensitivities. One scalarField per constraint.
void clearSensitivities()
Clear sensitivity fields from all adjoint solvers.
scalar print()
Print to screen.
A class for managing temporary objects.
static constexpr const zero Zero
Global zero (0)
label nAdjointSolvers() const
Total number of adjoint solvers.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual tmp< scalarField > aggregateSensitivities()
Aggregate sensitivities from various adjoint solvers.
const word & name() const
#define forAll(list, i)
Loop across all elements in list.
virtual bool readDict(const dictionary &dict)
virtual tmp< scalarField > constraintValues()
Get constraint values.
Base class for solution control classes.
messageStream Info
Information stream (uses stdout - output is on the master only)
word name(const complex &c)
Return string representation of complex.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
void computeAllSensitivities()
const dictionary & dict() const
Const access to the construction dictionary.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Mesh data needed to do the Finite Volume discretisation.
const PtrList< adjointSolver > & adjointSolvers() const
Const access to adjoint solvers.
const word & managerName() const
Const access to the manager name.
scalar objectiveValue()
Get objective value.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
virtual void solveAdjointEquations()
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
const word & primalSolverName() const
Const access to the primal solver name.
void updatePrimalBasedQuantities(const word &name)
Update fields related to primal solution.
virtual bool readDict(const dictionary &dict)
wordList toc() const
Return the table of contents.
void setSize(const label newSize)
Alias for resize(const label)
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
Report a warning using Foam::Warning.