65 if (optMethodIODict_.headerOk())
67 optMethodIODict_.readEntry(
"dxOld", dxOld_);
68 optMethodIODict_.readEntry(
"sOld", sOld_);
69 optMethodIODict_.readEntry(
"counter", counter_);
70 optMethodIODict_.readEntry(
"eta", eta_);
72 label nDVs = optMethodIODict_.get<label>(
"nDVs");
75 if (activeDesignVars_.empty())
99 coeffsDict().getOrDefault<
word>(
"betaType",
"FletcherReeves")
109 Info<<
"\t Did not find explicit definition of active design variables. "
110 <<
"Treating all available ones as active " <<
endl;
118 && !(
betaType_ ==
"PolakRibiereRestarted")
122 <<
"Invalid betaType " <<
betaType_ <<
". Valid options are "
123 <<
"FletcherReeves, PolakRibiere, PolakRibiereRestarted"
141 Info<<
"Using steepest descent for the first iteration" <<
endl;
142 correction_ = -eta_*objectiveDerivatives_;
144 dxOld_.map(-objectiveDerivatives_, activeDesignVars_);
150 dx.
map(-objectiveDerivatives_, activeDesignVars_);
153 if (betaType_ ==
"FletcherReeves")
155 beta = globalSum(dx*dx)/globalSum(dxOld_ * dxOld_);
157 else if (betaType_ ==
"PolakRibiere")
159 beta = globalSum(dx*(dx - dxOld_))/globalSum(dxOld_ * dxOld_);
161 else if (betaType_ ==
"PolakRibiereRestarted")
167 globalSum(dx*(dx - dxOld_))/globalSum(dxOld_ * dxOld_)
169 if (
beta == scalar(0))
171 Info<<
"Computed negative beta. Resetting to zero" <<
endl;
178 forAll(activeDesignVars_, varI)
180 correction_[activeDesignVars_[varI]] = eta_*
s[varI];
197 sOld_.map(oldCorrection, activeDesignVars_);
199 correction_ = oldCorrection;
205 optMethodIODict_.add<
scalarField>(
"dxOld", dxOld_,
true);
206 optMethodIODict_.add<
scalarField>(
"sOld", sOld_,
true);
207 optMethodIODict_.add<label>(
"counter", counter_,
true);
208 optMethodIODict_.add<label>(
"nDVs", objectiveDerivatives_.size(),
true);
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
void size(const label n)
Older name for setAddressableSize.
The Conjugate Gradient formula.
void computeCorrection()
Compute design variables correction.
void readFromDict()
Read old info from dict.
labelList activeDesignVars_
void allocateFields()
Allocate matrices in the first optimisation cycle.
virtual void write()
Write old info to dict.
virtual void updateOldCorrection(const scalarField &oldCorrection)
Update old correction. For use when eta has been changed externally.
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.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
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))
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
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.
static constexpr const zero Zero
Global zero (0)
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
dimensionedScalar beta("beta", dimless/dimTemperature, laminarTransport)
#define forAll(list, i)
Loop across all elements in list.
propsDict readIfPresent("fields", acceptFields)