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()
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)
582 if (!isA<processorPolyPatch>(pp))
586 isA<coupledPolyPatch>(pp)
591 oldToNew[
patchi] = newPatchi++;
600 if (isA<processorPolyPatch>(pp))
602 oldToNew[
patchi] = newPatchi++;
607 const label nKeepPatches = newPatchi;
610 if (nKeepPatches != pbm.
size())
613 <<
"Removing zero-sized patches:" << endl <<
incrIndent;
617 if (oldToNew[patchi] == -1)
620 <<
" type " << pbm[
patchi].type()
621 <<
" at position " << patchi <<
endl;
622 oldToNew[
patchi] = newPatchi++;
653 Info<<
"Wrote mesh in = " 658 int main(
int argc,
char *argv[])
664 "check all surface geometry for quality" 670 "simplify the surface using snappyHexMesh starting from a boundBox" 675 "(patch0 .. patchN)",
676 "only triangulate selected patches (wildcards supported)" 682 "name of the file to save the simplified surface to" 698 <<
"Create mesh for time = " 718 Info<<
"Read mesh in = " 746 const scalar mergeDist = getMergeDistance
749 meshDict.
lookup<scalar>(
"mergeTolerance")
752 const Switch keepPatches(meshDict.lookupOrDefault(
"keepPatches",
false));
775 decomposeDict.add(
"method",
"none");
776 decomposeDict.add(
"numberOfSubdomains", 1);
787 meshDict.lookupOrDefault<
label>
795 if (meshDict.readIfPresent(
"debugFlags", flags))
809 meshRefinement::debug = debugLevel;
810 snappyRefineDriver::debug = debugLevel;
811 snappySnapDriver::debug = debugLevel;
812 snappyLayerDriver::debug = debugLevel;
818 if (meshDict.readIfPresent(
"writeFlags", flags))
837 if (meshDict.readIfPresent(
"outputFlags", flags))
878 Info<<
"Reading refinement surfaces..." <<
endl;
897 "geometryToConformTo" 901 foamyHexMeshDict.
subDict(
"motionControl");
904 motionDict.
subDict(
"shapeControlFunctions");
907 const scalar defaultCellSize =
908 motionDict.
lookup<scalar>(
"defaultCellSize");
910 const scalar initialCellSize =
::pow(
meshPtr().V()[0], 1.0/3.0);
918 createRefinementSurfaces
924 initialCellSize/defaultCellSize
934 refineDict.
found(
"refinementSurfaces")
935 ? refineDict.
subDict(
"refinementSurfaces")
941 Info<<
"Read refinement surfaces in = " 957 forAll(surfaceGeometry, surfI)
959 label geomI = surfaceGeometry[surfI];
967 if (patchInfo.set(globalRegionI))
970 word(patchInfo[globalRegionI].
lookup(
"type"));
974 patchTypes[geomI][regionI] = wallPolyPatch::typeName;
1000 Info<<
"Reading refinement regions..." <<
endl;
1004 refineDict.
found(
"refinementRegions")
1005 ? refineDict.
subDict(
"refinementRegions")
1008 Info<<
"Read refinement regions in = " 1012 Info<<
"Setting refinement level of surface to be consistent" 1013 <<
" with shells.." <<
endl;
1015 Info<<
"Checked shell refinement in = " 1022 Info<<
"Reading features..." <<
endl;
1026 refineDict.
found(
"features")
1027 ? refineDict.
lookup(
"features")
1030 Info<<
"Read features in = " 1039 <<
"Determining initial surface intersections" << nl
1040 <<
"-----------------------------------------" << nl
1053 Info<<
"Calculated surface intersections in = " 1076 <<
"Adding patches for surface regions" << nl
1077 <<
"----------------------------------" << nl
1085 <<
setw(6) <<
"Patch" 1086 <<
setw(20) <<
"Type" 1087 <<
setw(30) <<
"Region" << nl
1088 <<
setw(6) <<
"-----" 1089 <<
setw(20) <<
"----" 1095 forAll(surfaceGeometry, surfI)
1097 label geomI = surfaceGeometry[surfI];
1101 Info<< surfaces.
names()[surfI] <<
':' << nl <<
nl;
1103 if (surfaces.
surfZones()[surfI].faceZoneName().empty())
1112 if (surfacePatchInfo.
set(globalRegionI))
1117 surfacePatchInfo[globalRegionI]
1123 patchInfo.
set(
"type", wallPolyPatch::typeName);
1133 <<
setw(6) << patchi
1135 <<
setw(30) << regNames[i] <<
nl;
1137 globalToMasterPatch[globalRegionI] =
patchi;
1138 globalToSlavePatch[globalRegionI] =
patchi;
1152 if (surfacePatchInfo.
set(globalRegionI))
1157 surfacePatchInfo[globalRegionI]
1163 patchInfo.
set(
"type", wallPolyPatch::typeName);
1173 <<
setw(6) << patchi
1175 <<
setw(30) << regNames[i] <<
nl;
1177 globalToMasterPatch[globalRegionI] =
patchi;
1181 const word slaveName = regNames[i] +
"_slave";
1184 if (surfacePatchInfo.
set(globalRegionI))
1189 surfacePatchInfo[globalRegionI]
1195 patchInfo.
set(
"type", wallPolyPatch::typeName);
1205 <<
setw(6) << patchi
1207 <<
setw(30) << slaveName <<
nl;
1209 globalToSlavePatch[globalRegionI] =
patchi;
1216 Info<<
"Added patches in = " 1237 <<
"You have selected decomposition method " 1238 << decomposer.typeName
1239 <<
" which is not parallel aware." << endl
1240 <<
"Please select one that is (hierarchical, ptscotch)" 1254 const Switch wantRefine(meshDict.lookup(
"castellatedMesh"));
1255 const Switch wantSnap(meshDict.lookup(
"snap"));
1256 const Switch wantLayers(meshDict.lookup(
"addLayers"));
1277 globalToMasterPatch,
1282 if (!overwrite && !debugLevel)
1288 refineDriver.doRefine
1293 refineParams.handleSnapProblems(),
1298 if (!keepPatches && !wantSnap && !wantLayers)
1300 removeZeroSizedPatches(mesh);
1311 Info<<
"Mesh refined in = " 1322 globalToMasterPatch,
1326 if (!overwrite && !debugLevel)
1332 scalar curvature = refineParams.curvature();
1333 scalar planarAngle = refineParams.planarAngle();
1344 if (!keepPatches && !wantLayers)
1346 removeZeroSizedPatches(mesh);
1357 Info<<
"Mesh snapped in = " 1368 globalToMasterPatch,
1375 (mesh.
nCells() >= refineParams.maxLocalCells()),
1380 if (!overwrite && !debugLevel)
1385 layerDriver.doLayers
1397 removeZeroSizedPatches(mesh);
1408 Info<<
"Layers added in = " 1415 Info<<
"Checking final mesh ..." <<
endl;
1426 Info<<
"Finished meshing with " << nErrors <<
" illegal faces" 1427 <<
" (concave, zero area or negative cell pyramid volume)" 1433 Info<<
"Finished meshing without any errors" <<
endl;
1438 if (surfaceSimplify)
1457 if (!isA<processorPolyPatch>(patch))
1459 includePatches.
insert(patchi);
1469 "constant/triSurface/simplifiedSurface.stl" 1485 "internalCellCentres",
1494 cellCentres.
write();
1498 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.
label checkGeometry(const scalar maxRatio, const scalar tolerance, const scalar minQuality, const bool report) const
All geometric checks. Return number of failed checks.
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 synchronise 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.
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.
Encapsulates queries for volume refinement ('refine all cells within shell').
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.
IOdictionary systemDict(const word &dictName, const argList &args, const objectRegistry &ob, const word ®ionName=polyMesh::defaultRegion)
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
void setMinLevelFields(const refinementRegions &shells)
Calculate minLevelFields.
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
static const word & geometryDir()
Return the geometry directory name.
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.
static const dictionary null
Null dictionary.
Container for searchableSurfaces.
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
const globalMeshData & globalData() const
Return parallel info.
Abstract base class for decomposition.
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.
fileName globalPath() const
Return the global path.
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
label size() const
Return the number of elements in the UPtrList.
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.
Foam::argList args(argc, argv)
void writeStats(const List< wordList > &, Ostream &) const
Write some stats.
fileName path() const
Return path.
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.