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;
123 label facei = pFaces[i];
125 const face& f = pp[facei];
138 if (nMatched == meshF.size())
155 label facei = pFaces[i];
170 if (nMatched == meshF.
size())
191 const face& f = faces[i];
196 if (((points[f[0]] - cc) &
n) < 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;
309 point& pt = points[pointi];
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' 366 << string::validate<word>(
regionName) << endl;
368 else if (nSpaces == 2)
375 Info<<
" " <<
"Line " << regionI <<
'\t' 376 << string::validate<word>(
regionName) << endl;
378 else if (physType == 2)
380 Info<<
" " <<
"Surface " << regionI <<
'\t' 381 << string::validate<word>(
regionName) << endl;
383 else if (physType == 3)
385 Info<<
" " <<
"Volume " << regionI <<
'\t' 386 << string::validate<word>(
regionName) << endl;
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,
446 Info<<
"Cells to be read:" << nElems << endl <<
endl;
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);
515 patchToPhys.
setSize(patchi + 1);
517 Info<<
"Mapping region " << regPhys <<
" to Foam patch " 519 physToPatch.
insert(regPhys, patchi);
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);
548 patchToPhys.
setSize(patchi + 1);
550 Info<<
"Mapping region " << regPhys <<
" to Foam patch " 552 physToPatch.
insert(regPhys, patchi);
553 patchToPhys[
patchi] = regPhys;
562 patchFaces[
patchi].append(quadPoints);
564 else if (elmType == MSHTET)
581 cells[celli++] =
cellShape(tet, tetPoints);
585 else if (elmType == MSHPYR)
597 >> pyrPoints[0] >> pyrPoints[1] >> pyrPoints[2]
598 >> pyrPoints[3] >> pyrPoints[4];
602 cells[celli++] =
cellShape(pyr, pyrPoints);
606 else if (elmType == MSHPRISM)
618 >> prismPoints[0] >> prismPoints[1] >> prismPoints[2]
619 >> prismPoints[3] >> prismPoints[4] >> prismPoints[5];
623 cells[celli] =
cellShape(prism, prismPoints);
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];
638 cells[celli] =
cellShape(prism, prismPoints);
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];
664 cells[celli] =
cellShape(hex, hexPoints);
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];
681 cells[celli] =
cellShape(hex, hexPoints);
690 Info<<
"Unhandled element " << elmType <<
" at line " 700 if (tag !=
"$ENDELM" && tag !=
"$EndElements")
703 <<
"Did not find $ENDELM tag on line " 710 forAll(patchFaces, patchi)
712 patchFaces[
patchi].shrink();
716 Info<<
"Cells:" << endl
717 <<
" total:" << cells.
size() << endl
718 <<
" hex :" << nHex << endl
719 <<
" prism:" << nPrism << endl
720 <<
" pyr :" << nPyr << endl
721 <<
" tet :" << nTet << endl
724 if (cells.
size() == 0)
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?" 735 Info<<
"CellZones:" << nl
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" 774 <<
"Creating polyMesh for region " << regionName <<
endl;
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)
889 if (iter != physicalNames.
end())
891 boundaryPatchNames[
patchi] = iter();
897 Info<<
"Patch " << patchi <<
" gets name " 902 wordList boundaryPatchTypes(boundaryFaces.size(), polyPatch::typeName);
903 word defaultFacesName =
"defaultFaces";
904 word defaultFacesType = polyPatch::typeName;
907 boundaryFaces.size(),
926 boundaryPatchPhysicalTypes
934 const polyPatch& pp = mesh.boundaryMesh().last();
941 forAll(patchFaces, patchi)
945 Info<<
"Finding faces of patch " << patchi <<
endl;
949 const face& f = pFaces[i];
952 label patchFacei = findFace(pp, f);
954 if (patchFacei != -1)
958 repatcher.changePatchID(meshFacei, patchi);
964 label meshFacei = findInternalFace(mesh, f);
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;
985 Info<<
"FaceZones:" << nl
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" 1041 cellSet cset(mesh, zoneName, zoneCells[zoneI]);
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" 1080 faceSet fset(mesh, zoneName, zoneFaces[zoneI]);
1087 boolList(zoneFaces[zoneI].size(),
true),
1102 label defaultPatchID = mesh.boundaryMesh().findPatchID(defaultFacesName);
1103 if (mesh.boundaryMesh()[defaultPatchID].size() == 0)
1106 label newPatchi = 0;
1109 if (patchi != defaultPatchID)
1113 newPatchPtrList[newPatchi] = patch.
clone 1115 mesh.boundaryMesh(),
1124 repatcher.changePatches(newPatchPtrList);
const labelListList & pointFaces() const
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or NULL.
An STL-conforming const_iterator.
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)
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
A face is a list of labels corresponding to mesh vertices.
Cell-face mesh analysis engine.
An analytical geometric cellShape.
void size(const label)
Override size to be inconsistent with allocated storage.
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
bool good() const
Return true if next operation might succeed.
static word defaultRegion
Return the default region name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Map< label > & meshPointMap() const
Mesh point map. Given the global point index find its.
static void noParallel()
Remove the parallel options.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
const fileName & name() const
Return the name of the stream.
label size() const
Return number of elements in table.
vector normal(const pointField &) const
Vector normal; magnitude is equal to area of face.
List< bool > boolList
Bool container classes.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
A list of faces which address into the list of points.
static const labelSphericalTensor labelI(1)
Identity labelTensor.
label start() const
Return start label of this patch in the polyMesh face list.
A mesh which allows changes in the patch distribution of the boundary faces. The change in patching i...
bool optionFound(const word &opt) const
Return true if the named option is found.
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
A class for handling words, derived from string.
void append(const T &)
Append an element at the end of the list.
bool found(const Key &) const
Return true if hashedEntry is found in table.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
word name(const complex &)
Return a string representation of a complex.
An instant of time. Contains the time value and name.
void setSize(const label)
Reset size of List.
faceList faces() const
Faces of this cell.
point centre(const pointField &) const
Centroid of the cell.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Tet storage. Null constructable (unfortunately tetrahedron<point, point> is not)
Input from memory buffer stream.
A collection of cell labels.
label lineNumber() const
Return current stream line number.
virtual const faceList & faces() const =0
Return faces.
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
void resize(const label newSize)
Resize the hash table for efficiency.
Mesh consisting of general polyhedral cells.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
A subset of mesh faces organised as a primitive patch.
const labelListList & pointFaces() const
Return point-face addressing.
A patch is a list of labels that address the faces in the global face list.
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
ISstream & getLine(string &)
Raw, low-level getline into a string function.