69 if (counter_ > nPrevSteps_)
73 newOrder[0] = nPrevSteps_ - 1;
74 for (label i = 1; i < nPrevSteps_; ++i)
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);
144 forAll(activeDesignVars_, varI)
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());
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);
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
The quasi-Newton Limited-memory BFGS formula. Keeps nPrevSteps_ of the y and s vectors and approximat...
PtrList< scalarField > y_
The previous differences of derivatives. Holds nPrevSteps_ fields.
void updateVectors()
Update y and s vectors.
void pivotFields(PtrList< scalarField > &list, const scalarField &f)
void computeCorrection()
Compute design variables correction.
void LBFGSUpdate()
Update based on LBFGS.
void readFromDict()
Read old info from dict.
PtrList< scalarField > s_
The previous correction. Holds nPrevSteps_ fields.
labelList activeDesignVars_
Map to active design variables.
label nPrevSteps_
Number of old corrections and grad differences kept.
void allocateMatrices()
Allocate matrices in the first optimisation cycle.
virtual void write()
Write old info to dict.
virtual void updateOldCorrection(const scalarField &oldCorrection)
void update()
Update design variables.
void steepestDescentUpdate()
Update based on steepest descent.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
void size(const label n)
Older name for setAddressableSize.
void reorder(const labelUList &oldToNew, const bool check=false)
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.
Abstract base class for optimisation methods.
scalarField objectiveDerivatives_
Derivatives of the objective functions.
dictionary coeffsDict()
Return optional dictionary with parameters specific to each method.
virtual void write()
Write useful quantities to files.
virtual void updateOldCorrection(const scalarField &oldCorrection)
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define DebugInfo
Report an information message using Foam::Info.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
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.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
static constexpr const zero Zero
Global zero (0)
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.
propsDict readIfPresent("fields", acceptFields)