65 static const scalar edgeTol = 1e-3;
68 void writeSet(
const cellSet& cells,
const string& msg)
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
236 Info<<
"Created patch oldInternalFaces at " << patchi <<
endl;
240 Info<<
"Reusing patch oldInternalFaces at " << patchi <<
endl;
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]];
541 Info<<
"Writing refined mesh to time " << runTime.
timeName() <<
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"));
665 Info<<
"Correcting for 2D motion" << endl <<
endl;
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)
783 cellSet inside(mesh,
"inside", mesh.nCells()/10);
784 cellSet outside(mesh,
"outside", mesh.nCells()/10);
785 cellSet cutCells(mesh,
"cutCells", mesh.nCells()/10);
786 cellSet selected(mesh,
"selected", mesh.nCells()/10);
807 Info<<
" Selected " << cutCells.
name() <<
" with " 808 << cutCells.
size() <<
" cells" <<
endl;
810 if ((curvDist > 0) && (meshMinEdgeLen < maxEdgeLen))
815 cellSet curveCells(mesh,
"curveCells", mesh.nCells()/10);
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);
877 Info<<
" Current cells : " << mesh.nCells() <<
nl 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." 905 Info<<
" After refinement:" << mesh.nCells() <<
nl 910 Info<<
" Writing refined mesh to time " << runTime.
timeName()
919 meshMinEdgeLen = getEdgeStats(mesh, normalDir);
926 cellSet inside(mesh,
"inside", mesh.nCells()/10);
927 cellSet outside(mesh,
"outside", mesh.nCells()/10);
928 cellSet cutCells(mesh,
"cutCells", mesh.nCells()/10);
929 cellSet selected(mesh,
"selected", mesh.nCells()/10);
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.
timeName() <<
nl 991 Info<<
"Writing refined mesh to time " << runTime.
timeName() <<
nl const fvPatchList & patches
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
const word & name() const
Return name.
A class for handling file names.
fileName relativeObjectPath() const
Return complete relativePath + object name.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A list of keyword definitions, which are a keyword followed by any number of values (e...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
label nInternalFaces() const
virtual const labelList & faceNeighbour() const
Return face neighbour.
Cell-face mesh analysis engine.
Templated form of IOobject providing type information for file reading and header type checking...
static unsigned int defaultPrecision()
Return the default precision.
Does multiple pass refinement to refine cells in multiple directions.
void size(const label)
Override size to be inconsistent with allocated storage.
bool empty() const
Return true if the hash table is empty.
Given list of cells to remove insert all the topology changes.
static word defaultRegion
Return the default region name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
virtual const pointField & points() const =0
Return mesh points.
label findPatchID(const word &patchName) const
Find patch index given a name.
static void noParallel()
Remove the parallel options.
A bounding box defined in terms of the points at its extremities.
const cellList & cells() const
Vector< scalar > vector
A scalar version of the templated Vector.
bool insert(const Key &key)
Insert a new entry.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
label size() const
Return number of elements in table.
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...
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm) const
Construct and return a clone, resetting the boundary mesh.
Helper class to search on triSurface.
vectorField pointField
pointField is a vectorField.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
bool found(const Key &) const
Return true if hashedEntry is found in table.
Class applies a two-dimensional correction to mesh motion point field.
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
A class for handling words, derived from string.
const fileName & local() const
const word & constant() const
Return constant name.
virtual const labelList & faceOwner() const
Return face owner.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
List< label > labelList
A List of labels.
const vectorField & cellCentres() const
errorManip< error > abort(error &err)
virtual void addSet(const topoSet &set)
Add elements present in set.
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.
void addPatches(const List< polyPatch *> &, const bool validBoundary=true)
Add boundary patches.
const word & system() const
Return system name.
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
void removeBoundary()
Remove boundary patches.
virtual void topoChange(const polyTopoChangeMap &map)
Update any stored data for new labels.
vector vec(const pointField &) const
Return the vector (end - start)
const vector & planeNormal() const
Return plane normal.
const Time & time() const
Return time.
Empty front and back plane patch. Used for 2-D geometries.
const triSurface & surface() const
Return reference to the surface.
label size() const
Return the number of elements in the UPtrList.
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
A topoSetSource to select cells based on relation to surface.
void setSize(const label)
Reset size of List.
#define WarningInFunction
Report a warning using Foam::Warning.
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurrences of environment variables.
A collection of cell labels.
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Direct mesh changes based on v1.3 polyTopoChange syntax.
label start() const
Return start label of this patch in the polyMesh face list.
dimensioned< scalar > mag(const dimensioned< Type > &)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
fileName & instance() const
Return the instance directory, constant, system, <time> etc.
Mesh consisting of general polyhedral cells.
List< Key > toc() const
Return the table of contents.
virtual bool write(const bool write=true) const
Write using setting from DB.
A patch is a list of labels that address the faces in the global face list.
virtual void setPoints(const pointField &)
Reset the points.
Triangulated surface description with patch information.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
const labelListList & cellCells() const
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.