61 temp[i][i] = scalar(1);
76 y.map(objectiveDerivatives_ - derivativesOld_, activeDesignVars_);
77 s.map(correctionOld_, activeDesignVars_);
82 scalar tempMag =
sqrt(globalSum(
sqr(temp)));
83 scalar yMag =
sqrt(globalSum(
sqr(
y)));
84 scalar HessYMag =
sqrt(globalSum(
sqr(rightMult(HessianInvOld_,
y))));
87 if (tempMag > ratioThreshold_ * yMag * HessYMag)
91 + (scalar(1)/(globalSum(temp*
y)))*outerProd(temp, temp);
96 <<
"Denominator of update too small. Keeping old Hessian" <<
endl;
97 HessianInv_ = HessianInvOld_;
106 if (counter_ < nSteepestDescent_)
108 Info<<
"Using steepest descent to update design variables ... " <<
endl;
109 correction_ = -eta_*objectiveDerivatives_;
114 activeDerivs.
map(objectiveDerivatives_, activeDesignVars_);
117 -etaHessian_*rightMult(HessianInv_, activeDerivs)
122 forAll(activeDesignVars_, varI)
124 correction_[activeDesignVars_[varI]] = activeCorrection[varI];
129 derivativesOld_ = objectiveDerivatives_;
130 correctionOld_ = correction_;
131 HessianInvOld_ = HessianInv_;
137 if (optMethodIODict_.headerOk())
139 optMethodIODict_.readEntry(
"HessianInvOld", HessianInvOld_);
140 optMethodIODict_.readEntry(
"derivativesOld", derivativesOld_);
141 optMethodIODict_.readEntry(
"correctionOld", correctionOld_);
142 optMethodIODict_.readEntry(
"counter", counter_);
143 optMethodIODict_.readEntry(
"eta", eta_);
145 const label
n(HessianInvOld_.n());
149 if (activeDesignVars_.empty())
159 Foam::SR1::SR1(
const fvMesh&
mesh,
const dictionary&
dict)
166 coeffsDict().getOrDefault<scalar>(
"etaHessian", 1)
170 coeffsDict().getOrDefault<label>(
"nSteepestDescent", 1)
174 coeffsDict().getOrDefault<scalar>(
"ratioThreshold", 1
e-08)
176 activeDesignVars_(0),
190 Info<<
"\t Didn't find explicit definition of active design variables. " 191 <<
"Treating all available ones as active " <<
endl;
220 correctionOld_ = oldCorrection;
232 optMethodIODict_.add<
scalarField>(
"derivativesOld", derivativesOld_,
true);
233 optMethodIODict_.add<
scalarField>(
"correctionOld", correctionOld_,
true);
234 optMethodIODict_.add<label>(
"counter", counter_,
true);
labelList activeDesignVars_
Map to active design variables.
void allocateMatrices()
Allocate matrices in the first optimisation cycle.
void size(const label n)
Older name for setAddressableSize.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
virtual void updateOldCorrection(const scalarField &oldCorrection)
Update old correction. Useful for quasi-Newton methods coupled with line search.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
virtual void updateOldCorrection(const scalarField &oldCorrection)
Update old correction. useful for quasi-newton methods coupled with line search.
const dimensionedScalar e
Elementary charge.
void computeCorrection()
Compute design variables correction.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
SquareMatrix< scalar > HessianInv_
The Hessian inverse. Should have the size of the active design variables.
propsDict readIfPresent("fields", acceptFields)
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
void update()
Update design variables.
void readFromDict()
Read old info from dict.
defineTypeNameAndDebug(combustionModel, 0)
SquareMatrix< scalar > HessianInvOld_
The previous Hessian inverse.
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
scalarField objectiveDerivatives_
Derivatives of the objective functions.
#define WarningInFunction
Report a warning using Foam::Warning.
void updateHessian()
Update approximation of the inverse Hessian.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual void write()
Write useful quantities to files.
virtual void write()
Write old info to dict.
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))
dictionary coeffsDict()
Return optional dictionary with parameters specific to each method.
static constexpr const zero Zero
Global zero (0)