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];
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());
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)
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
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
Defines the attributes of an object for which implicit objectRegistry management is supported,...
The IOstreamOption is a simple container for options an IOstream can normally have.
label n() const noexcept
The number of columns.
Output to file stream, using an OSstream.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
void size(const label n)
Older name for setAddressableSize.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
dictionary subOrEmptyDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX, const bool mandatory=false) const
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
A class for handling file names.
Mesh data needed to do the Finite Volume discretisation.
gradingDescriptor inv() const
Return the inverse gradingDescriptor with 1/expansionRatio.
splitCell * master() const
A class for managing temporary objects.
void clear() const noexcept
Abstract base class for optimisation methods.
void setConstraintValues(const scalarField &values)
Set constraints derivative.
virtual scalar meritFunctionDirectionalDerivative()
scalar globalSum(const scalarField &field)
Compute either global or local sum, based on globalSum flag.
dictionary coeffsDict()
Return optional dictionary with parameters specific to each method.
void setStep(const scalar eta)
Set step for optimisation methods.
const scalarField leftMult(const scalarField &, const SquareMatrix< scalar > &)
scalarField & returnCorrection()
Return the correction of the design variables.
bool initialEtaSet_
Is initially set?
const scalarField rightMult(const SquareMatrix< scalar > &, const scalarField &)
void setObjectiveValue(const scalar value)
Set constraints derivative.
void setConstraintDeriv(const PtrList< scalarField > &derivs)
Set constraints derivative.
virtual scalar computeMeritFunction()
virtual void write()
Write useful quantities to files.
IOdictionary optMethodIODict_
Used to output values useful for continuation runs.
virtual void updateOldCorrection(const scalarField &oldCorrection)
scalar eta_
Step multiplying the correction.
bool & initialEtaSet()
Return whether initial eta was set.
word correctionFolder_
Folder storing the corrections to file.
SquareMatrix< scalar > outerProd(const scalarField &, const scalarField &)
void setObjectiveDeriv(const scalarField &derivs)
Set objective derivative.
void setGlobalSum(const bool useGlobalSum)
Set globalSum variable.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
volSymmTensorField invA(inv(I *UEqn.A()+drag->Dcu()))
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
#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))
#define DebugInfo
Report an information message using Foam::Info.
Type gSum(const FieldField< Field, Type > &f)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
static constexpr const zero Zero
Global zero (0)
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
#define forAll(list, i)
Loop across all elements in list.