60 <<
"Updating design variables for field " << fluidID <<
endl;
75 field[cellI] + localCorrection[cellI],
88 for (label cellI : zoneCells)
95 field[cellI] + localCorrection[cellI],
109 SubField<scalar>
alpha(*
this, mesh_.nCells());
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);
146 Info<<
"Setting eta value to " << eta <<
endl;
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());
224 SubField<scalar>(*
this, mesh_.nCells(), offset) =
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())
267 for (
const fvPatch&
patch : mesh_.boundary())
269 if (isA<wallFvPatch>(
patch))
271 UIndirectList<scalar>(
alpha,
patch.faceCells()) = 1;
287 Foam::topODesignVariables::topODesignVariables
297 Foam::topODesignVariables::topODesignVariables
312 dict_.subDict(
"regularisation")
316 dict.getOrDefaultCompat<bool>
318 "writeAllFields", {{
"writeAllAlphaFields", 2306}},
false 341 return regularisation_.beta();
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
386 const scalarField& indicator = interpolationField(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();
463 labelList changedFaces(mesh_.nFaces(), -1);
465 writeFluidSolidInterface(-
beta(), -0.5, changedFaces, changedFacesInfo);
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(),
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Return the correction form of the given matrix by subtracting the matrix multiplied by the current fi...
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &sens)
Assemble sensitivity derivatives, by combining the part related to the primal and adjoint solution wi...
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
void size(const label n)
Older name for setAddressableSize.
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 tmp< scalarField > penaltySensitivities(const word &interpolationFieldName, const topOInterpolationFunction &interpolationFunc) const
Return the penalty term derivative.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Abstract base class for adjoint-based sensitivities.
Base class for primal solvers.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
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.
topOZones zones_
Cell zones useful for defining the constant and changing parts of the domain in topO.
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
A class that holds the data needed to identify things (zones, patches) in a dynamic mesh...
Ostream & endl(Ostream &os)
Add newline and flush stream.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
Design variables for porosity-based topology optimisation (topO) problems.
const adjointSolver & getAdjointSolver() const
Const access to adjoint solver.
virtual const volScalarField & beta() const
Get the indicator field.
Macros for easy insertion into run-time selection tables.
A field of fields is a PtrList of fields with reference counting.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
#define forAll(list, i)
Loop across all elements in list.
T & operator[](const label i)
Return element of UList.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
virtual scalar computeEta(scalarField &correction)
Compute eta if not set in the first step.
virtual void addTopOFvOptions() const
Add topO fvOptions.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
void writeEntry(const word &keyword, Ostream &os) const
Write as a dictionary entry with keyword.
virtual const scalarField & interpolationField(const word &interpolationFieldName="beta") const
Return interpolant.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual void writeDesignVars()
Write porosity field to file.
virtual void nullifyInSolidSensitivities(scalarField &sens, const topOInterpolationFunction &interpolationFunc, const word &designVariablesName) const
Nullify given field in the solid domain.
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.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
virtual tmp< scalarField > derivative(const scalarField &arg) const =0
Return of function with respect to the argument field.
#define DebugInfo
Report an information message using Foam::Info.
virtual void update(scalarField &correction)
Update design variables based on a given correction.
virtual bool writeData(Ostream &) const
The writeData function required by the regIOobject write operation.
Type gMax(const FieldField< Field, Type > &f)
defineTypeNameAndDebug(combustionModel, 0)
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...
DynamicID< cellZoneMesh > cellZoneID
Foam::cellZoneID.
void applyFixedValues()
Apply fixed values in certain zones.
virtual void nullifyInSolid(scalarField &field, const topOInterpolationFunction &interpolationFunc) const
Nullify given field in the solid domain.
virtual void setInitialValues()
Set initial values of the design variables.
virtual void updateField(const scalarField &correction, const label fluidID=0)
Update the design variables given their correction.
decomposeUsingBbs false
Use bounding boxes (default) or unique decomposition of triangles (i.e. do not duplicate triangles) ...
Abstract base class for defining design variables.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
label nCells() const noexcept
Number of mesh cells.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
const word & solverName() const
Return the solver name.
Mesh data needed to do the Finite Volume discretisation.
virtual tmp< scalarField > penalty(const word &interpolationFieldName, const topOInterpolationFunction &interpolationFunc) const
Return the Brinkman penalisation term.
Automatically write from objectRegistry::writeObject()
const labelList & adjointPorousZoneIDs() const
Cell zone IDs in which porosity is allowed to change.
const std::string patch
OpenFOAM patch number as a std::string.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
virtual void initialize()
Part of the constructor initialisation.
virtual void interpolate(const scalarField &arg, scalarField &res) const =0
Interpolate argument to result.
messageStream Info
Information stream (stdout output on master, null elsewhere)
dimensionedScalar beta("beta", dimless/dimTemperature, laminarTransport)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
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...
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...
List< label > labelList
A List of labels.
A class for managing temporary objects.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Base class for all design variables related to topology optimisation (topO). Provides the lookup func...
PtrList< adjointSolverManager > & adjointSolverManagers
Defines the attributes of an object for which implicit objectRegistry management is supported...
virtual bool globalSum() const
Whether to use global sum when computing matrix-vector products in update methods.
List< bool > boolList
A List of bools.
const autoPtr< volScalarField > & fieldSensPtr() const
Get the fieldSensPtr.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
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...
static constexpr const zero Zero
Global zero (0)