Go to the documentation of this file.
55 void Foam::polyMesh::calcDirections()
const
65 label nEmptyPatches = 0;
66 label nWedgePatches = 0;
74 if (isA<emptyPolyPatch>(pp))
86 else if (isA<wedgePolyPatch>(pp))
88 const wedgePolyPatch& wpp = refCast<const wedgePolyPatch>(pp);
92 (void)wpp.faceNormals();
97 wedgeDirVec +=
cmptMag(wpp.centreNormal());
102 reduce(nEmptyPatches, maxOp<label>());
103 reduce(nWedgePatches, maxOp<label>());
107 reduce(emptyDirVec, sumOp<vector>());
109 emptyDirVec.normalise();
113 if (emptyDirVec[cmpt] > 1
e-6)
115 solutionD_[cmpt] = -1;
119 solutionD_[cmpt] = 1;
127 geometricD_ = solutionD_;
131 reduce(wedgeDirVec, sumOp<vector>());
133 wedgeDirVec.normalise();
137 if (wedgeDirVec[cmpt] > 1
e-6)
139 geometricD_[cmpt] = -1;
143 geometricD_[cmpt] = 1;
173 Foam::polyMesh::polyMesh(
const IOobject& io,
const bool doInit)
182 time().findInstance(meshDir(),
"points"),
194 time().findInstance(meshDir(),
"faces"),
225 clearedPrimitives_(false),
249 tetBasePtIsPtr_(readTetBasePtIs()),
250 cellTreePtr_(nullptr),
308 globalMeshDataPtr_(nullptr),
310 topoChanging_(false),
311 storeOldCellCentres_(false),
313 oldPointsPtr_(nullptr),
314 oldCellCentresPtr_(nullptr)
346 <<
"mesh missing boundary on one or more domains" <<
endl;
351 <<
"no points in mesh" <<
endl;
356 <<
"no cells in mesh" <<
endl;
375 boundary_.updateMesh();
378 boundary_.calcGeometry();
387 Foam::polyMesh::polyMesh
451 clearedPrimitives_(
false),
466 bounds_(points_, syncPar),
470 tetBasePtIsPtr_(
nullptr),
471 cellTreePtr_(
nullptr),
514 globalMeshDataPtr_(
nullptr),
516 topoChanging_(
false),
517 storeOldCellCentres_(
false),
519 oldPointsPtr_(
nullptr),
520 oldCellCentresPtr_(
nullptr)
525 const face& curFace = faces_[facei];
527 if (
min(curFace) < 0 ||
max(curFace) > points_.size())
530 <<
"Face " << facei <<
"contains vertex labels out of range: "
531 << curFace <<
" Max point index = " << points_.size()
541 Foam::polyMesh::polyMesh
604 clearedPrimitives_(
false),
619 bounds_(points_, syncPar),
623 tetBasePtIsPtr_(
nullptr),
624 cellTreePtr_(
nullptr),
667 globalMeshDataPtr_(
nullptr),
669 topoChanging_(
false),
670 storeOldCellCentres_(
false),
672 oldPointsPtr_(
nullptr),
673 oldCellCentresPtr_(
nullptr)
678 const face& curFace = faces_[facei];
680 if (
min(curFace) < 0 ||
max(curFace) > points_.size())
683 <<
"Face " << facei <<
"contains vertex labels out of range: "
684 << curFace <<
" Max point index = " << points_.size()
695 const cell& curCell = cLst[celli];
697 if (
min(curCell) < 0 ||
max(curCell) > faces_.size())
700 <<
"Cell " << celli <<
"contains face labels out of range: "
701 << curCell <<
" Max face index = " << faces_.size()
711 Foam::polyMesh::polyMesh(
const IOobject& io,
const zero,
const bool syncPar)
725 const bool validBoundary
729 clearAddressing(
true);
735 points_.transfer(*
points);
736 bounds_ =
boundBox(points_, validBoundary);
741 faces_.transfer(*faces);
746 owner_.transfer(*owner);
751 neighbour_.transfer(*neighbour);
775 const face& curFace = faces_[facei];
777 if (
min(curFace) < 0 ||
max(curFace) > points_.size())
780 <<
"Face " << facei <<
" contains vertex labels out of range: "
781 << curFace <<
" Max point index = " << points_.size()
799 boundary_.updateMesh();
802 boundary_.calcGeometry();
812 <<
"no points or no cells in mesh" <<
endl;
833 return parent().dbDir();
842 return dbDir()/meshSubDir;
848 return points_.instance();
854 return faces_.instance();
860 if (geometricD_.x() == 0)
877 if (solutionD_.x() == 0)
894 if (!tetBasePtIsPtr_)
899 <<
"Forcing storage of base points."
903 tetBasePtIsPtr_.reset
921 return *tetBasePtIsPtr_;
956 return *cellTreePtr_;
963 const bool validBoundary
969 <<
"boundary already exists"
977 boundary_.transfer(plist);
983 globalMeshDataPtr_.clear();
988 boundary_.updateMesh();
991 boundary_.calcGeometry();
993 boundary_.checkDefinition();
1005 if (pointZones().size() || faceZones().size() || cellZones().size())
1008 <<
"point, face or cell zone already exists"
1015 pointZones_.setSize(pz.size());
1020 pointZones_.set(pI, pz[pI]);
1029 faceZones_.setSize(fz.size());
1034 faceZones_.set(fI, fz[fI]);
1043 cellZones_.setSize(cz.size());
1048 cellZones_.set(cI, cz[cI]);
1059 const bool validBoundary
1065 addPatches(plist, validBoundary);
1071 if (clearedPrimitives_)
1074 <<
"points deallocated"
1090 io.
eventNo() = points_.eventNo()+1;
1096 if (clearedPrimitives_)
1099 <<
"faces deallocated"
1133 oldPointsPtr_.reset(
new pointField(points_));
1134 curMotionTimeIndex_ = time().timeIndex();
1137 return *oldPointsPtr_;
1143 storeOldCellCentres_ =
true;
1147 return cellCentres();
1150 if (!oldCellCentresPtr_)
1152 oldCellCentresPtr_.reset(
new pointField(cellCentres()));
1155 return *oldCellCentresPtr_;
1165 <<
"Moving points for time " << time().value()
1166 <<
" index " << time().timeIndex() <<
endl;
1168 if (newPoints.size() != points_.size())
1171 <<
"Size of newPoints " << newPoints.size()
1172 <<
" does not correspond to current mesh points size "
1181 if (curMotionTimeIndex_ != time().
timeIndex())
1185 Info<<
"tmp<scalarField> polyMesh::movePoints(const pointField&) : "
1186 <<
" Storing current points for time " << time().value()
1187 <<
" index " << time().timeIndex() <<
endl;
1190 if (storeOldCellCentres_)
1192 oldCellCentresPtr_.clear();
1193 oldCellCentresPtr_.reset(
new pointField(cellCentres()));
1197 oldPointsPtr_.clear();
1198 oldPointsPtr_.reset(
new pointField(points_));
1199 curMotionTimeIndex_ = time().timeIndex();
1202 points_ = newPoints;
1204 bool moveError =
false;
1208 if (checkMeshMotion(points_,
true))
1213 <<
"Moving the mesh with given points will "
1214 <<
"invalidate the mesh." <<
nl
1215 <<
"Mesh motion should not be executed." <<
endl;
1220 points_.instance() = time().timeName();
1221 points_.eventNo() = getEvent();
1223 if (tetBasePtIsPtr_)
1226 tetBasePtIsPtr_->instance() = time().timeName();
1227 tetBasePtIsPtr_->eventNo() = getEvent();
1237 if (globalMeshDataPtr_)
1239 globalMeshDataPtr_->movePoints(points_);
1245 boundary_.movePoints(points_);
1247 pointZones_.movePoints(points_);
1248 faceZones_.movePoints(points_);
1249 cellZones_.movePoints(points_);
1260 cellTreePtr_.clear();
1270 meshObject::movePoints<polyMesh>(*
this);
1271 meshObject::movePoints<pointMesh>(*
this);
1273 const_cast<Time&
>(time()).functionObjects().movePoints(*
this);
1276 if (
debug && moveError)
1289 curMotionTimeIndex_ = 0;
1290 oldPointsPtr_.clear();
1291 oldCellCentresPtr_.clear();
1297 if (!globalMeshDataPtr_)
1301 Pout<<
"polyMesh::globalData() const : "
1302 <<
"Constructing parallelData from processor topology"
1309 return *globalMeshDataPtr_;
1327 fileName meshFilesPath = thisDb().time().
path()/instanceDir/meshDir();
1329 rm(meshFilesPath/
"points");
1330 rm(meshFilesPath/
"faces");
1331 rm(meshFilesPath/
"owner");
1332 rm(meshFilesPath/
"neighbour");
1333 rm(meshFilesPath/
"cells");
1334 rm(meshFilesPath/
"boundary");
1335 rm(meshFilesPath/
"pointZones");
1336 rm(meshFilesPath/
"faceZones");
1337 rm(meshFilesPath/
"cellZones");
1338 rm(meshFilesPath/
"meshModifiers");
1339 rm(meshFilesPath/
"parallelData");
1342 if (
isDir(meshFilesPath/
"sets"))
1344 rmDir(meshFilesPath/
"sets");
1351 removeFiles(instance());
1375 findTetFacePt(celli,
p, tetFacei, tetPti);
1391 tetFacei = tet.
face();
1392 tetPti = tet.
tetPt();
1411 case FACE_CENTRE_TRIS:
1419 label facei = cFaces[cFacei];
1420 const face&
f = faces_[facei];
1421 const point& fc = faceCentres()[facei];
1422 bool isOwn = (owner_[facei] == celli);
1432 nextPointi =
f.nextLabel(fp);
1436 pointi =
f.nextLabel(fp);
1459 case FACE_DIAG_TRIS:
1467 label facei = cFaces[cFacei];
1468 const face&
f = faces_[facei];
1470 for (label tetPti = 1; tetPti <
f.size() - 1; tetPti++)
1495 findTetFacePt(celli,
p, tetFacei, tetPti);
1497 return tetFacei != -1;
1515 && (decompMode == FACE_DIAG_TRIS || decompMode == CELL_TETS)
1524 (void)tetBasePtIs();
1532 if (decompMode == CELL_TETS)
1541 findCellFacePt(
p, celli, tetFacei, tetPti);
1556 (void)tetBasePtIs();
1560 label celli = findNearestCell(
p);
1563 if (pointInCell(
p, celli, decompMode))
1571 for (label celli = 0; celli < nCells(); celli++)
1573 if (pointInCell(
p, celli, decompMode))
int debug
Static debugging option.
void addPatches(PtrList< polyPatch > &plist, const bool validBoundary=true)
Add boundary patches.
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
vectorField pointField
pointField is a vectorField.
virtual const pointField & points() const
Return raw points.
virtual const pointField & oldCellCentres() const
Return old cellCentres (mesh motion)
Defines the attributes of an object for which implicit objectRegistry management is supported,...
treeBoundBox extend(Random &rndGen, const scalar s) const
Return slightly wider bounding box.
#define InfoInFunction
Report an information message using Foam::Info.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
void resetMotion() const
Reset motion.
cellDecomposition
Enumeration defining the decomposition of the cell for.
static Vector< Cmpt > uniform(const Cmpt &s)
Return a VectorSpace with all elements = s.
A class for handling file names.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
static word defaultRegion
Return the default region name.
static std::string path(const std::string &str)
Return directory path name (part before last /)
A class for managing temporary objects.
bool upToDate(const regIOobject &) const
Return true if up-to-date with respect to given object.
static constexpr const zero Zero
Global zero (0)
label nGeometricD() const
Return the number of valid geometric dimensions in the mesh.
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
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.
static labelList findFaceBasePts(const polyMesh &mesh, scalar tol=minTetQuality, bool report=false)
virtual const fileName & dbDir() const
Override the objectRegistry dbDir for a single-region case.
Standard boundBox with extra functionality for use in octree.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
bool pointInCell(const point &p, label celli) const
Return true if the point is in the cell.
label face() const
Return the face.
const fileName & facesInstance() const
Return the current instance directory for faces.
bool rm(const fileName &file)
Remove a file (or its gz equivalent), returning true if successful.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const point & max() const
Maximum describing the bounding box.
const word & headerClassName() const noexcept
Return name of the class name read from header.
label eventNo() const
Event number at last update.
const Vector< label > & solutionD() const
Return the vector of solved-for directions in mesh.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
void removeFiles() const
Remove all files from mesh instance()
writeOption writeOpt() const noexcept
The write option.
IOList< label > labelIOList
Label container classes.
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
bool pointInCell(const point &p, label celli, const cellDecomposition=CELL_TETS) const
Test if point p is in the celli.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Mesh consisting of general polyhedral cells.
label comm() const noexcept
Return communicator used for parallel communication.
const point & min() const
Minimum describing the bounding box.
label nPoints() const noexcept
Number of mesh points.
#define forAll(list, i)
Loop across all elements in list.
Point centre() const
Return centre (centroid)
Registry of regIOobjects.
void cmptMag(FieldField< Field, Type > &cf, const FieldField< Field, Type > &f)
A triangle primitive used to calculate face normals and swept volumes.
const fileName & pointsInstance() const
Return the current instance directory for points.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
label nCells() const noexcept
Number of mesh cells.
Encapsulation of data needed to search in/for cells. Used to find the cell containing a point (e....
Inter-processor communications stream.
virtual bool write(const bool valid=true) const
Write using setting from DB.
triPointRef faceTri(const polyMesh &mesh) const
Return the geometry corresponding to the tri on the face for.
messageStream Info
Information stream (stdout output on master, null elsewhere)
#define DebugInFunction
Report an information message using Foam::Info.
A patch is a list of labels that address the faces in the global face list.
PtrList< polyPatch > polyPatchList
container classes for polyPatch
virtual const labelList & faceOwner() const
Return face owner.
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 List of objects of type <T> with automated input and output using a compact storage....
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
label findInside(const point &) const
Find shape containing point. Only implemented for certain.
virtual const pointField & oldPoints() const
Return old points (mesh motion)
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
void findCellFacePt(const point &p, label &celli, label &tetFacei, label &tetPti) const
Find the cell, tetFacei and tetPti for point p.
virtual bool upToDatePoints(const regIOobject &io) const
Return true if io is up-to-date with points.
static tetIndices findTet(const polyMesh &mesh, label cI, const point &pt)
Find the tet decomposition of the cell containing the given point.
Cmpt cmptSum(const SphericalTensor< Cmpt > &st)
Return the sum of components of a SphericalTensor.
errorManip< error > abort(error &err)
label tetPt() const
Return the characterising tetPtI.
Vector< scalar > vector
A scalar version of the templated Vector.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
errorManipArg< error, int > exit(error &err, const int errNo=1)
label nSolutionD() const
Return the number of valid solved-for dimensions in the mesh.
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
const indexedOctree< treeDataCell > & cellTree() const
Return the cell search tree.
virtual ~polyMesh()
Destructor.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
virtual const faceList & faces() const
Return raw faces.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
bool rmDir(const fileName &directory, const bool silent=false)
Remove a directory and its contents (optionally silencing warnings)
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
static label worldComm
Default communicator (all processors)
static bool & parRun() noexcept
Test if this a parallel run.
const dimensionedScalar e
Elementary charge.
tmp< scalarField > movePoints(const pointField &p, const pointField &oldP)
Move points, returns volumes swept by faces in motion.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
A bounding box defined in terms of min/max extrema points.
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
SubField< vector > subField
Declare type of subField.
A face is a list of labels corresponding to mesh vertices.
const globalMeshData & globalData() const
Return parallel info.
vector areaNormal() const
The area normal - with magnitude equal to area of triangle.
void findTetFacePt(const label celli, const point &p, label &tetFacei, label &tetPti) const
Find the tetFacei and tetPti for point p in celli.
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
A cell is defined as a list of faces with extra functionality.
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
const Time & time() const noexcept
Return time registry.
virtual void setUpToDatePoints(regIOobject &io) const
Set io to be up-to-date with points.
virtual const labelList & faceNeighbour() const
Return face neighbour.
static constexpr direction nComponents
Number of components in this vector space.
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Cell-face mesh analysis engine.