60 if (!
mesh.isInternalFace(facei))
63 for (
const label edgei: faceEdges)
65 const labelList& edgeIFaces = edgeFaces[edgei];
66 for (
const label neiFacei : edgeIFaces)
68 if (neiFacei != facei && !
mesh.isInternalFace(neiFacei))
71 mesh.boundaryMesh().whichPatch(neiFacei);
104 addCuttingFaceToIsoline
109 cuttingFacesPerMeshFace,
116 cuttingFacesPerMeshFace[facei].push_back
118 isoSurfFaces.size() - 1
132 const label nSerialPatches,
140 if (facePoints.size() > 2)
145 labelList uniquePointIDs(facePoints.size(), -1);
148 label addedPoints =
Zero;
151 bool foundInNei =
false;
152 for (
const label cutMeshFacei : cellCutFaces)
160 cuttingFacesPerMeshFace[cutMeshFacei],
173 uniquePointIDs[
pi] = isoSurfPts.size() + addedPoints;
175 uniqueFacePoints.push_back(facePoints[
pi]);
179 face isoFace(uniquePointIDs);
180 isoSurfPts.append(uniqueFacePoints);
181 isoSurfFaces.append(isoFace);
194 const DynamicList<label>& cuttingFaces,
195 const DynamicList<point>& isoSurfPts,
196 const DynamicList<face>& isoSurfFaces,
200 for (
const label cuttingFacei : cuttingFaces)
202 const face& cuttingFace = isoSurfFaces[cuttingFacei];
203 for (
const label neiPi : cuttingFace)
205 if (
mag(pointi - isoSurfPts[neiPi]) < SMALL)
207 uniquePointIDs[pointID] = neiPi;
220 const scalar isoValue,
224 label& nChangedFaces,
240 const label start =
patch.start();
243 const label gFacei = start + facei;
249 for (
const label pti :
mesh.
faces()[gFacei])
251 isFluid = isFluid && (pointY[pti] >= isoValue);
253 if (isFluid && !addedFaces.found(gFacei))
259 meshFaceToChangedFace_.insert(gFacei, nChangedFaces);
261 changedFacesInfo[nChangedFaces] =
268 changedFaces[nChangedFaces] = gFacei;
270 changedFaceToCutFace.push_back(isoSurfFaces.size());
276 addCuttingFaceToIsoline
281 cuttingFacesPerMeshFace,
288 cuttingFacesPerMeshFace[gFacei].push_back
290 isoSurfFaces.size() - 1
305 const label nSerialPatches
313 fileName fname(isoSurfFolder_/localName);
316 vtkFile.writeGeometry();
317 vtkFile.beginCellData(1);
318 vtkFile.writeCellData(
"zoneIds", zoneIds);
346 pts, faces, zoneIds, faceIds
353 const faceList& surfFaces = surf().faces();
354 const labelList& surfZoneIds = surf().zoneIds();
357 labelList zoneSizes(nSerialPatches + 1, 0);
360 ++zoneSizes[surfZoneIds[fi]];
364 labelList cumulZoneSizes(nSerialPatches + 1, 0);
365 for (label zi = 1; zi < cumulZoneSizes.size(); ++zi)
367 cumulZoneSizes[zi] = cumulZoneSizes[zi - 1] + zoneSizes[zi - 1];
374 labelList passedFacesPerZone(surfZoneIds.size(), 0);
378 const label zi = surfZoneIds[fi];
379 faceMap[cumulZoneSizes[zi] + passedFacesPerZone[zi]] = fi;
380 ++passedFacesPerZone[zi];
402 zoneSizes[nSerialPatches],
403 cumulZoneSizes[nSerialPatches],
406 surfZones.setSize(zi + 1);
430Foam::topOVariablesBase::topOVariablesBase
444 IOobject::READ_IF_PRESENT,
451 (
mesh.time().globalPath()/
"optimisation"/
"topOIsoSurfaces"),
452 meshFaceToChangedFace_(),
468 const word& interpolationFieldName
483 const word& designVariablesName,
484 const word& interpolationFieldName
487 if (designVariablesName ==
"beta")
499 const scalar isoValue,
501 List<wallPointData<label>>& changedFacesInfo
504 const fvMesh&
mesh = zones_.mesh();
507 label nChangedFaces(0);
511 if (debug &&
mesh.time().writeTime())
513 pointY.rename(
"pointY");
528 meshFaceToChangedFace_.clearStorage();
542 if (!
cutCell.calcSubCell(celli, isoValue))
546 cuttingNf.normalise();
553 const label facei =
cells[celli][fi];
557 const scalar distSqr =
558 magSqr((Cf - cuttingCf) & cuttingNf);
560 Cf + ((cuttingCf - Cf) & cuttingNf)*cuttingNf;
561 cellCutFaces.push_back(facei);
563 if (!meshFaceToChangedFace_.found(facei))
567 bool addedToIsoSurf = addCutBoundaryFaceToIsoline
574 cuttingFacesPerMeshFace
579 meshFaceToChangedFace_.insert(facei, nChangedFaces);
581 changedFacesInfo[nChangedFaces] =
588 changedFaces[nChangedFaces] = facei;
590 changedFaceToCutFace.push_back(isoSurfFaces.size());
596 label visitedFace = meshFaceToChangedFace_.at(facei);
597 if (distSqr < changedFacesInfo[visitedFace].distSqr())
600 changedFacesInfo[visitedFace] =
608 changedFaceToCutFace[visitedFace] =
617 addCuttingFaceToIsoline
622 cuttingFacesPerMeshFace,
629 for (
const label facei : cellCutFaces)
631 cuttingFacesPerMeshFace[facei].push_back
633 isoSurfFaces.size() - 1
642 addBoundaryFacesToIsoline
645 meshFaceToChangedFace_,
653 changedFaceToCutFace,
654 cuttingFacesPerMeshFace
657 changedFaces.setSize(nChangedFaces);
658 changedFacesInfo.setSize(nChangedFaces);
661 surfPoints_.transfer(isoSurfPts);
662 surfFaces_.transfer(isoSurfFaces);
665 writeSurfaceFiles(surfPoints_, surfFaces_, zoneIds, nSerialPatches);
673 const label changedFacesOffset =
676 for (
auto& info : changedFacesInfo)
678 info.data() += changedFacesOffset;
constexpr scalar pi(M_PI)
Macros for easy insertion into run-time selection tables.
label size() const noexcept
The number of elements in list.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
void append(const T &val)
Copy append an element to the end of this list.
void push_back(const T &val)
Copy append an element to the end of this list.
bool found(const Key &key) const
Same as contains().
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ 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.
InfoProxy< IOobject > info() const noexcept
Return info proxy, for printing information to a stream.
fileName globalPath() const
The complete global path for the object (with instance, local,...).
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void append(const T &val)
Append an element at the end of the list.
void push_back(const T &val)
Append an element at the end of the list.
void setSize(label n)
Alias for resize().
A HashTable to objects of type <T> with a label key.
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats.
static void write(const fileName &name, const MeshedSurfaceProxy &surf, IOstreamOption streamOpt=IOstreamOption(), const dictionary &options=dictionary::null)
Write to file, select based on its extension.
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.
void size(const label n)
Older name for setAddressableSize.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Vector< Cmpt > & normalise(const scalar tol=ROOTVSMALL)
Inplace normalise the vector by its magnitude.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
static autoPtr< T > NewFrom(Args &&... args)
Construct autoPtr from derived type with forwarding arguments.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
Base class for selecting the betaMax value, i.e. the value multiplying the Brinkman penalisation term...
Class for cutting a cell, celli, of an fvMesh, mesh_, at its intersection with an isosurface defined ...
Service routines for cutting a cell, celli, of an fvMesh, mesh_, at its intersection with a surface.
Class for cutting a face, faceI, of an fvMesh, mesh_, at its intersection with an isosurface defined ...
Base class for cutting a face, faceI, of an fvMesh, mesh_, at its intersections.
void calcSubFace(const label faceI, const scalarList &pointStatus, label firstFullySubmergedPoint, DynamicList< point > &subFacePoints, DynamicList< point > &surfacePoints, label &faceStatus, vector &subFaceCentre, vector &subFaceArea)
Calculate cut points along edges of face with pointStatus, pointfield and computes geometric informat...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
A face is a list of labels corresponding to mesh vertices.
A class for handling file names.
Mesh data needed to do the Finite Volume discretisation.
const Time & time() const
Return the top-level database.
const surfaceVectorField & Cf() const
Return face centres as surfaceVectorField.
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
static IntType calcOffset(IntType localSize, const label comm=UPstream::worldComm)
Based on the local input size(s), calculate a globally-consistent local start offset.
localIOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
label nNonProcessor() const
The number of patches before the first processor patch.
label whichPatch(const label meshFacei) const
Return patch index for a given mesh face index. Uses binary search.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
virtual const faceList & faces() const
Return raw faces.
virtual const pointField & points() const
Return raw points.
bool isInternalFace(const label faceIndex) const noexcept
Return true if given face label is internal to the mesh.
label nPoints() const noexcept
Number of mesh points.
label nFaces() const noexcept
Number of mesh faces.
const cellList & cells() const
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
virtual void rename(const word &newName)
Rename.
A surface zone on a MeshedSurface.
static scalar defaultMergeDim
The default merge dimension (1e-8).
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.
virtual void sourceTerm(DimensionedField< scalar, volMesh > &field, const topOInterpolationFunction &interpolationFunc, const scalar betaMax, const word &interpolationFieldName="beta") const
Populate source terms for the flow equations.
Map< label > meshFaceToChangedFace_
Map between iso-surface and mesh faces (internal and boundary).
bool addCutBoundaryFaceToIsoline(const label facei, const cutFaceIso &cutFace, DynamicList< vector > &isoSurfPts, DynamicList< face > &isoSurfFaces, DynamicList< label > &zoneIDs, List< DynamicList< label > > &cuttingFacesPerMeshFace) const
Check whether the cutFace intersects the boundary of the initial domain and add fluid part of the int...
topOZones zones_
Cell zones useful for defining the constant and changing parts of the domain in topO.
virtual void sourceTermSensitivities(scalarField &sens, const topOInterpolationFunction &interpolationFunc, const scalar betaMax, const word &designVariablesName, const word &interpolationFieldName="beta") const
Post-processing sensitivities due to interpolations based on the indicator fields.
fileName isoSurfFolder_
Folder name holding the zero level-set iso-surface.
DynamicList< label > faceFaces(const label facei) const
Construct facesFaces for a given boundary face.
void addBoundaryFacesToIsoline(const pointScalarField &pointY, const Map< label > &addedFaces, const scalar isoValue, DynamicList< vector > &isoSurfPts, DynamicList< face > &isoSurfFaces, DynamicList< label > &zoneIDs, label &nChangedFaces, labelList &changedFaces, List< wallPointData< label > > &changedFacesInfo, labelList &changedFaceToCutFace, List< DynamicList< label > > &cuttingFacesPerMeshFace)
Check whether the boundary faces of the initial domain belong to the fluid part and add them to the s...
virtual const volScalarField & beta() const =0
Get field used for physical interpolations.
void writeSurfaceFiles(const pointField &pts, const faceList &faces, const labelList &zoneIds, const label nSerialPatches) const
Write the surface describing the fluid domain to stl and vtp files.
pointField surfPoints_
Per cutting face, the changed faces owned by it.
bool addCuttingFaceToIsoline(const DynamicList< point > &facePoints, const label nSerialPatches, const DynamicList< label > &cellCutFaces, const List< DynamicList< label > > &cuttingFacesPerMeshFace, DynamicList< vector > &isoSurfPts, DynamicList< face > &isoSurfFaces, DynamicList< label > &zoneIDs) const
Add the cutting face to the zero level-set iso-surface.
faceList surfFaces_
Iso-surface faces.
bool isDuplicatePoint(const label pointID, const vector &pointi, const DynamicList< label > &cuttingFaces, const DynamicList< point > &isoSurfPts, const DynamicList< face > &isoSurfFaces, labelList &uniquePointIDs) const
const fvMesh & mesh() const
Const reference to mesh.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Interpolate from cell centres to points (vertices) using inverse distance weighting.
void close()
End the file contents and close the file after writing.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
void writeCellData(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData.
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
virtual bool writeGeometry()
Write patch topology.
virtual bool beginFile(std::string title="")
Write file header (non-collective).
Holds information (coordinate and normal) regarding nearest wall point.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
const labelIOList & zoneIDs
Namespace for handling debugging switches.
const std::string patch
OpenFOAM patch number as a std::string.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
List< labelList > labelListList
List of labelList.
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
List< label > labelList
A List of labels.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
List< face > faceList
List of faces.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< cell > cellList
List of cell.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0).
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
vectorField pointField
pointField is a vectorField.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
dimensionedScalar beta("beta", dimless/dimTemperature, laminarTransport)
#define forAll(list, i)
Loop across all elements in list.