42 Foam::adjointSolverManager::adjointSolverManager
45 const word& managerType,
47 bool overrideUseSolverName
67 objectiveSolverIDs_(0),
68 constraintSolverIDs_(0),
71 dict.getOrDefault<scalar>(
"operatingPointWeight", 1)
77 const wordList adjSolverNames = adjointSolversDict.
toc();
83 forAll(adjSolverNames, namei)
86 adjointSolversDict.
subDict(adjSolverNames[namei]);
89 solverDict.
add<
bool>(
"useSolverNameForFields",
true);
116 <<
" adjoint solvers acting as constraints" <<
endl;
123 <<
"Number of adjoint solvers corresponding to objectives " 125 <<
"Consider aggregating your objectives to one" <<
endl;
136 const dictionary& adjointSolversDict =
dict.
subDict(
"adjointSolvers");
139 for (adjointSolver& solver : adjointSolvers_)
156 return primalSolverName_;
169 return adjointSolvers_;
176 return adjointSolvers_;
182 return operatingPointWeight_;
188 return constraintSolverIDs_.size();
194 return objectiveSolverIDs_.size();
200 return nConstraints() + nObjectives();
222 for (
const label solveri : objectiveSolverIDs_)
226 adjointSolvers_[solveri].getObjectiveSensitivities();
242 PtrList<scalarField> constraintSens(constraintSolverIDs_.size());
243 forAll(constraintSens, cI)
245 label consI = constraintSolverIDs_[cI];
249 new scalarField(adjointSolvers_[consI].getObjectiveSensitivities())
253 return constraintSens;
261 adjSolver.computeObjectiveSensitivities();
270 adjSolver.clearSensitivities();
277 scalar objValue(
Zero);
278 for (
const label solveri : objectiveSolverIDs_)
280 objectiveManager& objManager =
281 adjointSolvers_[solveri].getObjectiveManager();
282 objValue += objManager.print();
291 tmp<scalarField> tconstraintValues
295 scalarField& constraintValues = tconstraintValues.ref();
296 forAll(constraintValues, cI)
298 objectiveManager& objManager =
299 adjointSolvers_[constraintSolverIDs_[cI]].getObjectiveManager();
300 constraintValues[cI] = objManager.print();
303 return tconstraintValues;
309 if (primalSolverName_ ==
name)
311 for (adjointSolver& solver : adjointSolvers_)
313 solver.updatePrimalBasedQuantities();
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
void updatePrimalBasedQuantities(const word &name)
Update fields related to primal solution.
scalar objectiveValue()
Get objective value.
void size(const label n)
Older name for setAddressableSize.
virtual PtrList< scalarField > constraintSensitivities()
Get constraint sensitivities. One scalarField per constraint.
virtual tmp< scalarField > constraintValues()
Get constraint values.
label nObjectives() const
Number of adjoint solvers corresponding to objectives.
Base class for solution control classes.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
label nAdjointSolvers() const
Total number of adjoint solvers.
constexpr char nl
The newline '\n' character (0x0a)
scalar operatingPointWeight() const
Const access to adjoint solvers.
const word dictName("faMeshDefinition")
const word primalSolverName_
Ostream & endl(Ostream &os)
Add newline and flush stream.
void clearSensitivities()
Clear sensitivity fields from all adjoint solvers.
virtual tmp< scalarField > aggregateSensitivities()
Aggregate sensitivities from various adjoint solvers.
Base class for adjoint solvers.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
const word & managerName() const
Const access to the manager name.
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.
PtrList< adjointSolver > adjointSolvers_
#define forAll(list, i)
Loop across all elements in list.
labelList constraintSolverIDs_
label nConstraints() const
Number of adjoint solvers corresponding to constraints.
void computeAllSensitivities()
Compute sensitivities for all adjoint solvers (both objective- and constraint-related ones) ...
void setSize(const label n)
Alias for resize()
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static autoPtr< adjointSolver > New(fvMesh &mesh, const word &managerType, const dictionary &dict, const word &primalSolverName)
Return a reference to the selected turbulence model.
const PtrList< adjointSolver > & adjointSolvers() const
Const access to adjoint solvers.
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
const dictionary & dict() const
Const access to the construction dictionary.
virtual bool readDict(const dictionary &dict)
virtual void solve()=0
Main control loop.
defineTypeNameAndDebug(combustionModel, 0)
virtual void solveAdjointEquations()
Update objective function-related values and solve adjoint equations.
Class for managing adjoint solvers, which may be more than one per operating point.
#define WarningInFunction
Report a warning using Foam::Warning.
virtual bool readDict(const dictionary &dict)
Mesh data needed to do the Finite Volume discretisation.
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)
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
A class for managing temporary objects.
const word & primalSolverName() const
Const access to the primal solver name.
Defines the attributes of an object for which implicit objectRegistry management is supported...
labelList objectiveSolverIDs_
static constexpr const zero Zero
Global zero (0)