55 void Foam::polyMesh::calcDirections()
const 57 for (
direction cmpt=0; cmpt<vector::nComponents; cmpt++)
65 bool hasEmptyPatches =
false;
66 bool hasWedgePatches =
false;
74 if (isA<emptyPolyPatch>(
pp))
82 hasEmptyPatches =
true;
86 else if (isA<wedgePolyPatch>(
pp))
88 const wedgePolyPatch& wpp = refCast<const wedgePolyPatch>(
pp);
92 (void)wpp.faceNormals();
96 hasWedgePatches =
true;
97 wedgeDirVec +=
cmptMag(wpp.centreNormal());
105 reduce(emptyDirVec, sumOp<vector>());
107 emptyDirVec.normalise();
109 for (
direction cmpt=0; cmpt<vector::nComponents; cmpt++)
111 if (emptyDirVec[cmpt] > 1
e-6)
113 solutionD_[cmpt] = -1;
117 solutionD_[cmpt] = 1;
125 geometricD_ = solutionD_;
129 reduce(wedgeDirVec, sumOp<vector>());
131 wedgeDirVec.normalise();
133 for (
direction cmpt=0; cmpt<vector::nComponents; cmpt++)
135 if (wedgeDirVec[cmpt] > 1
e-6)
137 geometricD_[cmpt] = -1;
141 geometricD_[cmpt] = 1;
172 Foam::polyMesh::polyMesh(
const IOobject&
io,
const bool doInit)
181 time().findInstance(meshDir(),
"points"),
193 time().findInstance(meshDir(),
"faces"),
224 clearedPrimitives_(false),
248 tetBasePtIsPtr_(nullptr),
249 cellTreePtr_(nullptr),
307 globalMeshDataPtr_(nullptr),
309 topoChanging_(false),
310 storeOldCellCentres_(false),
312 oldPointsPtr_(nullptr),
313 oldCellCentresPtr_(nullptr)
344 <<
"Missing mesh boundary on one or more domains" <<
endl;
350 <<
"No points in mesh" <<
endl;
355 <<
"No cells in mesh" <<
endl;
374 boundary_.updateMesh();
377 boundary_.calcGeometry();
386 Foam::polyMesh::polyMesh
450 clearedPrimitives_(false),
465 bounds_(points_, syncPar),
469 tetBasePtIsPtr_(nullptr),
470 cellTreePtr_(nullptr),
513 globalMeshDataPtr_(nullptr),
515 topoChanging_(false),
516 storeOldCellCentres_(false),
518 oldPointsPtr_(nullptr),
519 oldCellCentresPtr_(nullptr)
524 const face& curFace = faces_[facei];
526 if (
min(curFace) < 0 ||
max(curFace) > points_.
size())
529 <<
"Face " << facei <<
"contains vertex labels out of range: " 530 << curFace <<
" Max point index = " << points_.
size()
540 Foam::polyMesh::polyMesh
603 clearedPrimitives_(false),
618 bounds_(points_, syncPar),
622 tetBasePtIsPtr_(nullptr),
623 cellTreePtr_(nullptr),
666 globalMeshDataPtr_(nullptr),
668 topoChanging_(false),
669 storeOldCellCentres_(false),
671 oldPointsPtr_(nullptr),
672 oldCellCentresPtr_(nullptr)
677 const face& curFace = faces_[facei];
679 if (
min(curFace) < 0 ||
max(curFace) > points_.
size())
682 <<
"Face " << facei <<
"contains vertex labels out of range: " 683 << curFace <<
" Max point index = " << points_.
size()
694 const cell& curCell = cLst[celli];
696 if (
min(curCell) < 0 ||
max(curCell) > faces_.
size())
699 <<
"Cell " << celli <<
"contains face labels out of range: " 700 << curCell <<
" Max face index = " << faces_.
size()
724 const bool validBoundary
728 clearAddressing(
true);
734 points_.transfer(*
points);
735 bounds_ =
boundBox(points_, validBoundary);
740 faces_.transfer(*faces);
745 owner_.transfer(*owner);
750 neighbour_.transfer(*neighbour);
757 boundary_[patchi] = polyPatch
774 const face& curFace = faces_[facei];
776 if (
min(curFace) < 0 ||
max(curFace) > points_.size())
779 <<
"Face " << facei <<
" contains vertex labels out of range: " 780 << curFace <<
" Max point index = " << points_.size()
798 boundary_.updateMesh();
801 boundary_.calcGeometry();
807 <<
"No points or no cells in mesh" <<
endl;
836 return parent().dbDir();
845 return dbDir()/meshSubDir;
857 return points_.instance();
863 return faces_.instance();
869 if (geometricD_.x() == 0)
886 if (solutionD_.x() == 0)
903 if (!tetBasePtIsPtr_)
908 <<
"Forcing storage of base points." 917 tetBasePtIsPtr_.reset
936 return *tetBasePtIsPtr_;
947 treeBoundBox overallBb(
points());
948 overallBb.inflate(
rndGen, 1
e-4, ROOTVSMALL);
952 new indexedOctree<treeDataCell>
968 return *cellTreePtr_;
975 const bool validBoundary
978 if (boundaryMesh().size())
981 <<
"boundary already exists" 989 boundary_.transfer(plist);
995 globalMeshDataPtr_.clear();
1000 boundary_.updateMesh();
1003 boundary_.calcGeometry();
1005 boundary_.checkDefinition();
1012 PtrList<pointZone>&& pz,
1013 PtrList<faceZone>&& fz,
1014 PtrList<cellZone>&& cz
1017 if (pointZones_.size() || faceZones_.size() || cellZones_.size())
1020 <<
"point, face or cell zone already exists" 1027 pointZones_.clear();
1028 pointZones_.transfer(pz);
1036 faceZones_.transfer(fz);
1044 cellZones_.transfer(cz);
1052 const List<polyPatch*>&
p,
1053 const bool validBoundary
1059 addPatches(plist, validBoundary);
1082 if (clearedPrimitives_)
1085 <<
"points deallocated" 1095 return io.upToDate(points_);
1101 io.eventNo() = points_.eventNo()+1;
1107 if (clearedPrimitives_)
1110 <<
"faces deallocated" 1144 oldPointsPtr_.reset(
new pointField(points_));
1145 curMotionTimeIndex_ = time().timeIndex();
1148 return *oldPointsPtr_;
1154 storeOldCellCentres_ =
true;
1158 return cellCentres();
1161 if (!oldCellCentresPtr_)
1166 return *oldCellCentresPtr_;
1173 <<
"Moving points for time " << time().value()
1174 <<
" index " << time().timeIndex() <<
endl;
1176 if (newPoints.size() != points_.size())
1179 <<
"Size of newPoints " << newPoints.size()
1180 <<
" does not correspond to current mesh points size " 1189 if (curMotionTimeIndex_ != time().
timeIndex())
1193 Info<<
"tmp<scalarField> polyMesh::movePoints(const pointField&) : " 1194 <<
" Storing current points for time " << time().value()
1195 <<
" index " << time().timeIndex() <<
endl;
1198 if (storeOldCellCentres_)
1200 oldCellCentresPtr_.clear();
1201 oldCellCentresPtr_.reset(
new pointField(cellCentres()));
1205 oldPointsPtr_.clear();
1206 oldPointsPtr_.reset(
new pointField(points_));
1207 curMotionTimeIndex_ = time().timeIndex();
1210 points_ = newPoints;
1212 bool moveError =
false;
1216 if (checkMeshMotion(points_,
true))
1221 <<
"Moving the mesh with given points will " 1222 <<
"invalidate the mesh." <<
nl 1223 <<
"Mesh motion should not be executed." <<
endl;
1228 points_.instance() = time().timeName();
1229 points_.eventNo() = getEvent();
1231 if (tetBasePtIsPtr_)
1234 tetBasePtIsPtr_->instance() = time().timeName();
1235 tetBasePtIsPtr_->eventNo() = getEvent();
1251 if (globalMeshDataPtr_)
1253 globalMeshDataPtr_->movePoints(points_);
1258 bounds_ = boundBox(points_);
1259 boundary_.movePoints(points_);
1261 pointZones_.movePoints(points_);
1262 faceZones_.movePoints(points_);
1263 cellZones_.movePoints(points_);
1274 cellTreePtr_.clear();
1284 meshObject::movePoints<polyMesh>(*this);
1285 meshObject::movePoints<pointMesh>(*this);
1287 const_cast<Time&
>(time()).functionObjects().movePoints(*
this);
1290 if (
debug && moveError)
1301 curMotionTimeIndex_ = 0;
1302 oldPointsPtr_.clear();
1303 oldCellCentresPtr_.clear();
1309 if (!globalMeshDataPtr_)
1313 Pout<<
"polyMesh::globalData() const : " 1314 <<
"Constructing parallelData from processor topology" 1321 return *globalMeshDataPtr_;
1339 fileName meshFilesPath = thisDb().time().
path()/instanceDir/meshDir();
1341 rm(meshFilesPath/
"points");
1342 rm(meshFilesPath/
"faces");
1343 rm(meshFilesPath/
"owner");
1344 rm(meshFilesPath/
"neighbour");
1345 rm(meshFilesPath/
"cells");
1346 rm(meshFilesPath/
"boundary");
1347 rm(meshFilesPath/
"pointZones");
1348 rm(meshFilesPath/
"faceZones");
1349 rm(meshFilesPath/
"cellZones");
1350 rm(meshFilesPath/
"meshModifiers");
1351 rm(meshFilesPath/
"parallelData");
1356 rmDir(meshFilesPath/
"sets");
1363 removeFiles(instance());
1382 celli =
tree.findInside(
p);
1387 findTetFacePt(celli,
p, tetFacei, tetPti);
1400 const polyMesh&
mesh = *
this;
1403 tetFacei = tet.face();
1404 tetPti = tet.tetPt();
1412 const cellDecomposition decompMode
1423 case FACE_CENTRE_TRIS:
1427 const cell& cFaces =
cells()[celli];
1431 label facei = cFaces[cFacei];
1432 const face&
f = faces_[facei];
1433 const point& fc = faceCentres()[facei];
1434 bool isOwn = (owner_[facei] == celli);
1444 nextPointi =
f.nextLabel(fp);
1448 pointi =
f.nextLabel(fp);
1459 vector proj =
p - faceTri.centre();
1461 if ((faceTri.areaNormal() & proj) > 0)
1471 case FACE_DIAG_TRIS:
1475 const cell& cFaces =
cells()[celli];
1479 label facei = cFaces[cFacei];
1480 const face&
f = faces_[facei];
1482 for (label tetPti = 1; tetPti <
f.
size() - 1; tetPti++)
1485 tetIndices faceTetIs(celli, facei, tetPti);
1489 vector proj =
p - faceTri.centre();
1491 if ((faceTri.areaNormal() & proj) > 0)
1507 findTetFacePt(celli,
p, tetFacei, tetPti);
1509 return tetFacei != -1;
1521 const cellDecomposition decompMode
1527 && (decompMode == FACE_DIAG_TRIS || decompMode == CELL_TETS)
1536 (void)tetBasePtIs();
1544 if (decompMode == CELL_TETS)
1553 findCellFacePt(
p, celli, tetFacei, tetPti);
1568 (void)tetBasePtIs();
1572 label celli = findNearestCell(
p);
1575 if (pointInCell(
p, celli, decompMode))
1583 for (label celli = 0; celli < nCells(); celli++)
1585 if (pointInCell(
p, celli, decompMode))
void size(const label n)
Older name for setAddressableSize.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
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.
A face is a list of labels corresponding to mesh vertices.
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.
const cellList & cells() const
bool pointInCell(const point &p, label celli) const
Return true if the point is in the cell.
virtual const fileName & dbDir() const
Override the objectRegistry dbDir for a single-region case.
static std::string path(const std::string &str)
Return directory path name (part before last /)
Ignore writing from objectRegistry::writeObject()
bool pointInCell(const point &p, label celli, const cellDecomposition=CELL_TETS) const
Test if point p is in the celli.
void movePoints(const pointField &p, const pointField &oldP)
Move points.
label nGeometricD() const
Return the number of valid geometric dimensions in the mesh.
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.
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.
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
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()
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.
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.
label comm() const noexcept
Return communicator used for parallel communication.
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.
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.
errorManip< error > abort(error &err)
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (uses typeFilePath to find file) 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.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
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.
A subset of mesh faces organised as a primitive patch.
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.
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
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())
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)