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];
196 if (((
points[
f[0]] - cc) & a) < 0)
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);
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'
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)
502 lineStr >> triPoints[0] >> triPoints[1] >> triPoints[2];
509 if (regFnd == physToPatch.
end())
512 patchi = patchFaces.size();
514 patchFaces.setSize(
patchi + 1);
517 Info<<
"Mapping region " << regPhys <<
" to Foam patch "
520 patchToPhys[
patchi] = regPhys;
529 patchFaces[
patchi].append(triPoints);
531 else if (elmType == MSHQUAD)
534 >> quadPoints[0] >> quadPoints[1] >> quadPoints[2]
542 if (regFnd == physToPatch.
end())
545 patchi = patchFaces.size();
547 patchFaces.setSize(
patchi + 1);
550 Info<<
"Mapping region " << regPhys <<
" to Foam patch "
553 patchToPhys[
patchi] = regPhys;
562 patchFaces[
patchi].append(quadPoints);
564 else if (elmType == MSHTET)
576 >> tetPoints[0] >> tetPoints[1] >> tetPoints[2]
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 "
712 patchFaces[
patchi].shrink();
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"
807 scalar versionFormat = 1;
810 while (inFile.
good())
818 if (tag ==
"$MeshFormat")
820 versionFormat = readMeshFormat(inFile);
822 else if (tag ==
"$PhysicalNames")
824 readPhysNames(inFile, physicalNames);
826 else if (tag ==
"$NOD" || tag ==
"$Nodes")
828 readPoints(inFile,
points, mshToFoam);
830 else if (tag ==
"$ELM" || tag ==
"$Elements")
848 Info<<
"Skipping tag " << tag <<
" at line "
852 if (!skipSection(inFile))
860 label nValidCellZones = 0;
864 if (zoneCells[zoneI].size())
883 wordList boundaryPatchNames(boundaryFaces.size());
891 if (iter != physicalNames.
end())
893 boundaryPatchNames[
patchi] = iter();
904 wordList boundaryPatchTypes(boundaryFaces.size(), polyPatch::typeName);
909 boundaryFaces.size(),
929 boundaryPatchPhysicalTypes
955 label patchFacei = findFace(pp,
f);
957 if (patchFacei != -1)
971 zoneFaces[
patchi].append(meshFacei);
976 <<
"Could not match gmsh face " <<
f
977 <<
" to any of the interior or exterior faces"
978 <<
" that share the same 0th point" <<
endl;
986 label nValidFaceZones = 0;
989 <<
"Zone\tSize" <<
endl;
993 zoneFaces[zoneI].shrink();
995 const labelList& zFaces = zoneFaces[zoneI];
1009 runTime.setTime(
instant(runTime.constant()), 0);
1020 if (nValidCellZones > 0)
1024 nValidCellZones = 0;
1028 if (zoneCells[zoneI].size())
1030 label physReg = zoneToPhys[zoneI];
1034 word zoneName =
"cellZone_" +
name(zoneI);
1035 if (iter != physicalNames.
end())
1040 Info<<
"Writing zone " << zoneI <<
" to cellZone "
1041 << zoneName <<
" and cellSet"
1058 if (nValidFaceZones > 0)
1062 nValidFaceZones = 0;
1066 if (zoneFaces[zoneI].size())
1068 label physReg = patchToPhys[zoneI];
1072 word zoneName =
"faceZone_" +
name(zoneI);
1073 if (iter != physicalNames.
end())
1078 Info<<
"Writing zone " << zoneI <<
" to faceZone "
1079 << zoneName <<
" and faceSet"
1089 boolList(zoneFaces[zoneI].size(),
true),
1107 label newPatchi = 0;
1110 if (
patchi != defaultPatchID)
1114 newPatchPtrList[newPatchi] = patch.
clone
#define forAll(list, i)
Loop across all elements in list.
label size() const
Return number of elements in table.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
bool found(const Key &) const
Return true if hashedEntry is found in table.
void resize(const label newSize)
Resize the hash table for efficiency.
const fileName & name() const
Return the name of the stream.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
label lineNumber() const
Return current stream line number.
bool good() const
Return true if next operation might succeed.
ISstream & getLine(string &, const bool continuation=true)
Read line into a string.
Input from memory buffer stream.
void append(const T &)
Append an element at the end of the list.
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
const Map< label > & meshPointMap() const
Mesh point map. Given the global point index find its.
const labelListList & pointFaces() const
Return point-face addressing.
label size() const
Return the number of elements in the UList.
label size() const
Return the number of elements in the UPtrList.
T & last()
Return reference to the last element of the list.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
bool optionFound(const word &opt) const
Return true if the named option is found.
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
static void noParallel()
Remove the parallel options.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
A collection of cell labels.
An analytical geometric cellShape.
point centre(const pointField &) const
Centroid of the cell.
faceList faces() const
Faces of this cell.
Named list of cell indices representing a sub-set of the mesh.
A cell is defined as a list of faces with extra functionality.
Named list of face indices representing a sub-set of the mesh faces.
A face is a list of labels corresponding to mesh vertices.
virtual bool write(const bool write=true) const
Write mesh using IO settings from time.
An instant of time. Contains the time value and name.
label findIndex(const word &patchName) const
Find patch index given a name.
Mesh consisting of general polyhedral cells.
const cellZoneList & cellZones() const
Return cell zones.
static word defaultRegion
Return the default region name.
virtual const faceList & faces() const
Return raw faces.
const faceZoneList & faceZones() const
Return face zones.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
A patch is a list of labels that address the faces in the global face list.
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.
Cell-face mesh analysis engine.
const labelListList & pointFaces() const
A mesh which allows changes in the patch distribution of the boundary faces. The change in patching i...
void changePatchID(const label faceID, const label patchID)
Change patch ID for a boundary face. Note: patchID should be in new.
void changePatches(const List< polyPatch * > &patches)
Change patches.
void repatch()
Re-patch the mesh.
A variable is a word with support for additional characters, in particular '$' and '/'.
A class for handling words, derived from string.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
int main(int argc, char *argv[])
#define WarningInFunction
Report a warning using Foam::Warning.
errorManipArg< error, int > exit(error &err, const int errNo=1)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static const labelSphericalTensor labelI(1)
Identity labelTensor.
const word & regionName(const solver ®ion)
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
IOstream & hex(IOstream &io)
List< bool > boolList
Bool container classes.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
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, &mergedCyclicPolyPatch::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]
Foam::argList args(argc, argv)
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable