65 static const scalar edgeTol = 1
e-3;
70 Info<<
"Writing " << msg <<
" (" <<
cells.
size() <<
") to cellSet "
85 if (
mag(normal &
vector(1, 0, 0)) > 1-edgeTol)
89 else if (
mag(normal &
vector(0, 1, 0)) > 1-edgeTol)
93 else if (
mag(normal &
vector(0, 0, 1)) > 1-edgeTol)
112 scalar maxX = -great;
116 scalar maxY = -great;
120 scalar maxZ = -great;
123 scalar minOther = great;
124 scalar maxOther = -great;
130 const edge&
e = edges[edgeI];
134 scalar eMag =
mag(eVec);
138 if (
mag(eVec &
x) > 1-edgeTol)
140 minX =
min(minX, eMag);
141 maxX =
max(maxX, eMag);
144 else if (
mag(eVec &
y) > 1-edgeTol)
146 minY =
min(minY, eMag);
147 maxY =
max(maxY, eMag);
150 else if (
mag(eVec & z) > 1-edgeTol)
152 minZ =
min(minZ, eMag);
153 maxZ =
max(maxZ, eMag);
158 minOther =
min(minOther, eMag);
159 maxOther =
max(maxOther, eMag);
164 <<
"Mesh edge statistics:" <<
nl
165 <<
" x aligned : number:" << nX <<
"\tminLen:" << minX
166 <<
"\tmaxLen:" << maxX <<
nl
167 <<
" y aligned : number:" << nY <<
"\tminLen:" << minY
168 <<
"\tmaxLen:" << maxY <<
nl
169 <<
" z aligned : number:" << nZ <<
"\tminLen:" << minZ
170 <<
"\tmaxLen:" << maxZ <<
nl
171 <<
" other : number:" << mesh.
nEdges() - nX - nY - nZ
172 <<
"\tminLen:" << minOther
173 <<
"\tmaxLen:" << maxOther <<
nl <<
endl;
175 if (excludeCmpt == 0)
177 return min(minY,
min(minZ, minOther));
179 else if (excludeCmpt == 1)
181 return min(minX,
min(minZ, minOther));
183 else if (excludeCmpt == 2)
185 return min(minX,
min(minY, minOther));
189 return min(minX,
min(minY,
min(minZ, minOther)));
216 emptyPolyPatch::typeName
249 void selectCurvatureCells
254 const scalar nearDist,
255 const scalar curvature,
287 void addCutNeighbours
290 const bool selectInside,
291 const bool selectOutside,
303 const label celli = iter.key();
308 const label facei = cFaces[i];
319 if (selectInside && inside.
found(nbr))
321 addCutFaces.insert(nbr);
323 else if (selectOutside && outside.
found(nbr))
325 addCutFaces.insert(nbr);
331 Info<<
" Selected an additional " << addCutFaces.size()
332 <<
" neighbours of cutCells to refine" <<
endl;
336 cutCells.
insert(iter.key());
345 bool limitRefinementLevel
348 const label limitDiff,
357 if (!excludeCells.
found(celli))
363 label nbr = cCells[i];
365 if (!excludeCells.
found(nbr))
367 if (refLevel[celli] - refLevel[nbr] >= limitDiff)
370 <<
"Level difference between neighbouring cells "
371 << celli <<
" and " << nbr
372 <<
" greater than or equal to " << limitDiff <<
endl
373 <<
"refLevels:" << refLevel[celli] <<
' '
387 const label celli = iter.key();
392 const label nbr = cCells[i];
394 if (!excludeCells.
found(nbr) && !cutCells.
found(nbr))
396 if (refLevel[celli] + 1 - refLevel[nbr] >= limitDiff)
398 addCutCells.insert(nbr);
404 if (addCutCells.size())
408 Info<<
"Added an additional " << addCutCells.size() <<
" cells"
409 <<
" to satisfy 1:" << limitDiff <<
" refinement level"
414 cutCells.
insert(iter.key());
420 Info<<
"Added no additional cells"
421 <<
" to satisfy 1:" << limitDiff <<
" refinement level"
455 for (
label celli = oldCells; celli < mesh.
nCells(); celli++)
462 forAll(addedCells, oldCelli)
464 const labelList& added = addedCells[oldCelli];
470 label masterLevel = ++refLevel[oldCelli];
474 refLevel[added[i]] = masterLevel;
485 const label writeMesh,
496 Info<<
"Mesh has:" << mesh.
nCells() <<
" cells."
497 <<
" Removing:" << cellLabels.size() <<
" cells" <<
endl;
500 labelList exposedFaces(cellRemover.getExposedFaces(cellLabels));
503 cellRemover.setRefinement
518 if (map().hasMotionPoints())
524 cellRemover.topoChange(map());
527 const labelList& cellMap = map().cellMap();
533 newRefLevel[i] = refLevel[cellMap[i]];
537 refLevel.transfer(newRefLevel);
541 Info<<
"Writing refined mesh to time " << runTime.
name() <<
nl
567 const bool selectCut,
568 const bool selectInside,
569 const bool selectOutside,
571 const label nCutLayers,
598 selected.
addSet(cutCells);
609 Info<<
"Determined cell status:" <<
endl
610 <<
" inside :" << inside.
size() <<
endl
611 <<
" outside :" << outside.
size() <<
endl
612 <<
" cutCells:" << cutCells.
size() <<
endl
613 <<
" selected:" << selected.
size() <<
endl
616 writeSet(inside,
"inside cells");
617 writeSet(outside,
"outside cells");
618 writeSet(cutCells,
"cut cells");
619 writeSet(selected,
"selected cells");
624 int main(
int argc,
char *argv[])
633 label newPatchi = addPatch(mesh,
"oldInternalFaces");
640 Info<<
"Checking for motionProperties\n" <<
endl;
654 if (motionObj.headerOk())
656 Info<<
"Reading " << runTime.
constant() /
"motionProperties"
661 Switch twoDMotion(motionProperties.lookup(
"twoDMotion"));
674 "autoRefineMeshDict",
691 scalar minEdgeLen(refineDict.
lookup<scalar>(
"minEdgeLen"));
692 scalar maxEdgeLen(refineDict.
lookup<scalar>(
"maxEdgeLen"));
693 scalar curvature(refineDict.
lookup<scalar>(
"curvature"));
694 scalar curvDist(refineDict.
lookup<scalar>(
"curvatureDistance"));
699 Info<<
"Cells to be used for meshing (0=false, 1=true):" <<
nl
700 <<
" cells cut by surface : " << selectCut <<
nl
701 <<
" cells inside of surface : " << selectInside <<
nl
702 <<
" cells outside of surface : " << selectOutside <<
nl
703 <<
" hanging cells : " << selectHanging <<
nl
707 if (nCutLayers > 0 && selectInside)
710 <<
"Illogical settings : Both nCutLayers>0 and selectInside true."
712 <<
"This would mean that inside cells get removed but should be"
713 <<
" included in final mesh" <<
endl;
726 forAll(outsidePts, outsideI)
728 const point& outsidePoint = outsidePts[outsideI];
730 if (queryMesh.findCell(outsidePoint, -1,
false) == -1)
733 <<
"outsidePoint " << outsidePoint
734 <<
" is not inside any cell"
760 Info<<
"Read existing refinement level from file "
762 <<
" min level : " <<
min(refLevel) <<
nl
763 <<
" max level : " << maxLevel <<
nl
768 Info<<
"Created zero refinement level in file "
777 direction normalDir(getNormalDir(correct2DPtr));
778 scalar meshMinEdgeLen = getEdgeStats(mesh, normalDir);
780 while (meshMinEdgeLen > minEdgeLen)
807 Info<<
" Selected " << cutCells.
name() <<
" with "
808 << cutCells.
size() <<
" cells" <<
endl;
810 if ((curvDist > 0) && (meshMinEdgeLen < maxEdgeLen))
827 Info<<
" Selected " << curveCells.name() <<
" with "
828 << curveCells.size() <<
" cells" <<
endl;
847 cutCells.
subset(curveCells);
849 Info<<
" Removed cells not on surface curvature. Selected "
858 subsetMesh(mesh, writeMesh, newPatchi, inside, cutCells, refLevel);
878 <<
" Selected for refinement :" << cutCells.
size() <<
nl
881 if (cutCells.
empty())
883 Info<<
"Stopping refining since 0 cells selected to be refined ..."
888 if ((mesh.
nCells() + 8*cutCells.
size()) > cellLimit)
890 Info<<
"Stopping refining since cell limit reached ..." <<
nl
891 <<
"Would refine from " << mesh.
nCells()
892 <<
" to " << mesh.
nCells() + 8*cutCells.
size() <<
" cells."
910 Info<<
" Writing refined mesh to time " << runTime.
name()
919 meshMinEdgeLen = getEdgeStats(mesh, normalDir);
955 Info<<
"Detected " << hanging.
size() <<
" hanging cells"
956 <<
" (cells with all points on"
957 <<
" outside of cellSet 'selected').\nThese would probably result"
958 <<
" in flattened cells when snapping the mesh to the surface"
961 Info<<
"Refining " << hanging.
size() <<
" hanging cells" <<
nl
978 doRefinement(mesh, refineDict, hanging, refLevel);
980 Info<<
"Writing refined mesh to time " << runTime.
name() <<
nl
991 Info<<
"Writing refined mesh to time " << runTime.
name() <<
nl
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
static twoDPointCorrector & New(const polyMesh &mesh)
bool insert(const Key &key)
Insert a new entry.
List< Key > toc() const
Return the table of contents.
label size() const
Return number of elements in table.
bool empty() const
Return true if the hash table is empty.
bool found(const Key &) const
Return true if hashedEntry is found in table.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
fileName relativeObjectPath() const
Return complete relativePath + object name.
const word & name() const
Return name.
static unsigned int defaultPrecision()
Return the default precision.
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
static const word & constant()
Return constant name.
static const word & system()
Return system name.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
label size() const
Return the number of elements in the UPtrList.
static void noParallel()
Remove the parallel options.
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 collection of cell labels.
virtual void topoChange(const polyTopoChangeMap &map)
Update any stored data for new labels.
A list of keyword definitions, which are a keyword followed by any number of values (e....
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
const word & name() const
Return const reference to name.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Empty front and back plane patch. Used for 2-D geometries.
A class for handling file names.
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Does multiple pass refinement to refine cells in multiple directions.
const Time & time() const
Return time.
label findPatchID(const word &patchName) const
Find patch index given a name.
Mesh consisting of general polyhedral cells.
static word defaultRegion
Return the default region name.
virtual const labelList & faceOwner() const
Return face owner.
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.
void removeBoundary()
Remove boundary patches.
virtual void setPoints(const pointField &)
Reset the points.
A patch is a list of labels that address the faces in the global face list.
label start() const
Return start label of this patch in the polyMesh face list.
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm) const
Construct and return a clone, resetting the boundary mesh.
Direct mesh changes based on v1.3 polyTopoChange syntax.
Cell-face mesh analysis engine.
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
const vectorField & cellCentres() const
const labelListList & cellCells() const
label nInternalFaces() const
virtual const pointField & points() const =0
Return mesh points.
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
const cellList & cells() const
virtual bool write(const bool write=true) const
Write using setting from DB.
Given list of cells to remove insert all the topology changes.
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurrences of environment variables.
static labelHashSet getHangingCells(const primitiveMesh &mesh, const labelHashSet &internalCells)
Get cells using points on 'outside' only.
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.
A topoSetSource to select cells based on relation to surface.
virtual void addSet(const topoSet &set)
Add elements present in set.
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Helper class to search on triSurface.
const triSurface & surface() const
Return reference to the surface.
Triangulated surface description with patch information.
Class applies a two-dimensional correction to mesh motion point field.
const vector & planeNormal() const
Return plane normal.
Templated form of IOobject providing type information for file reading and header type checking.
A class for handling words, derived from string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
int main(int argc, char *argv[])
const fvPatchList & patches
#define WarningInFunction
Report a warning using Foam::Warning.
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
Vector< scalar > vector
A scalar version of the templated Vector.
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.