61 label sizeCoeffToRefinement
63 const scalar level0Coeff,
64 const scalar sizeCoeff
67 return round(::
log(level0Coeff/sizeCoeff)/::
log(2));
76 const label gapLevelIncrement,
77 const scalar level0Coeff
86 const word& geomName = allGeometry.
names()[geomI];
88 if (surfacesDict.
found(geomName))
115 const word& geomName = allGeometry.
names()[geomI];
124 names[surfI] = geomName;
125 surfaces[surfI] = geomI;
132 const word scsFuncName =
133 shapeDict.
lookup(
"surfaceCellSizeFunction");
137 const scalar surfaceCellSize =
138 scsDict.
lookup<scalar>(
"surfaceCellSizeCoeff");
140 const label refLevel = sizeCoeffToRefinement
146 globalMinLevel[surfI] = refLevel;
147 globalMaxLevel[surfI] = refLevel;
148 globalLevelIncr[surfI] = gapLevelIncrement;
155 if (shapeDict.
found(
"patchInfo"))
167 if (shapeDict.
found(
"regions"))
171 allGeometry[surfaces[surfI]].regions();
183 if (regionDict.
found(
"patchInfo"))
185 regionPatchInfo[surfI].insert
196 if (shapeDict.
found(
"regions"))
201 allGeometry[surfaces[surfI]].regions();
208 shapeControlRegionsDict.
subDict
213 const word scsFuncName =
214 shapeControlRegionDict.
lookup
216 "surfaceCellSizeFunction"
221 scsFuncName +
"Coeffs"
224 const scalar surfaceCellSize =
225 scsDict.
lookup<scalar>(
"surfaceCellSizeCoeff");
227 const label refLevel = sizeCoeffToRefinement
233 regionMinLevel[surfI].insert(regionI, refLevel);
234 regionMaxLevel[surfI].insert(regionI, refLevel);
235 regionLevelIncr[surfI].insert(regionI, 0);
249 regionOffset[surfI] = nRegions;
250 nRegions += allGeometry[surfaces[surfI]].regions().
size();
259 forAll(globalMinLevel, surfI)
261 label nRegions = allGeometry[surfaces[surfI]].regions().
size();
264 for (
label i = 0; i < nRegions; i++)
266 label globalRegionI = regionOffset[surfI] + i;
267 minLevel[globalRegionI] = globalMinLevel[surfI];
268 maxLevel[globalRegionI] = globalMaxLevel[surfI];
269 gapLevel[globalRegionI] =
270 maxLevel[globalRegionI]
271 + globalLevelIncr[surfI];
273 if (globalPatchInfo.set(surfI))
278 globalPatchInfo[surfI].
clone()
286 label globalRegionI = regionOffset[surfI] + iter.key();
288 minLevel[globalRegionI] = iter();
289 maxLevel[globalRegionI] = regionMaxLevel[surfI][iter.key()];
290 gapLevel[globalRegionI] =
291 maxLevel[globalRegionI]
292 + regionLevelIncr[surfI][iter.key()];
298 label globalRegionI = regionOffset[surfI] + iter.key();
299 patchInfo.
set(globalRegionI, iter()().
clone());
337 <<
setw(10) <<
"Min Level"
338 <<
setw(10) <<
"Max Level"
339 <<
setw(10) <<
"Gap Level" <<
nl
340 <<
setw(maxLen) <<
"------"
341 <<
setw(10) <<
"---------"
342 <<
setw(10) <<
"---------"
386 patchSize.insert(pp.
name(), pp.
size());
396 label sz = compactZoneID.size();
397 compactZoneID.insert(iter.key(), sz);
409 patchToCompactZone[
patchi] = iter();
421 faceLabels.append(pp.
start()+i);
422 compactZones.append(patchToCompactZone[pp.
index()]);
439 allBoundary.meshPoints(),
440 allBoundary.meshPointMap(),
471 pointField allPoints = ListListOps::combine<pointField>
476 gatheredPoints.clear();
478 faceList allFaces = ListListOps::combine<faceList>
483 gatheredFaces.clear();
485 labelList allZones = ListListOps::combine<labelList>
490 gatheredZones.clear();
498 Info<<
"surfZone " << iter() <<
" : " << surfZones[iter()].name()
513 Info<<
"Writing merged surface to "
522 scalar getMergeDistance(
const polyMesh& mesh,
const scalar mergeTol)
525 scalar mergeDist = mergeTol *
meshBb.mag();
528 <<
"Overall mesh bounding box : " <<
meshBb <<
nl
529 <<
"Relative tolerance : " << mergeTol <<
nl
530 <<
"Absolute matching distance : " << mergeDist <<
nl
542 if (mergeTol < writeTol)
545 <<
"Your current settings specify ASCII writing with "
547 <<
"Your merging tolerance (" << mergeTol
548 <<
") is finer than this." <<
nl
549 <<
"Change to binary writeFormat, "
550 <<
"or increase the writePrecision" <<
endl
551 <<
"or adjust the merge tolerance (mergeTol)."
560 void removeZeroSizedPatches(
fvMesh& mesh)
578 oldToNew[
patchi] = newPatchi++;
582 const label nKeepPatches = newPatchi;
585 if (nKeepPatches != pbm.
size())
592 if (oldToNew[
patchi] == -1)
595 <<
" type " << pbm[
patchi].type()
597 oldToNew[
patchi] = newPatchi++;
620 Info<<
"Writing mesh to time " << meshRefiner.
name() <<
endl;
628 Info<<
"Wrote mesh in = "
633 int main(
int argc,
char *argv[])
640 "check all surface geometry for quality"
646 "simplify the surface using snappyHexMesh starting from a boundBox"
651 "(patch0 .. patchN)",
652 "only triangulate selected patches (wildcards supported)"
658 "name of the file to save the simplified surface to"
667 Info<<
"Read mesh in = "
679 <<
"Mesh provided is not fully 3D"
680 " as required for mesh relaxation after snapping" <<
nl
681 <<
"Convert all empty patches to appropriate types for a 3D mesh,"
708 const scalar mergeDist = getMergeDistance
711 meshDict.lookup<scalar>(
"mergeTolerance")
714 const Switch keepPatches(meshDict.lookupOrDefault(
"keepPatches",
false));
726 decomposeDict.
add(
"method",
"none");
727 decomposeDict.
add(
"numberOfSubdomains", 1);
738 meshDict.lookupOrDefault<
label>
746 if (meshDict.readIfPresent(
"debugFlags", flags))
760 meshRefinement::debug = debugLevel;
761 snappyRefineDriver::debug = debugLevel;
762 snappySnapDriver::debug = debugLevel;
763 snappyLayerDriver::debug = debugLevel;
769 if (meshDict.readIfPresent(
"writeFlags", flags))
788 if (meshDict.readIfPresent(
"outputFlags", flags))
820 meshDict.lookupOrDefault(
"singleRegionName",
true)
827 Info<<
"Reading refinement surfaces..." <<
endl;
832 refineDict.
found(
"refinementSurfaces")
833 ? refineDict.
subDict(
"refinementSurfaces")
838 Info<<
"Read refinement surfaces in = "
850 const labelList& surfaceGeometry = surfaces.surfaces();
851 forAll(surfaceGeometry, surfI)
853 label geomI = surfaceGeometry[surfI];
859 label globalRegionI = surfaces.globalRegion(surfI, regionI);
861 if (patchInfo.
set(globalRegionI))
864 word(patchInfo[globalRegionI].lookup(
"type"));
868 patchTypes[geomI][regionI] = wallPolyPatch::typeName;
894 Info<<
"Reading refinement regions..." <<
endl;
898 refineDict.
found(
"refinementRegions")
899 ? refineDict.
subDict(
"refinementRegions")
902 Info<<
"Read refinement regions in = "
910 Info<<
"Reading features..." <<
endl;
914 refineDict.
found(
"features")
915 ? refineDict.
lookup(
"features")
918 Info<<
"Read features in = "
927 <<
"Determining initial surface intersections" <<
nl
928 <<
"-----------------------------------------" <<
nl
942 Info<<
"Calculated surface intersections in = "
965 <<
"Adding patches for surface regions" <<
nl
966 <<
"----------------------------------" <<
nl
970 globalToMasterPatch.
setSize(surfaces.nRegions(), -1);
971 globalToSlavePatch.
setSize(surfaces.nRegions(), -1);
974 <<
setw(6) <<
"Patch"
975 <<
setw(20) <<
"Type"
976 <<
setw(30) <<
"Region" <<
nl
977 <<
setw(6) <<
"-----"
978 <<
setw(20) <<
"----"
981 const labelList& surfaceGeometry = surfaces.surfaces();
984 forAll(surfaceGeometry, surfI)
986 label geomI = surfaceGeometry[surfI];
990 Info<< surfaces.names()[surfI] <<
':' <<
nl <<
nl;
992 if (surfaces.surfZones()[surfI].faceZoneName().empty())
997 label globalRegionI = surfaces.globalRegion(surfI, i);
1001 if (surfacePatchInfo.
set(globalRegionI))
1006 surfacePatchInfo[globalRegionI]
1012 patchInfo.
set(
"type", wallPolyPatch::typeName);
1024 <<
setw(30) << regNames[i] <<
nl;
1026 globalToMasterPatch[globalRegionI] =
patchi;
1027 globalToSlavePatch[globalRegionI] =
patchi;
1035 label globalRegionI = surfaces.globalRegion(surfI, i);
1041 if (surfacePatchInfo.
set(globalRegionI))
1046 surfacePatchInfo[globalRegionI]
1052 patchInfo.
set(
"type", wallPolyPatch::typeName);
1064 <<
setw(30) << regNames[i] <<
nl;
1066 globalToMasterPatch[globalRegionI] =
patchi;
1070 const word slaveName = regNames[i] +
"_slave";
1073 if (surfacePatchInfo.
set(globalRegionI))
1078 surfacePatchInfo[globalRegionI]
1084 patchInfo.
set(
"type", wallPolyPatch::typeName);
1096 <<
setw(30) << slaveName <<
nl;
1098 globalToSlavePatch[globalRegionI] =
patchi;
1105 Info<<
"Added patches in = "
1127 const Switch wantRefine(meshDict.lookup(
"castellatedMesh"));
1128 const Switch wantSnap(meshDict.lookup(
"snap"));
1129 const Switch wantLayers(meshDict.lookup(
"addLayers"));
1146 globalToMasterPatch,
1150 if (!overwrite && !debugLevel)
1155 refineDriver.doRefine
1160 refineParams.handleSnapProblems(),
1164 if (!keepPatches && !wantSnap && !wantLayers)
1166 removeZeroSizedPatches(mesh);
1177 Info<<
"Mesh refined in = "
1178 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1188 globalToMasterPatch,
1192 if (!overwrite && !debugLevel)
1198 scalar curvature = refineParams.curvature();
1199 scalar planarAngle = refineParams.planarAngle();
1210 if (!keepPatches && !wantLayers)
1212 removeZeroSizedPatches(mesh);
1223 Info<<
"Mesh snapped in = "
1224 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1240 globalToMasterPatch,
1247 (mesh.
nCells() >= refineParams.maxLocalCells()),
1252 if (!overwrite && !debugLevel)
1257 layerDriver.doLayers
1269 removeZeroSizedPatches(mesh);
1280 Info<<
"Layers added in = "
1281 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1287 Info<<
"Checking final mesh ..." <<
endl;
1298 Info<<
"Finished meshing with " << nErrors <<
" illegal faces"
1299 <<
" (concave, zero area or negative cell pyramid volume)"
1305 Info<<
"Finished meshing without any errors" <<
endl;
1310 if (surfaceSimplify)
1329 if (!isA<processorPolyPatch>(patch))
1341 "constant/triSurface/simplifiedSurface.stl"
1357 "internalCellCentres",
1366 cellCentres.write();
1370 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 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.
label size() const
Return the number of elements in the UList.
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.
static void removeOption(const word &opt)
Remove option from validOptions and from optionUsage.
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 IOdictionary decomposeParDict(const Time &time)
Read and return the decomposeParDict.
static autoPtr< decompositionMethod > NewDistributor(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
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, if not found return the given default.
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.
const Time & time() const
Return time.
label index() const
Return the index of this patch in the boundaryMesh.
const word & name() const
Return name.
label findIndex(const word &patchName) const
Find patch index given a 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 indices corresponding to the given names.
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.
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
Functions for checking mesh topology and geometry.
bool checkMesh(const bool report, const polyMesh &mesh, const dictionary &dict, const labelList &checkFaces, const List< labelPair > &baffles, labelHashSet &wrongFaces)
Check (subset of mesh including baffles) with mesh settings in dict.
label checkGeometry(const polyMesh &mesh, const bool allGeometry, const scalar nonOrthThreshold, const scalar skewThreshold, const autoPtr< surfaceWriter > &, const autoPtr< setWriter > &)
Check the geometry.
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.
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)