43Foam::adjointSolverManager::adjointSolverManager
47 const word& managerType,
49 bool overrideUseSolverName
67 managerType_(managerType),
68 primalSolverName_(
dict.get<
word>(
"primalSolver")),
70 objectiveSolverIDs_(0),
71 oneSidedConstraintSolverIDs_(0),
72 doubleSidedConstraintSolverIDs_(0),
75 dict.getOrDefault<scalar>(
"operatingPointWeight", 1)
77 nActiveAdjointSolvers_(0),
78 designVars_(designVars)
83 const wordList adjSolverNames = adjointSolversDict.
toc();
91 forAll(adjSolverNames, namei)
94 adjointSolversDict.
subDict(adjSolverNames[namei]);
95 if (overrideUseSolverName)
97 solverDict.
add<
bool>(
"useSolverNameForFields",
true);
108 adjSolverNames[namei]
133 <<
" adjoint solvers acting as single-sided constraints" <<
endl;
136 <<
" adjoint solvers acting as double-sided constraints" <<
endl;
139 <<
" active adjoint solvers" <<
endl;
146 <<
"Number of adjoint solvers corresponding to objectives "
148 <<
"Consider aggregating your objectives to one\n" <<
endl;
159 const dictionary& adjointSolversDict =
dict.subDict(
"adjointSolvers");
162 for (adjointSolver& solver : adjointSolvers_)
206 forAll(adjointSolvers_, sI)
231 const dictionary& adjointSolversDict =
dict.subDict(
"adjointSolvers");
232 const wordList adjSolverNames = adjointSolversDict.
toc();
235 forAll(adjSolverNames, namei)
237 active = adjointSolversDict.
subDict(adjSolverNames[namei]).
238 getOrDefault<bool>(
"active",
true);
284 solver.updatePrimalBasedQuantities();
292 solver.computeObjectiveSensitivities(designVars_);
293 if (mesh_.time().writeTime())
301Foam::tmp<Foam::scalarField>
305 auto& sens = tsens.ref();
308 for (
const label solveri : objectiveSolverIDs_)
312 adjointSolvers_[solveri].getObjectiveSensitivities(designVars_);
328 PtrList<scalarField> constraintSens(nConstraints());
331 for (
const label consI : oneSidedConstraintSolverIDs_)
337 (adjointSolvers_[consI].getObjectiveSensitivities(designVars_))
342 for (
const label consI : doubleSidedConstraintSolverIDs_)
345 (adjointSolvers_[consI].getObjectiveSensitivities(designVars_));
350 return constraintSens;
358 adjSolver.computeObjectiveSensitivities(
designVars_);
367 adjSolver.clearSensitivities();
374 scalar objValue(
Zero);
375 for (
const label solveri : objectiveSolverIDs_)
377 objectiveManager& objManager =
378 adjointSolvers_[solveri].getObjectiveManager();
379 objValue += objManager.print();
389 scalarField& constraintValues = tconstraintValues.ref();
392 for (
const label consI : oneSidedConstraintSolverIDs_)
394 objectiveManager& objManager =
395 adjointSolvers_[consI].getObjectiveManager();
396 constraintValues[cI++] = objManager.print();
400 for (
const label consI : doubleSidedConstraintSolverIDs_)
403 adjointSolvers_[consI].getObjectiveManager();
404 constraintValues[cI++] = objManager.
print(
false);
408 return tconstraintValues;
414 if (primalSolverName_ ==
name)
416 for (adjointSolver& solver : adjointSolvers_)
418 solver.updatePrimalBasedQuantities();
426 return mesh_.lookupObject<
primalSolver>(primalSolverName_).isMaster();
@ 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.
const word & name() const noexcept
Return the object name.
void setSize(label n)
Alias for resize().
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
void size(const label n)
Older name for setAddressableSize.
Class for managing adjoint solvers, which may be more than one per operating point.
void clearSensitivities()
Clear sensitivity fields from all adjoint solvers.
label nOneSidedConstraints() const
Number of adjoint solvers corresponding to one-sided constraints.
scalar objectiveValue()
Get objective value.
labelList objectiveSolverIDs_
PtrList< scalarField > constraintSensitivities()
Get constraint sensitivities. One scalarField per constraint.
label nAdjointSolvers() const
Total number of adjoint solvers.
labelList doubleSidedConstraintSolverIDs_
tmp< scalarField > constraintValues()
Get constraint values.
bool isMaster() const
Whether the primal solver corresponding to the adjointSolverManager is the master one,...
bool readDict(const dictionary &dict)
labelList oneSidedConstraintSolverIDs_
tmp< scalarField > aggregateSensitivities()
Aggregate sensitivities from various adjoint solvers.
void computeAllSensitivities()
Compute sensitivities for all adjoint solvers (both objective- and constraint-related ones).
scalar operatingPointWeight_
const word & primalSolverName() const
Const access to the primal solver name.
void updatePrimalBasedQuantities(const word &name)
Update fields related to primal solution.
wordList adjointSolversNames() const
Return the names of all adjointSolvers.
PtrList< adjointSolver > adjointSolvers_
label nConstraints() const
Number of constraints.
void solveAdjointEquations()
Update objective function-related values and solve adjoint equations.
const dictionary & dict() const
Const access to the construction dictionary.
label nDoubleSidedConstraints() const
Number of adjoint solvers corresponding to double-sided constraints.
scalar operatingPointWeight() const
Const access to adjoint solvers.
autoPtr< designVariables > & designVars_
const word primalSolverName_
const PtrList< adjointSolver > & adjointSolvers() const
Const access to adjoint solvers.
label nActiveAdjointSolvers() const
Return number of active adjoint solvers, either corresponding.
label nObjectives() const
Number of adjoint solvers corresponding to objectives.
const word & managerName() const
Const access to the manager name.
label nActiveAdjointSolvers_
Base class for adjoint solvers.
static autoPtr< adjointSolver > New(fvMesh &mesh, const word &managerType, const dictionary &dict, const word &primalSolverName, const word &solverName)
Return a reference to the selected turbulence model.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
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.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
wordList toc() const
Return the table of contents.
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Mesh data needed to do the Finite Volume discretisation.
Class for managing objective functions.
scalar print(bool negate=false)
Print to screen.
Base class for primal solvers.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
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...
virtual bool readDict(const dictionary &dict)
virtual void solve()=0
Main control loop.
A class for managing temporary objects.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
const word dictName("faMeshDefinition")
#define WarningInFunction
Report a warning using Foam::Warning.
List< word > wordList
List of word.
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static constexpr const zero Zero
Global zero (0).
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.