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;
290 xferMoveTo<pointField>(points),
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 backgroud mesh according to cell size specification" <<
nl 589 backgroundMesh.mesh().
write();
592 const scalar tolDim = getMergeDistance
596 backgroundMesh.mesh().bounds()
605 const fvMesh& fvm = 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
655 fld = signedDistance(patchDistSqr, cc, geometry, surfaces);
663 cellDistance.write();
688 label ownDistSqr = distSqr[own];
693 pointDistSqr[f[fp]] =
max(pointDistSqr[f[fp]], ownDistSqr);
704 pointDistance.primitiveFieldRef() = signedDistance
714 pointDistance.write();
727 isoFaces.setSize(iso.size());
730 isoFaces[i] = iso[i].triFaceFace();
732 isoPoints = iso.points();
const fvPatch & patch() const
Return patch.
cachedRandom rndGen(label(0),-1)
const functionObjectList & functionObjects() const
Return the list of function objects.
#define forAll(list, i)
Loop across all elements in list.
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 NULL.
errorManipArg< error, int > exit(error &err, const int errNo=1)
const boundBox & bounds() const
Return mesh bounding box.
A face is a list of labels corresponding to mesh vertices.
void off()
Switch the function objects off.
const double e
Elementary charge.
const point & min() const
Minimum describing the bounding box.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
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.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An analytical geometric cellShape.
int neighbProcNo() const
Return neigbour processor number.
static unsigned int defaultPrecision()
Return the default precision.
void size(const label)
Override size to be inconsistent with allocated storage.
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
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.
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...
const labelList & processorPatches() const
Return list of processor patch labels.
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 volVectorField & C() const
Return cell centres as volVectorField.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const bool verbose=false) const
Write single surface geometry to file.
virtual const pointField & points() const
Return raw points.
static const pointMesh & New(const polyMesh &mesh)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Neighbour processor patch.
scalar mag() const
The magnitude of the bounding box span.
tmp< Field< Type > > patchInternalField(const UList< Type > &) const
Return given internal field next to patch as patch field.
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.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
bool optionFound(const word &opt) const
Return true if the named option is found.
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. ...
wordList patchNames(nPatches)
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
Container for searchableSurfaces.
const word & constant() const
Return constant name.
const vectorField & cellCentres() const
vector span() const
The bounding box span (from minimum to maximum)
faceListList boundary(nPatches)
A surface formed by the iso value. After "Polygonising A Scalar Field Using Tetrahedrons", Paul Bourke (http://paulbourke.net/geometry/polygonise) and "Regularised Marching Tetrahedra: improved iso-surface extraction", G.M. Treece, R.W. Prager and A.H. Gee.
IOstream::streamFormat writeFormat() const
Default write format.
Simple random number generator.
static autoPtr< decompositionMethod > New(const dictionary &decompositionDict)
Return a reference to the selected decomposition method.
const globalMeshData & globalData() const
Return parallel info.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
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.
static bool & parRun()
Is this a parallel run?
static label nProcs(const label communicator=0)
Number of processes in parallel run.
A surfaceWriter for VTK legacy format.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
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...
virtual bool write() const
Write using setting from DB.
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...
virtual Ostream & write(const token &)=0
Write next token to stream.
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.
const word & system() const
Return system name.
static void addNote(const string &)
Add extra notes for the usage information.
A class for managing temporary objects.
virtual const labelList & faceOwner() const
Return face owner.
virtual const faceList & faces() const
Return raw faces.
fileName path() const
Return path.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
const fileName & instance() const
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
label nInternalFaces() const
virtual bool write() const
Write mesh using IO settings from time.
const Time & time() const
Return the top-level database.