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++)
210Foam::updateMethod::updateMethod
214 autoPtr<designVariables>& designVars,
215 const label nConstraints,
227 IOobject::READ_IF_PRESENT,
234 designVars_(designVars),
235 nConstraints_(nConstraints),
236 activeDesignVars_(designVars().activeDesignVariables()),
237 objectiveDerivatives_(designVars().getVars().size(),
Zero),
238 constraintDerivatives_(0),
240 objectiveValueOld_(nullptr),
242 correction_(readOrZeroField(
"correction", designVars().getVars().size())),
243 cumulativeCorrection_(0),
245 counter_(getOrDefault<label>(
"counter",
Zero)),
246 initialEtaSet_(false),
247 correctionFolder_(mesh_.time().globalPath()/
"optimisation"/
"correction"),
248 globalSum_(designVars_->globalSum())
253 if (
dict.readIfPresent(
"eta",
eta_))
255 initialEtaSet_ = true;
281 const label nConstraints
286 Info<<
"updateMethod type : " << modelType <<
endl;
288 auto* ctorPtr = dictionaryConstructorTable(modelType);
297 *dictionaryConstructorTablePtr_
337 if (!objectiveValueOld_)
341 objectiveValueOld_.ref() = value;
417 if (cumulativeCorrection_.empty())
419 cumulativeCorrection_.setSize(correction_.size(),
Zero);
422 cumulativeCorrection_ += correction_;
424 fileName correctionFile
426 correctionFolder_/
"correction" + mesh_.time().timeName()
428 fileName cumulativeCorrectionFile
430 correctionFolder_/
"cumulativeCorrection" + mesh_.time().timeName()
433 OFstream corFile(correctionFile);
434 OFstream cumulCorFile(cumulativeCorrectionFile);
438 << cI <<
" " << correction_[cI] <<
endl;
478 os.writeEntry(
"eta", eta_);
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
label size() const noexcept
The number of elements in list.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ LAZY_READ
Reading is optional [identical to READ_IF_PRESENT].
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const Time & time() const noexcept
Return Time associated with the objectRegistry.
fileName globalPath() const
The complete global path for the object (with instance, local,...).
label n() const noexcept
The number of columns.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
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.
void size(const label n)
Older name for setAddressableSize.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
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...
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
A class for handling file names.
Mesh data needed to do the Finite Volume discretisation.
localIOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
A class for managing temporary objects.
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Abstract base class for optimisation methods.
void setConstraintValues(const scalarField &values)
Set values of constraints.
scalarField objectiveDerivatives_
Derivatives of the objective functions.
label nConstraints_
Number of constraints.
virtual scalar meritFunctionDirectionalDerivative()
Directional derivative of the merit function, in the direction of the correction. Could be different ...
scalarField correction_
Design variables correction.
bool globalSum_
Whether to use gSum or sum in the inner products.
dictionary coeffsDict(const word &type) const
Return optional dictionary with parameters specific to each method.
scalar globalSum(const scalarField &field)
Compute either global or local sum, based on globalSum flag.
scalarField cValues_
Constraint values.
scalar objectiveValue_
Objective value.
virtual bool writeAuxiliaryData()
Write non-continuation data, usually under the optimisation folder.
PtrList< scalarField > constraintDerivatives_
Derivatives of the constraints.
void setStep(const scalar eta)
Set step for optimisation methods.
virtual bool writeData(Ostream &os) const
Write continuation data under uniform.
const scalarField leftMult(const scalarField &, const SquareMatrix< scalar > &)
tmp< scalarField > readOrZeroField(const word &name, const label size)
Helper function to either read a scalarField of certain size from a dictionary, or construct a zero f...
scalarField & returnCorrection()
Return the correction of the design variables.
SquareMatrix< scalar > inv(SquareMatrix< scalar > A)
const labelList & activeDesignVars_
Map to active design variables.
scalar getObjectiveValue() const
Get objective value.
label getCycle() const
Get optimisation cycle.
bool initialEtaSet_
Is initially set?
const scalarField rightMult(const SquareMatrix< scalar > &, const scalarField &)
void setObjectiveValue(const scalar value)
Set objective value.
autoPtr< scalar > objectiveValueOld_
Old objective value.
static autoPtr< updateMethod > New(const fvMesh &mesh, const dictionary &dict, autoPtr< designVariables > &designVars, const label nConstraints)
Return a reference to the selected turbulence model.
const autoPtr< scalar > & getObjectiveValueOld() const
Get old objective value.
void setObjectiveValueOld(const scalar value)
Set old objective value.
label counter_
Optimisation cycle count.
void setConstaintsNumber(const label nConstraints)
Set the number of constraints.
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.
const scalarField & getConstraintValues() const
Get values of constraints.
label nConstraints() const
Get the number of constraints.
void modifyStep(const scalar multiplier)
Multiply step.
scalarField cumulativeCorrection_
Cumulative design variables correction throughout the optimisation loop.
virtual void updateOldCorrection(const scalarField &oldCorrection)
Update old correction. Useful for quasi-newton methods coupled with line search.
scalar eta_
Step multiplying the correction.
bool & initialEtaSet()
Return whether initial eta was set.
autoPtr< designVariables > & designVars_
Design variables.
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.
OBJstream os(runTime.globalPath()/outputName)
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)
List< label > labelList
A List of labels.
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution in the source.
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.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
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.