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");
141 shapeDict.
subDict(scsFuncName +
"Coeffs");
143 const scalar surfaceCellSize =
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 =
233 scsDict.
lookup(
"surfaceCellSizeCoeff")
236 const label refLevel = sizeCoeffToRefinement
242 regionMinLevel[surfI].insert(regionI, refLevel);
243 regionMaxLevel[surfI].insert(regionI, refLevel);
244 regionLevelIncr[surfI].insert(regionI, 0);
258 regionOffset[surfI] = nRegions;
259 nRegions += allGeometry[surfaces[surfI]].regions().
size();
268 forAll(globalMinLevel, surfI)
270 label nRegions = allGeometry[surfaces[surfI]].regions().
size();
273 for (
label i = 0; i < nRegions; i++)
275 label globalRegionI = regionOffset[surfI] + i;
276 minLevel[globalRegionI] = globalMinLevel[surfI];
277 maxLevel[globalRegionI] = globalMaxLevel[surfI];
278 gapLevel[globalRegionI] =
279 maxLevel[globalRegionI]
280 + globalLevelIncr[surfI];
282 if (globalPatchInfo.set(surfI))
287 globalPatchInfo[surfI].clone()
295 label globalRegionI = regionOffset[surfI] + iter.key();
297 minLevel[globalRegionI] = iter();
298 maxLevel[globalRegionI] = regionMaxLevel[surfI][iter.key()];
299 gapLevel[globalRegionI] =
300 maxLevel[globalRegionI]
301 + regionLevelIncr[surfI][iter.key()];
307 label globalRegionI = regionOffset[surfI] + iter.key();
308 patchInfo.
set(globalRegionI, iter()().clone());
338 forAll(regionNames, regionI)
346 <<
setw(10) <<
"Min Level" 347 <<
setw(10) <<
"Max Level" 348 <<
setw(10) <<
"Gap Level" << nl
349 <<
setw(maxLen) <<
"------" 350 <<
setw(10) <<
"---------" 351 <<
setw(10) <<
"---------" 362 forAll(regionNames, regionI)
366 Info<<
setw(maxLen) << regionNames[regionI]
395 patchSize.insert(pp.
name(), pp.size());
405 label sz = compactZoneID.size();
406 compactZoneID.insert(iter.key(), sz);
418 patchToCompactZone[
patchi] = iter();
430 faceLabels.append(pp.
start()+i);
431 compactZones.append(patchToCompactZone[pp.
index()]);
448 allBoundary.meshPoints(),
449 allBoundary.meshPointMap(),
485 gatheredPoints.clear();
487 faceList allFaces = ListListOps::combine<faceList>
492 gatheredFaces.clear();
494 labelList allZones = ListListOps::combine<labelList>
499 gatheredZones.clear();
507 Info<<
"surfZone " << iter() <<
" : " << surfZones[iter()].name()
525 ? runTime.
path()/
".."/outFileName
526 : runTime.
path()/outFileName
529 Info<<
"Writing merged surface to " << globalCasePath <<
endl;
531 sortedFace.
write(globalCasePath);
537 scalar getMergeDistance(
const polyMesh& mesh,
const scalar mergeTol)
540 scalar mergeDist = mergeTol * meshBb.
mag();
543 <<
"Overall mesh bounding box : " << meshBb << nl
544 <<
"Relative tolerance : " << mergeTol << nl
545 <<
"Absolute matching distance : " << mergeDist << nl
557 if (mergeTol < writeTol)
560 <<
"Your current settings specify ASCII writing with " 562 <<
"Your merging tolerance (" << mergeTol
563 <<
") is finer than this." << nl
564 <<
"Change to binary writeFormat, " 565 <<
"or increase the writePrecision" << endl
566 <<
"or adjust the merge tolerance (mergeTol)." 575 void removeZeroSizedPatches(
fvMesh& mesh)
591 if (!isA<processorPolyPatch>(pp))
595 isA<coupledPolyPatch>(pp)
600 oldToNew[
patchi] = newPatchi++;
609 if (isA<processorPolyPatch>(pp))
611 oldToNew[
patchi] = newPatchi++;
616 const label nKeepPatches = newPatchi;
619 if (nKeepPatches != pbm.
size())
622 <<
"Removing zero-sized patches:" << endl <<
incrIndent;
626 if (oldToNew[patchi] == -1)
629 <<
" type " << pbm[
patchi].type()
630 <<
" at position " << patchi <<
endl;
631 oldToNew[
patchi] = newPatchi++;
671 Info<<
"Wrote mesh in = " 676 int main(
int argc,
char *argv[])
682 "check all surface geometry for quality" 688 "simplify the surface using snappyHexMesh starting from a boundBox" 693 "(patch0 .. patchN)",
694 "only triangulate selected patches (wildcards supported)" 700 "name of the file to save the simplified surface to" 827 <<
"Create mesh for time = " 847 Info<<
"Read mesh in = " 877 const scalar mergeDist = getMergeDistance
883 const Switch keepPatches(meshDict.lookupOrDefault(
"keepPatches",
false));
906 decomposeDict.add(
"method",
"none");
907 decomposeDict.add(
"numberOfSubdomains", 1);
918 meshDict.lookupOrDefault<
label>
926 if (meshDict.readIfPresent(
"debugFlags", flags))
940 meshRefinement::debug = debugLevel;
941 snappyRefineDriver::debug = debugLevel;
942 snappySnapDriver::debug = debugLevel;
943 snappyLayerDriver::debug = debugLevel;
949 if (meshDict.readIfPresent(
"writeFlags", flags))
968 if (meshDict.readIfPresent(
"outputFlags", flags))
1010 Info<<
"Reading refinement surfaces." <<
endl;
1012 if (surfaceSimplify)
1029 "geometryToConformTo" 1033 foamyHexMeshDict.
subDict(
"motionControl");
1036 motionDict.
subDict(
"shapeControlFunctions");
1039 const scalar defaultCellSize =
1042 const scalar initialCellSize =
::pow(
meshPtr().V()[0], 1.0/3.0);
1050 createRefinementSurfaces
1056 initialCellSize/defaultCellSize
1066 refineDict.
subDict(
"refinementSurfaces"),
1071 Info<<
"Read refinement surfaces in = " 1087 forAll(surfaceGeometry, surfI)
1089 label geomI = surfaceGeometry[surfI];
1093 forAll(regNames, regionI)
1097 if (patchInfo.set(globalRegionI))
1100 word(patchInfo[globalRegionI].
lookup(
"type"));
1104 patchTypes[geomI][regionI] = wallPolyPatch::typeName;
1131 Info<<
"Reading refinement shells." <<
endl;
1135 refineDict.
subDict(
"refinementRegions")
1137 Info<<
"Read refinement shells in = " 1141 Info<<
"Setting refinement level of surface to be consistent" 1142 <<
" with shells." <<
endl;
1144 Info<<
"Checked shell refinement in = " 1151 Info<<
"Reading features." <<
endl;
1155 refineDict.
lookup(
"features")
1157 Info<<
"Read features in = " 1166 <<
"Determining initial surface intersections" << nl
1167 <<
"-----------------------------------------" << nl
1180 Info<<
"Calculated surface intersections in = " 1203 <<
"Adding patches for surface regions" << nl
1204 <<
"----------------------------------" << nl
1212 <<
setw(6) <<
"Patch" 1213 <<
setw(20) <<
"Type" 1214 <<
setw(30) <<
"Region" << nl
1215 <<
setw(6) <<
"-----" 1216 <<
setw(20) <<
"----" 1222 forAll(surfaceGeometry, surfI)
1224 label geomI = surfaceGeometry[surfI];
1228 Info<< surfaces.
names()[surfI] <<
':' << nl <<
nl;
1230 if (surfaces.
surfZones()[surfI].faceZoneName().empty())
1239 if (surfacePatchInfo.
set(globalRegionI))
1244 surfacePatchInfo[globalRegionI]
1250 patchInfo.
set(
"type", wallPolyPatch::typeName);
1260 <<
setw(6) << patchi
1262 <<
setw(30) << regNames[i] <<
nl;
1264 globalToMasterPatch[globalRegionI] =
patchi;
1265 globalToSlavePatch[globalRegionI] =
patchi;
1279 if (surfacePatchInfo.
set(globalRegionI))
1284 surfacePatchInfo[globalRegionI]
1290 patchInfo.
set(
"type", wallPolyPatch::typeName);
1300 <<
setw(6) << patchi
1302 <<
setw(30) << regNames[i] <<
nl;
1304 globalToMasterPatch[globalRegionI] =
patchi;
1308 const word slaveName = regNames[i] +
"_slave";
1311 if (surfacePatchInfo.
set(globalRegionI))
1316 surfacePatchInfo[globalRegionI]
1322 patchInfo.
set(
"type", wallPolyPatch::typeName);
1332 <<
setw(6) << patchi
1334 <<
setw(30) << slaveName <<
nl;
1336 globalToSlavePatch[globalRegionI] =
patchi;
1343 Info<<
"Added patches in = " 1364 <<
"You have selected decomposition method " 1365 << decomposer.typeName
1366 <<
" which is not parallel aware." << endl
1367 <<
"Please select one that is (hierarchical, ptscotch)" 1381 const Switch wantRefine(meshDict.lookup(
"castellatedMesh"));
1382 const Switch wantSnap(meshDict.lookup(
"snap"));
1383 const Switch wantLayers(meshDict.lookup(
"addLayers"));
1404 globalToMasterPatch,
1409 if (!overwrite && !debugLevel)
1415 refineDriver.doRefine
1420 refineParams.handleSnapProblems(),
1425 if (!keepPatches && !wantSnap && !wantLayers)
1427 removeZeroSizedPatches(mesh);
1438 Info<<
"Mesh refined in = " 1449 globalToMasterPatch,
1453 if (!overwrite && !debugLevel)
1459 scalar curvature = refineParams.curvature();
1460 scalar planarAngle = refineParams.planarAngle();
1471 if (!keepPatches && !wantLayers)
1473 removeZeroSizedPatches(mesh);
1484 Info<<
"Mesh snapped in = " 1495 globalToMasterPatch,
1502 (mesh.
nCells() >= refineParams.maxLocalCells()),
1507 if (!overwrite && !debugLevel)
1512 layerDriver.doLayers
1524 removeZeroSizedPatches(mesh);
1535 Info<<
"Layers added in = " 1542 Info<<
"Checking final mesh ..." <<
endl;
1553 Info<<
"Finished meshing with " << nErrors <<
" illegal faces" 1554 <<
" (concave, zero area or negative cell pyramid volume)" 1560 Info<<
"Finished meshing without any errors" <<
endl;
1565 if (surfaceSimplify)
1584 if (!isA<processorPolyPatch>(patch))
1586 includePatches.
insert(patchi);
1596 "constant/triSurface/simplifiedSurface.stl" 1612 "internalCellCentres",
1621 cellCentres.
write();
1625 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 Time & time() const
Return time.
const functionObjectList & functionObjects() const
Return the list of function objects.
A HashTable with keys but without contents.
wordList toc() const
Return the table of contents.
#define forAll(list, i)
Loop across all elements in list.
Simple container to keep together layer specific information.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
autoPtr< globalIndex > mergePoints(labelList &pointToGlobal, labelList &uniquePoints) const
Helper for merging (collocated!) mesh point data.
A class for handling file names.
Ostream & indent(Ostream &os)
Indent stream.
virtual bool parallelAware() const =0
Is method parallel aware (i.e. does it synchronize domains across.
An identifier for a surface zone on a meshed surface.
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
dimensionedScalar log(const dimensionedScalar &ds)
bool checkParallelSync(const bool report=false) const
Check whether all procs have all patches and in same order. Return.
errorManipArg< error, int > exit(error &err, const int errNo=1)
const boundBox & bounds() const
Return mesh bounding box.
void off()
Switch the function objects off.
const double e
Elementary charge.
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.
const PtrList< dictionary > & patchInfo() const
From global region number to patch type.
bool processorCase() const
Return true if this is a processor case.
const List< wordList > & regionNames() const
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.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
wordList patchTypes(nPatches)
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static const NamedEnum< IOwriteType, 4 > IOwriteTypeNames
static word defaultRegion
Return the default region name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const entry * lookupEntryPtr(const word &, bool recursive, bool patternMatch) const
Find and return an entry data stream pointer if present.
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.
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.
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.
Simple container to keep together refinement specific information.
bool insert(const Key &key)
Insert a new entry.
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.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
virtual const pointField & points() const
Return raw points.
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...
static void mapCombineScatter(const List< commsStruct > &comms, Container &Values, const int tag, const label comm)
Scatter data. Reverse of combineGather.
autoPtr< dictionary > clone() const
Construct and return clone.
Encapsulates queries for features.
bool write() const
Write mesh and all data.
scalar mag() const
The magnitude of the bounding box span.
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
label start() const
Return start label of this patch in the polyMesh face list.
bool optionFound(const word &opt) const
Return true if the named option is found.
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
A class for handling words, derived from string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const keyType & keyword() const
Return keyword.
Simple container to keep together snap specific information.
bool set(const label) const
Is element set.
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.
const word & constant() const
Return constant name.
const vectorField & cellCentres() const
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.
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Abstract base class for decomposition.
Encapsulates queries for volume refinement ('refine all cells within shell').
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
IOstream::streamFormat writeFormat() const
Default write format.
static void mapCombineGather(const List< commsStruct > &comms, Container &Values, const CombineOp &cop, const int tag, const label comm)
const word & name() const
Return name.
const labelList & gapLevel() const
From global region number to small gap refinement level.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
static autoPtr< decompositionMethod > New(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
const globalMeshData & globalData() const
Return parallel info.
Istream and Ostream manipulators taking arguments.
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
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.
const wordList & names() const
Names of surfaces.
static outputType outputLevel()
Get/set output level.
IOobject dictIO(dictName, runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE)
void printMeshInfo(const bool, const string &) const
Print some mesh stats.
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.
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
label globalRegion(const label surfI, const label regionI) const
From surface and region on surface to global region.
label checkTopology(const bool report) const
All topological checks. Return number of failed checks.
const wordList & names() const
All to do with snapping to surface.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
void setSize(const label)
Reset size of List.
static bool & parRun()
Is this a parallel run?
static label nProcs(const label communicator=0)
Number of processes in parallel run.
const PtrList< surfaceZonesInfo > & surfZones() const
word dictName("noiseDict")
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Mesh data needed to do the Finite Volume discretisation.
A List with indirect addressing.
IStringStream optionLookup(const word &opt) const
Return an IStringStream from the named option.
void insert(link *)
Add at head of list.
const labelList & surfaces() const
virtual bool write() const
Write using setting from DB.
void set(entry *)
Assign a new entry, overwrite any existing entry.
const labelList & maxLevel() const
From global region number to refinement level.
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...
virtual Ostream & write(const token &)=0
Write next token to stream.
Mesh consisting of general polyhedral cells.
const labelList & minLevel() const
From global region number to refinement level.
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.
const word & system() const
Return system name.
List< wordRe > wordReList
A List of wordRe (word or regular expression)
A patch is a list of labels that address the faces in the global face list.
virtual const faceList & faces() const
Return raw faces.
fileName path() const
Return path.
void setMinLevelFields(const shellSurfaces &shells)
Calculate minLevelFields.
Foam::argList args(argc, argv)
Ostream & incrIndent(Ostream &os)
Increment the indent level.
label findPatchID(const word &patchName) const
Find patch index given a name.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
const fvMesh & mesh() const
Reference to mesh.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
label index() const
Return the index of this patch in the boundaryMesh.
const word & name() const
Return name.
double elapsedCpuTime() const
Return CPU time (in seconds) from the start.
void writeStats(const List< wordList > &, Ostream &) const
Write some stats.
const Time & time() const
Return the top-level database.
word timeName() const
Replacement for Time::timeName() : return oldInstance (if.
A keyword and a list of tokens is an 'entry'.
label size() const
Return the number of elements in the UPtrList.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.