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)."
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"
668 Info<<
"Read mesh in = "
680 <<
"Mesh provided is not fully 3D"
681 " as required for mesh relaxation after snapping" <<
nl
682 <<
"Convert all empty patches to appropriate types for a 3D mesh,"
709 const scalar mergeDist = getMergeDistance
712 meshDict.lookup<scalar>(
"mergeTolerance")
715 const Switch keepPatches(meshDict.lookupOrDefault(
"keepPatches",
false));
727 decomposeDict.
add(
"method",
"none");
728 decomposeDict.
add(
"numberOfSubdomains", 1);
739 meshDict.lookupOrDefault<
label>
747 if (meshDict.readIfPresent(
"debugFlags", flags))
761 meshRefinement::debug = debugLevel;
762 snappyRefineDriver::debug = debugLevel;
763 snappySnapDriver::debug = debugLevel;
764 snappyLayerDriver::debug = debugLevel;
770 if (meshDict.readIfPresent(
"writeFlags", flags))
789 if (meshDict.readIfPresent(
"outputFlags", flags))
821 meshDict.lookupOrDefault(
"singleRegionName",
true)
828 Info<<
"Reading refinement surfaces..." <<
endl;
833 refineDict.
found(
"refinementSurfaces")
834 ? refineDict.
subDict(
"refinementSurfaces")
839 Info<<
"Read refinement surfaces in = "
851 const labelList& surfaceGeometry = surfaces.surfaces();
852 forAll(surfaceGeometry, surfI)
854 label geomI = surfaceGeometry[surfI];
860 label globalRegionI = surfaces.globalRegion(surfI, regionI);
862 if (patchInfo.
set(globalRegionI))
865 word(patchInfo[globalRegionI].lookup(
"type"));
869 patchTypes[geomI][regionI] = wallPolyPatch::typeName;
895 Info<<
"Reading refinement regions..." <<
endl;
899 refineDict.
found(
"refinementRegions")
900 ? refineDict.
subDict(
"refinementRegions")
903 Info<<
"Read refinement regions in = "
911 Info<<
"Reading features..." <<
endl;
915 refineDict.
found(
"features")
916 ? refineDict.
lookup(
"features")
919 Info<<
"Read features in = "
928 <<
"Determining initial surface intersections" <<
nl
929 <<
"-----------------------------------------" <<
nl
943 Info<<
"Calculated surface intersections in = "
966 <<
"Adding patches for surface regions" <<
nl
967 <<
"----------------------------------" <<
nl
971 globalToMasterPatch.
setSize(surfaces.nRegions(), -1);
972 globalToSlavePatch.
setSize(surfaces.nRegions(), -1);
975 <<
setw(6) <<
"Patch"
976 <<
setw(20) <<
"Type"
977 <<
setw(30) <<
"Region" <<
nl
978 <<
setw(6) <<
"-----"
979 <<
setw(20) <<
"----"
982 const labelList& surfaceGeometry = surfaces.surfaces();
985 forAll(surfaceGeometry, surfI)
987 label geomI = surfaceGeometry[surfI];
991 Info<< surfaces.names()[surfI] <<
':' <<
nl <<
nl;
993 if (surfaces.surfZones()[surfI].faceZoneName().empty())
998 label globalRegionI = surfaces.globalRegion(surfI, i);
1002 if (surfacePatchInfo.
set(globalRegionI))
1007 surfacePatchInfo[globalRegionI]
1013 patchInfo.set(
"type", wallPolyPatch::typeName);
1025 <<
setw(30) << regNames[i] <<
nl;
1027 globalToMasterPatch[globalRegionI] =
patchi;
1028 globalToSlavePatch[globalRegionI] =
patchi;
1036 label globalRegionI = surfaces.globalRegion(surfI, i);
1042 if (surfacePatchInfo.
set(globalRegionI))
1047 surfacePatchInfo[globalRegionI]
1053 patchInfo.set(
"type", wallPolyPatch::typeName);
1065 <<
setw(30) << regNames[i] <<
nl;
1067 globalToMasterPatch[globalRegionI] =
patchi;
1071 const word slaveName = regNames[i] +
"_slave";
1074 if (surfacePatchInfo.
set(globalRegionI))
1079 surfacePatchInfo[globalRegionI]
1085 patchInfo.set(
"type", wallPolyPatch::typeName);
1097 <<
setw(30) << slaveName <<
nl;
1099 globalToSlavePatch[globalRegionI] =
patchi;
1109 Info<<
"Added patches in = "
1131 const Switch wantRefine(meshDict.lookup(
"castellatedMesh"));
1132 const Switch wantSnap(meshDict.lookup(
"snap"));
1133 const Switch wantLayers(meshDict.lookup(
"addLayers"));
1150 globalToMasterPatch,
1159 refineDriver.doRefine
1164 refineParams.handleSnapProblems(),
1168 if (!keepPatches && !wantSnap && !wantLayers)
1170 removeZeroSizedPatches(
mesh);
1181 Info<<
"Mesh refined in = "
1182 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1192 globalToMasterPatch,
1202 scalar curvature = refineParams.curvature();
1203 scalar planarAngle = refineParams.planarAngle();
1214 if (!keepPatches && !wantLayers)
1216 removeZeroSizedPatches(
mesh);
1227 Info<<
"Mesh snapped in = "
1228 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1244 globalToMasterPatch,
1251 (
mesh.
nCells() >= refineParams.maxLocalCells()),
1261 layerDriver.doLayers
1273 removeZeroSizedPatches(
mesh);
1284 Info<<
"Layers added in = "
1285 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1291 Info<<
"Checking final mesh ..." <<
endl;
1302 Info<<
"Finished meshing with " << nErrors <<
" illegal faces"
1303 <<
" (concave, zero area or negative cell pyramid volume)"
1309 Info<<
"Finished meshing without any errors" <<
endl;
1314 if (surfaceSimplify)
1333 if (!isA<processorPolyPatch>(patch))
1345 "constant/triSurface/simplifiedSurface.stl"
1361 "internalCellCentres",
1370 cellCentres.write();
1374 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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
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.
T lookupOrDefault(const word &, const T &, const bool writeDefault=writeOptionalEntries > 0) const
Find and return a T, if not found return the given default.
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.
void addedMeshedPatches()
Complete adding patches originating from meshing.
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 patch set 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.
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.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
static const word & geometryDir()
Return the geometry directory name.
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.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#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.
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)
void pow(LagrangianPatchField< typename powProduct< Type, r >::type > &f, const LagrangianPatchField< Type > &f1)
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)
IOdictionary systemDict(const word &dictName, const argList &args, const objectRegistry &ob, const word ®ionName=polyMesh::defaultRegion, const fileName &path=fileName::null)
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)