60 <<
"Updating design variables for field " << fluidID <<
endl;
75 field[cellI] + localCorrection[cellI],
88 for (label cellI : zoneCells)
95 field[cellI] + localCorrection[cellI],
111 for (label cellI : zones_.IOCells())
117 forAll(zones_.fixedPorousZoneIDs(), zI)
119 const label
cellZoneID = zones_.fixedPorousZoneIDs()[zI];
121 const scalar alphaValue(zones_.fixedPorousValues()[zI]);
122 for (label cellI : zoneCells)
124 alpha[cellI] = alphaValue;
129 for (label
cellZoneID : zones_.fixedZeroPorousZoneIDs())
132 for (label cellI : zoneCells)
143 Info<<
"maxInitChange/maxChange \t"
144 << maxInitChange_() <<
"/" << maxChange <<
endl;
145 const scalar eta(maxInitChange_() / maxChange);
159 const label offset(fluidID*mesh_.nCells());
160 label varI(activeDesignVariables_.size());
161 activeDesignVariables_.setSize(offset + mesh_.nCells(), -1);
164 if (!zones_.adjointPorousZoneIDs().empty())
166 for (label
cellZoneID : zones_.adjointPorousZoneIDs())
168 for (
const label var : mesh_.cellZones()[
cellZoneID])
170 activeDesignVariables_[varI++] = var + offset;
177 boolList isActiveDV(mesh_.nCells(),
true);
179 for (label
cellZoneID : zones_.fixedPorousZoneIDs())
181 for (label cellI : mesh_.cellZones()[
cellZoneID])
183 isActiveDV[cellI] =
false;
186 for (label
cellZoneID : zones_.fixedZeroPorousZoneIDs())
188 for (label cellI : mesh_.cellZones()[
cellZoneID])
190 isActiveDV[cellI] =
false;
195 for (label cellI : zones_.IOCells())
197 isActiveDV[cellI] =
false;
204 if (isActiveDV[cellI])
206 activeDesignVariables_[varI++] = offset + cellI;
210 activeDesignVariables_.setSize(varI);
218 const bool setIOValues
221 const label offset(fluidID*mesh_.nCells());
232 mesh_.time().timeName(),
239 Info<<
"Setting design variables based on the alpha field "
259 setActiveDesignVariables();
262 readField(
"alpha", 0,
true);
264 if (regularisation_.growFromWalls())
287Foam::topODesignVariables::topODesignVariables
297Foam::topODesignVariables::topODesignVariables
312 dict_.subDict(
"regularisation")
316 dict.getOrDefaultCompat<bool>
318 "writeAllFields", {{
"writeAllAlphaFields", 2306}}, false
347 const word& interpolationFieldName
350 return beta().primitiveField();
361 const word& interpolationFieldName
364 const scalarField& indicator = interpolationField(interpolationFieldName);
366 interpolationFunc.
interpolate(indicator, interpolant);
369 const scalar
diff(solidValues[fieldi] - fluidValues[0][fieldi]);
370 field.primitiveFieldRef() = fluidValues[0][fieldi] + interpolant*
diff;
371 field.correctBoundaryConditions();
382 const word& designVariablesName,
383 const word& interpolationFieldName
388 (solidValues[fieldi] - fluidValues[0][fieldi])
402 field *= scalar(1) - interpolant;
410 const word& designVariablesName
420 const word& interpolationFieldName,
433 const word& interpolationFieldName,
451 regularisation_.updateBeta();
489 regularisation_.postProcessSens(objectiveSens);
492 if (writeAllFields_ && mesh_.time().writeTime())
499 mesh_.time().timeName(),
507 sens.primitiveFieldRef() = objectiveSens;
511 return tobjectiveSens;
537 const PtrList<adjointSolver>& adjointSolvers =
538 manager.adjointSolvers();
539 for (
const adjointSolver& solver : adjointSolvers)
550 if (writeAllFields_ && mesh_.time().writeTime())
557 mesh_.time().timeName(),
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A field of fields is a PtrList of fields with reference counting.
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
@ NO_READ
Nothing to be read.
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (respects is_globalIOobject trait) and check its info. A void type suppresses trait and t...
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
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....
SubField is a Field obtained as a section of another Field, without its own allocation....
A List with indirect addressing. Like IndirectList but does not store addressing.
bool empty() const noexcept
True if List is empty (ie, size() is zero).
scalar & operator[](const label i)
Abstract base class for adjoint-based sensitivities.
const adjointSolver & getAdjointSolver() const
Const access to adjoint solver.
Class for managing adjoint solvers, which may be more than one per operating point.
Base class for adjoint solvers.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Abstract base class for defining design variables.
autoPtr< scalar > maxInitChange_
Maximum design variables' change in the first optimisation cycle.
void readBounds(autoPtr< scalar > lowerBoundPtr=nullptr, autoPtr< scalar > upperBoundPtr=nullptr)
Read bounds for design variables, if present.
labelList activeDesignVariables_
Which of the design variables will be updated.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
T getOrDefaultCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value using any compatibility names if needed.
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.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Base class for primal solvers.
label nCells() const noexcept
Number of mesh cells.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
const autoPtr< volScalarField > & fieldSensPtr() const
Get the fieldSensPtr.
virtual void addTopOFvOptions() const
Add topO fvOptions.
const word & solverName() const
Return the solver name.
A class for managing temporary objects.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Design variables for porosity-based topology optimisation (topO) problems.
virtual void updateField(const scalarField &correction, const label fluidID=0)
Update the design variables given their correction.
virtual void update(scalarField &correction)
Update design variables based on a given correction.
virtual const scalarField & interpolationField(const word &interpolationFieldName="beta") const
Return interpolant.
void readField(const word &name, const label fluidID=0, const bool setIOValues=false)
Read field with (path of) the design variables and store input in the design variables list with opti...
fieldRegularisation regularisation_
Mechanism to regularise the field of design variables.
virtual scalar computeEta(scalarField &correction)
Compute eta if not set in the first step.
virtual bool writeData(Ostream &) const
The writeData function required by the regIOobject write operation.
virtual void initialize()
Part of the constructor initialisation.
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &sens)
Assemble sensitivity derivatives, by combining the part related to the primal and adjoint solution wi...
virtual tmp< scalarField > penaltySensitivities(const word &interpolationFieldName, const topOInterpolationFunction &interpolationFunc) const
Return the penalty term derivative.
bool addFvOptions_
Add the fvOptions necessary for topO automatically.
virtual void nullifyInSolidSensitivities(scalarField &sens, const topOInterpolationFunction &interpolationFunc, const word &designVariablesName) const
Nullify given field in the solid domain.
virtual void addFvOptions(const PtrList< primalSolver > &primalSolver, const PtrList< adjointSolverManager > &adjointSolverManagers)
Automatically add fvOptions depending on the design variables to the primal and adjoint solvers.
SubField< scalar > alpha_
A subfield of the design variables corresponding to the porosity field.
static autoPtr< topODesignVariables > New(fvMesh &mesh, const dictionary &dict)
Construct and return the selected design variables.
virtual void setActiveDesignVariables(const label fluidID=0, const bool activeIO=false)
Set active design variables.
bool writeAllFields_
Write all fields related to imposition of the Brinkman penalisation (i.e. design variables,...
virtual void interpolate(volScalarField &field, const topOInterpolationFunction &interpolationFunc, const FieldField< Field, scalar > &fluidValues, const scalarField &solidValues, const label fieldi, const word &interpolationFieldName="beta") const
Interpolate between the given field and solid values.
virtual void interpolationSensitivities(scalarField &sens, const topOInterpolationFunction &interpolationFunc, const FieldField< Field, scalar > &fluidValues, const scalarField &solidValues, const label fieldi, const word &designVariablesName, const word &interpolationFieldName="beta") const
Post-processing sensitivities due to interpolations based on the indicator fields.
virtual const volScalarField & beta() const
Get the indicator field.
virtual void setInitialValues()
Set initial values of the design variables.
virtual bool globalSum() const
Whether to use global sum when computing matrix-vector products in update methods.
void applyFixedValues()
Apply fixed values in certain zones.
virtual tmp< scalarField > penalty(const word &interpolationFieldName, const topOInterpolationFunction &interpolationFunc) const
Return the Brinkman penalisation term.
virtual void nullifyInSolid(scalarField &field, const topOInterpolationFunction &interpolationFunc) const
Nullify given field in the solid domain.
virtual void writeDesignVars()
Write porosity field to file.
virtual tmp< scalarField > derivative(const scalarField &arg) const =0
Return of function with respect to the argument field.
virtual void interpolate(const scalarField &arg, scalarField &res) const =0
Interpolate argument to result.
Base class for all design variables related to topology optimisation (topO). Provides the lookup func...
void writeFluidSolidInterface(const volScalarField &indicator, const scalar isoValue, labelList &changedFaces, List< wallPointData< label > > &changedFacesInfo)
Write the fluid-solid interface to files.
topOZones zones_
Cell zones useful for defining the constant and changing parts of the domain in topO.
const labelList & adjointPorousZoneIDs() const
Cell zone IDs in which porosity is allowed to change.
static bool try_movePoints(const fvMesh &mesh)
Trigger update of y-field for the "wallDist" MeshObject on the given mesh. A no-op if the wallDist is...
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
OBJstream os(runTime.globalPath()/outputName)
#define DebugInfo
Report an information message using Foam::Info.
const std::string patch
OpenFOAM patch number as a std::string.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
const dimensionSet dimless
Dimensionless.
List< label > labelList
A List of labels.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
messageStream Info
Information stream (stdout output on master, null elsewhere).
DynamicID< cellZoneMesh > cellZoneID
Foam::cellZoneID.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
List< bool > boolList
A List of bools.
static constexpr const zero Zero
Global zero (0).
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Type gMax(const FieldField< Field, Type > &f)
constexpr char nl
The newline '\n' character (0x0a).
dimensionedScalar beta("beta", dimless/dimTemperature, laminarTransport)
#define forAll(list, i)
Loop across all elements in list.
PtrList< adjointSolverManager > & adjointSolverManagers