51 void Foam::polyMesh::calcDirections()
const
61 label nEmptyPatches = 0;
62 label nWedgePatches = 0;
78 const wedgePolyPatch& wpp = refCast<const wedgePolyPatch>
84 wedgeDirVec +=
cmptMag(wpp.centreNormal());
89 reduce(nEmptyPatches, maxOp<label>());
90 reduce(nWedgePatches, maxOp<label>());
94 reduce(emptyDirVec, sumOp<vector>());
96 emptyDirVec /=
mag(emptyDirVec);
100 if (emptyDirVec[cmpt] > 1
e-6)
102 solutionD_[cmpt] = -1;
106 solutionD_[cmpt] = 1;
114 geometricD_ = solutionD_;
118 reduce(wedgeDirVec, sumOp<vector>());
120 wedgeDirVec /=
mag(wedgeDirVec);
124 if (wedgeDirVec[cmpt] > 1
e-6)
126 geometricD_[cmpt] = -1;
130 geometricD_[cmpt] = 1;
139 typeIOobject<labelIOList> io
155 return autoPtr<labelIOList>(
nullptr);
171 time().findInstance(meshDir(),
"points"),
183 time().findInstance(meshDir(),
"faces"),
214 clearedPrimitives_(false),
220 time().findInstance(meshDir(),
"boundary"),
232 tetBasePtIsPtr_(readTetBasePtIs()),
233 cellTreePtr_(nullptr),
288 globalMeshDataPtr_(nullptr),
289 curMotionTimeIndex_(-1),
290 oldPointsPtr_(nullptr),
291 oldCellCentresPtr_(nullptr),
292 storeOldCellCentres_(false),
326 boundary_.calcGeometry();
332 <<
"no points in mesh" <<
endl;
337 <<
"no cells in mesh" <<
endl;
409 clearedPrimitives_(false),
424 bounds_(points_, syncPar),
428 tetBasePtIsPtr_(readTetBasePtIs()),
429 cellTreePtr_(nullptr),
472 globalMeshDataPtr_(nullptr),
473 curMotionTimeIndex_(-1),
474 oldPointsPtr_(nullptr),
475 oldCellCentresPtr_(nullptr),
476 storeOldCellCentres_(false),
483 const face& curFace = faces_[facei];
485 if (
min(curFace) < 0 ||
max(curFace) > points_.
size())
488 <<
"Face " << facei <<
"contains vertex labels out of range: "
489 << curFace <<
" Max point index = " << points_.
size()
563 clearedPrimitives_(false),
578 bounds_(points_, syncPar),
582 tetBasePtIsPtr_(readTetBasePtIs()),
583 cellTreePtr_(nullptr),
626 globalMeshDataPtr_(nullptr),
627 curMotionTimeIndex_(-1),
628 oldPointsPtr_(nullptr),
629 oldCellCentresPtr_(nullptr),
630 storeOldCellCentres_(false),
637 const face& curFace = faces_[facei];
639 if (
min(curFace) < 0 ||
max(curFace) > points_.
size())
642 <<
"Face " << facei <<
"contains vertex labels out of range: "
643 << curFace <<
" Max point index = " << points_.
size()
654 const cell& curCell = cLst[celli];
656 if (
min(curCell) < 0 ||
max(curCell) > faces_.size())
659 <<
"Cell " << celli <<
"contains face labels out of range: "
660 << curCell <<
" Max face index = " << faces_.size()
674 points_(move(mesh.points_)),
675 faces_(move(mesh.faces_)),
676 owner_(move(mesh.owner_)),
677 neighbour_(move(mesh.neighbour_)),
678 clearedPrimitives_(mesh.clearedPrimitives_),
679 boundary_(move(mesh.boundary_)),
680 bounds_(move(mesh.bounds_)),
682 geometricD_(mesh.geometricD_),
683 solutionD_(mesh.solutionD_),
684 tetBasePtIsPtr_(move(mesh.tetBasePtIsPtr_)),
685 cellTreePtr_(move(mesh.cellTreePtr_)),
686 pointZones_(move(mesh.pointZones_)),
687 faceZones_(move(mesh.faceZones_)),
688 cellZones_(move(mesh.cellZones_)),
689 globalMeshDataPtr_(move(mesh.globalMeshDataPtr_)),
690 curMotionTimeIndex_(mesh.curMotionTimeIndex_),
691 oldPointsPtr_(move(mesh.oldPointsPtr_)),
692 oldCellCentresPtr_(move(mesh.oldCellCentresPtr_)),
693 storeOldCellCentres_(mesh.storeOldCellCentres_),
694 moving_(mesh.moving_),
695 topoChanged_(mesh.topoChanged_)
707 const bool validBoundary
711 clearAddressing(
true);
718 bounds_ =
boundBox(points_, validBoundary);
723 faces_ = move(faces);
728 owner_ = move(owner);
733 neighbour_ = move(neighbour);
752 setInstance(time().
name());
757 const face& curFace = faces_[facei];
759 if (
min(curFace) < 0 ||
max(curFace) > points_.size())
762 <<
"Face " << facei <<
" contains vertex labels out of range: "
763 << curFace <<
" Max point index = " << points_.
size()
781 boundary_.topoChange();
784 boundary_.calcGeometry();
794 <<
"no points or no cells in mesh"
804 clearAddressing(
true);
808 points_.swap(otherMesh.points_);
810 faces_.swap(otherMesh.faces_);
811 owner_.swap(otherMesh.owner_);
812 neighbour_.swap(otherMesh.neighbour_);
815 boundary_.clearGeom();
816 boundary_.clearAddressing();
821 auto updatePatches = []
827 boundaryMesh.resize(otherPatches.
size());
829 forAll(otherPatches, otherPatchi)
835 if (isA<processorPolyPatch>(otherPatches[otherPatchi]))
840 otherPatches[otherPatchi].
clone(boundaryMesh)
847 boundaryMesh[otherPatchi],
850 otherPatches[otherPatchi].size(),
851 otherPatches[otherPatchi].start()
869 updatePatches(otherPatches, boundary_);
870 updatePatches(
patches, otherMesh.boundary_);
874 globalMeshDataPtr_.clear();
875 otherMesh.globalMeshDataPtr_.clear();
878 setInstance(time().
name());
882 auto checkFaces = [](
const polyMesh& mesh)
884 forAll(mesh.faces_, facei)
886 const face& curFace = mesh.faces_[facei];
888 if (
min(curFace) < 0 ||
max(curFace) > mesh.points_.size())
891 <<
"Face " << facei <<
" contains vertex labels out of "
892 <<
"range: " << curFace <<
" Max point index = "
899 checkFaces(otherMesh);
904 otherMesh.initMesh();
907 boundary_.topoChange();
911 boundary_.calcGeometry();
912 otherMesh.boundary_.calcGeometry();
915 if (foundObject<pointMesh>(pointMesh::typeName))
925 if (pointZones_.size() == otherMesh.pointZones_.
size())
927 pointZones_.clearAddressing();
932 pointZones_[i].swap(otherMesh.pointZones_[i]);
938 <<
"Number of pointZones in other mesh = "
939 << otherMesh.pointZones_.
size()
940 <<
" is not the same as in the mesh = "
941 << pointZones_.size()
946 if (faceZones_.size() == otherMesh.faceZones_.
size())
948 faceZones_.clearAddressing();
953 faceZones_[i].swap(otherMesh.faceZones_[i]);
959 <<
"Number of faceZones in other mesh = "
960 << otherMesh.faceZones_.
size()
961 <<
" is not the same as in the mesh = "
967 if (cellZones_.size() == otherMesh.cellZones_.
size())
969 cellZones_.clearAddressing();
974 cellZones_[i].swap(otherMesh.cellZones_[i]);
980 <<
"Number of cellZones in other mesh = "
981 << otherMesh.cellZones_.
size()
982 <<
" is not the same as in the mesh = "
1004 return parent().dbDir();
1015 return dbDir()/meshSubDir;
1021 return points_.instance();
1027 return faces_.instance();
1033 return points_.writeOpt();
1039 return faces_.writeOpt();
1045 if (geometricD_.x() == 0)
1062 if (solutionD_.x() == 0)
1079 if (tetBasePtIsPtr_.empty())
1084 <<
"Forcing storage of base points."
1088 tetBasePtIsPtr_.reset
1106 return tetBasePtIsPtr_();
1113 if (cellTreePtr_.empty())
1133 return cellTreePtr_();
1140 const bool validBoundary
1143 if (boundaryMesh().size())
1146 <<
"boundary already exists"
1154 boundary_.setSize(
p.
size());
1159 boundary_.set(pI,
p[pI]);
1166 globalMeshDataPtr_.clear();
1171 boundary_.topoChange();
1174 boundary_.calcGeometry();
1176 boundary_.checkDefinition();
1188 if (pointZones().size() || faceZones().size() || cellZones().size())
1191 <<
"point, face or cell zone already exists"
1198 pointZones_.setSize(pz.
size());
1203 pointZones_.set(pI, pz[pI]);
1212 faceZones_.setSize(fz.
size());
1217 faceZones_.set(fI, fz[fI]);
1226 cellZones_.setSize(cz.
size());
1231 cellZones_.set(cI, cz[cI]);
1242 const bool validBoundary
1247 boundary_.clearGeom();
1248 clearAddressing(
true);
1272 meshObjects::reorderPatches<polyMesh>(*
this, newToOld, validBoundary);
1273 meshObjects::reorderPatches<pointMesh>(*
this, newToOld, validBoundary);
1279 const label insertPatchi,
1282 const word& defaultPatchFieldType,
1283 const bool validBoundary
1286 const label sz = boundary_.size();
1288 label startFacei = nFaces();
1289 if (insertPatchi < sz)
1291 startFacei = boundary_[insertPatchi].start();
1298 for (
label i = 0; i < insertPatchi; i++)
1302 for (
label i = insertPatchi; i < sz; i++)
1306 newToOld[insertPatchi] = -1;
1308 reorderPatches(newToOld,
false);
1312 boundary_.clearGeom();
1313 clearAddressing(
true);
1355 meshObjects::addPatch<polyMesh>(*
this, insertPatchi);
1356 meshObjects::addPatch<pointMesh>(*
this, insertPatchi);
1362 if (clearedPrimitives_)
1365 <<
"points deallocated"
1375 if (clearedPrimitives_)
1378 <<
"faces deallocated"
1405 if (oldPointsPtr_.empty())
1408 <<
"Old points have not been stored"
1412 return oldPointsPtr_();
1418 storeOldCellCentres_ =
true;
1422 return cellCentres();
1425 if (oldCellCentresPtr_.empty())
1428 <<
"Old cell centres have not been stored"
1432 return oldCellCentresPtr_();
1444 io.
eventNo() = points_.eventNo()+1;
1453 <<
"Set points for time " << time().value()
1454 <<
" index " << time().timeIndex() <<
endl;
1459 points_ = newPoints;
1461 setPointsInstance(time().
name());
1464 if (globalMeshDataPtr_.valid())
1466 globalMeshDataPtr_().movePoints(points_);
1472 boundary_.movePoints(points_);
1474 pointZones_.movePoints(points_);
1475 faceZones_.movePoints(points_);
1476 cellZones_.movePoints(points_);
1479 cellTreePtr_.clear();
1485 meshObjects::movePoints<polyMesh>(*
this);
1486 meshObjects::movePoints<pointMesh>(*
this);
1498 <<
"Moving points for time " << time().value()
1499 <<
" index " << time().timeIndex() <<
endl;
1503 if (curMotionTimeIndex_ != time().
timeIndex())
1505 oldPointsPtr_.clear();
1506 oldPointsPtr_.reset(
new pointField(points_));
1507 if (storeOldCellCentres_)
1509 oldCellCentresPtr_.clear();
1510 oldCellCentresPtr_.reset(
new pointField(cellCentres()));
1512 curMotionTimeIndex_ = time().timeIndex();
1515 points_ = newPoints;
1517 setPointsInstance(time().
name());
1526 if (globalMeshDataPtr_.valid())
1528 globalMeshDataPtr_().movePoints(points_);
1534 boundary_.movePoints(points_);
1536 pointZones_.movePoints(points_);
1537 faceZones_.movePoints(points_);
1538 cellZones_.movePoints(points_);
1541 cellTreePtr_.clear();
1547 meshObjects::movePoints<polyMesh>(*
this);
1548 meshObjects::movePoints<pointMesh>(*
this);
1556 curMotionTimeIndex_ = -1;
1557 oldPointsPtr_.clear();
1558 oldCellCentresPtr_.clear();
1564 if (globalMeshDataPtr_.empty())
1568 Pout<<
"polyMesh::globalData() const : "
1569 <<
"Constructing parallelData from processor topology"
1576 return globalMeshDataPtr_();
1594 fileName meshFilesPath = thisDb().time().
path()/instanceDir/meshDir();
1596 rm(meshFilesPath/
"points");
1597 rm(meshFilesPath/
"faces");
1598 rm(meshFilesPath/
"owner");
1599 rm(meshFilesPath/
"neighbour");
1600 rm(meshFilesPath/
"cells");
1601 rm(meshFilesPath/
"boundary");
1602 rm(meshFilesPath/
"pointZones");
1603 rm(meshFilesPath/
"faceZones");
1604 rm(meshFilesPath/
"cellZones");
1605 rm(meshFilesPath/
"meshModifiers");
1606 rm(meshFilesPath/
"parallelData");
1609 if (
isDir(meshFilesPath/
"sets"))
1611 rmDir(meshFilesPath/
"sets");
1618 removeFiles(instance());
1642 findTetFacePt(celli,
p, tetFacei, tetPti);
1658 tetFacei = tet.
face();
1659 tetPti = tet.
tetPt();
1678 case FACE_CENTRE_TRIS:
1686 label facei = cFaces[cFacei];
1687 const face&
f = faces_[facei];
1688 const point& fc = faceCentres()[facei];
1689 bool isOwn = (owner_[facei] == celli);
1699 nextPointi =
f.nextLabel(fp);
1703 pointi =
f.nextLabel(fp);
1716 if ((faceTri.
area() & proj) > 0)
1726 case FACE_DIAG_TRIS:
1734 label facei = cFaces[cFacei];
1735 const face&
f = faces_[facei];
1737 for (
label tetPti = 1; tetPti <
f.
size() - 1; tetPti++)
1746 if ((faceTri.
area() & proj) > 0)
1762 findTetFacePt(celli,
p, tetFacei, tetPti);
1764 return tetFacei != -1;
1782 && (decompMode == FACE_DIAG_TRIS || decompMode == CELL_TETS)
1791 (void)tetBasePtIs();
1799 if (decompMode == CELL_TETS)
1808 findCellFacePt(
p, celli, tetFacei, tetPti);
1818 label celli = findNearestCell(
p);
1821 if (pointInCell(
p, celli, decompMode))
1829 for (
label celli = 0; celli < nCells(); celli++)
1831 if (pointInCell(
p, celli, decompMode))
#define forAll(list, i)
Loop across all elements in list.
A List of objects of type <Type> with automated input and output using a compact storage....
static pointMesh & New(const polyMesh &mesh)
label size() const
Return number of elements in table.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
const word & headerClassName() const
Return name of the class name read from header.
writeOption
Enumeration defining the write options.
void size(const label)
Override size to be inconsistent with allocated storage.
void clearAddressing()
Clear addressing.
virtual void reorderPatches(const labelUList &newToOld, const bool validBoundary)=0
Reordered/removed trailing patches. If validBoundary call is parallel.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Inter-processor communications stream.
static bool & parRun()
Is this a parallel run?
label size() const
Return the number of elements in the UPtrList.
virtual void topoChange(const polyTopoChangeMap &map)=0
Update topology using the given map.
static const direction nComponents
Number of components in this vector space.
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
A bounding box defined in terms of the points at its extremities.
A cell is defined as a list of faces with extra functionality.
A list of keyword definitions, which are a keyword followed by any number of values (e....
A subset of mesh faces organised as a primitive patch.
A face is a list of labels corresponding to mesh vertices.
A class for handling file names.
fileName path() const
Return directory path name (part before last /)
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
label findInside(const point &) const
Find shape containing point. Only implemented for certain.
static void clearUpto(objectRegistry &)
Clear all meshObjects derived from FromType up to (but not including)
Registry of regIOobjects.
const Time & time() const
Return time.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
bool foundObject(const word &name) const
Is the named Type in registry.
Mesh representing a set of points created from polyMesh.
void reset()
Reset pointMesh with respect to the updated polyMesh.
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list.
void topoChange()
Correct polyBoundaryMesh after topology update.
void clearGeom()
Clear geometry at this level and at patches.
void clearAddressing()
Clear addressing at this level and at patches.
static labelList findFaceBasePts(const polyMesh &mesh, scalar tol=minTetQuality, bool report=false)
Find a suitable base point for each face for decomposition.
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.
void findCellFacePt(const point &p, label &celli, label &tetFacei, label &tetPti) const
Find the cell, tetFacei and tetPti for point p.
const fileName & facesInstance() const
Return the current instance directory for faces.
label nGeometricD() const
Return the number of valid geometric dimensions in the mesh.
static word defaultRegion
Return the default region name.
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
virtual void addPatch(const label insertPatchi, const polyPatch &patch, const dictionary &patchFieldDict, const word &defaultPatchFieldType, const bool validBoundary)
Add/insert single patch. If validBoundary the new situation.
cellDecomposition
Enumeration defining the decomposition of the cell for.
IOobject::writeOption facesWriteOpt() const
Return the points write option.
virtual const faceList & faces() const
Return raw faces.
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.
void resetPrimitives(pointField &&points, faceList &&faces, labelList &&owner, labelList &&neighbour, const labelList &patchSizes, const labelList &patchStarts, const bool validBoundary=true)
Reset mesh primitive data. Assumes all patch info correct.
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.
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 for mesh motion.
void swap(polyMesh &)
Swap mesh.
const fileName & pointsInstance() const
Return the current instance directory for points.
label comm() const
Return communicator used for parallel communication.
polyMesh(const IOobject &io)
Construct from IOobject.
void clearAddressing(const bool isMeshUpdate=false)
Clear addressing.
void resetMotion() const
Reset motion.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
virtual const labelList & faceNeighbour() const
Return face neighbour.
void addPatches(const List< polyPatch * > &, const bool validBoundary=true)
Add boundary patches.
bool upToDatePoints(const regIOobject &io) const
Return true if io is up-to-date with points.
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
virtual const pointField & points() const
Return raw points.
void setUpToDatePoints(regIOobject &io) const
Set io to be up-to-date with points.
const indexedOctree< treeDataCell > & cellTree() const
Return the cell search tree.
IOobject::writeOption pointsWriteOpt() const
Return the points write option.
void removeFiles() const
Remove all files from mesh instance()
virtual const pointField & oldCellCentres() const
Return old cell centres for mesh motion.
virtual void reorderPatches(const labelUList &newToOld, const bool validBoundary)
Reorder and trim existing patches. If validBoundary the new.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
void setInstance(const fileName &)
Set the instance for mesh files.
virtual void setPoints(const pointField &)
Reset the points.
const Vector< label > & solutionD() const
Return the vector of solved-for directions in mesh.
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.
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm) const
Construct and return a clone, resetting the boundary mesh.
Cell-face mesh analysis engine.
bool pointInCell(const point &p, label celli) const
Return true if the point is in the cell.
void clearGeom()
Clear geometry.
tmp< scalarField > movePoints(const pointField &p, const pointField &oldP)
Move points, returns volumes swept by faces in motion.
const vectorField & faceAreas() const
const cellList & cells() const
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
bool upToDate(const regIOobject &) const
Return true if up-to-date with respect to given object.
virtual bool write(const bool write=true) const
Write using setting from DB.
label eventNo() const
Event number at last update.
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
label face() const
Return the face.
label tetPt() const
Return the characterising tetPtI.
triPointRef faceTri(const polyMesh &mesh) const
Return the geometry corresponding to the tri on the face for.
A class for managing temporary objects.
Standard boundBox + extra functionality for use in octree.
Encapsulation of data needed to search in/for cells. Used to find the cell containing a point (e....
A triangle primitive used to calculate face areas and swept volumes.
vector area() const
Return vector area.
Point centre() const
Return centre (centroid)
A class for handling words, derived from string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const fvPatchList & patches
#define WarningInFunction
Report a warning using Foam::Warning.
#define InfoInFunction
Report an information message using Foam::Info.
errorManipArg< error, int > exit(error &err, const int errNo=1)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
errorManip< error > abort(error &err)
vectorField pointField
pointField is a vectorField.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
Vector< scalar > vector
A scalar version of the templated Vector.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dimensioned< scalar > mag(const dimensioned< Type > &)
bool rmDir(const fileName &)
Remove a directory and its contents.
defineTypeNameAndDebug(combustionModel, 0)
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
IOList< label > labelIOList
Label container classes.
dimensionSet cmptMag(const dimensionSet &)
prefixOSstream Pout(cout, "Pout")
Cmpt cmptSum(const VectorSpace< Form, Cmpt, Ncmpts > &vs)