91 if (
mesh.faces()[facei] ==
f)
105int 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];
431 if (findFace(
mesh,
f) >=
mesh.nInternalFaces())
433 boundaryFaces[facei] =
f;
442 label patchi = regionToPatch.
lookup(region, -1);
449 Info<<
"Mapping tetgen region " << region
457 for (label i = 1; i < nFaceAttr; i++)
479 Info<<
" region:" << iter.key()
480 <<
'\t' <<
"patch:" << iter.val() <<
nl;
501 List<DynamicList<face>> allPatchFaces(
nPatches);
507 allPatchFaces[patchi].append(boundaryFaces[facei]);
512 forAll(allPatchFaces, patchi)
515 << allPatchFaces[patchi].size() <<
endl;
517 patchFaces[patchi].transfer(allPatchFaces[patchi]);
const T & lookup(const Key &key, const T &deflt) const
Return hashed entry if it exists, or return the given default.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
@ NO_READ
Nothing to be read.
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
void setSize(label n)
Alias for resize().
A HashTable to objects of type <T> with a label key.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Like polyPatch but without reference to mesh. Used in boundaryMesh to hold data on patches....
Maps a geometry to a set of cell primitives.
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
A face is a list of labels corresponding to mesh vertices.
A class for handling file names.
static word defaultName(const label n=-1)
Default patch name: "patch" or "patchN".
Mesh consisting of general polyhedral cells.
static word defaultRegion
Return the default region name.
Cell-face mesh analysis engine.
Tet point storage. Default constructable (tetrahedron is not).
A class for handling words, derived from Foam::string.
Foam::autoPtr< Foam::dynamicFvMesh > meshPtr
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
List< word > wordList
List of word.
List< label > labelList
A List of labels.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< face > faceList
List of faces.
Ostream & endl(Ostream &os)
Add newline and flush stream.
List< faceList > faceListList
List of faceList.
errorManip< error > abort(error &err)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
vector point
Point is a vector.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< cellShape > cellShapeList
List of cellShape.
constexpr char nl
The newline '\n' character (0x0a).
wordList patchTypes(nPatches)
wordList patchNames(nPatches)
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];} pointMap[start]=pointMap[end]=Foam::min(start, end);} } 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};constexpr 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< DynamicList< face > > pFaces[nBCs]
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.