50 if (
s.size() != m.
n())
53 <<
"scalar derivative and HessianInv matrix do not have the " 63 res[i] +=
s[j]*m[j][i];
73 const SquareMatrix<scalar>& m,
77 if (
s.size() != m.n())
80 <<
"scalar derivative and HessianInv matrix do not have the " 90 res[i] += m[i][j]*
s[j];
104 if (a.size() !=
b.size())
107 <<
"operands of outerProduct do not have the same dimension" 111 SquareMatrix<scalar> res(a.size(),
Zero);
116 res[i][j] = a[i]*
b[j];
134 <<
"LU decomposed A " <<
A <<
endl;
137 for (label j = 0; j <
n; j++)
143 for (label i = 0; i <
n; i++)
192 scalar value = globalSum(tfield());
200 Foam::updateMethod::updateMethod
220 objectiveDerivatives_(0),
221 constraintDerivatives_(0),
225 cumulativeCorrection_(0),
227 initialEtaSet_(false),
228 correctionFolder_(mesh_.time().globalPath()/
"optimisation"/
"correction"),
231 dict.getOrDefault<bool>(
"globalSum", false)
243 if (
dict.readIfPresent(
"eta",
eta_))
270 Info<<
"updateMethod type : " << modelType <<
endl;
272 auto* ctorPtr = dictionaryConstructorTable(modelType);
281 *dictionaryConstructorTablePtr_
293 objectiveDerivatives_ = derivs;
302 constraintDerivatives_ = derivs;
308 objectiveValue_ = value;
326 globalSum_ = useGlobalSum;
342 if (cumulativeCorrection_.empty())
344 cumulativeCorrection_.setSize(correction_.size(),
Zero);
347 cumulativeCorrection_ += correction_;
349 fileName correctionFile
351 correctionFolder_/
"correction" + mesh_.time().timeName()
353 fileName cumulativeCorrectionFile
355 correctionFolder_/
"cumulativeCorrection" + mesh_.time().timeName()
358 OFstream corFile(correctionFile);
359 OFstream cumulCorFile(cumulativeCorrectionFile);
363 << cI <<
" " << correction_[cI] <<
endl;
365 << cI <<
" " << cumulativeCorrection_[cI] <<
endl;
373 return objectiveValue_;
379 return globalSum(objectiveDerivatives_*correction_);
385 return initialEtaSet_;
394 correction_ = oldCorrection;
403 optMethodIODict_.add<scalar>(
"eta", eta_,
true);
406 optMethodIODict_.add<
scalarField>(
"correction", correction_,
true);
414 optMethodIODict_.regIOobject::writeObject
void setConstraintDeriv(const PtrList< scalarField > &derivs)
Set constraints derivative.
virtual scalar computeMeritFunction()
Compute merit function. Could be different than the objective in the presence of constraints.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
virtual scalar meritFunctionDirectionalDerivative()
Directional derivative of the merit function, in the direction of the correction. Could be different ...
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.
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
Abstract base class for optimisation methods.
volSymmTensorField invA(inv(I *UEqn.A()+drag->Dcu()))
label n() const noexcept
The number of columns.
Ostream & endl(Ostream &os)
Add newline and flush stream.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
const scalarField rightMult(const SquareMatrix< scalar > &, const scalarField &)
bool & initialEtaSet()
Return whether initial eta was set.
const scalarField leftMult(const scalarField &, const SquareMatrix< scalar > &)
void setConstraintValues(const scalarField &values)
Set constraints derivative.
scalar eta_
Step multiplying the correction.
#define forAll(list, i)
Loop across all elements in list.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
static autoPtr< updateMethod > New(const fvMesh &mesh, const dictionary &dict)
Return a reference to the selected turbulence model.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
virtual void updateOldCorrection(const scalarField &oldCorrection)
Update old correction. useful for quasi-newton methods coupled with line search.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Type gSum(const FieldField< Field, Type > &f)
void setStep(const scalar eta)
Set step for optimisation methods.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
errorManip< error > abort(error &err)
#define DebugInfo
Report an information message using Foam::Info.
SquareMatrix< scalar > inv(SquareMatrix< scalar > A)
void setObjectiveValue(const scalar value)
Set constraints derivative.
void setObjectiveDeriv(const scalarField &derivs)
Set objective derivative.
scalar globalSum(const scalarField &field)
Compute either global or local sum, based on globalSum flag.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
defineTypeNameAndDebug(combustionModel, 0)
void setGlobalSum(const bool useGlobalSum)
Set globalSum variable.
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
Find and return a sub-dictionary as a copy, otherwise return an empty dictionary. ...
bool initialEtaSet_
Is initially set?
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Mesh data needed to do the Finite Volume discretisation.
SquareMatrix< scalar > outerProd(const scalarField &, const scalarField &)
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual void write()
Write useful quantities to files.
List< label > labelList
A List of labels.
word correctionFolder_
Folder storing the corrections to file.
IOdictionary optMethodIODict_
Used to output values useful for continuation runs.
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))
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
scalarField & returnCorrection()
Return the correction of the design variables.
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.
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution in the source.
dictionary coeffsDict()
Return optional dictionary with parameters specific to each method.
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)