45 levelSetDesignVariables,
84 vars =
y.primitiveField();
99 for (
const label IOcell :
zones_.IOCells())
101 betaIf[IOcell] =
Zero;
104 const labelList& fixedZeroPorousZones =
zones_.fixedZeroPorousZoneIDs();
109 for (
const label zoneID : fixedZeroPorousZones)
112 for (
const label cellI : zone)
114 betaIf[cellI] =
Zero;
119 forAll(fixedPorousZones, zI)
121 const label zoneID = fixedPorousZones[zI];
122 const scalar value = fixedPorousValues[zI];
124 for (
const label cellI : zone)
126 betaIf[cellI] = value >= 0 ? 0 : 1;
137 if (
zones_.adjointPorousZoneIDs().empty())
142 zones_.fixedZeroPorousZoneIDs();
143 for (
const label zoneID : fixedZeroPorousZones)
146 for (
const label cellI : zone)
148 isActiveVar[cellI] =
false;
153 for (
const label zoneID : fixedPorousZones)
156 for (
const label cellI : zone)
158 isActiveVar[cellI] =
false;
164 for (label cellI :
zones_.IOCells())
166 isActiveVar[cellI] =
false;
185 for (
const label
cellZoneID : adjointPorousZoneIDs)
189 for (
const label cellI : zone)
210 beta_.correctBoundaryConditions();
216 Info<<
"Re-initilising the level-set distance field" <<
nl <<
endl;
223 mesh_.time().timeName(),
232 y.primitiveFieldRef() = aTilda_.primitiveFieldRef();
233 y.correctBoundaryConditions();
235 changedFaces_.clear();
236 changedFaces_.setSize(mesh_.nFaces(), -1);
238 changedFacesInfo_.clear();
239 changedFacesInfo_.setSize(mesh_.nFaces());
241 writeFluidSolidInterface(aTilda_, 0, changedFaces_, changedFacesInfo_);
244 allCellInfo_.clear();
245 allCellInfo_.setSize(mesh_.nCells());
254 mesh_.globalData().nTotalCells() + 1
258 forAll(allCellInfo_, celli)
260 if (allCellInfo_[celli].valid(wave.data()))
262 signedDistances_[celli] =
266 signedDistances_.correctBoundaryConditions();
272levelSetDesignVariables::levelSetDesignVariables
281 (regularisationRadius::
New(
mesh,
dict.subDict(
"regularisation"), false)),
283 (regularisationPDE::
New(
mesh,
dict.subDict(
"regularisation"), zones_)),
291 IOobject::READ_IF_PRESENT,
296 fvPatchFieldBase::zeroGradientType()
305 IOobject::READ_IF_PRESENT,
310 fvPatchFieldBase::zeroGradientType()
323 IOobject::READ_IF_PRESENT,
329 fixATildaValues_(
dict.getOrDefault<bool>(
"fixATildaValues", true)),
330 writeAllDistanceFields_
331 (
dict.getOrDefault<bool>(
"writeAllDistanceFields", false)),
341 scalar maxDist =
gMax(*
this);
348 autoPtr<scalar>(
new scalar(lowerBound)),
349 autoPtr<scalar>(
new scalar(upperBound))
352 <<
"Using lower/upper bounds "
428 Info<<
"maxInitChange/maxChange \t"
462 regularise(
aTilda_, objectiveSens, objectiveSens,
false,
radius_());
464 objectiveSens *=
mesh_.
V();
481 sens.primitiveFieldRef() = objectiveSens;
485 return tobjectiveSens;
506 alpha.primitiveFieldRef() = *
this;
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Wave propagation of information through grid. Every iteration information goes through one layer of c...
const TrackingData & data() const noexcept
Additional data to be passed into container.
void operator+=(const UList< scalar > &)
void writeEntry(const word &keyword, Ostream &os) const
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.
void correctBoundaryConditions()
Correct boundary field.
@ NO_READ
Nothing to be read.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ 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,...
const Time & time() const noexcept
Return Time associated with the objectRegistry.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void setSize(label n)
Alias for resize().
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
bool writeTime() const noexcept
True if this is a write interval.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
label size() const noexcept
void size(const label n)
Older name for setAddressableSize.
Abstract base class for adjoint-based sensitivities.
const adjointSolver & getAdjointSolver() const
Const access to adjoint solver.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Abstract base class for defining design variables.
autoPtr< scalarField > upperBounds_
Upper bounds of the 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.
autoPtr< scalarField > lowerBounds_
Lower bounds of the design variables.
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 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...
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.
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
const Time & time() const
Return the top-level database.
Template invariant parts for fvPatchField.
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Signed distance field design variables for level-set based topology optimization (topO).
virtual void update(scalarField &correction)
Update design variables based on a given correction.
void applyFixedPorosityValues()
Apply fixed values in certain zones.
autoPtr< regularisationRadius > radius_
The regularisation radius.
virtual bool writeData(Ostream &) const
The writeData function required by the regIOobject write operation.
void updateBeta()
Update the beta field.
virtual tmp< scalarField > assembleSensitivities(adjointSensitivity &adjointSens)
Add contributions from the adjoint to the regularization PDE, the derivative of the interpolation fun...
List< wallPointData< label > > changedFacesInfo_
Seed distances to MeshWave and cell distances.
bool fixATildaValues_
Fix aTilda values in fixed{Zero}PorousZones and IOcells.
void setActiveDesignVariables(bool activeIO=false)
Determine which design variables are active.
volScalarField beta_
The indicator field.
List< wallPointData< label > > allCellInfo_
autoPtr< topOInterpolationFunction > interpolation_
Function to transorm signed distances to the indicator field beta_.
void readField()
Read the design variables field.
virtual bool globalSum() const
Whether to use global sum when computing matrix-vector products in update methods.
void updateSignedDistances()
Make aTilda a signed distance field based on the zero iso-surface of the current aTilda field.
autoPtr< regularisationPDE > regularisation_
Regularisation mechanism.
virtual const volScalarField & beta() const
Const reference to the beta field.
labelList changedFaces_
Mesh faces acting as the source of MeshWave.
static autoPtr< levelSetDesignVariables > New(fvMesh &mesh, const dictionary &dict)
Return a reference to the selected turbulence model.
bool writeAllDistanceFields_
Write all fields related to the distance calculation (debugging).
virtual scalar computeEta(scalarField &correction)
Compute eta if not set in the first step.
volScalarField aTilda_
The regularised field.
volScalarField signedDistances_
The signed distances field.
virtual void writeDesignVars()
Write useful quantities to files.
static autoPtr< patchDistMethod > New(const dictionary &dict, const fvMesh &mesh, const labelHashSet &patchIDs, const word &defaultPatchDistMethod=word::null)
static wordList patchTypes(const fvMesh &mesh, const labelHashSet &patchIDs)
Return the patch types for y and n.
labelHashSet findPatchIDs() const
Find patch indices for a given polyPatch type (uses isA test).
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
Base class for selecting the regulatisation PDE.
Base class for selecting the regulatisation radius.
const autoPtr< volScalarField > & fieldSensPtr() const
Get the fieldSensPtr.
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.
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.
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...
Base class for mesh zones.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Abstract base class for interpolation functions used in topology optimisation.
OBJstream os(runTime.globalPath()/outputName)
List< wallPoints > allFaceInfo(mesh_.nFaces())
#define DebugInfo
Report an information message using Foam::Info.
Namespace for handling debugging switches.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
const dimensionSet dimless
Dimensionless.
dimensionedScalar sign(const dimensionedScalar &ds)
List< label > labelList
A List of labels.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
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.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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...
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
List< scalar > scalarList
List of scalar.
Type gMax(const FieldField< Field, Type > &f)
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.