69 if (counter_ > nPrevSteps_)
73 newOrder[0] = nPrevSteps_ - 1;
74 for (label i = 1; i < nPrevSteps_; ++i)
78 list.reorder(newOrder);
81 list[nPrevSteps_ - 1] =
f;
85 list[counter_ - 1] =
f;
95 (objectiveDerivatives_ - derivativesOld_, activeDesignVars_);
96 pivotFields(y_, yRecent);
99 scalarField sActive(correctionOld_, activeDesignVars_);
100 pivotFields(s_, sActive);
103 <<
"y fields" <<
nl << y_ <<
endl;
105 <<
"s fields" <<
nl << s_ <<
endl;
111 Info<<
"Using steepest descent to update design variables" <<
endl;
112 correction_ = -eta_*objectiveDerivatives_;
120 label nSteps(
min(counter_, nPrevSteps_));
121 label nLast(nSteps - 1);
122 scalarField q(objectiveDerivatives_, activeDesignVars_);
125 for (label i = nLast; i > -1; --i)
127 r[i] = 1./globalSum(y_[i]*s_[i]);
128 a[i] = r[i]*globalSum(s_[i]*q);
133 globalSum(y_[nLast]*s_[nLast])/globalSum(y_[nLast]*y_[nLast]);
137 for (label i = 0; i < nSteps; ++i)
139 b = r[i]*globalSum(y_[i]*q);
140 q += s_[i]*(a[i] -
b);
146 correction_[activeDesignVars_[varI]] = -etaHessian_*q[varI];
155 if (counter_ < nSteepestDescent_)
157 steepestDescentUpdate();
166 derivativesOld_ = objectiveDerivatives_;
167 correctionOld_ = correction_;
173 if (optMethodIODict_.headerOk())
175 optMethodIODict_.readEntry(
"y", y_);
176 optMethodIODict_.readEntry(
"s", s_);
177 optMethodIODict_.readEntry(
"derivativesOld", derivativesOld_);
178 optMethodIODict_.readEntry(
"counter", counter_);
179 optMethodIODict_.readEntry(
"eta", eta_);
180 optMethodIODict_.readEntry(
"correctionOld", correctionOld_);
184 if (activeDesignVars_.empty())
186 activeDesignVars_ =
identity(derivativesOld_.size());
197 const dictionary&
dict 205 coeffsDict().getOrDefault<scalar>(
"etaHessian", 1)
209 coeffsDict().getOrDefault<label>(
"nSteepestDescent", 1)
211 activeDesignVars_(0),
214 coeffsDict().getOrDefault<label>(
"nPrevSteps", 10)
228 Info<<
"\t Did not find explicit definition of active design variables. " 229 <<
"Treating all available ones as active " <<
endl;
258 correctionOld_ = oldCorrection;
266 optMethodIODict_.add<
scalarField>(
"derivativesOld", derivativesOld_,
true);
267 optMethodIODict_.add<
scalarField>(
"correctionOld", correctionOld_,
true);
268 optMethodIODict_.add<label>(
"counter", counter_,
true);
void allocateMatrices()
Allocate matrices in the first optimisation cycle.
void size(const label n)
Older name for setAddressableSize.
void update()
Update design variables.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
void readFromDict()
Read old info from dict.
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual void write()
Write old info to dict.
void steepestDescentUpdate()
Update based on steepest descent.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
labelList activeDesignVars_
Map to active design variables.
virtual void updateOldCorrection(const scalarField &oldCorrection)
Update old correction. Useful for quasi-Newton methods coupled with line search.
virtual void updateOldCorrection(const scalarField &oldCorrection)
Update old correction. useful for quasi-newton methods coupled with line search.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
void pivotFields(PtrList< scalarField > &list, const scalarField &f)
Move pointers in PtrList to the left and replace last element with given field.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
PtrList< scalarField > s_
The previous correction. Holds nPrevSteps_ fields.
label nPrevSteps_
Number of old corrections and grad differences kept.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
#define DebugInfo
Report an information message using Foam::Info.
void LBFGSUpdate()
Update based on LBFGS.
void computeCorrection()
Compute design variables correction.
defineTypeNameAndDebug(combustionModel, 0)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
scalarField objectiveDerivatives_
Derivatives of the objective functions.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
PtrList< scalarField > y_
The previous differences of derivatives. Holds nPrevSteps_ fields.
meshDefDict readIfPresent("polyMeshPatches", polyPatchNames)
messageStream Info
Information stream (stdout output on master, null elsewhere)
void updateVectors()
Update y and s vectors.
virtual void write()
Write useful quantities to files.
List< label > labelList
A List of labels.
dictionary coeffsDict()
Return optional dictionary with parameters specific to each method.
static constexpr const zero Zero
Global zero (0)