56 void Foam::polyMesh::calcDirections()
const 66 bool hasEmptyPatches =
false;
67 bool hasWedgePatches =
false;
75 if (isA<emptyPolyPatch>(
pp))
83 hasEmptyPatches =
true;
87 else if (isA<wedgePolyPatch>(
pp))
89 const wedgePolyPatch& wpp = refCast<const wedgePolyPatch>(
pp);
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;
173 Foam::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),
326 <<
"Missing mesh boundary on one or more domains" <<
endl;
332 <<
"No points in mesh" <<
endl;
337 <<
"No cells in mesh" <<
endl;
356 boundary_.updateMesh();
359 boundary_.calcGeometry();
368 Foam::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()
518 Foam::polyMesh::polyMesh
582 clearedPrimitives_(
false),
597 bounds_(points_, syncPar),
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()
684 Foam::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);
736 boundary_[patchi] = polyPatch
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;
826 return parent().dbDir();
835 return dbDir()/meshSubDir;
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
1049 addPatches(plist, 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_);
1248 bounds_ = boundBox(points_);
1249 boundary_.movePoints(points_);
1251 pointZones_.movePoints(points_);
1252 faceZones_.movePoints(points_);
1253 cellZones_.movePoints(points_);
1264 cellTreePtr_.reset(
nullptr);
1274 meshObject::movePoints<polyMesh>(*this);
1275 meshObject::movePoints<pointMesh>(*this);
1277 const_cast<Time&
>(time()).functionObjects().movePoints(*
this);
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");
1347 removeFiles(instance());
1366 celli =
tree.findInside(
p);
1371 findTetFacePt(celli,
p, tetFacei, tetPti);
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:
1459 const cell& cFaces =
cells()[celli];
1463 label facei = cFaces[cFacei];
1464 const face&
f = faces_[facei];
1466 for (label tetPti = 1; tetPti <
f.
size() - 1; tetPti++)
1469 tetIndices faceTetIs(celli, facei, 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))
1585 IOstreamOption streamOpt,
1586 const bool writeOnProc
void size(const label n)
Older name for setAddressableSize.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
A class for handling file names.
static labelList findFaceBasePts(const polyMesh &mesh, scalar tol=minTetQuality, bool report=false)
Find a suitable base point for each face for decomposition into tets.
List< cell > cellList
List of cell.
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual void movePoints(const pointField &)
Move points.
const fileName & facesInstance() const
Return the current instance directory for faces.
label nPoints() const noexcept
Number of mesh points.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
Cmpt cmptSum(const SphericalTensor< Cmpt > &st)
Return the sum of components of a SphericalTensor.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual const labelList & faceNeighbour() const
Return face neighbour.
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
const word & regionName() const
The mesh region name or word::null if polyMesh::defaultRegion.
virtual void setUpToDatePoints(regIOobject &io) const
Set io to be up-to-date with points.
const word & name() const noexcept
Return the object name.
Cell-face mesh analysis engine.
void resetMotion() const
Reset motion.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
const Vector< label > & solutionD() const
Return the vector of solved-for directions in mesh.
constexpr char nl
The newline '\n' character (0x0a)
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
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.
A bounding box defined in terms of min/max extrema points.
bool pointInCell(const point &p, label celli) const
Return true if the point is in the cell.
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
virtual const fileName & dbDir() const
Override the objectRegistry dbDir for a single-region case.
Ignore writing from objectRegistry::writeObject()
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
bool pointInCell(const point &p, label celli, const cellDecomposition=CELL_TETS) const
Test if point p is in the celli.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
void movePoints(const pointField &p, const pointField &oldP)
Move points.
label nGeometricD() const
Return the number of valid geometric dimensions in the mesh.
void reduce(T &value, [[maybe_unused]] BinaryOp bop, [[maybe_unused]] const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce)
bool hasHeaderClass() const noexcept
True if headerClassName() is non-empty (after reading)
virtual const pointField & points() const
Return raw points.
#define forAll(list, i)
Loop across all elements in list.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write the objects using stream options.
static tetIndices findTet(const polyMesh &mesh, label cI, const point &pt)
Find the tet decomposition of the cell containing the given point.
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
writeOption writeOpt() const noexcept
Get the write option.
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
const fileName & pointsInstance() const
Return the current instance directory for points.
IOList< label > labelIOList
IO for a List of label.
void removeFiles() const
Remove all files from mesh instance()
bool hasGlobalData() const noexcept
Is demand-driven parallel info available?
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
A class for handling words, derived from Foam::string.
const Time & time() const noexcept
Return time registry.
void findCellFacePt(const point &p, label &celli, label &tetFacei, label &tetPti) const
Find the cell, tetFacei and tetPti for point p.
#define DebugInFunction
Report an information message using Foam::Info.
static word defaultRegion
Return the default region name.
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
Tree tree(triangles.begin(), triangles.end())
void addZones(PtrList< pointZone > &&pz, PtrList< faceZone > &&fz, PtrList< cellZone > &&cz)
Add mesh zones.
virtual const pointField & oldPoints() const
Return old points (mesh motion)
virtual const labelList & faceOwner() const
Return face owner.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
static const word null
An empty word.
const globalMeshData & globalData() const
Return parallel info (demand-driven)
Storage and named access for the indices of a tet which is part of the decomposition of a cell...
virtual const faceList & faces() const
Return raw faces.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
errorManip< error > abort(error &err)
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (respects is_globalIOobject trait) and check its info.
bool rmDir(const fileName &directory, const bool silent=false, const bool emptyOnly=false)
Remove a directory and its contents recursively,.
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross-product operators.
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
CompactIOList< cell, label > cellCompactIOList
Compact IO for a List of cell.
label nSolutionD() const
Return the number of valid solved-for dimensions in the mesh.
virtual bool upToDatePoints(const regIOobject &io) const
Return true if io is up-to-date with points.
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
const indexedOctree< treeDataCell > & cellTree() const
Return the cell search tree.
virtual const pointField & oldCellCentres() const
Return old cellCentres (mesh motion)
vector point
Point is a vector.
#define WarningInFunction
Report a warning using Foam::Warning.
label nCells() const noexcept
Number of mesh cells.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Automatically write from objectRegistry::writeObject()
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
void findTetFacePt(const label celli, const point &p, label &tetFacei, label &tetPti) const
Find the tetFacei and tetPti for point p in celli.
triangle< point, const point & > triPointRef
A triangle using referred points.
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
virtual ~polyMesh()
Destructor.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
messageStream Info
Information stream (stdout output on master, null elsewhere)
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
SubField< vector > subField
Declare type of subField.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
Reading is optional [identical to READ_IF_PRESENT].
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Mesh consisting of general polyhedral cells.
List< label > labelList
A List of labels.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Registry of regIOobjects.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
void addPatches(polyPatchList &plist, const bool validBoundary=true)
Add boundary patches.
Defines the attributes of an object for which implicit objectRegistry management is supported...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Inter-processor communications stream.
Do not request registration (bool: false)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
A keyword and a list of tokens is an 'entry'.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
#define InfoInFunction
Report an information message using Foam::Info.
static constexpr const zero Zero
Global zero (0)
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc=true) const
Write items held in the objectRegistry. Normally includes mesh components (points, faces, etc) and any registered fields.