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) =
253 setActiveDesignVariables();
256 readField(
"alpha", 0,
true);
258 if (regularisation_.growFromWalls())
261 for (
const fvPatch&
patch : mesh_.boundary())
263 if (isA<wallFvPatch>(
patch))
268 alpha[faceCells[cI]] = 1.;
285 Foam::topODesignVariables::topODesignVariables
295 Foam::topODesignVariables::topODesignVariables
310 dict_.subDict(
"regularisation")
314 dict.getOrDefaultCompat<bool>
316 "writeAllFields", {{
"writeAllAlphaFields", 2306}}, false
339 return regularisation_.beta();
345 const word& interpolationFieldName
348 return beta().primitiveField();
359 const word& interpolationFieldName
362 const scalarField& indicator = interpolationField(interpolationFieldName);
364 interpolationFunc.
interpolate(indicator, interpolant);
367 const scalar
diff(solidValues[fieldi] - fluidValues[0][fieldi]);
368 field.primitiveFieldRef() = fluidValues[0][fieldi] + interpolant*
diff;
369 field.correctBoundaryConditions();
380 const word& designVariablesName,
381 const word& interpolationFieldName
384 const scalarField& indicator = interpolationField(interpolationFieldName);
386 (solidValues[fieldi] - fluidValues[0][fieldi])
400 field *= scalar(1) - interpolant;
408 const word& designVariablesName
418 const word& interpolationFieldName,
431 const word& interpolationFieldName,
449 regularisation_.updateBeta();
461 labelList changedFaces(mesh_.nFaces(), -1);
463 writeFluidSolidInterface(-
beta(), -0.5, changedFaces, changedFacesInfo);
487 regularisation_.postProcessSens(objectiveSens);
490 if (writeAllFields_ && mesh_.time().writeTime())
497 mesh_.time().timeName(),
505 sens.primitiveFieldRef() = objectiveSens;
509 return tobjectiveSens;
535 const PtrList<adjointSolver>& adjointSolvers =
536 manager.adjointSolvers();
537 for (
const adjointSolver& solver : adjointSolvers)
548 if (writeAllFields_ && mesh_.time().writeTime())
555 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.
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.
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)
OBJstream os(runTime.globalPath()/outputName)
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.
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)