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 =
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
528 globalCasePath.
clean();
530 Info<<
"Writing merged surface to " << globalCasePath <<
endl;
532 sortedFace.
write(globalCasePath);
538 scalar getMergeDistance(
const polyMesh& mesh,
const scalar mergeTol)
541 scalar mergeDist = mergeTol * meshBb.
mag();
544 <<
"Overall mesh bounding box : " << meshBb << nl
545 <<
"Relative tolerance : " << mergeTol << nl
546 <<
"Absolute matching distance : " << mergeDist << nl
558 if (mergeTol < writeTol)
561 <<
"Your current settings specify ASCII writing with " 563 <<
"Your merging tolerance (" << mergeTol
564 <<
") is finer than this." << nl
565 <<
"Change to binary writeFormat, " 566 <<
"or increase the writePrecision" << endl
567 <<
"or adjust the merge tolerance (mergeTol)." 576 void removeZeroSizedPatches(
fvMesh& mesh)
592 if (!isA<processorPolyPatch>(pp))
596 isA<coupledPolyPatch>(pp)
601 oldToNew[
patchi] = newPatchi++;
610 if (isA<processorPolyPatch>(pp))
612 oldToNew[
patchi] = newPatchi++;
617 const label nKeepPatches = newPatchi;
620 if (nKeepPatches != pbm.
size())
623 <<
"Removing zero-sized patches:" << endl <<
incrIndent;
627 if (oldToNew[patchi] == -1)
630 <<
" type " << pbm[
patchi].type()
631 <<
" at position " << patchi <<
endl;
632 oldToNew[
patchi] = newPatchi++;
663 Info<<
"Wrote mesh in = " 668 int main(
int argc,
char *argv[])
674 "check all surface geometry for quality" 680 "simplify the surface using snappyHexMesh starting from a boundBox" 685 "(patch0 .. patchN)",
686 "only triangulate selected patches (wildcards supported)" 692 "name of the file to save the simplified surface to" 708 <<
"Create mesh for time = " 728 Info<<
"Read mesh in = " 758 const scalar mergeDist = getMergeDistance
764 const Switch keepPatches(meshDict.lookupOrDefault(
"keepPatches",
false));
787 decomposeDict.add(
"method",
"none");
788 decomposeDict.add(
"numberOfSubdomains", 1);
799 meshDict.lookupOrDefault<
label>
807 if (meshDict.readIfPresent(
"debugFlags", flags))
821 meshRefinement::debug = debugLevel;
822 snappyRefineDriver::debug = debugLevel;
823 snappySnapDriver::debug = debugLevel;
824 snappyLayerDriver::debug = debugLevel;
830 if (meshDict.readIfPresent(
"writeFlags", flags))
849 if (meshDict.readIfPresent(
"outputFlags", flags))
891 Info<<
"Reading refinement surfaces." <<
endl;
910 "geometryToConformTo" 914 foamyHexMeshDict.
subDict(
"motionControl");
917 motionDict.
subDict(
"shapeControlFunctions");
920 const scalar defaultCellSize =
923 const scalar initialCellSize =
::pow(
meshPtr().V()[0], 1.0/3.0);
931 createRefinementSurfaces
937 initialCellSize/defaultCellSize
947 refineDict.
subDict(
"refinementSurfaces"),
952 Info<<
"Read refinement surfaces in = " 968 forAll(surfaceGeometry, surfI)
970 label geomI = surfaceGeometry[surfI];
978 if (patchInfo.set(globalRegionI))
981 word(patchInfo[globalRegionI].
lookup(
"type"));
985 patchTypes[geomI][regionI] = wallPolyPatch::typeName;
1012 Info<<
"Reading refinement shells." <<
endl;
1016 refineDict.
subDict(
"refinementRegions")
1018 Info<<
"Read refinement shells in = " 1022 Info<<
"Setting refinement level of surface to be consistent" 1023 <<
" with shells." <<
endl;
1025 Info<<
"Checked shell refinement in = " 1032 Info<<
"Reading features." <<
endl;
1036 refineDict.
lookup(
"features")
1038 Info<<
"Read features in = " 1047 <<
"Determining initial surface intersections" << nl
1048 <<
"-----------------------------------------" << nl
1061 Info<<
"Calculated surface intersections in = " 1084 <<
"Adding patches for surface regions" << nl
1085 <<
"----------------------------------" << nl
1093 <<
setw(6) <<
"Patch" 1094 <<
setw(20) <<
"Type" 1095 <<
setw(30) <<
"Region" << nl
1096 <<
setw(6) <<
"-----" 1097 <<
setw(20) <<
"----" 1103 forAll(surfaceGeometry, surfI)
1105 label geomI = surfaceGeometry[surfI];
1109 Info<< surfaces.
names()[surfI] <<
':' << nl <<
nl;
1111 if (surfaces.
surfZones()[surfI].faceZoneName().empty())
1120 if (surfacePatchInfo.
set(globalRegionI))
1125 surfacePatchInfo[globalRegionI]
1131 patchInfo.
set(
"type", wallPolyPatch::typeName);
1141 <<
setw(6) << patchi
1143 <<
setw(30) << regNames[i] <<
nl;
1145 globalToMasterPatch[globalRegionI] =
patchi;
1146 globalToSlavePatch[globalRegionI] =
patchi;
1160 if (surfacePatchInfo.
set(globalRegionI))
1165 surfacePatchInfo[globalRegionI]
1171 patchInfo.
set(
"type", wallPolyPatch::typeName);
1181 <<
setw(6) << patchi
1183 <<
setw(30) << regNames[i] <<
nl;
1185 globalToMasterPatch[globalRegionI] =
patchi;
1189 const word slaveName = regNames[i] +
"_slave";
1192 if (surfacePatchInfo.
set(globalRegionI))
1197 surfacePatchInfo[globalRegionI]
1203 patchInfo.
set(
"type", wallPolyPatch::typeName);
1213 <<
setw(6) << patchi
1215 <<
setw(30) << slaveName <<
nl;
1217 globalToSlavePatch[globalRegionI] =
patchi;
1224 Info<<
"Added patches in = " 1245 <<
"You have selected decomposition method " 1246 << decomposer.typeName
1247 <<
" which is not parallel aware." << endl
1248 <<
"Please select one that is (hierarchical, ptscotch)" 1262 const Switch wantRefine(meshDict.lookup(
"castellatedMesh"));
1263 const Switch wantSnap(meshDict.lookup(
"snap"));
1264 const Switch wantLayers(meshDict.lookup(
"addLayers"));
1285 globalToMasterPatch,
1290 if (!overwrite && !debugLevel)
1296 refineDriver.doRefine
1301 refineParams.handleSnapProblems(),
1306 if (!keepPatches && !wantSnap && !wantLayers)
1308 removeZeroSizedPatches(mesh);
1319 Info<<
"Mesh refined in = " 1330 globalToMasterPatch,
1334 if (!overwrite && !debugLevel)
1340 scalar curvature = refineParams.curvature();
1341 scalar planarAngle = refineParams.planarAngle();
1352 if (!keepPatches && !wantLayers)
1354 removeZeroSizedPatches(mesh);
1365 Info<<
"Mesh snapped in = " 1376 globalToMasterPatch,
1383 (mesh.
nCells() >= refineParams.maxLocalCells()),
1388 if (!overwrite && !debugLevel)
1393 layerDriver.doLayers
1405 removeZeroSizedPatches(mesh);
1416 Info<<
"Layers added in = " 1423 Info<<
"Checking final mesh ..." <<
endl;
1434 Info<<
"Finished meshing with " << nErrors <<
" illegal faces" 1435 <<
" (concave, zero area or negative cell pyramid volume)" 1441 Info<<
"Finished meshing without any errors" <<
endl;
1446 if (surfaceSimplify)
1465 if (!isA<processorPolyPatch>(patch))
1467 includePatches.
insert(patchi);
1477 "constant/triSurface/simplifiedSurface.stl" 1493 "internalCellCentres",
1502 cellCentres.
write();
1506 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.
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.
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.
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.
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').
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
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...
virtual Ostream & write(const token &)=0
Write next token to stream.
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.
A patch is a list of labels that address the faces in the global face list.
virtual bool write(const bool valid=true) const
Write using setting from DB.
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.