46void objective::makeFolder()
106 const word& adjointSolverName,
107 const word& primalSolverName
128 adjointSolverName_(adjointSolverName),
129 primalSolverName_(primalSolverName),
131 computeMeanFields_(false),
133 normalize_(
dict.getOrDefault<
bool>(
"normalize", false)),
136 JMean_(this->getOrDefault<scalar>(
"JMean",
Zero)),
138 normFactor_(nullptr),
145 integrationStartTimePtr_(nullptr),
146 integrationEndTimePtr_(nullptr),
154 bdSdbMultPtr_(nullptr),
155 bdndbMultPtr_(nullptr),
156 bdxdbMultPtr_(nullptr),
157 bdxdbDirectMultPtr_(nullptr),
158 bEdgeContribution_(nullptr),
159 divDxDbMultPtr_(nullptr),
160 gradDxDbMultPtr_(nullptr),
162 objFunctionFolder_(
"word"),
163 objFunctionFilePtr_(nullptr),
164 instantValueFilePtr_(nullptr),
165 meanValueFilePtr_(nullptr),
166 width_(
IOstream::defaultPrecision() + 5)
175 new scalar(
dict.
get<scalar>(
"integrationStartTime"))
182 new scalar(
dict.
get<scalar>(
"integrationEndTime"))
189 scalar normFactor(
Zero);
208 const word& objectiveType,
209 const word& adjointSolverName,
210 const word& primalSolverName
213 auto* ctorPtr = objectiveConstructorTable(objectiveType);
222 *objectiveConstructorTablePtr_
290 if (iAverageIter == 0)
294 scalar avIter(iAverageIter);
295 scalar oneOverItP1 = 1./(avIter + 1);
296 scalar mult = avIter*oneOverItP1;
311 const scalar denom = elapsedTime + dt;
318 <<
"Unallocated integration start or end time"
344 dJdbPtr_().primitiveFieldRef() *= oneOverNorm;
396 <<
"Unallocated integration start or end time"
413 <<
"Unallocated integration start or end time"
426 createZeroFieldPtr<scalar>
498 <<
"Unallocated boundaryEdgeMultiplier field"
560 <<
"Unallocated boundaryEdgeMultiplier field"
575 createZeroFieldPtr<scalar>
596 createZeroFieldPtr<tensor>
671 ios_base::fmtflags flags = file.
flags();
672 flags |= std::cout.left;
685 file<<
setw(4) <<
"#" <<
" ";
Istream and Ostream manipulators taking arguments.
Generic GeometricBoundaryField class.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const Time & time() const
Return Time associated with the objectRegistry.
An IOstream is an abstract base class for all input/output systems; be they streams,...
bool good() const noexcept
True if next operation might succeed.
Output to file stream, using an OSstream.
virtual ios_base::fmtflags flags() const
Get stream flags.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
fileName globalPath() const
Return global path for the case.
dimensionedScalar deltaT() const
Return time step.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
static word timeName(const scalar t, const int precision=precision_)
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
bool valid() const noexcept
Identical to good(), or bool operator.
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
const Type & value() const
Return const reference to value.
A class for handling file names.
virtual bool write()
Write the output fields.
Mesh data needed to do the Finite Volume discretisation.
const Time & time() const
Return the top-level database.
localIOdictionary is derived from IOdictionary but excludes parallel master reading.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
virtual void writeInstantaneousSeparator() const
virtual void writeInstantaneousValue() const
Write objective function history at each primal solver iteration.
autoPtr< OFstream > instantValueFilePtr_
autoPtr< boundaryVectorField > bdJdbPtr_
Term from material derivative.
const boundaryVectorField & dSdbMultiplier()
Multiplier of delta(n dS)/delta b for all patches.
const volTensorField & gradDxDbMultiplier()
Multiplier of grad( delta(x)/delta b) for volume-based sensitivities.
void accumulateJMean()
Accumulate contribution for the mean objective value.
scalar JMean_
Average objective value.
autoPtr< boundaryVectorField > bdSdbMultPtr_
Term multiplying delta(n dS)/delta b.
const word objectiveName_
bool hasBoundaryEdgeContribution() const
bool hasGradDxDbMult() const
void setMeanValueFilePtr() const
Set the output file ptr for the mean value.
virtual void writeMeanValue() const
Write mean objective function history.
autoPtr< OFstream > objFunctionFilePtr_
File to keep the objective values after the end of the primal solver.
autoPtr< OFstream > meanValueFilePtr_
virtual void addHeaderColumns() const
Write headers for additional columns.
scalar weight() const
Return the objective function weight.
autoPtr< boundaryVectorField > bdxdbDirectMultPtr_
bool hasIntegrationStartTime() const
virtual void nullify()
Nullify adjoint contributions.
autoPtr< scalar > integrationStartTimePtr_
Objective integration start and end times (for unsteady flows)
const boundaryVectorField & boundarydJdb()
Contribution to surface sensitivities for all patches.
void setObjectiveFilePtr() const
Set the output file ptr.
autoPtr< volScalarField > dJdbPtr_
Contribution to field sensitivity derivatives.
autoPtr< scalar > normFactor_
Normalization factor.
scalar weight_
Objective weight.
const volScalarField & divDxDbMultiplier()
Multiplier of grad( delta(x)/delta b) for volume-based sensitivities.
const boundaryVectorField & dxdbDirectMultiplier()
Multiplier of delta(x)/delta b for all patches.
unsigned int width_
Default width of entries when writing in the objective files.
virtual scalar J()=0
Return the instantaneous objective function value.
autoPtr< scalar > integrationEndTimePtr_
virtual void addHeaderInfo() const
Write any information that needs to go the header of the file.
bool hasDivDxDbMult() const
autoPtr< volScalarField > divDxDbMultPtr_
Multiplier of d(Volume)/db.
const boundaryVectorField & dndbMultiplier()
Multiplier of delta(n dS)/delta b for all patches.
scalar J_
Objective function value and weight.
bool hasdxdbDirectMult() const
void setInstantValueFilePtr() const
Set the output file ptr for the instantaneous value.
void incrementIntegrationTimes(const scalar timeSpan)
Increment integration times.
virtual void doNormalization()
Normalize all fields allocated by the objective.
bool normalize() const
Is the objective normalized.
const dictionary & dict() const
Return objective dictionary.
const volScalarField & dJdb()
Contribution to field sensitivities.
bool hasBoundarydJdb() const
bool hasIntegrationEndTime() const
virtual void updateNormalizationFactor()
fileName objFunctionFolder_
Output file variables.
autoPtr< scalar > target_
Target value, in case the objective is used as a constraint.
autoPtr< boundaryVectorField > bdndbMultPtr_
Term multiplying delta(n)/delta b.
autoPtr< boundaryVectorField > bdxdbMultPtr_
Term multiplying delta(x)/delta b at the boundary.
const word adjointSolverName_
const boundaryVectorField & dxdbMultiplier()
Multiplier of delta(x)/delta b for all patches.
virtual void addColumnValues() const
Write information to additional columns.
const vectorField3 & boundaryEdgeMultiplier()
Multiplier located at patch boundary edges.
bool isWithinIntegrationTime() const
Check whether this is an objective integration time.
autoPtr< vectorField3 > bEdgeContribution_
autoPtr< volTensorField > gradDxDbMultPtr_
Emerging from volume objectives that include spatial derivatives.
Base class for solver control classes.
bool doAverageIter() const
label & averageIter()
Return average iteration index reference.
splitCell * master() const
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#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)
const word dictName("faMeshDefinition")
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const dimensionSet dimless
Dimensionless.
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
dimensionedScalar pow3(const dimensionedScalar &ds)
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Omanip< int > setw(const int i)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static constexpr const zero Zero
Global zero (0)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensionSet pow2(const dimensionSet &ds)
constexpr char tab
The tab '\t' character(0x09)
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
A non-counting (dummy) refCount.