58 UpdateMethod.nConstraints(),
61 LagrangianDerivatives_(designVars().getVars().size(),
Zero),
62 constraintDerivativesOld_
64 UpdateMethod.nConstraints(),
69 UpdateMethod.
found(
"lamdas") ?
70 scalarField(
"lamdas", UpdateMethod, UpdateMethod.nConstraints()) :
75 mesh.time().globalPath()/
"optimisation"/
"objective"/
78 meritFunctionFile_(nullptr),
82 UpdateMethod.coeffsDict(
type).getOrDefault<scalar>(
"delta", 0.1)
111 forAll(constraintDerivativesOld_, cI)
113 constraintDerivativesOld_[cI].
114 writeEntry(
"constraintDerivativesOld" +
Foam::name(cI),
os);
116 lamdas_.writeEntry(
"lamdas",
os);
124 scalar objectivePart = UpdateMethod.getObjectiveValue();
125 scalar constraintPart = mu_*meritFunctionConstraintPart();
126 scalar merit = objectivePart + constraintPart;
127 const scalarField& cValues = UpdateMethod.getConstraintValues();
131 unsigned int constraintsSize = lamdas_.size();
132 constraintsSize = constraintsSize*(width + 1) + 2;
135 if (!meritFunctionFile_)
137 meritFunctionFile_.reset
139 new OFstream(objFunctionFolder_/word(
"meritFunction"))
143 <<
setw(1) <<
"#" <<
" "
144 <<
setw(width) <<
"merit" <<
" "
145 <<
setw(width) <<
"J" <<
" "
146 <<
setw(constraintsSize) <<
"lamdas" <<
" "
147 <<
setw(constraintsSize) <<
"constraints" <<
" "
148 <<
setw(width) <<
"mu" <<
" "
149 <<
setw(width) <<
"constraintContr" <<
endl;
154 <<
setw(1) << UpdateMethod.getCycle() <<
" "
155 <<
setw(width) << merit <<
" "
156 <<
setw(width) << objectivePart <<
" "
162 <<
setw(width) << lamdas_[cI] <<
setw(1) <<
" ";
164 meritFunctionFile_() <<
setw(3) <<
")(";
168 <<
setw(width) << cValues[cI] <<
setw(1) <<
" ";
170 meritFunctionFile_() <<
setw(2) <<
") ";
171 meritFunctionFile_() <<
setw(width) << mu_ <<
" ";
172 meritFunctionFile_() <<
setw(width) << constraintPart <<
endl;
Istream and Ostream manipulators taking arguments.
Macros for easy insertion into run-time selection tables.
static unsigned int defaultPrecision() noexcept
Return the default precision.
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,...
Base class for Sequantial Quadratic Programming (SQP) methods.
scalarField lamdas_
Lagrange multipliers.
virtual bool addToFile(Ostream &os) const
Write continuation info.
scalar mu_
Penalty value for the merit function.
virtual bool writeMeritFunction(const updateMethod &UpdateMethod)
Write info about the merit function.
List< scalarField > constraintDerivativesOld_
The previous constraint derivatives.
autoPtr< OFstream > meritFunctionFile_
File including the l1 merit function.
scalar delta_
Safety factor.
virtual scalar meritFunctionConstraintPart() const =0
Get the part the merit function that depends on the constraints.
fileName objFunctionFolder_
Name of the objective folder.
scalarField LagrangianDerivatives_
Derivatives of the Lagrangian function.
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.
Abstract base class for optimisation methods supporting constraints. Does not add functionality to up...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Mesh data needed to do the Finite Volume discretisation.
Abstract base class for optimisation methods.
scalar getObjectiveValue() const
Get objective value.
label getCycle() const
Get optimisation cycle.
const scalarField & getConstraintValues() const
Get values of constraints.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
OBJstream os(runTime.globalPath()/outputName)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Omanip< int > setw(const int i)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static constexpr const zero Zero
Global zero (0).
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
#define forAll(list, i)
Loop across all elements in list.