1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "objectRegistry.H"
29 #include "ensightMesh.H"
31 #include "globalMeshData.H"
32 #include "PstreamCombineReduceOps.H"
33 #include "processorPolyPatch.H"
34 #include "cellModeller.H"
37 #include "ensightWriteBinary.H"
40 // * * * * * * * * * * * * * Private Functions * * * * * * * * * * * * * * //
44 //- Proxy-class to hold the patch processor list combination operator
45 class concatPatchProcs
53 const List<labelList>& y
58 const labelList& yPatches = y[i];
62 labelList& xPatches = x[i];
64 label offset = xPatches.size();
65 xPatches.setSize(offset + yPatches.size());
69 xPatches[i + offset] = yPatches[i];
75 } // End namespace Foam
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80 Foam::ensightMesh::ensightMesh
90 meshCellSets_(mesh_.nCells()),
91 boundaryFaceSets_(mesh_.boundary().size()),
97 const cellShapeList& cellShapes = mesh.cellShapes();
99 const cellModel& tet = *(cellModeller::lookup("tet"));
100 const cellModel& pyr = *(cellModeller::lookup("pyr"));
101 const cellModel& prism = *(cellModeller::lookup("prism"));
102 const cellModel& wedge = *(cellModeller::lookup("wedge"));
103 const cellModel& hex = *(cellModeller::lookup("hex"));
105 if (!args.optionFound("noPatches"))
107 allPatchNames_ = wordList::subList
109 mesh_.boundaryMesh().names(), mesh_.boundary().size()
110 - mesh_.globalData().processorPatches().size()
113 allPatchProcs_.setSize(allPatchNames_.size());
115 forAll (allPatchProcs_, patchi)
117 if (mesh_.boundary()[patchi].size())
119 allPatchProcs_[patchi].setSize(1);
120 allPatchProcs_[patchi][0] = Pstream::myProcNo();
124 combineReduce(allPatchProcs_, concatPatchProcs());
126 if (args.optionFound("patches"))
128 wordList patchNameList(args.optionLookup("patches")());
130 if (patchNameList.empty())
132 patchNameList = allPatchNames_;
135 forAll (patchNameList, i)
137 patchNames_.insert(patchNameList[i]);
142 if (patchNames_.size())
145 patchPartOffset_ = 1;
150 labelList& tets = meshCellSets_.tets;
151 labelList& pyrs = meshCellSets_.pyrs;
152 labelList& prisms = meshCellSets_.prisms;
153 labelList& wedges = meshCellSets_.wedges;
154 labelList& hexes = meshCellSets_.hexes;
155 labelList& polys = meshCellSets_.polys;
164 forAll(cellShapes, cellI)
166 const cellShape& cellShape = cellShapes[cellI];
167 const cellModel& cellModel = cellShape.model();
169 if (cellModel == tet)
171 tets[nTets++] = cellI;
173 else if (cellModel == pyr)
175 pyrs[nPyrs++] = cellI;
177 else if (cellModel == prism)
179 prisms[nPrisms++] = cellI;
181 else if (cellModel == wedge)
183 wedges[nWedges++] = cellI;
185 else if (cellModel == hex)
187 hexes[nHexes++] = cellI;
191 polys[nPolys++] = cellI;
197 prisms.setSize(nPrisms);
198 wedges.setSize(nWedges);
199 hexes.setSize(nHexes);
200 polys.setSize(nPolys);
202 meshCellSets_.nTets = nTets;
203 reduce(meshCellSets_.nTets, sumOp<label>());
205 meshCellSets_.nPyrs = nPyrs;
206 reduce(meshCellSets_.nPyrs, sumOp<label>());
208 meshCellSets_.nPrisms = nPrisms;
209 reduce(meshCellSets_.nPrisms, sumOp<label>());
211 meshCellSets_.nHexesWedges = nHexes + nWedges;
212 reduce(meshCellSets_.nHexesWedges, sumOp<label>());
214 meshCellSets_.nPolys = nPolys;
215 reduce(meshCellSets_.nPolys, sumOp<label>());
218 if (!args.optionFound("noPatches"))
220 forAll (mesh.boundary(), patchi)
222 if (mesh.boundary()[patchi].size())
224 const polyPatch& p = mesh.boundaryMesh()[patchi];
226 labelList& tris = boundaryFaceSets_[patchi].tris;
227 labelList& quads = boundaryFaceSets_[patchi].quads;
228 labelList& polys = boundaryFaceSets_[patchi].polys;
230 tris.setSize(p.size());
231 quads.setSize(p.size());
232 polys.setSize(p.size());
240 const face& f = p[faceI];
244 tris[nTris++] = faceI;
246 else if (f.size() == 4)
248 quads[nQuads++] = faceI;
252 polys[nPolys++] = faceI;
257 quads.setSize(nQuads);
258 polys.setSize(nPolys);
264 forAll(allPatchNames_, patchi)
266 const word& patchName = allPatchNames_[patchi];
269 if (patchNames_.empty() || patchNames_.found(patchName))
271 if (mesh.boundary()[patchi].size())
273 nfp.nPoints = mesh.boundaryMesh()[patchi].localPoints().size();
274 nfp.nTris = boundaryFaceSets_[patchi].tris.size();
275 nfp.nQuads = boundaryFaceSets_[patchi].quads.size();
276 nfp.nPolys = boundaryFaceSets_[patchi].polys.size();
280 reduce(nfp.nPoints, sumOp<label>());
281 reduce(nfp.nTris, sumOp<label>());
282 reduce(nfp.nQuads, sumOp<label>());
283 reduce(nfp.nPolys, sumOp<label>());
285 nPatchPrims_.insert(patchName, nfp);
290 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
292 Foam::ensightMesh::~ensightMesh()
296 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
298 void Foam::ensightMesh::writePoints
300 const scalarField& pointsComponent,
301 OFstream& ensightGeometryFile
304 forAll(pointsComponent, pointI)
306 ensightGeometryFile<< setw(12) << float(pointsComponent[pointI]) << nl;
311 Foam::cellShapeList Foam::ensightMesh::ensMap
313 const cellShapeList& cellShapes,
314 const labelList& prims
317 cellShapeList mcsl(prims.size());
321 mcsl[i] = cellShapes[prims[i]];
328 Foam::cellShapeList Foam::ensightMesh::ensMap
330 const cellShapeList& cellShapes,
331 const labelList& hexes,
332 const labelList& wedges
335 cellShapeList mcsl(hexes.size() + wedges.size());
339 mcsl[i] = cellShapes[hexes[i]];
342 label offset = hexes.size();
344 const cellModel& hex = *(cellModeller::lookup("hex"));
345 labelList hexLabels(8);
349 const cellShape& cellPoints = cellShapes[wedges[i]];
351 hexLabels[0] = cellPoints[0];
352 hexLabels[1] = cellPoints[1];
353 hexLabels[2] = cellPoints[0];
354 hexLabels[3] = cellPoints[2];
355 hexLabels[4] = cellPoints[3];
356 hexLabels[5] = cellPoints[4];
357 hexLabels[6] = cellPoints[6];
358 hexLabels[7] = cellPoints[5];
360 mcsl[i + offset] = cellShape(hex, hexLabels);
367 void Foam::ensightMesh::writePrims
369 const cellShapeList& cellShapes,
370 const label pointOffset,
371 OFstream& ensightGeometryFile
374 label po = pointOffset + 1;
376 forAll(cellShapes, i)
378 const cellShape& cellPoints = cellShapes[i];
380 forAll(cellPoints, pointI)
382 ensightGeometryFile<< setw(10) << cellPoints[pointI] + po;
384 ensightGeometryFile << nl;
389 void Foam::ensightMesh::writePrimsBinary
391 const cellShapeList& cellShapes,
392 const label pointOffset,
393 std::ofstream& ensightGeometryFile
396 label po = pointOffset + 1;
398 if (cellShapes.size())
400 // All the cellShapes have the same number of elements!
401 int numIntElem = cellShapes.size()*cellShapes[0].size();
402 List<int> temp(numIntElem);
406 forAll(cellShapes, i)
408 const cellShape& cellPoints = cellShapes[i];
410 forAll(cellPoints, pointI)
412 temp[n] = cellPoints[pointI] + po;
417 ensightGeometryFile.write
419 reinterpret_cast<char*>(temp.begin()),
420 numIntElem*sizeof(int)
426 void Foam::ensightMesh::writePolysNFaces
428 const labelList& polys,
429 const cellList& cellFaces,
430 OFstream& ensightGeometryFile
436 << setw(10) << cellFaces[polys[i]].size() << nl;
441 void Foam::ensightMesh::writePolysNPointsPerFace
443 const labelList& polys,
444 const cellList& cellFaces,
445 const faceList& faces,
446 OFstream& ensightGeometryFile
451 const labelList& cf = cellFaces[polys[i]];
456 << setw(10) << faces[cf[faceI]].size() << nl;
462 void Foam::ensightMesh::writePolysPoints
464 const labelList& polys,
465 const cellList& cellFaces,
466 const faceList& faces,
467 const label pointOffset,
468 OFstream& ensightGeometryFile
471 label po = pointOffset + 1;
475 const labelList& cf = cellFaces[polys[i]];
479 const face& f = faces[cf[faceI]];
483 ensightGeometryFile << setw(10) << f[pointI] + po;
485 ensightGeometryFile << nl;
491 void Foam::ensightMesh::writeAllPolys
493 const labelList& pointOffsets,
494 OFstream& ensightGeometryFile
497 if (meshCellSets_.nPolys)
499 const cellList& cellFaces = mesh_.cells();
500 const faceList& faces = mesh_.faces();
502 if (Pstream::master())
505 << "nfaced" << nl << setw(10) << meshCellSets_.nPolys << nl;
508 // Number of faces for each poly cell
509 if (Pstream::master())
519 for (int slave=1; slave<Pstream::nProcs(); slave++)
521 IPstream fromSlave(Pstream::scheduled, slave);
522 labelList polys(fromSlave);
523 cellList cellFaces(fromSlave);
535 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
536 toMaster<< meshCellSets_.polys << cellFaces;
539 // Number of points for each face of the above list
540 if (Pstream::master())
543 writePolysNPointsPerFace
551 for (int slave=1; slave<Pstream::nProcs(); slave++)
553 IPstream fromSlave(Pstream::scheduled, slave);
554 labelList polys(fromSlave);
555 cellList cellFaces(fromSlave);
556 faceList faces(fromSlave);
558 writePolysNPointsPerFace
569 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
570 toMaster<< meshCellSets_.polys << cellFaces << faces;
573 // List of points id for each face of the above list
574 if (Pstream::master())
586 for (int slave=1; slave<Pstream::nProcs(); slave++)
588 IPstream fromSlave(Pstream::scheduled, slave);
589 labelList polys(fromSlave);
590 cellList cellFaces(fromSlave);
591 faceList faces(fromSlave);
598 pointOffsets[slave-1],
605 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
606 toMaster<< meshCellSets_.polys << cellFaces << faces;
612 void Foam::ensightMesh::writePolysNFacesBinary
614 const labelList& polys,
615 const cellList& cellFaces,
616 std::ofstream& ensightGeometryFile
623 cellFaces[polys[i]].size(),
630 void Foam::ensightMesh::writePolysNPointsPerFaceBinary
632 const labelList& polys,
633 const cellList& cellFaces,
634 const faceList& faces,
635 std::ofstream& ensightGeometryFile
640 const labelList& cf = cellFaces[polys[i]];
646 faces[cf[faceI]].size(),
654 void Foam::ensightMesh::writePolysPointsBinary
656 const labelList& polys,
657 const cellList& cellFaces,
658 const faceList& faces,
659 const label pointOffset,
660 std::ofstream& ensightGeometryFile
663 label po = pointOffset + 1;
667 const labelList& cf = cellFaces[polys[i]];
671 const face& f = faces[cf[faceI]];
675 writeEnsDataBinary(f[pointI] + po,ensightGeometryFile);
682 void Foam::ensightMesh::writeAllPolysBinary
684 const labelList& pointOffsets,
685 std::ofstream& ensightGeometryFile
688 if (meshCellSets_.nPolys)
690 const cellList& cellFaces = mesh_.cells();
691 const faceList& faces = mesh_.faces();
693 if (Pstream::master())
695 writeEnsDataBinary("nfaced",ensightGeometryFile);
696 writeEnsDataBinary(meshCellSets_.nPolys,ensightGeometryFile);
699 // Number of faces for each poly cell
700 if (Pstream::master())
703 writePolysNFacesBinary
710 for (int slave=1; slave<Pstream::nProcs(); slave++)
712 IPstream fromSlave(Pstream::scheduled, slave);
713 labelList polys(fromSlave);
714 cellList cellFaces(fromSlave);
716 writePolysNFacesBinary
726 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
727 toMaster<< meshCellSets_.polys << cellFaces;
730 // Number of points for each face of the above list
731 if (Pstream::master())
734 writePolysNPointsPerFaceBinary
742 for (int slave=1; slave<Pstream::nProcs(); slave++)
744 IPstream fromSlave(Pstream::scheduled, slave);
745 labelList polys(fromSlave);
746 cellList cellFaces(fromSlave);
747 faceList faces(fromSlave);
749 writePolysNPointsPerFaceBinary
760 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
761 toMaster<< meshCellSets_.polys << cellFaces << faces;
764 // List of points id for each face of the above list
765 if (Pstream::master())
768 writePolysPointsBinary
777 for (int slave=1; slave<Pstream::nProcs(); slave++)
779 IPstream fromSlave(Pstream::scheduled, slave);
780 labelList polys(fromSlave);
781 cellList cellFaces(fromSlave);
782 faceList faces(fromSlave);
784 writePolysPointsBinary
789 pointOffsets[slave-1],
796 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
797 toMaster<< meshCellSets_.polys << cellFaces << faces;
803 void Foam::ensightMesh::writeAllPrims
807 const cellShapeList& cellShapes,
808 const labelList& pointOffsets,
809 OFstream& ensightGeometryFile
814 if (Pstream::master())
816 ensightGeometryFile << key << nl << setw(10) << nPrims << nl;
818 writePrims(cellShapes, 0, ensightGeometryFile);
820 for (int slave=1; slave<Pstream::nProcs(); slave++)
822 IPstream fromSlave(Pstream::scheduled, slave);
823 cellShapeList cellShapes(fromSlave);
828 pointOffsets[slave-1],
835 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
836 toMaster<< cellShapes;
842 void Foam::ensightMesh::writeAllPrimsBinary
846 const cellShapeList& cellShapes,
847 const labelList& pointOffsets,
848 std::ofstream& ensightGeometryFile
853 if (Pstream::master())
855 writeEnsDataBinary(key,ensightGeometryFile);
856 writeEnsDataBinary(nPrims,ensightGeometryFile);
858 writePrimsBinary(cellShapes, 0, ensightGeometryFile);
860 for (int slave=1; slave<Pstream::nProcs(); slave++)
862 IPstream fromSlave(Pstream::scheduled, slave);
863 cellShapeList cellShapes(fromSlave);
868 pointOffsets[slave-1],
875 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
876 toMaster<< cellShapes;
882 void Foam::ensightMesh::writeFacePrims
884 const faceList& patchFaces,
885 const label pointOffset,
886 OFstream& ensightGeometryFile
889 if (patchFaces.size())
891 label po = pointOffset + 1;
893 forAll(patchFaces, i)
895 const face& patchFace = patchFaces[i];
897 forAll(patchFace, pointI)
899 ensightGeometryFile << setw(10) << patchFace[pointI] + po;
901 ensightGeometryFile << nl;
907 void Foam::ensightMesh::writeFacePrimsBinary
909 const faceList& patchFaces,
910 const label pointOffset,
911 std::ofstream& ensightGeometryFile
914 if (patchFaces.size())
916 label po = pointOffset + 1;
918 forAll(patchFaces, i)
920 const face& patchFace = patchFaces[i];
922 forAll(patchFace, pointI)
926 patchFace[pointI] + po,
935 Foam::faceList Foam::ensightMesh::ensMap
937 const faceList& patchFaces,
938 const labelList& prims
941 faceList ppf(prims.size());
945 ppf[i] = patchFaces[prims[i]];
952 void Foam::ensightMesh::writeAllFacePrims
955 const labelList& prims,
957 const faceList& patchFaces,
958 const labelList& pointOffsets,
959 const labelList& patchProcessors,
960 OFstream& ensightGeometryFile
965 if (Pstream::master())
967 ensightGeometryFile << key << nl << setw(10) << nPrims << nl;
973 ensMap(patchFaces, prims),
979 forAll (patchProcessors, i)
981 if (patchProcessors[i] != 0)
983 label slave = patchProcessors[i];
984 IPstream fromSlave(Pstream::scheduled, slave);
985 faceList patchFaces(fromSlave);
996 else if (&prims != NULL)
998 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
999 toMaster<< ensMap(patchFaces, prims);
1005 void Foam::ensightMesh::writeNSidedNPointsPerFace
1007 const faceList& patchFaces,
1008 OFstream& ensightGeometryFile
1011 forAll(patchFaces, i)
1014 << setw(10) << patchFaces[i].size() << nl;
1019 void Foam::ensightMesh::writeNSidedPoints
1021 const faceList& patchFaces,
1022 const label pointOffset,
1023 OFstream& ensightGeometryFile
1035 void Foam::ensightMesh::writeAllNSided
1037 const labelList& prims,
1039 const faceList& patchFaces,
1040 const labelList& pointOffsets,
1041 const labelList& patchProcessors,
1042 OFstream& ensightGeometryFile
1047 if (Pstream::master())
1050 << "nsided" << nl << setw(10) << nPrims << nl;
1053 // Number of points for each face
1054 if (Pstream::master())
1058 writeNSidedNPointsPerFace
1060 ensMap(patchFaces, prims),
1065 forAll (patchProcessors, i)
1067 if (patchProcessors[i] != 0)
1069 label slave = patchProcessors[i];
1070 IPstream fromSlave(Pstream::scheduled, slave);
1071 faceList patchFaces(fromSlave);
1073 writeNSidedNPointsPerFace
1081 else if (&prims != NULL)
1083 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1084 toMaster<< ensMap(patchFaces, prims);
1087 // List of points id for each face
1088 if (Pstream::master())
1094 ensMap(patchFaces, prims),
1100 forAll (patchProcessors, i)
1102 if (patchProcessors[i] != 0)
1104 label slave = patchProcessors[i];
1105 IPstream fromSlave(Pstream::scheduled, slave);
1106 faceList patchFaces(fromSlave);
1117 else if (&prims != NULL)
1119 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1120 toMaster<< ensMap(patchFaces, prims);
1126 void Foam::ensightMesh::writeNSidedPointsBinary
1128 const faceList& patchFaces,
1129 const label pointOffset,
1130 std::ofstream& ensightGeometryFile
1133 writeFacePrimsBinary
1142 void Foam::ensightMesh::writeNSidedNPointsPerFaceBinary
1144 const faceList& patchFaces,
1145 std::ofstream& ensightGeometryFile
1148 forAll(patchFaces, i)
1152 patchFaces[i].size(),
1159 void Foam::ensightMesh::writeAllNSidedBinary
1161 const labelList& prims,
1163 const faceList& patchFaces,
1164 const labelList& pointOffsets,
1165 const labelList& patchProcessors,
1166 std::ofstream& ensightGeometryFile
1171 if (Pstream::master())
1173 writeEnsDataBinary("nsided",ensightGeometryFile);
1174 writeEnsDataBinary(nPrims,ensightGeometryFile);
1177 // Number of points for each face
1178 if (Pstream::master())
1182 writeNSidedNPointsPerFaceBinary
1184 ensMap(patchFaces, prims),
1189 forAll (patchProcessors, i)
1191 if (patchProcessors[i] != 0)
1193 label slave = patchProcessors[i];
1194 IPstream fromSlave(Pstream::scheduled, slave);
1195 faceList patchFaces(fromSlave);
1197 writeNSidedNPointsPerFaceBinary
1205 else if (&prims != NULL)
1207 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1208 toMaster<< ensMap(patchFaces, prims);
1211 // List of points id for each face
1212 if (Pstream::master())
1216 writeNSidedPointsBinary
1218 ensMap(patchFaces, prims),
1224 forAll (patchProcessors, i)
1226 if (patchProcessors[i] != 0)
1228 label slave = patchProcessors[i];
1229 IPstream fromSlave(Pstream::scheduled, slave);
1230 faceList patchFaces(fromSlave);
1232 writeNSidedPointsBinary
1241 else if (&prims != NULL)
1243 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1244 toMaster<< ensMap(patchFaces, prims);
1250 void Foam::ensightMesh::writeAllFacePrimsBinary
1253 const labelList& prims,
1255 const faceList& patchFaces,
1256 const labelList& pointOffsets,
1257 const labelList& patchProcessors,
1258 std::ofstream& ensightGeometryFile
1263 if (Pstream::master())
1265 writeEnsDataBinary(key,ensightGeometryFile);
1266 writeEnsDataBinary(nPrims,ensightGeometryFile);
1270 writeFacePrimsBinary
1272 ensMap(patchFaces, prims),
1278 forAll (patchProcessors, i)
1280 if (patchProcessors[i] != 0)
1282 label slave = patchProcessors[i];
1283 IPstream fromSlave(Pstream::scheduled, slave);
1284 faceList patchFaces(fromSlave);
1286 writeFacePrimsBinary
1295 else if (&prims != NULL)
1297 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1298 toMaster<< ensMap(patchFaces, prims);
1304 void Foam::ensightMesh::write
1306 const fileName& postProcPath,
1307 const word& prepend,
1308 const label timeIndex,
1309 Ostream& ensightCaseFile
1314 writeBinary(postProcPath, prepend, timeIndex, ensightCaseFile);
1318 writeAscii(postProcPath, prepend, timeIndex, ensightCaseFile);
1323 void Foam::ensightMesh::writeAscii
1325 const fileName& postProcPath,
1326 const word& prepend,
1327 const label timeIndex,
1328 Ostream& ensightCaseFile
1331 const Time& runTime = mesh_.time();
1332 const pointField& points = mesh_.points();
1333 const cellShapeList& cellShapes = mesh_.cellShapes();
1335 word timeFile = prepend;
1341 else if (mesh_.moving())
1343 timeFile += itoa(timeIndex) + '.';
1346 // set the filename of the ensight file
1347 fileName ensightGeometryFileName = timeFile + "mesh";
1349 OFstream *ensightGeometryFilePtr = NULL;
1350 if (Pstream::master())
1352 ensightGeometryFilePtr = new OFstream
1354 postProcPath/ensightGeometryFileName,
1355 ios_base::out|ios_base::trunc,
1356 runTime.writeFormat(),
1357 runTime.writeVersion(),
1358 IOstream::UNCOMPRESSED
1362 OFstream& ensightGeometryFile = *ensightGeometryFilePtr;
1364 if (Pstream::master())
1367 ensightGeometryFile.setf
1369 ios_base::scientific,
1370 ios_base::floatfield
1372 ensightGeometryFile.precision(5);
1375 << "EnSight Geometry File" << nl
1376 << "written from FOAM-" << Foam::FOAMversion << nl
1377 << "node id assign" << nl
1378 << "element id assign" << nl;
1381 labelList pointOffsets(Pstream::nProcs(), 0);
1383 if (patchNames_.empty())
1385 label nPoints = points.size();
1386 Pstream::gather(nPoints, sumOp<label>());
1388 if (Pstream::master())
1392 << setw(10) << 1 << nl
1393 << "internalMesh" << nl
1394 << "coordinates" << nl
1395 << setw(10) << nPoints
1398 for (direction d=0; d<vector::nComponents; d++)
1400 writePoints(points.component(d), ensightGeometryFile);
1401 pointOffsets[0] = points.size();
1403 for (int slave=1; slave<Pstream::nProcs(); slave++)
1405 IPstream fromSlave(Pstream::scheduled, slave);
1406 scalarField pointsComponent(fromSlave);
1407 writePoints(pointsComponent, ensightGeometryFile);
1408 pointOffsets[slave] =
1409 pointOffsets[slave-1]
1410 + pointsComponent.size();
1416 for (direction d=0; d<vector::nComponents; d++)
1418 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1419 toMaster<< points.component(d);
1426 meshCellSets_.nHexesWedges,
1427 ensMap(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
1435 meshCellSets_.nPrisms,
1436 ensMap(cellShapes, meshCellSets_.prisms),
1444 meshCellSets_.nPyrs,
1445 ensMap(cellShapes, meshCellSets_.pyrs),
1453 meshCellSets_.nTets,
1454 ensMap(cellShapes, meshCellSets_.tets),
1467 label ensightPatchI = patchPartOffset_;
1469 forAll(allPatchNames_, patchi)
1471 const word& patchName = allPatchNames_[patchi];
1472 const labelList& patchProcessors = allPatchProcs_[patchi];
1474 if (patchNames_.empty() || patchNames_.found(patchName))
1476 const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
1478 const labelList *trisPtr = NULL;
1479 const labelList *quadsPtr = NULL;
1480 const labelList *polysPtr = NULL;
1482 const pointField *patchPointsPtr = NULL;
1483 const faceList *patchFacesPtr = NULL;
1485 if (mesh_.boundary()[patchi].size())
1487 const polyPatch& p = mesh_.boundaryMesh()[patchi];
1489 trisPtr = &boundaryFaceSets_[patchi].tris;
1490 quadsPtr = &boundaryFaceSets_[patchi].quads;
1491 polysPtr = &boundaryFaceSets_[patchi].polys;
1493 patchPointsPtr = &(p.localPoints());
1494 patchFacesPtr = &(p.localFaces());
1497 const labelList& tris = *trisPtr;
1498 const labelList& quads = *quadsPtr;
1499 const labelList& polys = *polysPtr;
1500 const pointField& patchPoints = *patchPointsPtr;
1501 const faceList& patchFaces = *patchFacesPtr;
1503 if (nfp.nTris || nfp.nQuads || nfp.nPolys)
1505 labelList patchPointOffsets(Pstream::nProcs(), 0);
1507 if (Pstream::master())
1511 << setw(10) << ensightPatchI++ << nl
1513 << "coordinates" << nl
1514 << setw(10) << nfp.nPoints
1517 for (direction d=0; d<vector::nComponents; d++)
1523 patchPoints.component(d),
1528 patchPointOffsets = 0;
1530 forAll (patchProcessors, i)
1532 if (patchProcessors[i] != 0)
1534 label slave = patchProcessors[i];
1535 IPstream fromSlave(Pstream::scheduled, slave);
1536 scalarField patchPointsComponent(fromSlave);
1540 patchPointsComponent,
1544 if (i < Pstream::nProcs()-1)
1546 patchPointOffsets[i+1] =
1547 patchPointOffsets[i]
1548 + patchPointsComponent.size();
1553 if (i < Pstream::nProcs()-1)
1555 patchPointOffsets[i+1] =
1556 patchPointOffsets[i]
1557 + patchPoints.size();
1563 else if (patchPointsPtr)
1565 for (direction d=0; d<vector::nComponents; d++)
1572 toMaster<< patchPoints.component(d);
1611 if (Pstream::master())
1613 delete ensightGeometryFilePtr;
1618 void Foam::ensightMesh::writeBinary
1620 const fileName& postProcPath,
1621 const word& prepend,
1622 const label timeIndex,
1623 Ostream& ensightCaseFile
1626 //const Time& runTime = mesh.time();
1627 const pointField& points = mesh_.points();
1628 const cellShapeList& cellShapes = mesh_.cellShapes();
1630 word timeFile = prepend;
1636 else if (mesh_.moving())
1638 timeFile += itoa(timeIndex) + '.';
1641 // set the filename of the ensight file
1642 fileName ensightGeometryFileName = timeFile + "mesh";
1644 std::ofstream *ensightGeometryFilePtr = NULL;
1646 if (Pstream::master())
1648 ensightGeometryFilePtr = new std::ofstream
1650 (postProcPath/ensightGeometryFileName).c_str(),
1651 ios_base::out | ios_base::binary | ios_base::trunc
1653 // Check on file opened?
1656 std::ofstream& ensightGeometryFile = *ensightGeometryFilePtr;
1658 if (Pstream::master())
1660 writeEnsDataBinary("C binary", ensightGeometryFile);
1661 writeEnsDataBinary("EnSight Geometry File", ensightGeometryFile);
1662 writeEnsDataBinary("written from FOAM", ensightGeometryFile);
1663 writeEnsDataBinary("node id assign", ensightGeometryFile);
1664 writeEnsDataBinary("element id assign", ensightGeometryFile);
1667 labelList pointOffsets(Pstream::nProcs(), 0);
1669 if (patchNames_.empty())
1671 label nPoints = points.size();
1672 Pstream::gather(nPoints, sumOp<label>());
1674 if (Pstream::master())
1676 writeEnsDataBinary("part",ensightGeometryFile);
1677 writeEnsDataBinary(1,ensightGeometryFile);
1678 writeEnsDataBinary("internalMesh",ensightGeometryFile);
1679 writeEnsDataBinary("coordinates",ensightGeometryFile);
1680 writeEnsDataBinary(nPoints,ensightGeometryFile);
1682 for (direction d=0; d<vector::nComponents; d++)
1684 //writePointsBinary(points.component(d), ensightGeometryFile);
1685 writeEnsDataBinary(points.component(d), ensightGeometryFile);
1686 pointOffsets[0] = points.size();
1688 for (int slave=1; slave<Pstream::nProcs(); slave++)
1690 IPstream fromSlave(Pstream::scheduled, slave);
1691 scalarField pointsComponent(fromSlave);
1692 //writePointsBinary(pointsComponent, ensightGeometryFile);
1693 writeEnsDataBinary(pointsComponent, ensightGeometryFile);
1694 pointOffsets[slave] =
1695 pointOffsets[slave-1]
1696 + pointsComponent.size();
1702 for (direction d=0; d<vector::nComponents; d++)
1704 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1705 toMaster<< points.component(d);
1712 meshCellSets_.nHexesWedges,
1713 ensMap(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
1721 meshCellSets_.nPrisms,
1722 ensMap(cellShapes, meshCellSets_.prisms),
1730 meshCellSets_.nPyrs,
1731 ensMap(cellShapes, meshCellSets_.pyrs),
1739 meshCellSets_.nTets,
1740 ensMap(cellShapes, meshCellSets_.tets),
1753 label ensightPatchI = patchPartOffset_;
1756 forAll(allPatchNames_, patchi)
1759 const word& patchName = allPatchNames_[patchi];
1760 const labelList& patchProcessors = allPatchProcs_[patchi];
1762 if (patchNames_.empty() || patchNames_.found(patchName))
1764 const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
1766 const labelList *trisPtr = NULL;
1767 const labelList *quadsPtr = NULL;
1768 const labelList *polysPtr = NULL;
1770 const pointField *patchPointsPtr = NULL;
1771 const faceList *patchFacesPtr = NULL;
1773 if (mesh_.boundary()[patchi].size())
1775 const polyPatch& p = mesh_.boundaryMesh()[patchi];
1777 trisPtr = &boundaryFaceSets_[patchi].tris;
1778 quadsPtr = &boundaryFaceSets_[patchi].quads;
1779 polysPtr = &boundaryFaceSets_[patchi].polys;
1781 patchPointsPtr = &(p.localPoints());
1782 patchFacesPtr = &(p.localFaces());
1785 const labelList& tris = *trisPtr;
1786 const labelList& quads = *quadsPtr;
1787 const labelList& polys = *polysPtr;
1788 const pointField& patchPoints = *patchPointsPtr;
1789 const faceList& patchFaces = *patchFacesPtr;
1791 if (nfp.nTris || nfp.nQuads || nfp.nPolys)
1793 labelList patchPointOffsets(Pstream::nProcs(), 0);
1795 if (Pstream::master())
1797 writeEnsDataBinary("part",ensightGeometryFile);
1798 writeEnsDataBinary(ensightPatchI++,ensightGeometryFile);
1799 //writeEnsDataBinary(patchName.c_str(),ensightGeometryFile);
1800 writeEnsDataBinary(patchName.c_str(),ensightGeometryFile);
1801 writeEnsDataBinary("coordinates",ensightGeometryFile);
1802 writeEnsDataBinary(nfp.nPoints,ensightGeometryFile);
1804 for (direction d=0; d<vector::nComponents; d++)
1811 patchPoints.component(d),
1816 patchPointOffsets = 0;
1819 forAll (patchProcessors, i)
1821 if (patchProcessors[i] != 0)
1823 label slave = patchProcessors[i];
1824 IPstream fromSlave(Pstream::scheduled, slave);
1825 scalarField patchPointsComponent(fromSlave);
1830 patchPointsComponent,
1834 if (i < Pstream::nProcs()-1)
1836 patchPointOffsets[i+1] =
1837 patchPointOffsets[i]
1838 + patchPointsComponent.size();
1843 if (i < Pstream::nProcs()-1)
1845 patchPointOffsets[i+1] =
1846 patchPointOffsets[i]
1847 + patchPoints.size();
1853 else if (patchPointsPtr)
1855 for (direction d=0; d<vector::nComponents; d++)
1862 toMaster<< patchPoints.component(d);
1866 writeAllFacePrimsBinary
1877 writeAllFacePrimsBinary
1888 writeAllNSidedBinary
1902 if (Pstream::master())
1904 delete ensightGeometryFilePtr;
1909 // ************************************************************************* //