54 static const scalar defaultMergeTol = 1
e-6;
57 scalar getMergeDistance
64 scalar mergeTol = defaultMergeTol;
70 Info<<
"Merge tolerance : " << mergeTol <<
nl 71 <<
"Write tolerance : " << writeTol <<
endl;
76 <<
"Your current settings specify ASCII writing with " 78 <<
"Your merging tolerance (" << mergeTol <<
") is finer than this." 80 <<
"Please change your writeFormat to binary" 81 <<
" or increase the writePrecision" << endl
82 <<
"or adjust the merge tolerance (-mergeTol)." 86 scalar mergeDist = mergeTol * bb.
mag();
88 Info<<
"Overall meshes bounding box : " << bb <<
nl 89 <<
"Relative tolerance : " << mergeTol <<
nl 90 <<
"Absolute matching distance : " << mergeDist <<
nl 97 void printMeshData(
const polyMesh& mesh)
124 label maxProcCells = 0;
125 label totProcFaces = 0;
126 label maxProcPatches = 0;
127 label totProcPatches = 0;
128 label maxProcFaces = 0;
133 <<
"Processor " << proci <<
nl 134 <<
" Number of cells = " << globalCells.localSize(proci)
137 label nProcFaces = 0;
139 const labelList& nei = patchNeiProcNo[proci];
141 forAll(patchNeiProcNo[proci], i)
143 Info<<
" Number of faces shared with processor " 144 << patchNeiProcNo[proci][i] <<
" = " << patchSize[proci][i]
147 nProcFaces += patchSize[proci][i];
150 Info<<
" Number of processor patches = " << nei.
size() <<
nl 151 <<
" Number of processor faces = " << nProcFaces <<
nl 152 <<
" Number of boundary faces = " 153 << globalBoundaryFaces.localSize(proci) <<
endl;
155 maxProcCells =
max(maxProcCells, globalCells.localSize(proci));
156 totProcFaces += nProcFaces;
157 totProcPatches += nei.
size();
158 maxProcPatches =
max(maxProcPatches, nei.
size());
159 maxProcFaces =
max(maxProcFaces, nProcFaces);
169 if (totProcPatches == 0)
173 if (totProcFaces == 0)
179 <<
"Number of processor faces = " << totProcFaces/2 <<
nl 180 <<
"Max number of cells = " << maxProcCells
181 <<
" (" << 100.0*(maxProcCells-avgProcCells)/avgProcCells
182 <<
"% above average " << avgProcCells <<
")" <<
nl 183 <<
"Max number of processor patches = " << maxProcPatches
184 <<
" (" << 100.0*(maxProcPatches-avgProcPatches)/avgProcPatches
185 <<
"% above average " << avgProcPatches <<
")" <<
nl 186 <<
"Max number of faces between processors = " << maxProcFaces
187 <<
" (" << 100.0*(maxProcFaces-avgProcFaces)/avgProcFaces
188 <<
"% above average " << avgProcFaces <<
")" <<
nl 202 return i*nCells[1]*nCells[2]+j*nCells[2]+
k;
232 if (nCells[0]+nCells[1]+nCells[2] > 0)
234 points.
setSize((nCells[0]+1)*(nCells[1]+1)*(nCells[2]+1));
237 for (
label i = 0; i <= nCells[0]; i++)
239 for (
label j = 0; j <= nCells[1]; j++)
241 for (
label k = 0;
k <= nCells[2];
k++)
244 pt.
x() += i*cellSize[0];
245 pt.
y() += j*cellSize[1];
246 pt.
z() +=
k*cellSize[2];
247 points[vtxLabel(nCells, i, j,
k)] = pt;
259 for (
label i = 0; i < nCells[0]; i++)
261 for (
label j = 0; j < nCells[1]; j++)
263 for (
label k = 0;
k < nCells[2];
k++)
265 hexPoints[0] = vtxLabel(nCells, i, j,
k);
266 hexPoints[1] = vtxLabel(nCells, i+1, j,
k);
267 hexPoints[2] = vtxLabel(nCells, i+1, j+1,
k);
268 hexPoints[3] = vtxLabel(nCells, i, j+1,
k);
269 hexPoints[4] = vtxLabel(nCells, i, j,
k+1);
270 hexPoints[5] = vtxLabel(nCells, i+1, j,
k+1);
271 hexPoints[6] = vtxLabel(nCells, i+1, j+1,
k+1);
272 hexPoints[7] = vtxLabel(nCells, i, j+1,
k+1);
281 word defaultFacesName =
"defaultFaces";
282 word defaultFacesType = polyPatch::typeName;
338 forAll(nearestSurfaces, i)
340 if (nearestSurfaces[i] == surfI)
342 surfPoints.append(points[i]);
343 surfIndices.append(i);
348 label geomI = surfaces[surfI];
350 geometry[geomI].getVolumeType(surfPoints, volType);
355 label pointi = surfIndices[i];
356 scalar dist =
mag(points[pointi] - nearest[pointi].hitPoint());
371 <<
"getVolumeType failure, neither INSIDE or OUTSIDE" 384 int main(
int argc,
char *argv[])
388 "Generate foamyHexMesh-consistent representation of surfaces" 393 "write the resulting mesh and distance fields" 399 "specify the merge distance relative to the bounding box size " 407 const bool writeMesh = args.
optionFound(
"writeMesh");
411 Info<<
"Writing resulting mesh and cellDistance, pointDistance fields." 433 "cvSearchableSurfaces",
440 foamyHexMeshDict.subDict(
"geometry"),
441 foamyHexMeshDict.lookupOrDefault(
"singleRegionName",
true)
451 foamyHexMeshDict.subDict(
"surfaceConformation")
457 foamyHexMeshDict.subDict(
"motionControl"),
466 const treeBoundBox& bb = geometryToConformTo.globalBounds();
470 vector nScalarCells = span/cellShapeControls.defaultCellSize();
476 label(nScalarCells.
x())+2,
477 label(nScalarCells.
y())+2,
487 Info<<
"Generating initial hex mesh with" <<
nl 488 <<
" bounding box : " << bb <<
nl 489 <<
" nCells : " << nCells <<
nl 490 <<
" cellSize : " << cellSize <<
nl 548 const scalar tolDim = getMergeDistance
558 Info<<
"Wanted distribution:" 559 << distributor.countCells(decomp) <<
nl <<
endl;
569 Info<<
"Writing redistributed mesh" <<
nl <<
endl;
574 Info<<
"Refining background mesh according to cell size specification" <<
nl 589 backgroundMesh.mesh().
write();
592 const scalar tolDim = getMergeDistance
596 backgroundMesh.mesh().bounds()
605 const fvMesh& mesh = backgroundMesh.mesh();
623 const labelList& surfaces = geometryToConformTo.surfaces();
629 const labelList& cellLevel = backgroundMesh.cellLevel();
634 distSqr[celli] =
magSqr(cellSize)/
pow(2, cellLevel[celli]);
639 cellDistance.primitiveFieldRef() = signedDistance
651 cellDistance.boundaryFieldRef()[
patchi];
656 fld = signedDistance(patchDistSqr, cc, geometry, surfaces);
664 cellDistance.write();
689 label ownDistSqr = distSqr[own];
694 pointDistSqr[f[fp]] =
max(pointDistSqr[f[fp]], ownDistSqr);
705 pointDistance.primitiveFieldRef() = signedDistance
715 pointDistance.write();
727 isoFaces.setSize(iso.size());
730 isoFaces[i] = iso[i];
732 isoPoints = iso.points();
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
#define forAll(list, i)
Loop across all elements in list.
const labelList & processorPatches() const
Return list of processor patch labels.
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.
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A face is a list of labels corresponding to mesh vertices.
void off()
Switch the function objects off.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label nInternalFaces() const
static void findNearest(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &, const scalarField &nearestDistSqr, labelList &surfaces, List< pointIndexHit > &)
Find nearest. Return -1 (and a miss()) or surface and nearest.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An analytical geometric cellShape.
static unsigned int defaultPrecision()
Return the default precision.
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.
static bool master(const label communicator=0)
Am I the master process.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces) const
Write single surface geometry to file.
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.
Vector< scalar > vector
A scalar version of the templated Vector.
label k
Boltzmann constant.
const Time & time() const
Return the top-level database.
virtual bool write(const bool write=true) const
Write mesh using IO settings from time.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
const dimensionSet dimLength
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Neighbour processor patch.
virtual const pointField & points() const
Return raw points.
A list of faces which address into the list of points.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
A List obtained as a section of another List.
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
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.
const cellShapeList & cellShapes
Extract command arguments and options from the supplied argc and argv parameters. ...
scalar mag() const
The magnitude of the bounding box span.
wordList patchNames(nPatches)
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.
virtual const labelList & faceOwner() const
Return face owner.
Container for searchableSurfaces.
const globalMeshData & globalData() const
Return parallel info.
faceListList boundary(nPatches)
virtual const faceList & faces() const
Return raw faces.
int neighbProcNo() const
Return neighbour processor number.
const vectorField & cellCentres() const
const fvPatch & patch() const
Return patch.
const word & system() const
Return system name.
static autoPtr< decompositionMethod > New(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
IOstream::streamFormat writeFormat() const
Default write format.
tmp< Field< Type > > patchInternalField(const UList< Type > &) const
Return given internal field next to patch as patch field.
static pointMesh & New(polyMesh &mesh)
void setInstance(const fileName &)
Set the instance for mesh files.
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 fileName & instance() const
static label nProcs(const label communicator=0)
Number of processes in parallel run.
const functionObjectList & functionObjects() const
Return the list of function objects.
A surfaceWriter for VTK legacy format with support for writing ASCII or binary.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Mesh data needed to do the Finite Volume discretisation.
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
vector span() const
The bounding box span (from minimum to maximum)
Standard boundBox + extra functionality for use in octree.
dimensioned< scalar > mag(const dimensioned< Type > &)
Store a background polyMesh to use for the decomposition of space and queries for parallel conformalV...
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.
Marching tet iso surface algorithm with filtering to remove unnecessary topology. ...
const volVectorField & C() const
Return cell centres as volVectorField.
const point & min() const
Minimum describing the bounding box.
static void addNote(const string &)
Add extra notes for the usage information.
virtual bool write(const bool write=true) const
Write using setting from DB.
A class for managing temporary objects.
fileName path() const
Return path.
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.