82 static label MSHTRI = 2;
83 static label MSHQUAD = 3;
84 static label MSHTET = 4;
85 static label MSHPYR = 7;
86 static label MSHPRISM = 6;
87 static label MSHHEX = 5;
103 while (line.size() < 4 || line.substr(0, 4) !=
"$End");
128 if (!meshPointMap.
found(meshF[0]))
130 Warning<<
"Not using gmsh face " << meshF
131 <<
" since zero vertex is not on boundary of polyMesh" <<
endl;
142 label faceI = pFaces[i];
144 const face&
f = pp[faceI];
157 if (nMatched == meshF.size())
174 label faceI = pFaces[i];
189 if (nMatched == meshF.
size())
210 const face& f = faces[i];
215 if (((points[f[0]] - cc) & n) < 0)
238 if (zoneFnd == physToZone.
end())
241 label zoneI = zoneCells.size();
242 zoneCells.setSize(zoneI+1);
245 Info<<
"Mapping region " << regPhys <<
" to Foam cellZone "
247 physToZone.
insert(regPhys, zoneI);
249 zoneToPhys[zoneI] = regPhys;
250 zoneCells[zoneI].
append(cellI);
255 zoneCells[zoneFnd()].append(cellI);
261 scalar readMeshFormat(
IFstream& inFile)
270 label asciiFlag, nBytes;
271 lineStr >> version >> asciiFlag >> nBytes;
273 Info<<
"Read format version " << version <<
" ascii " << asciiFlag <<
endl;
278 <<
"Can only read ascii msh files."
286 if (tag !=
"$EndMeshFormat")
289 <<
"Did not find $ENDNOD tag on line "
310 Info<<
"Vertices to be read:" << nVerts <<
endl;
313 mshToFoam.
resize(2*nVerts);
315 for (label pointI = 0; pointI < nVerts; pointI++)
318 scalar xVal, yVal, zVal;
324 lineStr >> mshLabel >> xVal >> yVal >> zVal;
326 point& pt = points[pointI];
332 mshToFoam.
insert(mshLabel, pointI);
341 if (tag !=
"$ENDNOD" && tag !=
"$EndNodes")
344 <<
"Did not find $ENDNOD tag on line "
354 Info<<
"Starting to read physical names at line " << inFile.
lineNumber()
364 Info<<
"Physical names:" << nNames <<
endl;
366 physicalNames.
resize(nNames);
368 for (label i = 0; i < nNames; i++)
376 label nSpaces = lineStr.str().count(
' ');
382 Info<<
" " << regionI <<
'\t'
383 << string::validate<word>(
regionName) << endl;
385 else if(nSpaces == 2)
392 Info<<
" " <<
"Line " << regionI <<
'\t'
393 << string::validate<word>(
regionName) << endl;
395 else if (physType == 2)
397 Info<<
" " <<
"Surface " << regionI <<
'\t'
398 << string::validate<word>(
regionName) << endl;
400 else if (physType == 3)
402 Info<<
" " <<
"Volume " << regionI <<
'\t'
403 << string::validate<word>(
regionName) << endl;
407 physicalNames.
insert(regionI, string::validate<word>(regionName));
414 if (tag !=
"$EndPhysicalNames")
417 <<
"Did not find $EndPhysicalNames tag on line "
427 const scalar versionFormat,
428 const bool keepOrientation,
463 Info<<
"Cells to be read:" << nElems << endl <<
endl;
483 for (label elemI = 0; elemI < nElems; elemI++)
489 label elmNumber, elmType, regPhys;
491 if (versionFormat >= 2)
493 lineStr >> elmNumber >> elmType;
502 for (label i = 1; i < nTags; i++)
511 label regElem, nNodes;
512 lineStr >> elmNumber >> elmType >> regPhys >> regElem >> nNodes;
517 if (elmType == MSHTRI)
519 lineStr >> triPoints[0] >> triPoints[1] >> triPoints[2];
526 if (regFnd == physToPatch.
end())
529 patchI = patchFaces.size();
531 patchFaces.setSize(patchI + 1);
532 patchToPhys.
setSize(patchI + 1);
534 Info<<
"Mapping region " << regPhys <<
" to Foam patch "
536 physToPatch.
insert(regPhys, patchI);
537 patchToPhys[patchI] = regPhys;
546 patchFaces[patchI].append(triPoints);
548 else if (elmType == MSHQUAD)
551 >> quadPoints[0] >> quadPoints[1] >> quadPoints[2]
559 if (regFnd == physToPatch.
end())
562 patchI = patchFaces.size();
564 patchFaces.setSize(patchI + 1);
565 patchToPhys.
setSize(patchI + 1);
567 Info<<
"Mapping region " << regPhys <<
" to Foam patch "
569 physToPatch.
insert(regPhys, patchI);
570 patchToPhys[patchI] = regPhys;
579 patchFaces[patchI].append(quadPoints);
581 else if (elmType == MSHTET)
593 >> tetPoints[0] >> tetPoints[1] >> tetPoints[2]
598 cells[cellI++] =
cellShape(tet, tetPoints);
602 else if (elmType == MSHPYR)
614 >> pyrPoints[0] >> pyrPoints[1] >> pyrPoints[2]
615 >> pyrPoints[3] >> pyrPoints[4];
619 cells[cellI++] =
cellShape(pyr, pyrPoints);
623 else if (elmType == MSHPRISM)
635 >> prismPoints[0] >> prismPoints[1] >> prismPoints[2]
636 >> prismPoints[3] >> prismPoints[4] >> prismPoints[5];
640 cells[cellI] =
cellShape(prism, prismPoints);
644 if (!keepOrientation && !correctOrientation(points, cell))
646 Info<<
"Inverting prism " << cellI <<
endl;
648 prismPoints[0] = cell[0];
649 prismPoints[1] = cell[2];
650 prismPoints[2] = cell[1];
651 prismPoints[3] = cell[3];
652 prismPoints[4] = cell[4];
653 prismPoints[5] = cell[5];
655 cells[cellI] =
cellShape(prism, prismPoints);
662 else if (elmType == MSHHEX)
674 >> hexPoints[0] >> hexPoints[1]
675 >> hexPoints[2] >> hexPoints[3]
676 >> hexPoints[4] >> hexPoints[5]
677 >> hexPoints[6] >> hexPoints[7];
681 cells[cellI] =
cellShape(hex, hexPoints);
685 if (!keepOrientation && !correctOrientation(points, cell))
687 Info<<
"Inverting hex " << cellI <<
endl;
689 hexPoints[0] = cell[4];
690 hexPoints[1] = cell[5];
691 hexPoints[2] = cell[6];
692 hexPoints[3] = cell[7];
693 hexPoints[4] = cell[0];
694 hexPoints[5] = cell[1];
695 hexPoints[6] = cell[2];
696 hexPoints[7] = cell[3];
698 cells[cellI] =
cellShape(hex, hexPoints);
707 Info<<
"Unhandled element " << elmType <<
" at line "
717 if (tag !=
"$ENDELM" && tag !=
"$EndElements")
720 <<
"Did not find $ENDELM tag on line "
727 forAll(patchFaces, patchI)
729 patchFaces[patchI].shrink();
733 Info<<
"Cells:" << endl
734 <<
" total:" << cells.
size() << endl
735 <<
" hex :" << nHex << endl
736 <<
" prism:" << nPrism << endl
737 <<
" pyr :" << nPyr << endl
738 <<
" tet :" << nTet << endl
741 if (cells.
size() == 0)
744 <<
"No cells read from file " << inFile.
name() <<
nl
745 <<
"Does your file specify any 3D elements (hex=" << MSHHEX
746 <<
", prism=" << MSHPRISM <<
", pyramid=" << MSHPYR
747 <<
", tet=" << MSHTET <<
")?" <<
nl
748 <<
"Perhaps you have not exported the 3D elements?"
753 <<
"Zone\tSize" <<
endl;
757 zoneCells[zoneI].shrink();
759 const labelList& zCells = zoneCells[zoneI];
772 int main(
int argc,
char *argv[])
806 scalar versionFormat = 1;
811 while (inFile.
good())
819 if (tag ==
"$MeshFormat")
821 Info<<
"Found $MeshFormat tag; assuming version 2 file format."
823 versionFormat = readMeshFormat(inFile);
825 else if (tag ==
"$PhysicalNames")
827 readPhysNames(inFile, physicalNames);
829 else if (tag ==
"$NOD" || tag ==
"$Nodes")
831 readPoints(inFile, points, mshToFoam);
833 else if (tag ==
"$ELM" || tag ==
"$Elements")
851 Info<<
"Skipping tag " << tag <<
" at line "
855 if (!skipSection(inFile))
863 label nValidCellZones = 0;
867 if (zoneCells[zoneI].size())
886 wordList boundaryPatchNames(boundaryFaces.size());
888 forAll(boundaryPatchNames, patchI)
890 label physReg = patchToPhys[patchI];
894 if (iter != physicalNames.
end())
896 boundaryPatchNames[patchI] = iter();
900 boundaryPatchNames[patchI] =
word(
"patch") +
name(patchI);
902 Info<<
"Patch " << patchI <<
" gets name "
903 << boundaryPatchNames[patchI] <<
endl;
907 wordList boundaryPatchTypes(boundaryFaces.size(), polyPatch::typeName);
912 boundaryFaces.size(),
931 boundaryPatchPhysicalTypes
939 const polyPatch& pp = mesh.boundaryMesh()[mesh.boundaryMesh().size()-1];
946 forAll(patchFaces, patchI)
950 Info<<
"Finding faces of patch " << patchI <<
endl;
954 const face& f = pFaces[i];
957 label patchFaceI = findFace(pp, f);
959 if (patchFaceI != -1)
961 label meshFaceI = pp.
start() + patchFaceI;
963 repatcher.changePatchID(meshFaceI, patchI);
969 label meshFaceI = findInternalFace(mesh, f);
973 zoneFaces[patchI].append(meshFaceI);
978 <<
"Could not match gmsh face " << f
979 <<
" to any of the interior or exterior faces"
980 <<
" that share the same 0th point" << endl;
988 label nValidFaceZones = 0;
990 Info<<
"FaceZones:" << nl
991 <<
"Zone\tSize" <<
endl;
995 zoneFaces[zoneI].shrink();
997 const labelList& zFaces = zoneFaces[zoneI];
1010 runTime.setTime(
instant(runTime.constant()), 0);
1012 repatcher.repatch();
1021 if (nValidCellZones > 0)
1025 nValidCellZones = 0;
1029 if (zoneCells[zoneI].size())
1031 label physReg = zoneToPhys[zoneI];
1035 word zoneName =
"cellZone_" +
name(zoneI);
1036 if (iter != physicalNames.
end())
1041 Info<<
"Writing zone " << zoneI <<
" to cellZone "
1042 << zoneName <<
" and cellSet"
1045 cellSet cset(mesh, zoneName, zoneCells[zoneI]);
1060 if (nValidFaceZones > 0)
1064 nValidFaceZones = 0;
1068 if (zoneFaces[zoneI].size())
1070 label physReg = zoneToPhys[zoneI];
1074 word zoneName =
"faceZone_" +
name(zoneI);
1075 if (iter != physicalNames.
end())
1080 Info<<
"Writing zone " << zoneI <<
" to faceZone "
1081 << zoneName <<
" and faceSet"
1084 faceSet fset(mesh, zoneName, zoneFaces[zoneI]);
1091 boolList(zoneFaces[zoneI].size(),
true),