49 Foam::conjugateGradient::conjugateGradient
54 const label nConstraints,
60 dxOld_(readOrZeroField(
"dxOld", activeDesignVars_.size())),
61 sOld_(readOrZeroField(
"sOld", activeDesignVars_.size())),
62 betaType_(coeffsDict(
type).getOrDefault<
word>(
"betaType",
"FletcherReeves"))
69 && !(
betaType_ ==
"PolakRibiereRestarted")
73 <<
"Invalid betaType " <<
betaType_ <<
". Valid options are " 74 <<
"FletcherReeves, PolakRibiere, PolakRibiereRestarted" 87 Info<<
"Using steepest descent for the first iteration" <<
endl;
88 for (
const label varI : activeDesignVars_)
90 correction_[varI] = -eta_*objectiveDerivatives_[varI];
93 dxOld_.map(-objectiveDerivatives_, activeDesignVars_);
99 dx.
map(-objectiveDerivatives_, activeDesignVars_);
102 if (betaType_ ==
"FletcherReeves")
104 beta = globalSum(dx*dx)/globalSum(dxOld_ * dxOld_);
106 else if (betaType_ ==
"PolakRibiere")
108 beta = globalSum(dx*(dx - dxOld_))/globalSum(dxOld_ * dxOld_);
110 else if (betaType_ ==
"PolakRibiereRestarted")
116 globalSum(dx*(dx - dxOld_))/globalSum(dxOld_ * dxOld_)
118 if (
beta == scalar(0))
120 Info<<
"Computed negative beta. Resetting to zero" <<
endl;
127 forAll(activeDesignVars_, varI)
129 correction_[activeDesignVars_[varI]] = eta_*
s[varI];
146 sOld_.map(oldCorrection, activeDesignVars_);
148 correction_ = oldCorrection;
154 dxOld_.writeEntry(
"dxOld",
os);
155 sOld_.writeEntry(
"sOld",
os);
virtual void updateOldCorrection(const scalarField &oldCorrection)
Update old correction. For use when eta has been changed externally.
void computeCorrection()
Compute design variables correction.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr char nl
The newline '\n' character (0x0a)
Abstract base class for optimisation methods.
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.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual bool writeData(Ostream &os) const
Write useful quantities to files.
void map(const UList< Type > &mapF, const labelUList &mapAddressing)
1 to 1 map from the given field
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
Mesh data needed to do the Finite Volume discretisation.
messageStream Info
Information stream (stdout output on master, null elsewhere)
dimensionedScalar beta("beta", dimless/dimTemperature, laminarTransport)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
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))
virtual bool writeData(Ostream &os) const
Write continuation data under uniform.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)