70 static const scalar edgeTol = 1
e-3;
75 Info<<
"Writing " << msg <<
" (" <<
cells.
size() <<
") to cellSet " 88 if (
mag(normal.x()) > 1-edgeTol)
92 else if (
mag(normal.y()) > 1-edgeTol)
96 else if (
mag(normal.z()) > 1-edgeTol)
123 for (
const edge&
e : edges)
127 scalar eMag =
mag(eVec);
131 if (
mag(eVec.x()) > 1-edgeTol)
136 else if (
mag(eVec.y()) > 1-edgeTol)
141 else if (
mag(eVec.z()) > 1-edgeTol)
154 <<
"Mesh edge statistics:" <<
nl 155 <<
" x aligned : number:" << nX
156 <<
"\tminLen:" << limitsX.min() <<
"\tmaxLen:" << limitsX.max() <<
nl 157 <<
" y aligned : number:" << nY
158 <<
"\tminLen:" << limitsY.min() <<
"\tmaxLen:" << limitsY.max() <<
nl 159 <<
" z aligned : number:" << nZ
160 <<
"\tminLen:" << limitsZ.min() <<
"\tmaxLen:" << limitsZ.max() <<
nl 161 <<
" other : number:" << nAny
162 <<
"\tminLen:" << limitsAny.min()
163 <<
"\tmaxLen:" << limitsAny.max() <<
nl <<
endl;
165 if (excludeCmpt == vector::X)
181 else if (excludeCmpt == vector::Z)
230 emptyPolyPatch::typeName
255 Info<<
"Created patch oldInternalFaces at " << patchi <<
endl;
259 Info<<
"Reusing patch oldInternalFaces at " << patchi <<
endl;
268 void selectCurvatureCells
273 const scalar nearDist,
274 const scalar curvature,
306 void addCutNeighbours
309 const bool selectInside,
310 const bool selectOutside,
320 for (
const label celli : cutCells)
326 const label facei = cFaces[i];
337 if (selectInside && inside.
found(nbr))
339 addCutFaces.insert(nbr);
341 else if (selectOutside && outside.
found(nbr))
343 addCutFaces.insert(nbr);
349 Info<<
" Selected an additional " << addCutFaces.size()
350 <<
" neighbours of cutCells to refine" <<
endl;
352 for (
const label facei : addCutFaces)
354 cutCells.insert(facei);
363 bool limitRefinementLevel
366 const label limitDiff,
375 if (!excludeCells.
found(celli))
381 label nbr = cCells[i];
383 if (!excludeCells.
found(nbr))
385 if (refLevel[celli] - refLevel[nbr] >= limitDiff)
388 <<
"Level difference between neighbouring cells " 389 << celli <<
" and " << nbr
390 <<
" greater than or equal to " << limitDiff <<
endl 391 <<
"refLevels:" << refLevel[celli] <<
' ' 402 for (
const label celli : cutCells)
409 const label nbr = cCells[i];
411 if (!excludeCells.
found(nbr) && !cutCells.found(nbr))
413 if (refLevel[celli] + 1 - refLevel[nbr] >= limitDiff)
415 addCutCells.insert(nbr);
421 if (addCutCells.size())
425 Info<<
"Added an additional " << addCutCells.size() <<
" cells" 426 <<
" to satisfy 1:" << limitDiff <<
" refinement level" 429 for (
const label celli : addCutCells)
431 cutCells.insert(celli);
436 Info<<
"Added no additional cells" 437 <<
" to satisfy 1:" << limitDiff <<
" refinement level" 470 for (label celli = oldCells; celli <
mesh.
nCells(); celli++)
477 forAll(addedCells, oldCelli)
479 const labelList& added = addedCells[oldCelli];
485 label masterLevel = ++refLevel[oldCelli];
489 refLevel[added[i]] = masterLevel;
500 const label writeMesh,
512 <<
" Removing:" << cellLabels.size() <<
" cells" <<
endl;
515 labelList exposedFaces(cellRemover.getExposedFaces(cellLabels));
518 cellRemover.setRefinement
533 if (morphMap().hasMotionPoints())
539 cellRemover.updateMesh(morphMap());
542 const labelList& cellMap = morphMap().cellMap();
548 newRefLevel[i] = refLevel[cellMap[i]];
586 const bool selectCut,
587 const bool selectInside,
588 const bool selectOutside,
590 const label nCutLayers,
617 selected.
addSet(cutCells);
628 Info<<
"Determined cell status:" <<
endl 629 <<
" inside :" << inside.size() <<
endl 630 <<
" outside :" << outside.size() <<
endl 631 <<
" cutCells:" << cutCells.
size() <<
endl 632 <<
" selected:" << selected.
size() <<
endl 635 writeSet(inside,
"inside cells");
636 writeSet(outside,
"outside cells");
637 writeSet(cutCells,
"cut cells");
638 writeSet(selected,
"selected cells");
643 int main(
int argc,
char *argv[])
647 "Refine cells near to a surface" 656 label newPatchi = addPatch(
mesh,
"oldInternalFaces");
663 Info<<
"Checking for motionProperties\n" <<
endl;
684 if (motionProperties.get<
bool>(
"twoDMotion"))
695 "snappyRefineMeshDict",
705 const label nCutLayers(refineDict.
get<label>(
"nCutLayers"));
706 const label cellLimit(refineDict.
get<label>(
"cellLimit"));
707 const bool selectCut(refineDict.
get<
bool>(
"selectCut"));
708 const bool selectInside(refineDict.
get<
bool>(
"selectInside"));
709 const bool selectOutside(refineDict.
get<
bool>(
"selectOutside"));
710 const bool selectHanging(refineDict.
get<
bool>(
"selectHanging"));
712 const scalar minEdgeLen(refineDict.
get<scalar>(
"minEdgeLen"));
713 const scalar maxEdgeLen(refineDict.
get<scalar>(
"maxEdgeLen"));
714 const scalar curvature(refineDict.
get<scalar>(
"curvature"));
715 const scalar curvDist(refineDict.
get<scalar>(
"curvatureDistance"));
717 const label refinementLimit(refineDict.
get<label>(
"splitLevel"));
718 const bool writeMesh(refineDict.
get<
bool>(
"writeMesh"));
720 Info<<
"Cells to be used for meshing (0=false, 1=true):" <<
nl 721 <<
" cells cut by surface : " << selectCut <<
nl 722 <<
" cells inside of surface : " << selectInside <<
nl 723 <<
" cells outside of surface : " << selectOutside <<
nl 724 <<
" hanging cells : " << selectHanging <<
nl 728 if (nCutLayers > 0 && selectInside)
731 <<
"Illogical settings : Both nCutLayers>0 and selectInside true." 733 <<
"This would mean that inside cells get removed but should be" 734 <<
" included in final mesh" <<
endl;
747 forAll(outsidePts, outsidei)
749 const point& outsidePoint = outsidePts[outsidei];
751 if (queryMesh.findCell(outsidePoint, -1,
false) == -1)
754 <<
"outsidePoint " << outsidePoint
755 <<
" is not inside any cell" 777 label maxLevel =
max(refLevel);
781 Info<<
"Read existing refinement level from file " 783 <<
" min level : " <<
min(refLevel) <<
nl 784 <<
" max level : " << maxLevel <<
nl 789 Info<<
"Created zero refinement level in file " 798 direction normalDir(getNormalDir(correct2DPtr));
799 scalar meshMinEdgeLen = getEdgeStats(
mesh, normalDir);
801 while (meshMinEdgeLen > minEdgeLen)
828 Info<<
" Selected " << cutCells.
name() <<
" with " 829 << cutCells.
size() <<
" cells" <<
endl;
831 if ((curvDist > 0) && (meshMinEdgeLen < maxEdgeLen))
848 Info<<
" Selected " << curveCells.name() <<
" with " 849 << curveCells.size() <<
" cells" <<
endl;
868 cutCells.
subset(curveCells);
870 Info<<
" Removed cells not on surface curvature. Selected " 879 subsetMesh(
mesh, writeMesh, newPatchi, inside, cutCells, refLevel);
899 <<
" Selected for refinement :" << cutCells.
size() <<
nl 902 if (cutCells.
empty())
904 Info<<
"Stopping refining since 0 cells selected to be refined ..." 911 Info<<
"Stopping refining since cell limit reached ..." <<
nl 944 meshMinEdgeLen = getEdgeStats(
mesh, normalDir);
980 Info<<
"Detected " << hanging.
size() <<
" hanging cells" 981 <<
" (cells with all points on" 982 <<
" outside of cellSet 'selected').\nThese would probably result" 983 <<
" in flattened cells when snapping the mesh to the surface" 986 Info<<
"Refining " << hanging.
size() <<
" hanging cells" <<
nl 1003 doRefinement(
mesh, refineDict, hanging, refLevel);
1018 else if (!writeMesh)
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
virtual void subset(const labelUList &elems)
Subset contents. Only elements present in both sets remain.
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream. ...
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
static void addNote(const string ¬e)
Add extra notes for the usage information.
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool found(const Key &key) const
Same as contains()
virtual const labelList & faceNeighbour() const
Return face neighbour.
const word & name() const noexcept
Return the object name.
Cell-face mesh analysis engine.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Add elements to current set.
constexpr char nl
The newline '\n' character (0x0a)
Does multiple pass refinement to refine cells in multiple directions.
Given list of cells to remove, insert all the topology changes.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
static unsigned int defaultPrecision() noexcept
Return the default precision.
static void noParallel()
Remove the parallel options.
A bounding box defined in terms of min/max extrema points.
const cellList & cells() const
Ignore writing from objectRegistry::writeObject()
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
const Time & time() const
Return the top-level database.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
fileName objectPath() const
The complete path + object name.
bool isInternalFace(const label faceIndex) const noexcept
Return true if given face label is internal to the mesh.
static labelHashSet getHangingCells(const primitiveMesh &mesh, const labelHashSet &internalCells)
Get cells using points on 'outside' only.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
virtual const pointField & points() const
Return raw points.
#define forAll(list, i)
Loop across all elements in list.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
label size() const noexcept
The number of elements in table.
Helper class to search on triSurface.
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
void setSize(const label n)
Alias for resize()
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
Class applies a two-dimensional correction to mesh motion point field.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
A class for handling words, derived from Foam::string.
static word defaultRegion
Return the default region name.
label size() const noexcept
The number of entries in the list.
const word & system() const noexcept
Return system name.
virtual const labelList & faceOwner() const
Return face owner.
Reading is optional [identical to LAZY_READ].
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
label nInternalFaces() const noexcept
Number of internal faces.
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
const vectorField & cellCentres() const
errorManip< error > abort(error &err)
static void getSurfaceSets(const polyMesh &mesh, const fileName &surfName, const triSurface &surf, const triSurfaceSearch &querySurf, const pointField &outsidePts, const label nCutLayers, labelHashSet &inside, labelHashSet &outside, labelHashSet &cut)
Divide cells into cut,inside and outside.
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
virtual void addSet(const labelUList &elems)
Add given elements to the set.
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh...
void removeBoundary()
Remove boundary patches.
bool empty() const noexcept
True if the hash table is empty.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
const word & constant() const noexcept
Return constant name.
const vector & planeNormal() const
Return plane normal.
Empty front and back plane patch. Used for 2-D geometries.
const triSurface & surface() const
Return reference to the surface.
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
A topoSetCellSource to select cells based on relation to a surface given by an external file...
#define WarningInFunction
Report a warning using Foam::Warning.
string & expand(const bool allowEmpty=false)
Inplace expand initial tags, tildes, and all occurrences of environment variables as per stringOps::e...
label nCells() const noexcept
Number of mesh cells.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
A collection of cell labels.
PtrList< volScalarField > & Y
Direct mesh changes based on v1.3 polyTopoChange syntax.
const polyBoundaryMesh & patches
Automatically write from objectRegistry::writeObject()
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Mesh consisting of general polyhedral cells.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
List< label > labelList
A List of labels.
A patch is a list of labels that address the faces in the global face list.
Triangulated surface description with patch information.
void addPatches(polyPatchList &plist, const bool validBoundary=true)
Add boundary patches.
Defines the attributes of an object for which implicit objectRegistry management is supported...
const labelListList & cellCells() const
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
static constexpr const zero Zero
Global zero (0)