56void Foam::polyMesh::calcDirections()
const
66 bool hasEmptyPatches =
false;
67 bool hasWedgePatches =
false;
83 hasEmptyPatches =
true;
93 (void)wpp.faceNormals();
97 hasWedgePatches =
true;
98 wedgeDirVec +=
cmptMag(wpp.centreNormal());
106 reduce(emptyDirVec, sumOp<vector>());
108 emptyDirVec.normalise();
112 if (emptyDirVec[cmpt] > 1
e-6)
114 solutionD_[cmpt] = -1;
118 solutionD_[cmpt] = 1;
126 geometricD_ = solutionD_;
130 reduce(wedgeDirVec, sumOp<vector>());
132 wedgeDirVec.normalise();
136 if (wedgeDirVec[cmpt] > 1
e-6)
138 geometricD_[cmpt] = -1;
142 geometricD_[cmpt] = 1;
149Foam::autoPtr<Foam::labelIOList> Foam::polyMesh::readTetBasePtIs()
const
173Foam::polyMesh::polyMesh(
const IOobject&
io,
const bool doInit)
183 time().findInstance(meshDir(),
"points"),
195 time().findInstance(meshDir(),
"faces"),
226 clearedPrimitives_(false),
293 topoChanging_(false),
294 storeOldCellCentres_(false),
303 cellCompactIOList cLst
308 time().findInstance(meshDir(),
"cells"),
326 <<
"Missing mesh boundary on one or more domains" << endl;
329 if (returnReduceAnd(!nPoints()))
332 <<
"No points in mesh" << endl;
337 <<
"No cells in mesh" <<
endl;
356 boundary_.updateMesh();
359 boundary_.calcGeometry();
368Foam::polyMesh::polyMesh
433 clearedPrimitives_(false),
448 bounds_(points_, syncPar),
495 topoChanging_(false),
496 storeOldCellCentres_(false),
502 const face& curFace = faces_[facei];
504 if (
min(curFace) < 0 ||
max(curFace) > points_.
size())
507 <<
"Face " << facei <<
"contains vertex labels out of range: "
508 << curFace <<
" Max point index = " << points_.
size()
518Foam::polyMesh::polyMesh
529 data_(static_cast<const objectRegistry&>(*this)),
582 clearedPrimitives_(false),
597 bounds_(points_, syncPar),
598 comm_(UPstream::worldComm),
644 topoChanging_(false),
645 storeOldCellCentres_(false),
651 const face& curFace = faces_[facei];
653 if (
min(curFace) < 0 ||
max(curFace) > points_.
size())
656 <<
"Face " << facei <<
"contains vertex labels out of range: "
657 << curFace <<
" Max point index = " << points_.
size()
668 const cell& curCell = cLst[celli];
670 if (
min(curCell) < 0 ||
max(curCell) > faces_.size())
673 <<
"Cell " << celli <<
"contains face labels out of range: "
674 << curCell <<
" Max face index = " << faces_.size()
684Foam::polyMesh::polyMesh
703 const bool validBoundary
707 clearAddressing(
true);
713 points_.transfer(*
points);
714 bounds_ =
boundBox(points_, validBoundary);
719 faces_.transfer(*faces);
724 owner_.transfer(*owner);
729 neighbour_.transfer(*neighbour);
753 const face& curFace = faces_[facei];
755 if (
min(curFace) < 0 ||
max(curFace) > points_.size())
758 <<
"Face " << facei <<
" contains vertex labels out of range: "
759 << curFace <<
" Max point index = " << points_.size()
777 boundary_.updateMesh();
780 boundary_.calcGeometry();
786 <<
"No points or no cells in mesh" <<
endl;
847 return points_.instance();
853 return faces_.instance();
859 if (geometricD_.x() == 0)
876 if (solutionD_.x() == 0)
893 if (!tetBasePtIsPtr_)
898 <<
"Forcing storage of base points."
907 tetBasePtIsPtr_.reset
926 return *tetBasePtIsPtr_;
937 treeBoundBox overallBb(
points());
938 overallBb.inflate(
rndGen, 1
e-4, ROOTVSMALL);
942 new indexedOctree<treeDataCell>
958 return *cellTreePtr_;
965 const bool validBoundary
968 if (boundaryMesh().size())
971 <<
"boundary already exists"
979 boundary_.transfer(plist);
985 globalMeshDataPtr_.reset(
nullptr);
990 boundary_.updateMesh();
993 boundary_.calcGeometry();
995 boundary_.checkDefinition();
1002 PtrList<pointZone>&& pz,
1003 PtrList<faceZone>&& fz,
1004 PtrList<cellZone>&& cz
1007 if (pointZones_.size() || faceZones_.size() || cellZones_.size())
1010 <<
"point, face or cell zone already exists"
1017 pointZones_.clear();
1018 pointZones_.transfer(pz);
1026 faceZones_.transfer(fz);
1034 cellZones_.transfer(cz);
1042 const List<polyPatch*>&
p,
1043 const bool validBoundary
1072 if (clearedPrimitives_)
1075 <<
"points deallocated"
1085 return io.upToDate(points_);
1091 io.eventNo() = points_.eventNo()+1;
1097 if (clearedPrimitives_)
1100 <<
"faces deallocated"
1134 oldPointsPtr_.reset(
new pointField(points_));
1135 curMotionTimeIndex_ =
time().timeIndex();
1138 return *oldPointsPtr_;
1144 storeOldCellCentres_ =
true;
1148 return cellCentres();
1151 if (!oldCellCentresPtr_)
1156 return *oldCellCentresPtr_;
1163 <<
"Moving points for time " << time().value()
1164 <<
" index " << time().timeIndex() <<
endl;
1166 if (newPoints.size() != points_.size())
1169 <<
"Size of newPoints " << newPoints.size()
1170 <<
" does not correspond to current mesh points size "
1179 if (curMotionTimeIndex_ != time().
timeIndex())
1183 Info<<
"void polyMesh::movePoints(const pointField&) : "
1184 <<
" Storing current points for time " << time().value()
1185 <<
" index " << time().timeIndex() <<
endl;
1188 if (storeOldCellCentres_)
1190 oldCellCentresPtr_.reset(
nullptr);
1191 oldCellCentresPtr_.reset(
new pointField(cellCentres()));
1195 oldPointsPtr_.reset(
nullptr);
1196 oldPointsPtr_.reset(
new pointField(points_));
1197 curMotionTimeIndex_ = time().timeIndex();
1200 points_ = newPoints;
1202 bool moveError =
false;
1206 if (checkMeshMotion(points_,
true))
1211 <<
"Moving the mesh with given points will "
1212 <<
"invalidate the mesh." <<
nl
1213 <<
"Mesh motion should not be executed." <<
endl;
1218 points_.instance() = time().timeName();
1219 points_.eventNo() = getEvent();
1221 if (tetBasePtIsPtr_)
1224 tetBasePtIsPtr_->instance() = time().timeName();
1225 tetBasePtIsPtr_->eventNo() = getEvent();
1241 if (globalMeshDataPtr_)
1243 globalMeshDataPtr_->movePoints(points_);
1249 boundary_.movePoints(points_);
1251 pointZones_.movePoints(points_);
1252 faceZones_.movePoints(points_);
1253 cellZones_.movePoints(points_);
1264 cellTreePtr_.reset(
nullptr);
1280 if (
debug && moveError)
1291 curMotionTimeIndex_ = 0;
1292 oldPointsPtr_.reset(
nullptr);
1293 oldCellCentresPtr_.reset(
nullptr);
1299 return bool(globalMeshDataPtr_);
1305 if (!globalMeshDataPtr_)
1309 Pout<<
"polyMesh::globalData() const : "
1310 <<
"Constructing parallelData from processor topology"
1317 return *globalMeshDataPtr_;
1323 fileName meshFilesPath = thisDb().time().path()/instanceDir/meshDir();
1325 rm(meshFilesPath/
"points");
1326 rm(meshFilesPath/
"faces");
1327 rm(meshFilesPath/
"owner");
1328 rm(meshFilesPath/
"neighbour");
1329 rm(meshFilesPath/
"cells");
1330 rm(meshFilesPath/
"boundary");
1331 rm(meshFilesPath/
"pointZones");
1332 rm(meshFilesPath/
"faceZones");
1333 rm(meshFilesPath/
"cellZones");
1334 rm(meshFilesPath/
"meshModifiers");
1335 rm(meshFilesPath/
"parallelData");
1340 rmDir(meshFilesPath/
"sets");
1366 celli =
tree.findInside(
p);
1384 const polyMesh&
mesh = *
this;
1387 tetFacei = tet.face();
1388 tetPti = tet.tetPt();
1396 const cellDecomposition decompMode
1407 case FACE_CENTRE_TRIS:
1411 const cell& cFaces =
cells()[celli];
1415 label facei = cFaces[cFacei];
1416 const face&
f = faces_[facei];
1417 const point& fc = faceCentres()[facei];
1418 bool isOwn = (owner_[facei] == celli);
1428 nextPointi =
f.nextLabel(fp);
1432 pointi =
f.nextLabel(fp);
1443 vector proj =
p - faceTri.centre();
1445 if ((faceTri.areaNormal() & proj) > 0)
1455 case FACE_DIAG_TRIS:
1463 label facei = cFaces[cFacei];
1464 const face&
f = faces_[facei];
1466 for (label tetPti = 1; tetPti <
f.
size() - 1; tetPti++)
1473 vector proj =
p - faceTri.centre();
1475 if ((faceTri.areaNormal() & proj) > 0)
1491 findTetFacePt(celli,
p, tetFacei, tetPti);
1493 return tetFacei != -1;
1505 const cellDecomposition decompMode
1511 && (decompMode == FACE_DIAG_TRIS || decompMode == CELL_TETS)
1520 (void)tetBasePtIs();
1528 if (decompMode == CELL_TETS)
1537 findCellFacePt(
p, celli, tetFacei, tetPti);
1552 (void)tetBasePtIs();
1556 label celli = findNearestCell(
p);
1559 if (pointInCell(
p, celli, decompMode))
1567 for (label celli = 0; celli < nCells(); celli++)
1569 if (pointInCell(
p, celli, decompMode))
1586 const bool writeOnProc
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
SubField< vector > subField
label size() const noexcept
@ NO_REGISTER
Do not request registration (bool: false).
writeOption writeOpt() const noexcept
Get the write option.
@ NO_READ
Nothing to be read.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
@ LAZY_READ
Reading is optional [identical to READ_IF_PRESENT].
@ 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 word & name() const noexcept
Return the object name.
bool hasHeaderClass() const noexcept
True if headerClassName() is non-empty (after reading).
const fileName & instance() const noexcept
Read access to instance path component.
A simple container for options an IOstream can normally have.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
void size(const label n)
Older name for setAddressableSize.
Inter-processor communications stream.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static bool & parRun() noexcept
Test if this a parallel run.
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
static const Vector< Cmpt > one
static constexpr direction nComponents
Number of components in this vector space.
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
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.
A bounding box defined in terms of min/max extrema points.
void inflate(const scalar factor)
Expand box by factor*mag(span) in all dimensions.
A cell is defined as a list of faces with extra functionality.
A keyword and a list of tokens is an 'entry'.
A face is a list of labels corresponding to mesh vertices.
A class for handling file names.
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
Non-pointer based hierarchical recursive searching.
static void movePoints(objectRegistry &obr)
Update for mesh motion.
Registry of regIOobjects.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write the objects using stream options.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
const objectRegistry & parent() const noexcept
Return the parent objectRegistry.
const Time & time() const noexcept
Return time registry.
label getEvent() const
Return new event number.
static labelList findFaceBasePts(const polyMesh &mesh, scalar tol=minTetQuality, bool report=false)
Find a suitable base point for each face for decomposition into tets.
static tetIndices findTet(const polyMesh &mesh, label cI, const point &pt)
Find the tet decomposition of the cell containing the given point.
Mesh consisting of general polyhedral cells.
virtual ~polyMesh()
Destructor.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
void findCellFacePt(const point &p, label &celli, label &tetFacei, label &tetPti) const
Find the cell, tetFacei and tetPti for point p.
void setInstance(const fileName &instance, const IOobjectOption::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
const fileName & facesInstance() const
Return the current instance directory for faces.
label nGeometricD() const
Return the number of valid geometric dimensions in the mesh.
bool hasGlobalData() const noexcept
Is demand-driven parallel info available?
static word defaultRegion
Return the default region name.
void addPatches(polyPatchList &plist, const bool validBoundary=true)
Add boundary patches.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc=true) const
Write items held in the objectRegistry. Normally includes mesh components (points,...
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir).
cellDecomposition
Enumeration defining the decomposition of the cell for.
virtual const faceList & faces() const
Return raw faces.
bool moving() const noexcept
Is mesh moving.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
virtual const fileName & dbDir() const
Override the objectRegistry dbDir for a single-region case.
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
virtual const labelList & faceOwner() const
Return face owner.
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
void findTetFacePt(const label celli, const point &p, label &tetFacei, label &tetPti) const
Find the tetFacei and tetPti for point p in celli.
const globalMeshData & globalData() const
Return parallel info (demand-driven).
bool pointInCell(const point &p, label celli, const cellDecomposition=CELL_TETS) const
Test if point p is in the celli.
label nSolutionD() const
Return the number of valid solved-for dimensions in the mesh.
virtual const pointField & oldPoints() const
Return old points (mesh motion).
const fileName & pointsInstance() const
Return the current instance directory for points.
void clearAddressing(const bool isMeshUpdate=false)
Clear addressing.
void resetMotion() const
Reset motion.
void addZones(PtrList< pointZone > &&pz, PtrList< faceZone > &&fz, PtrList< cellZone > &&cz)
Add mesh zones.
virtual const labelList & faceNeighbour() const
Return face neighbour.
virtual bool upToDatePoints(const regIOobject &io) const
Return true if io is up-to-date with points.
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
virtual void movePoints(const pointField &)
Move points.
const objectRegistry & thisDb() const noexcept
Return the object registry.
virtual const pointField & points() const
Return raw points.
virtual void setUpToDatePoints(regIOobject &io) const
Set io to be up-to-date with points.
const indexedOctree< treeDataCell > & cellTree() const
Return the cell search tree.
void removeFiles() const
Remove all files from mesh instance().
virtual const pointField & oldCellCentres() const
Return old cellCentres (mesh motion).
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh").
void resetPrimitives(autoPtr< pointField > &&points, autoPtr< faceList > &&faces, autoPtr< labelList > &&owner, autoPtr< labelList > &&neighbour, const labelUList &patchSizes, const labelUList &patchStarts, const bool validBoundary=true)
Reset mesh primitive data. Assumes all patch info correct.
const word & regionName() const
The mesh region name or word::null if polyMesh::defaultRegion.
void clearOut(const bool isMeshUpdate=false)
Clear all geometry and addressing.
const Vector< label > & solutionD() const
Return the vector of solved-for directions in mesh.
virtual bool checkMeshMotion(const pointField &newPoints, const bool report=false, const bool detailedReport=false) const
Check mesh motion for correctness given motion points.
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
A patch is a list of labels that address the faces in the global face list.
Cell-face mesh analysis engine.
label findNearestCell(const point &location) const
Find the cell with the nearest cell centre to location.
bool pointInCell(const point &p, label celli) const
Return true if the point is in the cell.
const vectorField & faceCentres() const
const vectorField & cellCentres() const
label nCells() const noexcept
Number of mesh cells.
void movePoints(const pointField &p, const pointField &oldP)
Move points.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
const cellList & cells() const
virtual void updateGeom()
Update all geometric data.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
label face() const noexcept
Return the face index.
triPointRef faceTri(const polyMesh &mesh) const
The triangle geometry for the face for this tet. The normal of the tri points out of the cell.
label tetPt() const noexcept
Return the characterising tet point index.
Standard boundBox with extra functionality for use in octree.
Encapsulation of data needed to search in/for cells. Used to find the cell containing a point (e....
static vector areaNormal(const Point &p0, const Point &p1, const Point &p2)
The area normal for a triangle defined by three points (right-hand rule). Magnitude equal to area of ...
static Point centre(const Point &p0, const Point &p1, const Point &p2)
The centre (centroid) of three points.
A class for handling words, derived from Foam::string.
static const word null
An empty word.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
#define InfoInFunction
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
List< label > labelList
A List of labels.
IOList< label > labelIOList
IO for a List of label.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< face > faceList
List of faces.
Cmpt cmptSum(const SphericalTensor< Cmpt > &st)
Return the sum of components of a SphericalTensor.
Ostream & endl(Ostream &os)
Add newline and flush stream.
List< cell > cellList
List of cell.
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
vector point
Point is a vector.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
static constexpr const zero Zero
Global zero (0).
triangle< point, const point & > triPointRef
A triangle using referred points.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
UList< label > labelUList
A UList of labels.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
constexpr char nl
The newline '\n' character (0x0a).
Tree tree(triangles.begin(), triangles.end())
#define forAll(list, i)
Loop across all elements in list.