Go to the documentation of this file.
50 if (
s.size() != m.
n())
53 <<
"scalar derivative and HessianInv matrix do not have the "
63 res[i] +=
s[j]*m[j][i];
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"
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
213 mesh_.time().timeName(),
220 objectiveDerivatives_(0),
221 constraintDerivatives_(0),
225 cumulativeCorrection_(0),
227 initialEtaSet_(
false),
228 correctionFolder_(mesh_.time().globalPath()/
"optimisation"/
"correction"),
237 mkDir(correctionFolder_);
245 initialEtaSet_ =
true;
247 else if (optMethodIODict_.readIfPresent(
"eta", eta_))
249 initialEtaSet_ =
true;
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_;
351 correctionFolder_/
"correction" + mesh_.time().timeName()
355 correctionFolder_/
"cumulativeCorrection" + mesh_.time().timeName()
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
scalarField & returnCorrection()
Return the correction of the design variables.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const scalarField rightMult(const SquareMatrix< scalar > &, const scalarField &)
A class for handling words, derived from Foam::string.
A class for handling file names.
void clear() const noexcept
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))
void setGlobalSum(const bool useGlobalSum)
Set globalSum variable.
void setConstraintValues(const scalarField &values)
Set constraints derivative.
A class for managing temporary objects.
label n() const noexcept
The number of columns.
static constexpr const zero Zero
Global zero (0)
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
virtual scalar meritFunctionDirectionalDerivative()
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
static bool master(const label communicator=worldComm)
Am I the master process.
SquareMatrix< scalar > outerProd(const scalarField &, const scalarField &)
volSymmTensorField invA(inv(I *UEqn.A()+drag->Dcu()))
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual scalar computeMeritFunction()
Type gSum(const FieldField< Field, Type > &f)
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
void setConstraintDeriv(const PtrList< scalarField > &derivs)
Set constraints derivative.
#define forAll(list, i)
Loop across all elements in list.
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
virtual void updateOldCorrection(const scalarField &oldCorrection)
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Generic templated field type.
messageStream Info
Information stream (stdout output on master, null elsewhere)
The IOstreamOption is a simple container for options an IOstream can normally have.
static autoPtr< updateMethod > New(const fvMesh &mesh, const dictionary &dict)
Return a reference to the selected turbulence model.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
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.
errorManip< error > abort(error &err)
bool & initialEtaSet()
Return whether initial eta was set.
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
errorManipArg< error, int > exit(error &err, const int errNo=1)
Output to file stream, using an OSstream.
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
void setStep(const scalar eta)
Set step for optimisation methods.
dictionary coeffsDict()
Return optional dictionary with parameters specific to each method.
virtual void write()
Write useful quantities to files.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void setObjectiveValue(const scalar value)
Set constraints derivative.
#define DebugInfo
Report an information message using Foam::Info.
scalar globalSum(const scalarField &field)
Compute either global or local sum, based on globalSum flag.
const scalarField leftMult(const scalarField &, const SquareMatrix< scalar > &)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
SquareMatrix< scalar > inv(SquareMatrix< scalar > A)
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
defineTypeNameAndDebug(combustionModel, 0)
void setObjectiveDeriv(const scalarField &derivs)
Set objective derivative.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const