67 label sizeCoeffToRefinement
69 const scalar level0Coeff,
70 const scalar sizeCoeff
73 return round(::
log(level0Coeff/sizeCoeff)/::
log(2));
82 const label gapLevelIncrement,
83 const scalar level0Coeff
92 const word& geomName = allGeometry.
names()[geomI];
94 if (surfacesDict.
found(geomName))
121 const word& geomName = allGeometry.
names()[geomI];
130 names[surfI] = geomName;
131 surfaces[surfI] = geomI;
138 const word scsFuncName =
139 shapeDict.
lookup(
"surfaceCellSizeFunction");
143 const scalar surfaceCellSize =
144 scsDict.
lookup<scalar>(
"surfaceCellSizeCoeff");
146 const label refLevel = sizeCoeffToRefinement
152 globalMinLevel[surfI] = refLevel;
153 globalMaxLevel[surfI] = refLevel;
154 globalLevelIncr[surfI] = gapLevelIncrement;
161 if (shapeDict.
found(
"patchInfo"))
173 if (shapeDict.
found(
"regions"))
177 allGeometry[surfaces[surfI]].regions();
189 if (regionDict.
found(
"patchInfo"))
191 regionPatchInfo[surfI].insert
202 if (shapeDict.
found(
"regions"))
207 allGeometry[surfaces[surfI]].regions();
214 shapeControlRegionsDict.
subDict
219 const word scsFuncName =
220 shapeControlRegionDict.
lookup
222 "surfaceCellSizeFunction"
227 scsFuncName +
"Coeffs"
230 const scalar surfaceCellSize =
231 scsDict.
lookup<scalar>(
"surfaceCellSizeCoeff");
233 const label refLevel = sizeCoeffToRefinement
239 regionMinLevel[surfI].insert(regionI, refLevel);
240 regionMaxLevel[surfI].insert(regionI, refLevel);
241 regionLevelIncr[surfI].insert(regionI, 0);
255 regionOffset[surfI] = nRegions;
256 nRegions += allGeometry[surfaces[surfI]].regions().
size();
265 forAll(globalMinLevel, surfI)
267 label nRegions = allGeometry[surfaces[surfI]].regions().
size();
270 for (
label i = 0; i < nRegions; i++)
272 label globalRegionI = regionOffset[surfI] + i;
273 minLevel[globalRegionI] = globalMinLevel[surfI];
274 maxLevel[globalRegionI] = globalMaxLevel[surfI];
275 gapLevel[globalRegionI] =
276 maxLevel[globalRegionI]
277 + globalLevelIncr[surfI];
279 if (globalPatchInfo.set(surfI))
284 globalPatchInfo[surfI].
clone()
292 label globalRegionI = regionOffset[surfI] + iter.key();
294 minLevel[globalRegionI] = iter();
295 maxLevel[globalRegionI] = regionMaxLevel[surfI][iter.key()];
296 gapLevel[globalRegionI] =
297 maxLevel[globalRegionI]
298 + regionLevelIncr[surfI][iter.key()];
304 label globalRegionI = regionOffset[surfI] + iter.key();
305 patchInfo.
set(globalRegionI, iter()().
clone());
343 <<
setw(10) <<
"Min Level"
344 <<
setw(10) <<
"Max Level"
345 <<
setw(10) <<
"Gap Level" <<
nl
346 <<
setw(maxLen) <<
"------"
347 <<
setw(10) <<
"---------"
348 <<
setw(10) <<
"---------"
392 patchSize.insert(pp.
name(), pp.size());
402 label sz = compactZoneID.size();
403 compactZoneID.insert(iter.key(), sz);
415 patchToCompactZone[
patchi] = iter();
427 faceLabels.append(pp.
start()+i);
428 compactZones.append(patchToCompactZone[pp.
index()]);
445 allBoundary.meshPoints(),
446 allBoundary.meshPointMap(),
477 pointField allPoints = ListListOps::combine<pointField>
482 gatheredPoints.clear();
484 faceList allFaces = ListListOps::combine<faceList>
489 gatheredFaces.clear();
491 labelList allZones = ListListOps::combine<labelList>
496 gatheredZones.clear();
504 Info<<
"surfZone " << iter() <<
" : " << surfZones[iter()].name()
519 Info<<
"Writing merged surface to "
528 scalar getMergeDistance(
const polyMesh& mesh,
const scalar mergeTol)
531 scalar mergeDist = mergeTol *
meshBb.mag();
534 <<
"Overall mesh bounding box : " <<
meshBb <<
nl
535 <<
"Relative tolerance : " << mergeTol <<
nl
536 <<
"Absolute matching distance : " << mergeDist <<
nl
548 if (mergeTol < writeTol)
551 <<
"Your current settings specify ASCII writing with "
553 <<
"Your merging tolerance (" << mergeTol
554 <<
") is finer than this." <<
nl
555 <<
"Change to binary writeFormat, "
556 <<
"or increase the writePrecision" <<
endl
557 <<
"or adjust the merge tolerance (mergeTol)."
566 void removeZeroSizedPatches(
fvMesh& mesh)
584 oldToNew[
patchi] = newPatchi++;
588 const label nKeepPatches = newPatchi;
591 if (nKeepPatches != pbm.
size())
598 if (oldToNew[
patchi] == -1)
601 <<
" type " << pbm[
patchi].type()
603 oldToNew[
patchi] = newPatchi++;
626 Info<<
"Writing mesh to time " << meshRefiner.
name() <<
endl;
634 Info<<
"Wrote mesh in = "
639 int main(
int argc,
char *argv[])
645 "check all surface geometry for quality"
651 "simplify the surface using snappyHexMesh starting from a boundBox"
656 "(patch0 .. patchN)",
657 "only triangulate selected patches (wildcards supported)"
663 "name of the file to save the simplified surface to"
678 <<
"Create mesh for time = "
699 Info<<
"Read mesh in = "
707 <<
"Mesh provided is not fully 3D"
708 " as required for mesh relaxation after snapping" <<
nl
709 <<
"Convert all empty patches to appropriate types for a 3D mesh,"
736 const scalar mergeDist = getMergeDistance
739 meshDict.lookup<scalar>(
"mergeTolerance")
742 const Switch keepPatches(meshDict.lookupOrDefault(
"keepPatches",
false));
754 decomposeDict.
add(
"method",
"none");
755 decomposeDict.
add(
"numberOfSubdomains", 1);
766 meshDict.lookupOrDefault<
label>
774 if (meshDict.readIfPresent(
"debugFlags", flags))
788 meshRefinement::debug = debugLevel;
789 snappyRefineDriver::debug = debugLevel;
790 snappySnapDriver::debug = debugLevel;
791 snappyLayerDriver::debug = debugLevel;
797 if (meshDict.readIfPresent(
"writeFlags", flags))
816 if (meshDict.readIfPresent(
"outputFlags", flags))
848 meshDict.lookupOrDefault(
"singleRegionName",
true)
855 Info<<
"Reading refinement surfaces..." <<
endl;
860 refineDict.
found(
"refinementSurfaces")
861 ? refineDict.
subDict(
"refinementSurfaces")
866 Info<<
"Read refinement surfaces in = "
878 const labelList& surfaceGeometry = surfaces.surfaces();
879 forAll(surfaceGeometry, surfI)
881 label geomI = surfaceGeometry[surfI];
887 label globalRegionI = surfaces.globalRegion(surfI, regionI);
889 if (patchInfo.
set(globalRegionI))
892 word(patchInfo[globalRegionI].lookup(
"type"));
896 patchTypes[geomI][regionI] = wallPolyPatch::typeName;
922 Info<<
"Reading refinement regions..." <<
endl;
926 refineDict.
found(
"refinementRegions")
927 ? refineDict.
subDict(
"refinementRegions")
930 Info<<
"Read refinement regions in = "
938 Info<<
"Reading features..." <<
endl;
942 refineDict.
found(
"features")
943 ? refineDict.
lookup(
"features")
946 Info<<
"Read features in = "
955 <<
"Determining initial surface intersections" <<
nl
956 <<
"-----------------------------------------" <<
nl
970 Info<<
"Calculated surface intersections in = "
993 <<
"Adding patches for surface regions" <<
nl
994 <<
"----------------------------------" <<
nl
998 globalToMasterPatch.
setSize(surfaces.nRegions(), -1);
999 globalToSlavePatch.
setSize(surfaces.nRegions(), -1);
1002 <<
setw(6) <<
"Patch"
1003 <<
setw(20) <<
"Type"
1004 <<
setw(30) <<
"Region" <<
nl
1005 <<
setw(6) <<
"-----"
1006 <<
setw(20) <<
"----"
1009 const labelList& surfaceGeometry = surfaces.surfaces();
1012 forAll(surfaceGeometry, surfI)
1014 label geomI = surfaceGeometry[surfI];
1018 Info<< surfaces.names()[surfI] <<
':' <<
nl <<
nl;
1020 if (surfaces.surfZones()[surfI].faceZoneName().empty())
1025 label globalRegionI = surfaces.globalRegion(surfI, i);
1029 if (surfacePatchInfo.
set(globalRegionI))
1034 surfacePatchInfo[globalRegionI]
1040 patchInfo.
set(
"type", wallPolyPatch::typeName);
1052 <<
setw(30) << regNames[i] <<
nl;
1054 globalToMasterPatch[globalRegionI] =
patchi;
1055 globalToSlavePatch[globalRegionI] =
patchi;
1063 label globalRegionI = surfaces.globalRegion(surfI, i);
1069 if (surfacePatchInfo.
set(globalRegionI))
1074 surfacePatchInfo[globalRegionI]
1080 patchInfo.
set(
"type", wallPolyPatch::typeName);
1092 <<
setw(30) << regNames[i] <<
nl;
1094 globalToMasterPatch[globalRegionI] =
patchi;
1098 const word slaveName = regNames[i] +
"_slave";
1101 if (surfacePatchInfo.
set(globalRegionI))
1106 surfacePatchInfo[globalRegionI]
1112 patchInfo.
set(
"type", wallPolyPatch::typeName);
1124 <<
setw(30) << slaveName <<
nl;
1126 globalToSlavePatch[globalRegionI] =
patchi;
1133 Info<<
"Added patches in = "
1155 const Switch wantRefine(meshDict.lookup(
"castellatedMesh"));
1156 const Switch wantSnap(meshDict.lookup(
"snap"));
1157 const Switch wantLayers(meshDict.lookup(
"addLayers"));
1174 globalToMasterPatch,
1178 if (!overwrite && !debugLevel)
1183 refineDriver.doRefine
1188 refineParams.handleSnapProblems(),
1192 if (!keepPatches && !wantSnap && !wantLayers)
1194 removeZeroSizedPatches(mesh);
1205 Info<<
"Mesh refined in = "
1206 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1216 globalToMasterPatch,
1220 if (!overwrite && !debugLevel)
1226 scalar curvature = refineParams.curvature();
1227 scalar planarAngle = refineParams.planarAngle();
1238 if (!keepPatches && !wantLayers)
1240 removeZeroSizedPatches(mesh);
1251 Info<<
"Mesh snapped in = "
1252 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1268 globalToMasterPatch,
1275 (mesh.
nCells() >= refineParams.maxLocalCells()),
1280 if (!overwrite && !debugLevel)
1285 layerDriver.doLayers
1297 removeZeroSizedPatches(mesh);
1308 Info<<
"Layers added in = "
1309 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1315 Info<<
"Checking final mesh ..." <<
endl;
1326 Info<<
"Finished meshing with " << nErrors <<
" illegal faces"
1327 <<
" (concave, zero area or negative cell pyramid volume)"
1333 Info<<
"Finished meshing without any errors" <<
endl;
1338 if (surfaceSimplify)
1357 if (!isA<processorPolyPatch>(patch))
1369 "constant/triSurface/simplifiedSurface.stl"
1385 "internalCellCentres",
1394 cellCentres.write();
1398 Info<<
"Finished meshing in = "
Istream and Ostream manipulators taking arguments.
#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.
A HashTable with keys but without contents.
bool insert(const Key &key)
Insert a new entry.
bool set(const Key &, const T &newElmt)
Assign a new hashedEntry, overwriting existing entries.
bool erase(T *p)
Remove the specified element from the list and delete it.
A primitive field of type <Type> with automated input and output.
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...
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.
virtual Ostream & write(const char)=0
Write character.
A list of faces which address into the list of points.
static void mapCombineScatter(const List< commsStruct > &comms, Container &Values, const int tag, const label comm)
Scatter data. Reverse of combineGather.
static void mapCombineGather(const List< commsStruct > &comms, Container &Values, const CombineOp &cop, const int tag, const label comm)
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
bool set(const label) const
Is element set.
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.
fileName globalPath() const
Return the global path.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
fileName path() const
Explicitly inherit path from TimePaths to disambiguate from.
IOstream::streamFormat writeFormat() const
Default write format.
A List with indirect addressing.
static bool master(const label communicator=0)
Am I the master process.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static bool & parRun()
Is this a parallel run?
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
label size() const
Return the number of elements in the UPtrList.
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
bool optionFound(const word &opt) const
Return true if the named option is found.
const word & executable() const
Name of executable without the path.
IStringStream optionLookup(const word &opt) const
Return an IStringStream from the named option.
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
void set(T *)
Set pointer to that given.
A bounding box defined in terms of the points at its extremities.
Starts timing CPU usage and return elapsed time from start.
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
double elapsedCpuTime() const
Return CPU time (in seconds) from the start.
Abstract base class for decomposition.
static autoPtr< decompositionMethod > NewDistributor(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
static dictionary decomposeParDict(const Time &time)
Read and return the decomposeParDict.
A list of keyword definitions, which are a keyword followed by any number of values (e....
autoPtr< dictionary > clone() const
Construct and return clone.
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
void set(entry *)
Assign a new entry, overwrite any existing entry.
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
wordList toc() const
Return the table of contents.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
static const dictionary null
Null dictionary.
const word & name() const
Return const reference to name.
A keyword and a list of tokens is an 'entry'.
const keyType & keyword() const
Return keyword.
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
A class for handling file names.
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
Mesh data needed to do the Finite Volume discretisation.
const Time & time() const
Return the top-level database.
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
Simple container to keep together layer specific information.
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
static int readFlags(const Enum &namedEnum, const wordList &)
Helper: convert wordList into bit pattern using provided.
word name() const
Replacement for Time::name() : return oldInstance (if.
const fvMesh & mesh() const
Reference to mesh.
static const NamedEnum< IOwriteType, 5 > IOwriteTypeNames
void printMeshInfo(const bool, const string &) const
Print some mesh stats.
static const NamedEnum< IOdebugType, 5 > IOdebugTypeNames
static void checkCoupledFaceZones(const polyMesh &)
Helper function: check that face zones are synced.
label addMeshedPatch(const word &name, const dictionary &)
Add patch originating from meshing. Update meshedPatches_.
static const NamedEnum< IOoutputType, 1 > IOoutputTypeNames
bool write() const
Write mesh and all data.
static writeType writeLevel()
Get/set write level.
static outputType outputLevel()
Get/set output level.
static bool checkMesh(const bool report, const polyMesh &mesh, const dictionary &dict, labelHashSet &wrongFaces)
Check mesh with mesh settings in dict. Collects incorrect faces.
const Time & time() const
Return time.
label index() const
Return the index of this patch in the boundaryMesh.
const word & name() const
Return name.
wordList types() const
Return a list of patch types.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
label findPatchID(const word &patchName) const
Find patch index given a name.
bool checkParallelSync(const bool report=false) const
Check whether all procs have all patches and in same order. Return.
Mesh consisting of general polyhedral cells.
static word defaultRegion
Return the default region name.
virtual const faceList & faces() const
Return raw faces.
const globalMeshData & globalData() const
Return parallel info.
label nSolutionD() const
Return the number of valid solved-for dimensions in the mesh.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
virtual const pointField & points() const
Return raw points.
const boundBox & bounds() const
Return mesh bounding box.
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.
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
const vectorField & cellCentres() const
Encapsulates queries for features.
Simple container to keep together refinement specific information.
Encapsulates queries for volume refinement ('refine all cells within shell').
Container for data on surfaces used for surface-driven refinement. Contains all the data about the le...
const wordList & names() const
Names of surfaces.
const labelList & minLevel() const
From global region number to refinement level.
const labelList & maxLevel() const
From global region number to refinement level.
const labelList & surfaces() const
label globalRegion(const label surfi, const label regioni) const
From surface and region on surface to global region.
const labelList & gapLevel() const
From global region number to small gap refinement level.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
static const word & geometryDir()
Return the geometry directory name.
Container for searchableSurfaces.
label checkGeometry(const scalar maxRatio, const scalar tolerance, const scalar minQuality, const bool report) const
All geometric checks. Return number of failed checks.
const wordList & names() const
const List< wordList > & regionNames() const
label checkTopology(const bool report) const
All topological checks. Return number of failed checks.
void writeStats(const List< wordList > &, Ostream &) const
Write some stats.
Simple container to keep together snap specific information.
All to do with adding layers.
All to do with snapping to surface.
An identifier for a surface zone on a meshed surface.
Implements a timeout mechanism via sigalarm.
A class for handling words, derived from string.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
int main(int argc, char *argv[])
const polyBoundaryMesh & bMesh
errorManipArg< error, int > exit(error &err, const int errNo=1)
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
IOdictionary systemDict(const word &dictName, const argList &args, const objectRegistry &ob, const word ®ionName=polyMesh::defaultRegion)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Omanip< int > setw(const int i)
vectorField pointField
pointField is a vectorField.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
label checkGeometry(const polyMesh &mesh, const bool allGeometry, const autoPtr< surfaceWriter > &, const autoPtr< setWriter > &)
Check the geometry.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar log(const dimensionedScalar &ds)
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Ostream & indent(Ostream &os)
Indent stream.
wordList patchTypes(nPatches)
List< treeBoundBox > meshBb(1, treeBoundBox(boundBox(coarseMesh.points(), false)).extend(1e-3))
labelHashSet includePatches
const Foam::wordList regionNames(args.optionFound("allRegions") ? runTime .controlDict().subDict("regionSolvers").toc() :wordList(1, args.optionFound("region") ? args.optionRead< word >("region") :polyMesh::defaultRegion))
Foam::argList args(argc, argv)