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();
179 forAll(regionNames, regionI)
181 if (regionsDict.
found(regionNames[regionI]))
189 if (regionDict.
found(
"patchInfo"))
191 regionPatchInfo[surfI].insert
202 if (shapeDict.
found(
"regions"))
207 allGeometry[surfaces[surfI]].regions();
209 forAll(regionNames, regionI)
211 if (shapeControlRegionsDict.
found(regionNames[regionI]))
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());
335 forAll(regionNames, regionI)
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) <<
"---------" 359 forAll(regionNames, regionI)
363 Info<<
setw(maxLen) << regionNames[regionI]
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(),
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()
522 ? runTime.
path()/
".."/outFileName
523 : runTime.
path()/outFileName
525 globalCasePath.
clean();
527 Info<<
"Writing merged surface to " << globalCasePath <<
endl;
529 sortedFace.
write(globalCasePath);
535 scalar getMergeDistance(
const polyMesh& mesh,
const scalar mergeTol)
538 scalar mergeDist = mergeTol * meshBb.
mag();
541 <<
"Overall mesh bounding box : " << meshBb << nl
542 <<
"Relative tolerance : " << mergeTol << nl
543 <<
"Absolute matching distance : " << mergeDist << nl
555 if (mergeTol < writeTol)
558 <<
"Your current settings specify ASCII writing with " 560 <<
"Your merging tolerance (" << mergeTol
561 <<
") is finer than this." << nl
562 <<
"Change to binary writeFormat, " 563 <<
"or increase the writePrecision" << endl
564 <<
"or adjust the merge tolerance (mergeTol)." 573 void removeZeroSizedPatches(
fvMesh& mesh)
589 if (!isA<processorPolyPatch>(pp))
593 isA<coupledPolyPatch>(pp)
598 oldToNew[
patchi] = newPatchi++;
607 if (isA<processorPolyPatch>(pp))
609 oldToNew[
patchi] = newPatchi++;
614 const label nKeepPatches = newPatchi;
617 if (nKeepPatches != pbm.
size())
620 <<
"Removing zero-sized patches:" << endl <<
incrIndent;
624 if (oldToNew[patchi] == -1)
627 <<
" type " << pbm[
patchi].type()
628 <<
" at position " << patchi <<
endl;
629 oldToNew[
patchi] = newPatchi++;
660 Info<<
"Wrote mesh in = " 665 int main(
int argc,
char *argv[])
671 "check all surface geometry for quality" 677 "simplify the surface using snappyHexMesh starting from a boundBox" 682 "(patch0 .. patchN)",
683 "only triangulate selected patches (wildcards supported)" 689 "name of the file to save the simplified surface to" 705 <<
"Create mesh for time = " 725 Info<<
"Read mesh in = " 755 const scalar mergeDist = getMergeDistance
758 meshDict.
lookup<scalar>(
"mergeTolerance")
761 const Switch keepPatches(meshDict.lookupOrDefault(
"keepPatches",
false));
784 decomposeDict.add(
"method",
"none");
785 decomposeDict.add(
"numberOfSubdomains", 1);
796 meshDict.lookupOrDefault<
label>
804 if (meshDict.readIfPresent(
"debugFlags", flags))
818 meshRefinement::debug = debugLevel;
819 snappyRefineDriver::debug = debugLevel;
820 snappySnapDriver::debug = debugLevel;
821 snappyLayerDriver::debug = debugLevel;
827 if (meshDict.readIfPresent(
"writeFlags", flags))
846 if (meshDict.readIfPresent(
"outputFlags", flags))
888 Info<<
"Reading refinement surfaces." <<
endl;
907 "geometryToConformTo" 911 foamyHexMeshDict.
subDict(
"motionControl");
914 motionDict.
subDict(
"shapeControlFunctions");
917 const scalar defaultCellSize =
918 motionDict.
lookup<scalar>(
"defaultCellSize");
920 const scalar initialCellSize =
::pow(
meshPtr().V()[0], 1.0/3.0);
928 createRefinementSurfaces
934 initialCellSize/defaultCellSize
944 refineDict.
subDict(
"refinementSurfaces"),
949 Info<<
"Read refinement surfaces in = " 965 forAll(surfaceGeometry, surfI)
967 label geomI = surfaceGeometry[surfI];
975 if (patchInfo.set(globalRegionI))
978 word(patchInfo[globalRegionI].
lookup(
"type"));
982 patchTypes[geomI][regionI] = wallPolyPatch::typeName;
1009 Info<<
"Reading refinement shells." <<
endl;
1013 refineDict.
subDict(
"refinementRegions")
1015 Info<<
"Read refinement shells in = " 1019 Info<<
"Setting refinement level of surface to be consistent" 1020 <<
" with shells." <<
endl;
1022 Info<<
"Checked shell refinement in = " 1029 Info<<
"Reading features." <<
endl;
1033 refineDict.
lookup(
"features")
1035 Info<<
"Read features in = " 1044 <<
"Determining initial surface intersections" << nl
1045 <<
"-----------------------------------------" << nl
1058 Info<<
"Calculated surface intersections in = " 1081 <<
"Adding patches for surface regions" << nl
1082 <<
"----------------------------------" << nl
1090 <<
setw(6) <<
"Patch" 1091 <<
setw(20) <<
"Type" 1092 <<
setw(30) <<
"Region" << nl
1093 <<
setw(6) <<
"-----" 1094 <<
setw(20) <<
"----" 1100 forAll(surfaceGeometry, surfI)
1102 label geomI = surfaceGeometry[surfI];
1106 Info<< surfaces.
names()[surfI] <<
':' << nl <<
nl;
1108 if (surfaces.
surfZones()[surfI].faceZoneName().empty())
1117 if (surfacePatchInfo.
set(globalRegionI))
1122 surfacePatchInfo[globalRegionI]
1128 patchInfo.
set(
"type", wallPolyPatch::typeName);
1138 <<
setw(6) << patchi
1140 <<
setw(30) << regNames[i] <<
nl;
1142 globalToMasterPatch[globalRegionI] =
patchi;
1143 globalToSlavePatch[globalRegionI] =
patchi;
1157 if (surfacePatchInfo.
set(globalRegionI))
1162 surfacePatchInfo[globalRegionI]
1168 patchInfo.
set(
"type", wallPolyPatch::typeName);
1178 <<
setw(6) << patchi
1180 <<
setw(30) << regNames[i] <<
nl;
1182 globalToMasterPatch[globalRegionI] =
patchi;
1186 const word slaveName = regNames[i] +
"_slave";
1189 if (surfacePatchInfo.
set(globalRegionI))
1194 surfacePatchInfo[globalRegionI]
1200 patchInfo.
set(
"type", wallPolyPatch::typeName);
1210 <<
setw(6) << patchi
1212 <<
setw(30) << slaveName <<
nl;
1214 globalToSlavePatch[globalRegionI] =
patchi;
1221 Info<<
"Added patches in = " 1242 <<
"You have selected decomposition method " 1243 << decomposer.typeName
1244 <<
" which is not parallel aware." << endl
1245 <<
"Please select one that is (hierarchical, ptscotch)" 1259 const Switch wantRefine(meshDict.lookup(
"castellatedMesh"));
1260 const Switch wantSnap(meshDict.lookup(
"snap"));
1261 const Switch wantLayers(meshDict.lookup(
"addLayers"));
1282 globalToMasterPatch,
1287 if (!overwrite && !debugLevel)
1293 refineDriver.doRefine
1298 refineParams.handleSnapProblems(),
1303 if (!keepPatches && !wantSnap && !wantLayers)
1305 removeZeroSizedPatches(mesh);
1316 Info<<
"Mesh refined in = " 1327 globalToMasterPatch,
1331 if (!overwrite && !debugLevel)
1337 scalar curvature = refineParams.curvature();
1338 scalar planarAngle = refineParams.planarAngle();
1349 if (!keepPatches && !wantLayers)
1351 removeZeroSizedPatches(mesh);
1362 Info<<
"Mesh snapped in = " 1373 globalToMasterPatch,
1380 (mesh.
nCells() >= refineParams.maxLocalCells()),
1385 if (!overwrite && !debugLevel)
1390 layerDriver.doLayers
1402 removeZeroSizedPatches(mesh);
1413 Info<<
"Layers added in = " 1420 Info<<
"Checking final mesh ..." <<
endl;
1431 Info<<
"Finished meshing with " << nErrors <<
" illegal faces" 1432 <<
" (concave, zero area or negative cell pyramid volume)" 1438 Info<<
"Finished meshing without any errors" <<
endl;
1443 if (surfaceSimplify)
1462 if (!isA<processorPolyPatch>(patch))
1464 includePatches.
insert(patchi);
1474 "constant/triSurface/simplifiedSurface.stl" 1490 "internalCellCentres",
1499 cellCentres.
write();
1503 Info<<
"Finished meshing in = " static bool checkMesh(const bool report, const polyMesh &mesh, const dictionary &dict, labelHashSet &wrongFaces)
Check mesh with mesh settings in dict. Collects incorrect faces.
A surface geometry mesh, in which the surface zone information is conveyed by the 'zoneId' associated...
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
void printMeshInfo(const bool, const string &) const
Print some mesh stats.
A HashTable with keys but without contents.
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
#define forAll(list, i)
Loop across all elements in list.
bool processorCase() const
Return true if this is a processor case.
fileName path() const
Return path.
Simple container to keep together layer specific information.
virtual Ostream & write(const char)=0
Write character.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const word & name() const
Return name.
const word & name() const
Return name.
A class for handling file names.
const labelList & surfaces() const
Ostream & indent(Ostream &os)
Indent stream.
virtual bool parallelAware() const =0
Is method parallel aware (i.e. does it synchronize domains across.
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
bool set(const label) const
Is element set.
An identifier for a surface zone on a meshed surface.
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
const keyType & keyword() const
Return keyword.
label checkTopology(const bool report) const
All topological checks. Return number of failed checks.
dimensionedScalar log(const dimensionedScalar &ds)
errorManipArg< error, int > exit(error &err, const int errNo=1)
void off()
Switch the function objects off.
A list of keyword definitions, which are a keyword followed by any number of values (e...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool clean()
Cleanup file name.
static unsigned int defaultPrecision()
Return the default precision.
static const NamedEnum< IOoutputType, 1 > IOoutputTypeNames
void size(const label)
Override size to be inconsistent with allocated storage.
wordList patchTypes(nPatches)
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static word defaultRegion
Return the default region name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool optionFound(const word &opt) const
Return true if the named option is found.
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.
static bool master(const label communicator=0)
Am I the master process.
static writeType writeLevel()
Get/set write level.
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
label findPatchID(const word &patchName) const
Find patch index given a name.
A bounding box defined in terms of the points at its extremities.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
const labelList & minLevel() const
From global region number to refinement level.
const Time & time() const
Return the top-level database.
Simple container to keep together refinement specific information.
bool insert(const Key &key)
Insert a new entry.
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.
bool erase(T *p)
Remove the specified element from the list and delete it.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
autoPtr< dictionary > clone() const
Construct and return clone.
wordList toc() const
Return the table of contents.
const fvMesh & mesh() const
Reference to mesh.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Container for data on surfaces used for surface-driven refinement. Contains all the data about the le...
virtual const pointField & points() const
Return raw points.
static void mapCombineScatter(const List< commsStruct > &comms, Container &Values, const int tag, const label comm)
Scatter data. Reverse of combineGather.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Encapsulates queries for features.
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
A list of faces which address into the list of points.
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
vectorField pointField
pointField is a vectorField.
stressControl lookup("compactNormalStress") >> compactNormalStress
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
A class for handling words, derived from string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Simple container to keep together snap specific information.
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
const labelList & gapLevel() const
From global region number to small gap refinement level.
const List< wordList > & regionNames() const
scalar mag() const
The magnitude of the bounding box span.
const word & constant() const
Return constant name.
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
static const NamedEnum< IOdebugType, 5 > IOdebugTypeNames
static void checkCoupledFaceZones(const polyMesh &)
Helper function: check that face zones are synced.
Container for searchableSurfaces.
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
const globalMeshData & globalData() const
Return parallel info.
const word dictName("particleTrackDict")
Abstract base class for decomposition.
Encapsulates queries for volume refinement ('refine all cells within shell').
static void mapCombineGather(const List< commsStruct > &comms, Container &Values, const CombineOp &cop, const int tag, const label comm)
virtual const faceList & faces() const
Return raw faces.
const PtrList< surfaceZonesInfo > & surfZones() const
const vectorField & cellCentres() const
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
word timeName() const
Replacement for Time::timeName() : return oldInstance (if.
const word & system() const
Return system name.
static autoPtr< decompositionMethod > New(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
Istream and Ostream manipulators taking arguments.
bool checkParallelSync(const bool report=false) const
Check whether all procs have all patches and in same order. Return.
IOstream::streamFormat writeFormat() const
Default write format.
const Time & time() const
Return time.
static int readFlags(const Enum &namedEnum, const wordList &)
Helper: convert wordList into bit pattern using provided.
label addMeshedPatch(const word &name, const dictionary &)
Add patch originating from meshing. Update meshedPatches_.
void set(T *)
Set pointer to that given.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
labelHashSet includePatches
All to do with adding layers.
static outputType outputLevel()
Get/set output level.
IOobject dictIO(dictName, runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE)
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
label size() const
Return the number of elements in the UPtrList.
label checkGeometry(const scalar maxRatio, const scalar tolerance, const autoPtr< writer< scalar >> &setWriter, const scalar minQuality, const bool report) const
All geometric checks. Return number of failed checks.
All to do with snapping to surface.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
void setSize(const label)
Reset size of List.
const boundBox & bounds() const
Return mesh bounding box.
static bool & parRun()
Is this a parallel run?
const wordList & names() const
Names of surfaces.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
double elapsedCpuTime() const
Return CPU time (in seconds) from the start.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
const functionObjectList & functionObjects() const
Return the list of function objects.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
const wordList & names() const
Mesh data needed to do the Finite Volume discretisation.
A List with indirect addressing.
label index() const
Return the index of this patch in the boundaryMesh.
label start() const
Return start label of this patch in the polyMesh face list.
label globalRegion(const label surfI, const label regionI) const
From surface and region on surface to global region.
void set(entry *)
Assign a new entry, overwrite any existing entry.
const PtrList< dictionary > & patchInfo() const
From global region number to patch type.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
const doubleScalar e
Elementary charge.
Mesh consisting of general polyhedral cells.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Omanip< int > setw(const int i)
Starts timing CPU usage and return elapsed time from start.
List< wordRe > wordReList
A List of wordRe (word or regular expression)
bool write() const
Write mesh and all data.
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.
void setMinLevelFields(const shellSurfaces &shells)
Calculate minLevelFields.
Foam::argList args(argc, argv)
void writeStats(const List< wordList > &, Ostream &) const
Write some stats.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
A primitive field of type <T> with automated input and output.
A keyword and a list of tokens is an 'entry'.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
static const NamedEnum< IOwriteType, 5 > IOwriteTypeNames
const labelList & maxLevel() const
From global region number to refinement level.
IStringStream optionLookup(const word &opt) const
Return an IStringStream from the named option.