105 int main(
int argc,
char *argv[])
109 "Convert tetgen .ele and .node and .face files to an OpenFOAM mesh" 116 "Skip reading .face file for boundary information" 123 const bool readFaceFile = !
args.
found(
"noFaceFile");
125 const fileName nodeFile(prefix +
".node");
126 const fileName eleFile(prefix +
".ele");
127 const fileName faceFile(prefix +
".face");
132 <<
" nodes : " << nodeFile <<
endl 133 <<
" elems : " << eleFile <<
endl 139 <<
" nodes : " << nodeFile <<
endl 140 <<
" elems : " << eleFile <<
endl 141 <<
" faces : " << faceFile <<
endl 144 Info<<
"Reading .face file for boundary information" <<
nl <<
endl;
150 <<
"Cannot read " << nodeFile <<
" or " << eleFile
154 if (readFaceFile && !
isFile(faceFile))
157 <<
"Cannot read " << faceFile <<
endl 158 <<
"Did you run tetgen with -f option?" <<
endl 159 <<
"If you don't want to read the .face file and thus not have" 160 <<
" patches please\nrerun with the -noFaceFile option" 176 nodeStream.getLine(
line);
178 while (
line.starts_with(
'#'));
182 label nNodes, nDims, nNodeAttr;
185 nodeLine >> nNodes >> nDims >> nNodeAttr >> hasRegion;
189 <<
" nodes : " << nNodes <<
endl 190 <<
" nDims : " << nDims <<
endl 191 <<
" nAttr : " << nNodeAttr <<
endl 192 <<
" hasRegion : " << hasRegion <<
endl 207 while (nodeStream.good())
209 nodeStream.getLine(
line);
219 nodeLine >> nodeI >>
x >>
y >> z;
221 for (label i = 0; i < nNodeAttr; i++)
233 nodeToPoint.insert(nodeI, pointi);
237 if (pointi != nNodes)
240 <<
"Only " << pointi <<
" nodes present instead of " << nNodes
253 eleStream.getLine(
line);
255 while (
line.starts_with(
'#'));
259 label nTets, nPtsPerTet, nElemAttr;
261 eleLine >> nTets >> nPtsPerTet >> nElemAttr;
265 <<
" tets : " << nTets <<
endl 266 <<
" pointsPerTet : " << nPtsPerTet <<
endl 267 <<
" nAttr : " << nElemAttr <<
endl 273 <<
"Cannot handle tets with " 274 << nPtsPerTet <<
" points per tetrahedron in .ele file" <<
endl 275 <<
"Can only handle tetrahedra with four points" 282 <<
"Element attributes (third elemenent in .ele header)" 283 <<
" not used" <<
endl;
294 while (eleStream.good())
296 eleStream.getLine(
line);
305 for (label i = 0; i < 4; i++)
315 for (label i = 0; i < nElemAttr; i++)
369 faceStream.getLine(
line);
371 while (
line.starts_with(
'#'));
375 label nFaces, nFaceAttr;
377 faceLine >> nFaces >> nFaceAttr;
381 <<
" faces : " << nFaces <<
endl 382 <<
" nAttr : " << nFaceAttr <<
endl 389 <<
"Expect boundary markers to be" 390 <<
" present in .face file." <<
endl 391 <<
"This is the second number in the header which is now:" 409 while (faceStream.good())
411 faceStream.getLine(
line);
417 label tetGenFacei, dummy, region;
419 faceLine >> tetGenFacei;
423 for (label i = 0; i < 3; i++)
427 f[2-i] = nodeToPoint[nodeI];
433 boundaryFaces[facei] =
f;
444 const auto patchFind = regionToPatch.
cfind(region);
446 if (patchFind.good())
454 Info<<
"Mapping tetgen region " << region
464 for (label i = 1; i < nFaceAttr; i++)
486 Info<<
" region:" << iter.key()
487 <<
'\t' <<
"patch:" << iter.val() <<
nl;
514 allPatchFaces[patchi].append(boundaryFaces[facei]);
519 forAll(allPatchFaces, patchi)
522 << allPatchFaces[patchi].
size() <<
endl;
524 patchFaces[patchi].transfer(allPatchFaces[patchi]);
static word defaultName(const label n=-1)
Default patch name: "patch" or "patchN".
List< faceList > faceListList
List of faceList.
static void addNote(const string ¬e)
Add extra notes for the usage information.
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
Like polyPatch but without reference to mesh. Used in boundaryMesh to hold data on patches...
errorManipArg< error, int > exit(error &err, const int errNo=1)
A face is a list of labels corresponding to mesh vertices.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Cell-face mesh analysis engine.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr char nl
The newline '\n' character (0x0a)
wordList patchTypes(nPatches)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static unsigned int defaultPrecision() noexcept
Return the default precision.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
#define forAll(list, i)
Loop across all elements in list.
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
vectorField pointField
pointField is a vectorField.
void setSize(const label n)
Alias for resize()
Foam::autoPtr< Foam::dynamicFvMesh > meshPtr
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
A class for handling words, derived from Foam::string.
static word defaultRegion
Return the default region name.
wordList patchNames(nPatches)
label nInternalFaces() const noexcept
Number of internal faces.
virtual const faceList & faces() const
Return raw faces.
errorManip< error > abort(error &err)
const word & constant() const noexcept
Return constant name.
Input from file stream, using an ISstream.
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=cellModel::ref(cellModel::HEX);labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells].reset(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< SMALL) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &oldCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
List< word > wordList
List of word.
vector point
Point is a vector.
T get(const label index) const
Get a value from the argument at index.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Tet point storage. Default constructable (tetrahedron is not)
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Automatically write from objectRegistry::writeObject()
Maps a geometry to a set of cell primitives.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
messageStream Info
Information stream (stdout output on master, null elsewhere)
const labelListList & pointFaces() const
Mesh consisting of general polyhedral cells.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
bool found(const word &optName) const
Return true if the named option is found.
forAllConstIters(mixture.phases(), phase)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...