39 namespace incompressible
49 optimisationType::optimisationType
68 dict_.subDict(
"updateMethod").subOrEmptyDict(
"lineSearch"),
75 label nConstraints(0);
78 nConstraints += adjManagerI.nConstraints();
89 const auto& cnstrTable =
90 *(constrainedOptimisationMethod::dictionaryConstructorTablePtr_);
94 <<
"Found " << nConstraints <<
" adjoint solvers corresponding to " 95 <<
"constraints but the optimisation method (" 97 <<
") is not a constrainedOptimisationMethod." <<
nl 98 <<
"Available constrainedOptimisationMethods:" <<
nl 99 << cnstrTable.sortedToc()
110 <<
"Did not find any adjoint solvers corresponding to " 111 <<
"constraints but the optimisation method (" 113 <<
") is a constrainedOptimisationMethod." <<
nl <<
nl 114 <<
"This can cause some constraintOptimisationMethods to misbehave." 116 <<
"Either the isConstraint bool is not set in one of the adjoint " 117 <<
"solvers or you should consider using an updateMethod " 118 <<
"that is not a constrainedOptimisationMethod" 133 const word modelType(
dict.subDict(
"optimisationType").get<
word>(
"type"));
135 Info<<
"optimisationType type : " << modelType <<
endl;
137 auto* ctorPtr = dictionaryConstructorTable(modelType);
146 *dictionaryConstructorTablePtr_
150 return autoPtr<optimisationType>
194 scalar objectiveValue(
Zero);
228 scalar& objectiveValue,
234 const scalar opWeight = adjSolvManager.operatingPointWeight();
238 adjSolvManager.aggregateSensitivities();
240 if (objectiveSens.
empty())
242 objectiveSens.
setSize(tadjointSolverManagerSens().size(),
Zero);
245 objectiveSens += opWeight*tadjointSolverManagerSens();
246 objectiveValue += opWeight*adjSolvManager.objectiveValue();
250 adjSolvManager.constraintSensitivities();
254 if (constraintSens.
empty())
256 constraintSens.
setSize(adjointSolverManagerConstSens.
size());
257 forAll(constraintSens, cI)
264 adjointSolverManagerConstSens[cI].size(),
268 constraintValues.
setSize(cValues().size());
269 constraintValues =
Zero;
273 forAll(constraintSens, cI)
275 constraintSens[cI] += opWeight*adjointSolverManagerConstSens[cI];
277 constraintValues += opWeight*cValues();
286 scalar objectiveValue(
Zero);
291 const scalar opWeight = adjSolvManager.operatingPointWeight();
293 objectiveValue += opWeight*adjSolvManager.objectiveValue();
294 tmp<scalarField> cValues = adjSolvManager.constraintValues();
296 if (constraintValues.empty())
298 constraintValues.setSize(cValues().size(),
Zero);
300 constraintValues += opWeight*cValues();
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
virtual void updateDesignVariables(scalarField &correction)=0
Update the design variables given their correction.
void size(const label n)
Older name for setAddressableSize.
defineTypeNameAndDebug(adjointEikonalSolver, 0)
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
constexpr char nl
The newline '\n' character (0x0a)
Abstract base class for optimisation methods.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static autoPtr< optimisationType > New(fvMesh &mesh, const dictionary &dict, PtrList< adjointSolverManager > &adjointSolverManagers)
Return a reference to the selected turbulence model.
virtual void updateOldCorrection(const scalarField &)
Update old correction. Needed for quasi-Newton Methods.
virtual void update()
Update design variables.
Abstract base class for optimisation methods.
#define forAll(list, i)
Loop across all elements in list.
autoPtr< volScalarField > sourcePtr_
void setSize(const label n)
Alias for resize()
PtrList< adjointSolverManager > & adjointSolvManagers_
virtual tmp< scalarField > computeDirection()
Compute update direction.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
autoPtr< updateMethod > updateMethod_
label size() const noexcept
The number of elements in the list.
const autoPtr< volScalarField > & sourcePtr()
Get source term.
virtual void computeEta(scalarField &correction)=0
Compute eta if not set in the first step.
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
void setSize(const label newLen)
Same as resize()
virtual void updateGradientsAndValues(scalarField &objectiveSens, PtrList< scalarField > &constraintSens, scalar &objectiveValue, scalarField &constraintValues)
Compute cumulative objective and constraint gradients.
defineRunTimeSelectionTable(adjointSensitivity, dictionary)
Abstract base class for line search methods.
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &alphaRhoPhi, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
virtual scalar meritFunctionDirectionalDerivative()
Derivative of the merit function.
Class for managing adjoint solvers, which may be more than one per operating point.
#define WarningInFunction
Report a warning using Foam::Warning.
virtual scalar computeMeritFunction()
Compute the merit function of the optimisation problem.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Mesh data needed to do the Finite Volume discretisation.
autoPtr< lineSearch > & getLineSearch()
Get a reference to the line search object.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Macros to ease declaration of run-time selection tables.
A class for managing temporary objects.
PtrList< adjointSolverManager > & adjointSolverManagers
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
autoPtr< lineSearch > lineSearch_
virtual void write()
Write useful quantities to files.
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)