Go to the documentation of this file.
63 static label MSHTRI = 2;
64 static label MSHQUAD = 3;
65 static label MSHTET = 4;
66 static label MSHPYR = 7;
67 static label MSHPRISM = 6;
68 static label MSHHEX = 5;
84 while (
line.size() < 4 ||
line.substr(0, 4) !=
"$End");
109 if (!meshPointMap.found(meshF[0]))
111 Warning<<
"Not using gmsh face " << meshF
112 <<
" since zero vertex is not on boundary of polyMesh" <<
endl;
125 const face&
f = pp[faceI];
138 if (nMatched == meshF.size())
170 if (nMatched == meshF.
size())
191 const face&
f = faces[i];
219 if (zoneFnd == physToZone.end())
222 label zoneI = zoneCells.size();
223 zoneCells.setSize(zoneI+1);
226 Info<<
"Mapping region " << regPhys <<
" to Foam cellZone "
228 physToZone.insert(regPhys, zoneI);
230 zoneToPhys[zoneI] = regPhys;
231 zoneCells[zoneI].
append(cellI);
236 zoneCells[zoneFnd()].append(cellI);
242 scalar readMeshFormat(
IFstream& inFile)
244 Info<<
"Starting to read mesh format at line "
253 label asciiFlag, nBytes;
254 lineStr >> version >> asciiFlag >> nBytes;
256 Info<<
"Read format version " << version <<
" ascii " << asciiFlag <<
endl;
261 <<
"Can only read ascii msh files."
269 if (tag !=
"$EndMeshFormat")
272 <<
"Did not find $ENDNOD tag on line "
293 Info<<
"Vertices to be read:" << nVerts <<
endl;
296 mshToFoam.resize(2*nVerts);
298 for (
label pointI = 0; pointI < nVerts; pointI++)
301 scalar xVal, yVal, zVal;
307 lineStr >> mshLabel >> xVal >> yVal >> zVal;
315 mshToFoam.insert(mshLabel, pointI);
318 Info<<
"Vertices read:" << mshToFoam.size() <<
endl;
324 if (tag !=
"$ENDNOD" && tag !=
"$EndNodes")
327 <<
"Did not find $ENDNOD tag on line "
337 Info<<
"Starting to read physical names at line " << inFile.
lineNumber()
347 Info<<
"Physical names:" << nNames <<
endl;
349 physicalNames.resize(nNames);
351 for (
label i = 0; i < nNames; i++)
359 label nSpaces = lineStr.str().count(
' ');
365 Info<<
" " << regionI <<
'\t'
368 else if (nSpaces == 2)
375 Info<<
" " <<
"Line " << regionI <<
'\t'
378 else if (physType == 2)
380 Info<<
" " <<
"Surface " << regionI <<
'\t'
383 else if (physType == 3)
385 Info<<
" " <<
"Volume " << regionI <<
'\t'
390 physicalNames.insert(regionI, string::validate<word>(
regionName));
397 if (tag !=
"$EndPhysicalNames")
400 <<
"Did not find $EndPhysicalNames tag on line "
410 const scalar versionFormat,
411 const bool keepOrientation,
466 for (
label elemI = 0; elemI < nElems; elemI++)
472 label elmNumber, elmType, regPhys;
474 if (versionFormat >= 2)
476 lineStr >> elmNumber >> elmType;
485 for (
label i = 1; i < nTags; i++)
494 label regElem, nNodes;
495 lineStr >> elmNumber >> elmType >> regPhys >> regElem >> nNodes;
500 if (elmType == MSHTRI)
509 if (regFnd == physToPatch.end())
515 patchToPhys.
setSize(patchI + 1);
517 Info<<
"Mapping region " << regPhys <<
" to Foam patch "
519 physToPatch.insert(regPhys, patchI);
520 patchToPhys[patchI] = regPhys;
531 else if (elmType == MSHQUAD)
534 >> quadPoints[0] >> quadPoints[1] >> quadPoints[2]
542 if (regFnd == physToPatch.end())
548 patchToPhys.
setSize(patchI + 1);
550 Info<<
"Mapping region " << regPhys <<
" to Foam patch "
552 physToPatch.insert(regPhys, patchI);
553 patchToPhys[patchI] = regPhys;
564 else if (elmType == MSHTET)
585 else if (elmType == MSHPYR)
597 >> pyrPoints[0] >> pyrPoints[1] >> pyrPoints[2]
598 >> pyrPoints[3] >> pyrPoints[4];
606 else if (elmType == MSHPRISM)
618 >> prismPoints[0] >> prismPoints[1] >> prismPoints[2]
619 >> prismPoints[3] >> prismPoints[4] >> prismPoints[5];
627 if (!keepOrientation && !correctOrientation(
points,
cell))
629 Info<<
"Inverting prism " << cellI <<
endl;
631 prismPoints[0] =
cell[0];
632 prismPoints[1] =
cell[2];
633 prismPoints[2] =
cell[1];
634 prismPoints[3] =
cell[3];
635 prismPoints[4] =
cell[4];
636 prismPoints[5] =
cell[5];
645 else if (elmType == MSHHEX)
657 >> hexPoints[0] >> hexPoints[1]
658 >> hexPoints[2] >> hexPoints[3]
659 >> hexPoints[4] >> hexPoints[5]
660 >> hexPoints[6] >> hexPoints[7];
668 if (!keepOrientation && !correctOrientation(
points,
cell))
670 Info<<
"Inverting hex " << cellI <<
endl;
672 hexPoints[0] =
cell[4];
673 hexPoints[1] =
cell[5];
674 hexPoints[2] =
cell[6];
675 hexPoints[3] =
cell[7];
676 hexPoints[4] =
cell[0];
677 hexPoints[5] =
cell[1];
678 hexPoints[6] =
cell[2];
679 hexPoints[7] =
cell[3];
690 Info<<
"Unhandled element " << elmType <<
" at line "
700 if (tag !=
"$ENDELM" && tag !=
"$EndElements")
703 <<
"Did not find $ENDELM tag on line "
718 <<
" hex :" << nHex <<
endl
719 <<
" prism:" << nPrism <<
endl
720 <<
" pyr :" << nPyr <<
endl
721 <<
" tet :" << nTet <<
endl
727 <<
"No cells read from file " << inFile.
name() <<
nl
728 <<
"Does your file specify any 3D elements (hex=" << MSHHEX
729 <<
", prism=" << MSHPRISM <<
", pyramid=" << MSHPYR
730 <<
", tet=" << MSHTET <<
")?" <<
nl
731 <<
"Perhaps you have not exported the 3D elements?"
736 <<
"Zone\tSize" <<
endl;
740 zoneCells[zoneI].shrink();
742 const labelList& zCells = zoneCells[zoneI];
754 int main(
int argc,
char *argv[])
761 "retain raw orientation for prisms/hexs"
805 scalar versionFormat = 1;
808 while (inFile.
good())
816 if (tag ==
"$MeshFormat")
818 versionFormat = readMeshFormat(inFile);
820 else if (tag ==
"$PhysicalNames")
822 readPhysNames(inFile, physicalNames);
824 else if (tag ==
"$NOD" || tag ==
"$Nodes")
826 readPoints(inFile,
points, mshToFoam);
828 else if (tag ==
"$ELM" || tag ==
"$Elements")
846 Info<<
"Skipping tag " << tag <<
" at line "
850 if (!skipSection(inFile))
858 label nValidCellZones = 0;
862 if (zoneCells[zoneI].size())
881 wordList boundaryPatchNames(boundaryFaces.size());
883 forAll(boundaryPatchNames, patchI)
885 label physReg = patchToPhys[patchI];
889 if (iter != physicalNames.end())
891 boundaryPatchNames[patchI] = iter();
895 boundaryPatchNames[patchI] =
word(
"patch") +
name(patchI);
897 Info<<
"Patch " << patchI <<
" gets name "
898 << boundaryPatchNames[patchI] <<
endl;
902 wordList boundaryPatchTypes(boundaryFaces.size(), polyPatch::typeName);
907 boundaryFaces.size(),
926 boundaryPatchPhysicalTypes
945 Info<<
"Finding faces of patch " << patchI <<
endl;
952 label patchFaceI = findFace(pp,
f);
954 if (patchFaceI != -1)
958 repatcher.changePatchID(meshFaceI, patchI);
968 zoneFaces[patchI].append(meshFaceI);
973 <<
"Could not match gmsh face " <<
f
974 <<
" to any of the interior or exterior faces"
975 <<
" that share the same 0th point" <<
endl;
983 label nValidFaceZones = 0;
986 <<
"Zone\tSize" <<
endl;
990 zoneFaces[zoneI].shrink();
992 const labelList& zFaces = zoneFaces[zoneI];
1006 runTime.setTime(
instant(runTime.constant()), 0);
1008 repatcher.repatch();
1017 if (nValidCellZones > 0)
1021 nValidCellZones = 0;
1025 if (zoneCells[zoneI].size())
1027 label physReg = zoneToPhys[zoneI];
1031 word zoneName =
"cellZone_" +
name(zoneI);
1032 if (iter != physicalNames.end())
1037 Info<<
"Writing zone " << zoneI <<
" to cellZone "
1038 << zoneName <<
" and cellSet"
1056 if (nValidFaceZones > 0)
1060 nValidFaceZones = 0;
1064 if (zoneFaces[zoneI].size())
1066 label physReg = patchToPhys[zoneI];
1070 word zoneName =
"faceZone_" +
name(zoneI);
1071 if (iter != physicalNames.end())
1076 Info<<
"Writing zone " << zoneI <<
" to faceZone "
1077 << zoneName <<
" and faceSet"
1087 boolList(zoneFaces[zoneI].size(),
true),
1106 label newPatchI = 0;
1109 if (patchI != defaultPatchID)
1113 newPatchPtrList[newPatchI] = patch.
clone
1124 repatcher.changePatches(newPatchPtrList);
static SLList< string > validArgs
A list of valid (mandatory) arguments.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
const labelListList & pointFaces() const
Return point-face addressing.
point centre(const pointField &) const
Centroid of the cell.
const fileName & name() const
Return the name of the stream.
T & last()
Return reference to the last element of the list.
label findPatchID(const word &patchName) const
Find patch index given a name.
A class for handling words, derived from string.
static word defaultRegion
Return the default region name.
#define forAll(list, i)
Loop across all elements in list.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
An STL-conforming const_iterator.
const labelListList & pointFaces() const
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
const cellZoneMesh & cellZones() const
Return cell zone mesh.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Ostream & endl(Ostream &os)
Add newline and flush stream.
faceList faces() const
Faces of this cell.
labelList patchFaces(const polyBoundaryMesh &patches, const wordList &names)
Mesh consisting of general polyhedral cells.
const faceZoneMesh & faceZones() const
Return face zone mesh.
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=*(cellModeller::lookup("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]=cellShape(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]
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
virtual bool write() const
Write mesh using IO settings from time.
Triangle storage. Null constructable (unfortunately triangle<point, point> is not)
A mesh which allows changes in the patch distribution of the boundary faces. The change in patching i...
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Pre-declare SubField and related Field type.
A subset of mesh faces organised as a primitive patch.
void append(const T &)
Append an element at the end of the list.
ISstream & getLine(string &)
Raw, low-level getline into a string function.
A patch is a list of labels that address the faces in the global face list.
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or NULL.
int main(int argc, char *argv[])
An analytical geometric cellShape.
Input from memory buffer stream.
A collection of cell labels.
List< bool > boolList
Bool container classes.
label start() const
Return start label of this patch in the polyMesh face list.
virtual autoPtr< polyPatch > clone(const polyBoundaryMesh &bm) const
Construct and return a clone, resetting the boundary mesh.
errorManipArg< error, int > exit(error &err, const int errNo=1)
IOstream & hex(IOstream &io)
Tet storage. Null constructable (unfortunately tetrahedron<point, point> is not)
void setSize(const label)
Reset size of List.
virtual const faceList & faces() const
Return raw faces.
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
label size() const
Return the number of elements in the PtrList.
bool optionFound(const word &opt) const
Return true if the named option is found.
label lineNumber() const
Return current stream line number.
A face is a list of labels corresponding to mesh vertices.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
An instant of time. Contains the time value and name.
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
void size(const label)
Override size to be inconsistent with allocated storage.
const Map< label > & meshPointMap() const
Mesh point map. Given the global point index find its.
static void noParallel()
Remove the parallel options.
bool good() const
Return true if next operation might succeed.
Foam::argList args(argc, argv)
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
#define WarningInFunction
Report a warning using Foam::Warning.
A cell is defined as a list of faces with extra functionality.
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
word name(const complex &)
Return a string representation of a complex.
A list of faces which address into the list of points.
static const labelSphericalTensor labelI(1)
Identity labelTensor.
Cell-face mesh analysis engine.