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),
250 tetBasePtIsPtr_(nullptr),
251 cellTreePtr_(nullptr),
294 globalMeshDataPtr_(nullptr),
296 topoChanging_(false),
297 storeOldCellCentres_(false),
299 oldPointsPtr_(nullptr),
300 oldCellCentresPtr_(nullptr)
331 <<
"Missing mesh boundary on one or more domains" <<
endl;
337 <<
"No points in mesh" <<
endl;
342 <<
"No cells in mesh" <<
endl;
361 boundary_.updateMesh();
364 boundary_.calcGeometry();
373 Foam::polyMesh::polyMesh
438 clearedPrimitives_(false),
453 bounds_(points_, syncPar),
457 tetBasePtIsPtr_(nullptr),
458 cellTreePtr_(nullptr),
501 globalMeshDataPtr_(
nullptr),
503 topoChanging_(
false),
504 storeOldCellCentres_(
false),
506 oldPointsPtr_(
nullptr),
507 oldCellCentresPtr_(
nullptr)
512 const face& curFace = faces_[facei];
514 if (
min(curFace) < 0 ||
max(curFace) > points_.size())
517 <<
"Face " << facei <<
"contains vertex labels out of range: " 518 << curFace <<
" Max point index = " << points_.size()
528 Foam::polyMesh::polyMesh
592 clearedPrimitives_(
false),
607 bounds_(points_, syncPar),
611 tetBasePtIsPtr_(
nullptr),
612 cellTreePtr_(
nullptr),
655 globalMeshDataPtr_(
nullptr),
657 topoChanging_(
false),
658 storeOldCellCentres_(
false),
660 oldPointsPtr_(
nullptr),
661 oldCellCentresPtr_(
nullptr)
666 const face& curFace = faces_[facei];
668 if (
min(curFace) < 0 ||
max(curFace) > points_.size())
671 <<
"Face " << facei <<
"contains vertex labels out of range: " 672 << curFace <<
" Max point index = " << points_.size()
683 const cell& curCell = cLst[celli];
685 if (
min(curCell) < 0 ||
max(curCell) > faces_.size())
688 <<
"Cell " << celli <<
"contains face labels out of range: " 689 << curCell <<
" Max face index = " << faces_.size()
699 Foam::polyMesh::polyMesh
718 const bool validBoundary
722 clearAddressing(
true);
728 points_.transfer(*
points);
729 bounds_ =
boundBox(points_, validBoundary);
734 faces_.transfer(*faces);
739 owner_.transfer(*owner);
744 neighbour_.transfer(*neighbour);
751 boundary_[patchi] = polyPatch
768 const face& curFace = faces_[facei];
770 if (
min(curFace) < 0 ||
max(curFace) > points_.size())
773 <<
"Face " << facei <<
" contains vertex labels out of range: " 774 << curFace <<
" Max point index = " << points_.size()
792 boundary_.updateMesh();
795 boundary_.calcGeometry();
801 <<
"No points or no cells in mesh" <<
endl;
841 return parent().dbDir();
850 return dbDir()/meshSubDir;
862 return points_.instance();
868 return faces_.instance();
874 if (geometricD_.x() == 0)
891 if (solutionD_.x() == 0)
908 if (!tetBasePtIsPtr_)
913 <<
"Forcing storage of base points." 922 tetBasePtIsPtr_.reset
941 return *tetBasePtIsPtr_;
952 treeBoundBox overallBb(
points());
953 overallBb.inflate(
rndGen, 1
e-4, ROOTVSMALL);
957 new indexedOctree<treeDataCell>
973 return *cellTreePtr_;
980 const bool validBoundary
983 if (boundaryMesh().size())
986 <<
"boundary already exists" 994 boundary_.transfer(plist);
1000 globalMeshDataPtr_.reset(
nullptr);
1005 boundary_.updateMesh();
1008 boundary_.calcGeometry();
1010 boundary_.checkDefinition();
1017 PtrList<pointZone>&& pz,
1018 PtrList<faceZone>&& fz,
1019 PtrList<cellZone>&& cz
1022 if (pointZones_.size() || faceZones_.size() || cellZones_.size())
1025 <<
"point, face or cell zone already exists" 1032 pointZones_.clear();
1033 pointZones_.transfer(pz);
1041 faceZones_.transfer(fz);
1049 cellZones_.transfer(cz);
1057 const List<polyPatch*>&
p,
1058 const bool validBoundary
1064 addPatches(plist, validBoundary);
1087 if (clearedPrimitives_)
1090 <<
"points deallocated" 1100 return io.upToDate(points_);
1106 io.eventNo() = points_.eventNo()+1;
1112 if (clearedPrimitives_)
1115 <<
"faces deallocated" 1149 oldPointsPtr_.reset(
new pointField(points_));
1150 curMotionTimeIndex_ = time().timeIndex();
1153 return *oldPointsPtr_;
1159 storeOldCellCentres_ =
true;
1163 return cellCentres();
1166 if (!oldCellCentresPtr_)
1171 return *oldCellCentresPtr_;
1178 <<
"Moving points for time " << time().value()
1179 <<
" index " << time().timeIndex() <<
endl;
1181 if (newPoints.size() != points_.size())
1184 <<
"Size of newPoints " << newPoints.size()
1185 <<
" does not correspond to current mesh points size " 1194 if (curMotionTimeIndex_ != time().
timeIndex())
1198 Info<<
"tmp<scalarField> polyMesh::movePoints(const pointField&) : " 1199 <<
" Storing current points for time " << time().value()
1200 <<
" index " << time().timeIndex() <<
endl;
1203 if (storeOldCellCentres_)
1205 oldCellCentresPtr_.clear();
1206 oldCellCentresPtr_.reset(
new pointField(cellCentres()));
1210 oldPointsPtr_.clear();
1211 oldPointsPtr_.reset(
new pointField(points_));
1212 curMotionTimeIndex_ = time().timeIndex();
1215 points_ = newPoints;
1217 bool moveError =
false;
1221 if (checkMeshMotion(points_,
true))
1226 <<
"Moving the mesh with given points will " 1227 <<
"invalidate the mesh." <<
nl 1228 <<
"Mesh motion should not be executed." <<
endl;
1233 points_.instance() = time().timeName();
1234 points_.eventNo() = getEvent();
1236 if (tetBasePtIsPtr_)
1239 tetBasePtIsPtr_->instance() = time().timeName();
1240 tetBasePtIsPtr_->eventNo() = getEvent();
1256 if (globalMeshDataPtr_)
1258 globalMeshDataPtr_->movePoints(points_);
1263 bounds_ = boundBox(points_);
1264 boundary_.movePoints(points_);
1266 pointZones_.movePoints(points_);
1267 faceZones_.movePoints(points_);
1268 cellZones_.movePoints(points_);
1279 cellTreePtr_.clear();
1289 meshObject::movePoints<polyMesh>(*this);
1290 meshObject::movePoints<pointMesh>(*this);
1292 const_cast<Time&
>(time()).functionObjects().movePoints(*
this);
1295 if (
debug && moveError)
1306 curMotionTimeIndex_ = 0;
1307 oldPointsPtr_.clear();
1308 oldCellCentresPtr_.clear();
1314 return bool(globalMeshDataPtr_);
1320 if (!globalMeshDataPtr_)
1324 Pout<<
"polyMesh::globalData() const : " 1325 <<
"Constructing parallelData from processor topology" 1332 return *globalMeshDataPtr_;
1338 fileName meshFilesPath = thisDb().time().path()/instanceDir/meshDir();
1340 rm(meshFilesPath/
"points");
1341 rm(meshFilesPath/
"faces");
1342 rm(meshFilesPath/
"owner");
1343 rm(meshFilesPath/
"neighbour");
1344 rm(meshFilesPath/
"cells");
1345 rm(meshFilesPath/
"boundary");
1346 rm(meshFilesPath/
"pointZones");
1347 rm(meshFilesPath/
"faceZones");
1348 rm(meshFilesPath/
"cellZones");
1349 rm(meshFilesPath/
"meshModifiers");
1350 rm(meshFilesPath/
"parallelData");
1355 rmDir(meshFilesPath/
"sets");
1362 removeFiles(instance());
1381 celli =
tree.findInside(
p);
1386 findTetFacePt(celli,
p, tetFacei, tetPti);
1399 const polyMesh&
mesh = *
this;
1402 tetFacei = tet.face();
1403 tetPti = tet.tetPt();
1411 const cellDecomposition decompMode
1422 case FACE_CENTRE_TRIS:
1426 const cell& cFaces =
cells()[celli];
1430 label facei = cFaces[cFacei];
1431 const face&
f = faces_[facei];
1432 const point& fc = faceCentres()[facei];
1433 bool isOwn = (owner_[facei] == celli);
1443 nextPointi =
f.nextLabel(fp);
1447 pointi =
f.nextLabel(fp);
1458 vector proj =
p - faceTri.centre();
1460 if ((faceTri.areaNormal() & proj) > 0)
1470 case FACE_DIAG_TRIS:
1474 const cell& cFaces =
cells()[celli];
1478 label facei = cFaces[cFacei];
1479 const face&
f = faces_[facei];
1481 for (label tetPti = 1; tetPti <
f.
size() - 1; tetPti++)
1484 tetIndices faceTetIs(celli, facei, tetPti);
1488 vector proj =
p - faceTri.centre();
1490 if ((faceTri.areaNormal() & proj) > 0)
1506 findTetFacePt(celli,
p, tetFacei, tetPti);
1508 return tetFacei != -1;
1520 const cellDecomposition decompMode
1526 && (decompMode == FACE_DIAG_TRIS || decompMode == CELL_TETS)
1535 (void)tetBasePtIs();
1543 if (decompMode == CELL_TETS)
1552 findCellFacePt(
p, celli, tetFacei, tetPti);
1567 (void)tetBasePtIs();
1571 label celli = findNearestCell(
p);
1574 if (pointInCell(
p, celli, decompMode))
1582 for (label celli = 0; celli < nCells(); celli++)
1584 if (pointInCell(
p, celli, decompMode))
1600 IOstreamOption streamOpt,
1601 const bool writeOnProc
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.
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.
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.
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.
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()
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.
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.
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.
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.
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())
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.