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"
219 shapeControlRegionDict.
typeDict(scsFuncName);
221 const scalar surfaceCellSize =
222 scsDict.
lookup<scalar>(
"surfaceCellSizeCoeff");
224 const label refLevel = sizeCoeffToRefinement
230 regionMinLevel[surfI].insert(regionI, refLevel);
231 regionMaxLevel[surfI].insert(regionI, refLevel);
232 regionLevelIncr[surfI].insert(regionI, 0);
246 regionOffset[surfI] = nRegions;
247 nRegions += allGeometry[surfaces[surfI]].regions().
size();
256 forAll(globalMinLevel, surfI)
258 label nRegions = allGeometry[surfaces[surfI]].regions().
size();
261 for (
label i = 0; i < nRegions; i++)
263 label globalRegionI = regionOffset[surfI] + i;
264 minLevel[globalRegionI] = globalMinLevel[surfI];
265 maxLevel[globalRegionI] = globalMaxLevel[surfI];
266 gapLevel[globalRegionI] =
267 maxLevel[globalRegionI]
268 + globalLevelIncr[surfI];
270 if (globalPatchInfo.set(surfI))
275 globalPatchInfo[surfI].
clone()
283 label globalRegionI = regionOffset[surfI] + iter.key();
285 minLevel[globalRegionI] = iter();
286 maxLevel[globalRegionI] = regionMaxLevel[surfI][iter.key()];
287 gapLevel[globalRegionI] =
288 maxLevel[globalRegionI]
289 + regionLevelIncr[surfI][iter.key()];
295 label globalRegionI = regionOffset[surfI] + iter.key();
296 patchInfo.set(globalRegionI, iter()().
clone());
334 <<
setw(10) <<
"Min Level"
335 <<
setw(10) <<
"Max Level"
336 <<
setw(10) <<
"Gap Level" <<
nl
337 <<
setw(maxLen) <<
"------"
338 <<
setw(10) <<
"---------"
339 <<
setw(10) <<
"---------"
383 patchSize.insert(pp.
name(), pp.
size());
393 label sz = compactZoneID.size();
394 compactZoneID.insert(iter.key(), sz);
406 patchToCompactZone[
patchi] = iter();
418 faceLabels.append(pp.
start()+i);
419 compactZones.append(patchToCompactZone[pp.
index()]);
436 allBoundary.meshPoints(),
437 allBoundary.meshPointMap(),
468 pointField allPoints = ListListOps::combine<pointField>
473 gatheredPoints.clear();
475 faceList allFaces = ListListOps::combine<faceList>
480 gatheredFaces.clear();
482 labelList allZones = ListListOps::combine<labelList>
487 gatheredZones.clear();
495 Info<<
"surfZone " << iter() <<
" : " << surfZones[iter()].name()
510 Info<<
"Writing merged surface to "
519 scalar getMergeDistance(
const polyMesh&
mesh,
const scalar mergeTol)
522 scalar mergeDist = mergeTol *
meshBb.mag();
525 <<
"Overall mesh bounding box : " <<
meshBb <<
nl
526 <<
"Relative tolerance : " << mergeTol <<
nl
527 <<
"Absolute matching distance : " << mergeDist <<
nl
539 if (mergeTol < writeTol)
542 <<
"Your current settings specify ASCII writing with "
544 <<
"Your merging tolerance (" << mergeTol
545 <<
") is finer than this." <<
nl
546 <<
"Change to binary writeFormat, "
547 <<
"or increase the writePrecision" <<
endl
548 <<
"or adjust the merge tolerance (mergeTol)."
575 oldToNew[
patchi] = newPatchi++;
579 const label nKeepPatches = newPatchi;
582 if (nKeepPatches != pbm.
size())
589 if (oldToNew[
patchi] == -1)
592 <<
" type " << pbm[
patchi].type()
594 oldToNew[
patchi] = newPatchi++;
617 Info<<
"Writing mesh to time " << meshRefiner.
name() <<
endl;
625 Info<<
"Wrote mesh in = "
630 int main(
int argc,
char *argv[])
636 "check all surface geometry for quality"
642 "simplify the surface using snappyHexMesh starting from a boundBox"
647 "(patch0 .. patchN)",
648 "only triangulate selected patches (wildcards supported)"
654 "name of the file to save the simplified surface to"
664 Info<<
"Read mesh in = "
676 <<
"Mesh provided is not fully 3D"
677 " as required for mesh relaxation after snapping" <<
nl
678 <<
"Convert all empty patches to appropriate types for a 3D mesh,"
679 " current patch types are" <<
nl
706 const scalar mergeDist = getMergeDistance
709 meshDict.lookup<scalar>(
"mergeTolerance")
712 const Switch keepPatches(meshDict.lookupOrDefault(
"keepPatches",
false));
724 decomposeDict.
add(
"method",
"none");
725 decomposeDict.
add(
"numberOfSubdomains", 1);
736 meshDict.lookupOrDefault<
label>
744 if (meshDict.readIfPresent(
"debugFlags", flags))
758 meshRefinement::debug = debugLevel;
759 snappyRefineDriver::debug = debugLevel;
760 snappySnapDriver::debug = debugLevel;
761 snappyLayerDriver::debug = debugLevel;
767 if (meshDict.readIfPresent(
"writeFlags", flags))
786 if (meshDict.readIfPresent(
"outputFlags", flags))
818 meshDict.lookupOrDefault(
"singleRegionName",
true)
825 Info<<
"Reading refinement surfaces..." <<
endl;
830 refineDict.
found(
"refinementSurfaces")
831 ? refineDict.
subDict(
"refinementSurfaces")
836 Info<<
"Read refinement surfaces in = "
848 const labelList& surfaceGeometry = surfaces.surfaces();
849 forAll(surfaceGeometry, surfI)
851 label geomI = surfaceGeometry[surfI];
857 label globalRegionI = surfaces.globalRegion(surfI, regionI);
859 if (patchInfo.
set(globalRegionI))
862 word(patchInfo[globalRegionI].
lookup(
"type"));
892 Info<<
"Reading refinement regions..." <<
endl;
896 refineDict.
found(
"refinementRegions")
897 ? refineDict.
subDict(
"refinementRegions")
900 Info<<
"Read refinement regions in = "
908 Info<<
"Reading features..." <<
endl;
912 refineDict.
found(
"features")
913 ? refineDict.
lookup(
"features")
916 Info<<
"Read features in = "
925 <<
"Determining initial surface intersections" <<
nl
926 <<
"-----------------------------------------" <<
nl
940 Info<<
"Calculated surface intersections in = "
963 <<
"Adding patches for surface regions" <<
nl
964 <<
"----------------------------------" <<
nl
968 globalToMasterPatch.
setSize(surfaces.nRegions(), -1);
969 globalToSlavePatch.
setSize(surfaces.nRegions(), -1);
972 <<
setw(6) <<
"Patch"
973 <<
setw(20) <<
"Type"
974 <<
setw(30) <<
"Region" <<
nl
975 <<
setw(6) <<
"-----"
976 <<
setw(20) <<
"----"
979 const labelList& surfaceGeometry = surfaces.surfaces();
982 forAll(surfaceGeometry, surfI)
984 label geomI = surfaceGeometry[surfI];
988 Info<< surfaces.names()[surfI] <<
':' <<
nl <<
nl;
990 if (surfaces.surfZones()[surfI].faceZoneName().empty())
995 label globalRegionI = surfaces.globalRegion(surfI, i);
999 if (surfacePatchInfo.
set(globalRegionI))
1004 surfacePatchInfo[globalRegionI]
1022 <<
setw(30) << regNames[i] <<
nl;
1024 globalToMasterPatch[globalRegionI] =
patchi;
1025 globalToSlavePatch[globalRegionI] =
patchi;
1033 label globalRegionI = surfaces.globalRegion(surfI, i);
1039 if (surfacePatchInfo.
set(globalRegionI))
1044 surfacePatchInfo[globalRegionI]
1062 <<
setw(30) << regNames[i] <<
nl;
1064 globalToMasterPatch[globalRegionI] =
patchi;
1068 const word slaveName = regNames[i] +
"_slave";
1071 if (surfacePatchInfo.
set(globalRegionI))
1076 surfacePatchInfo[globalRegionI]
1094 <<
setw(30) << slaveName <<
nl;
1096 globalToSlavePatch[globalRegionI] =
patchi;
1106 Info<<
"Added patches in = "
1128 const Switch wantRefine(meshDict.lookup(
"castellatedMesh"));
1129 const Switch wantSnap(meshDict.lookup(
"snap"));
1130 const Switch wantLayers(meshDict.lookup(
"addLayers"));
1147 globalToMasterPatch,
1156 refineDriver.doRefine
1161 refineParams.handleSnapProblems(),
1165 if (!keepPatches && !wantSnap && !wantLayers)
1167 removeZeroSizedPatches(
mesh);
1178 Info<<
"Mesh refined in = "
1179 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1189 globalToMasterPatch,
1199 scalar curvature = refineParams.curvature();
1200 scalar planarAngle = refineParams.planarAngle();
1211 if (!keepPatches && !wantLayers)
1213 removeZeroSizedPatches(
mesh);
1224 Info<<
"Mesh snapped in = "
1225 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1241 globalToMasterPatch,
1248 (
mesh.
nCells() >= refineParams.maxLocalCells()),
1258 layerDriver.doLayers
1270 removeZeroSizedPatches(
mesh);
1281 Info<<
"Layers added in = "
1282 <<
timer.cpuTimeIncrement() <<
" s." <<
endl;
1288 Info<<
"Checking final mesh ..." <<
endl;
1299 Info<<
"Finished meshing with " << nErrors <<
" illegal faces"
1300 <<
" (concave, zero area or negative cell pyramid volume)"
1306 Info<<
"Finished meshing without any errors" <<
endl;
1311 if (surfaceSimplify)
1330 if (!isA<processorPolyPatch>(patch))
1342 "constant/triSurface/simplifiedSurface.stl"
1358 "internalCellCentres",
1367 cellCentres.write();
1371 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 token &)
Write token.
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.
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.
T lookupOrDefault(const word &, const T &) const
Find and return a T, if not found return the given default.
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 & typeDict(const word &typeName) const
Find and return a type sub-dictionary.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
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 dictionary & optionalTypeDict(const word &typeName) const
Find and return an optional type sub-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.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
const polyMesh & poly() const
Return reference to polyMesh.
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.
const polyBoundaryMesh & boundary() const
Return boundary mesh.
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.
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.
virtual bool constraint() const
Return false as this patch is not 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.
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
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)
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
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)
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.
List< wordRe > wordReList
A List of wordRe (word or regular expression)
tmp< DimensionedField< typename powProduct< Type, r >::type, GeoMesh, Field > > pow(const DimensionedField< Type, GeoMesh, PrimitiveField > &df, typename powProduct< Type, r >::type)
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.
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
wordList patchTypes(nPatches)
labelHashSet includePatches
List< treeBoundBox > meshBb(1, treeBoundBox(boundBox(coarseMesh.points(), false)).extend(1e-3))
const Foam::wordList regionNames(args.optionFound("allRegions") ? runTime.regionNames() :wordList(1, args.optionFound("region") ? args.optionRead< word >("region") :polyMesh::defaultRegion))
Foam::argList args(argc, argv)