52 Foam::lineSearch::lineSearch
73 directionalDeriv_(
Zero),
79 lineSearchDict_.getOrDefault<scalar>(
"prevMeritDeriv",
Zero)
81 initialStep_(
dict.getOrDefault<scalar>(
"initialStep", 1.)),
82 minStep_(
dict.getOrDefault<scalar>(
"minStep", 0.3)),
84 iter_(lineSearchDict_.getOrDefault<label>(
"iter", 0)),
86 maxIters_(
dict.getOrDefault<label>(
"maxIters", 4)),
87 extrapolateInitialStep_
89 dict.getOrDefault<bool>
91 "extrapolateInitialStep",
96 updateMethod_(UpdateMethod)
113 Info<<
"lineSearch type : " << modelType <<
endl;
115 if (modelType !=
"none")
117 auto* ctorPtr = dictionaryConstructorTable(modelType);
126 *dictionaryConstructorTablePtr_
130 lineSrch.reset((ctorPtr(
dict, time, UpdateMethod)).ptr());
134 Info<<
"No line search method specified. " 135 <<
"Proceeding with constant step" <<
endl;
146 directionalDeriv_ = deriv;
147 stepUpdate_->setDeriv(deriv);
159 newMeritValue_ = value;
160 stepUpdate_->setNewMeritValue(value);
166 oldMeritValue_ = value;
167 stepUpdate_->setOldMeritValue(value);
174 if (extrapolateInitialStep_ && iter_ != 0)
180 clamp(step_*prevMeritDeriv_/directionalDeriv_, minStep_, scalar(1));
181 Info<<
"\n------- Computing initial step-------" <<
endl;
182 Info<<
"old dphi(0) " << prevMeritDeriv_ <<
endl;
183 Info<<
"dphi(0) " << directionalDeriv_ <<
endl;
184 Info<<
"Setting initial step value " << step_ <<
endl <<
endl;
188 step_ = initialStep_;
207 const bool isRunning = innerIter_ < maxIters_;
233 prevMeritDeriv_ = directionalDeriv_;
234 lineSearchDict_.add<scalar>(
"prevMeritDeriv", prevMeritDeriv_,
true);
235 lineSearchDict_.add<label>(
"iter", iter_,
true);
236 if (lineSearchDict_.time().writeTime())
238 lineSearchDict_.regIOobject::writeObject
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
errorManipArg< error, int > exit(error &err, const int errNo=1)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
virtual void updateStep()=0
Update the line search step based on the specific line search strategy, e.g. bisection, quadratic fit, etc.
const dictionary dict_
Subdict within updateMethod.
virtual void updateCorrection(scalarField &correction)
Update the correction.
const dictionary & coeffsDict()
Optional coeffs dict.
Abstract base class for optimisation methods.
Ostream & endl(Ostream &os)
Add newline and flush stream.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
virtual void postUpdate()
Execute steps at the end of the line search iterations.
A simple container for options an IOstream can normally have.
void setNewMeritValue(const scalar value)
Set new objective value.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
virtual void setNewDeriv(const scalar deriv)
Set new directional derivative.
virtual void setDeriv(const scalar deriv)
Set directional derivative.
static autoPtr< lineSearch > New(const dictionary &dict, const Time &time, updateMethod &UpdateMethod)
Return a reference to the selected turbulence model.
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
A class for handling words, derived from Foam::string.
void setOldMeritValue(const scalar value)
Set old objective value.
virtual lineSearch & operator++()
Increment iteration number and store merit value corresponding to the previous optimisation cycle...
virtual void reset()
Reset step to initial value.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
Abstract base class for line search methods.
Abstract base class for step update methods used in line search.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool loop()
Return true if lineSearch should continue and if so increment inner.
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...
Defines the attributes of an object for which implicit objectRegistry management is supported...
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
dimensionSet clamp(const dimensionSet &a, const dimensionSet &range)
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)
virtual bool computeGradient() const
Does line search need to update the gradient?