Go to the documentation of this file.
39 namespace incompressible
49 optimisationType::optimisationType
68 dict_.subDict(
"updateMethod").subOrEmptyDict(
"lineSearch"),
75 label nConstraints(0);
78 nConstraints += adjManagerI.nConstraints();
86 && !isA<constrainedOptimisationMethod>(updateMethod_())
92 constrainedOptimisationMethod::dictionaryConstructorTablePtr_
95 <<
"Found " << nConstraints <<
" adjoint solvers corresponding to "
96 <<
"constraints but the optimisation method used "
97 <<
"(" << updateMethod_().type() <<
") "
98 <<
"is not a constrainedOptimisationMethod. " <<
nl
99 <<
"Available constrainedOptimisationMethods are :" <<
nl
100 << cstTablePtr->sortedToc()
106 && isA<constrainedOptimisationMethod>(updateMethod_())
111 <<
"Did not find any adjoint solvers corresponding to "
112 <<
"constraints but the optimisation method used "
113 <<
"(" << updateMethod_().type() <<
") "
114 <<
"is a constrainedOptimisationMethod. " <<
nl <<
nl
115 <<
"This can cause some constraintOptimisationMethods to misbehave."
117 <<
"Either the isConstraint bool is not set in one of the adjoint "
118 <<
"solvers or you should consider using an updateMethod "
119 <<
"that is not a constrainedOptimisationMethod"
134 const word modelType(
dict.subDict(
"optimisationType").get<
word>(
"type"));
136 Info<<
"optimisationType type : " << modelType <<
endl;
138 auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
140 if (!cstrIter.found())
147 *dictionaryConstructorTablePtr_
198 scalar objectiveValue(
Zero);
229 scalar& objectiveValue,
235 const scalar opWeight = adjSolvManager.operatingPointWeight();
239 adjSolvManager.aggregateSensitivities();
241 if (objectiveSens.empty())
243 objectiveSens.setSize(tadjointSolverManagerSens().size(),
Zero);
246 objectiveSens += opWeight*tadjointSolverManagerSens();
247 objectiveValue += opWeight*adjSolvManager.objectiveValue();
251 adjSolvManager.constraintSensitivities();
255 if (constraintSens.empty())
257 constraintSens.
setSize(adjointSolverManagerConstSens.size());
258 forAll(constraintSens, cI)
265 adjointSolverManagerConstSens[cI].size(),
269 constraintValues.setSize(cValues().size());
270 constraintValues =
Zero;
274 forAll(constraintSens, cI)
276 constraintSens[cI] += opWeight*adjointSolverManagerConstSens[cI];
278 constraintValues += opWeight*cValues();
287 scalar objectiveValue(
Zero);
292 const scalar opWeight = adjSolvManager.operatingPointWeight();
294 objectiveValue += opWeight*adjSolvManager.objectiveValue();
297 if (constraintValues.empty())
299 constraintValues.setSize(cValues().size(),
Zero);
301 constraintValues += opWeight*cValues();
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
autoPtr< lineSearch > & getLineSearch()
Get a reference to the line search object.
A class for handling words, derived from Foam::string.
defineTypeNameAndDebug(adjointEikonalSolver, 0)
virtual scalar meritFunctionDirectionalDerivative()
Derivative of the merit function.
virtual void write()
Write useful quantities to files.
A class for managing temporary objects.
static constexpr const zero Zero
Global zero (0)
const autoPtr< volScalarField > & sourcePtr()
Get source term.
autoPtr< volScalarField > sourcePtr_
Ostream & endl(Ostream &os)
Add newline and flush stream.
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix.
virtual tmp< scalarField > computeDirection()
Compute update direction.
defineRunTimeSelectionTable(adjointSensitivity, dictionary)
#define forAll(list, i)
Loop across all elements in list.
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
virtual void updateDesignVariables(scalarField &correction)=0
Update the design variables given their correction.
messageStream Info
Information stream (uses stdout - output is on the master only)
static autoPtr< lineSearch > New(const dictionary &dict, const Time &time)
Return a reference to the selected turbulence model.
static autoPtr< updateMethod > New(const fvMesh &mesh, const dictionary &dict)
Return a reference to the selected turbulence model.
void setSize(const label newLen)
Same as resize()
PtrList< adjointSolverManager > & adjointSolverManagers
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Class for managing adjoint solvers, which may be more than one per operating point.
PtrList< adjointSolverManager > & adjointSolvManagers_
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 T * set(const label i) const
Return const pointer to element (if set) or nullptr.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
autoPtr< updateMethod > updateMethod_
Macros to ease declaration of run-time selection tables.
virtual void computeEta(scalarField &correction)=0
Compute eta if not set in the first step.
virtual void updateGradientsAndValues(scalarField &objectiveSens, PtrList< scalarField > &constraintSens, scalar &objectiveValue, scalarField &constraintValues)
Compute cumulative objective and constraint gradients.
static autoPtr< optimisationType > New(fvMesh &mesh, const dictionary &dict, PtrList< adjointSolverManager > &adjointSolverManagers)
Return a reference to the selected turbulence model.
virtual void update()
Update design variables.
#define WarningInFunction
Report a warning using Foam::Warning.
virtual void updateOldCorrection(const scalarField &)
Update old correction. Needed for quasi-Newton Methods.
autoPtr< lineSearch > lineSearch_
virtual scalar computeMeritFunction()
Compute the merit function of the optimisation problem.