76 Info<<
"Scaling Hessian with factor " << scaleFactor <<
endl;
79 Hessian_()[varI][varI] /= scaleFactor;
85 <<
" y*s is negative. Skipping the scaling of the first Hessian"
96 <<
" y*s is below threshold. Using damped form" <<
endl;
101 <<
"Unmodified Hessian curvature index " << ys <<
endl;
118 Info<<
"Hessian " << Hessian_() <<
endl;
119 Info<<
"HessianInv " << HessianInv <<
endl;
120 label
n = Hessian_().n();
122 for (label
k = 0;
k <
n;
k++)
124 for (label l = 0; l <
n; l++)
127 for (label i = 0; i <
n; i++)
129 elem += Hessian_()[
k][i] * HessianInv[i][l];
134 Info<<
"Validation " << test <<
endl;
138 label nc = constraintDerivatives_.size();
142 activeDerivs.map(LagrangianDerivatives_, activeDesignVars_);
143 scalarField WgradL = rightMult(HessianInv, activeDerivs);
149 activeConsDerivs.map(constraintDerivatives_[cI], activeDesignVars_);
150 lamdaRHS[cI] = globalSum(activeConsDerivs * WgradL) - cValues_[cI];
153 Info<<
"lamdaRHS total|deriv part|constraint part "
154 << lamdaRHS[cI] <<
" " << globalSum(activeConsDerivs * WgradL)
155 <<
" " << cValues_[cI] <<
endl;
162 for (label j = 0; j < nc; j++)
165 gradcJ.map(constraintDerivatives_[j], activeDesignVars_);
166 WA.set(j,
new scalarField(rightMult(HessianInv, gradcJ)));
167 for (label i = 0; i < nc; i++)
170 gradcI.map(constraintDerivatives_[i], activeDesignVars_);
171 AWA[i][j] = globalSum(gradcI * WA[j]);
175 scalarField deltaLamda = rightMult(invAWA, lamdaRHS);
180 Info<<
"lamda update " << deltaLamda <<
endl;
182 lamdas_ += deltaLamda;
188 activeCorrection += WA[cI]*deltaLamda[cI];
190 activeCorrection *= etaHessian_;
193 forAll(activeDesignVars_, varI)
195 correction_[activeDesignVars_[varI]] = activeCorrection[varI];
204void Foam::SQP::storeOldFields()
206 derivativesOld_ = objectiveDerivatives_;
207 if (constraintDerivativesOld_.empty())
209 constraintDerivativesOld_.setSize(constraintDerivatives_.size());
211 forAll(constraintDerivativesOld_, cI)
213 constraintDerivativesOld_[cI] = constraintDerivatives_[cI];
215 correctionOld_ = correction_;
236 const label nConstraints,
244 coeffsDict(
type).getOrDefault<scalar>(
"dumpingThreshold", 0.2)
255 LagrangianDerivatives_ = objectiveDerivatives_;
266 if (mu_ <
max(
mag(lamdas_)) + delta_)
268 mu_ =
max(
mag(lamdas_)) + 2*delta_;
271 Info<<
"Updated mu value to " << mu_ <<
endl;
274 scalar
L = objectiveValue_ + mu_*
sum(
mag(cValues_));
Istream and Ostream manipulators taking arguments.
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Base class for Sequantial Quadratic Programming (SQP) methods.
scalarField lamdas_
Lagrange multipliers.
virtual bool addToFile(Ostream &os) const
Write continuation info.
scalar mu_
Penalty value for the merit function.
virtual bool writeMeritFunction(const updateMethod &UpdateMethod)
Write info about the merit function.
List< scalarField > constraintDerivativesOld_
The previous constraint derivatives.
scalar delta_
Safety factor.
virtual scalar meritFunctionConstraintPart() const =0
Get the part the merit function that depends on the constraints.
scalarField LagrangianDerivatives_
Derivatives of the Lagrangian function.
The quasi-Newton SQP formula for constrained optimisation.
void computeCorrection()
Compute design variables correction.
virtual scalar meritFunctionDirectionalDerivative()
Derivative of the merit function. Could be different than the objective derivative in the presence of...
virtual bool writeAuxiliaryData()
Write merit function information.
virtual bool writeData(Ostream &os) const
Write useful quantities to files.
virtual scalar computeMeritFunction()
Compute merit function. Could be different than the objective in the presence of constraints.
scalar dumpingThreshold_
Curvature threshold.
A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix.
void size(const label n)
Older name for setAddressableSize.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Abstract base class for optimisation methods supporting constraints. Does not add functionality to up...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
Mesh data needed to do the Finite Volume discretisation.
Base class for quasi-Newton methods.
void computeCorrection()
Compute design variables correction.
scalarField correctionOld_
The previous correction.
autoPtr< SquareMatrix< scalar > > Hessian_
The Hessian or its inverse, depending on the deriving class.
virtual bool writeData(Ostream &os) const
Write useful quantities to files.
virtual void updateHessian()=0
Update approximation of the inverse Hessian.
virtual void update()=0
Update design variables.
bool scaleFirstHessian_
Scale the initial unitary Hessian approximation.
scalarField derivativesOld_
The previous derivatives.
void allocateHessian()
Allocate the Hessian matrix.
Abstract base class for optimisation methods.
scalarField objectiveDerivatives_
Derivatives of the objective functions.
scalarField correction_
Design variables correction.
dictionary coeffsDict(const word &type) const
Return optional dictionary with parameters specific to each method.
scalar globalSum(const scalarField &field)
Compute either global or local sum, based on globalSum flag.
scalarField cValues_
Constraint values.
scalar objectiveValue_
Objective value.
PtrList< scalarField > constraintDerivatives_
Derivatives of the constraints.
const scalarField leftMult(const scalarField &, const SquareMatrix< scalar > &)
const labelList & activeDesignVars_
Map to active design variables.
const scalarField rightMult(const SquareMatrix< scalar > &, const scalarField &)
label counter_
Optimisation cycle count.
label nConstraints() const
Get the number of constraints.
SquareMatrix< scalar > outerProd(const scalarField &, const scalarField &)
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for handling debugging switches.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
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.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
static constexpr const zero Zero
Global zero (0).
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
#define forAll(list, i)
Loop across all elements in list.
const vector L(dict.get< vector >("L"))