1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "objectRegistry.H"
30 #include "ensightMesh.H"
32 #include "globalMeshData.H"
33 #include "PstreamCombineReduceOps.H"
34 #include "processorPolyPatch.H"
35 #include "cellModeller.H"
38 #include "ensightWriteBinary.H"
41 // * * * * * * * * * * * * * Private Functions * * * * * * * * * * * * * * //
45 //- Proxy-class to hold the patch processor list combination operator
46 class concatPatchProcs
54 const List<labelList>& y
59 const labelList& yPatches = y[i];
63 labelList& xPatches = x[i];
65 label offset = xPatches.size();
66 xPatches.setSize(offset + yPatches.size());
70 xPatches[i + offset] = yPatches[i];
76 } // End namespace Foam
79 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 Foam::ensightMesh::ensightMesh
91 meshCellSets_(mesh_.nCells()),
92 boundaryFaceSets_(mesh_.boundary().size()),
98 const cellShapeList& cellShapes = mesh.cellShapes();
100 const cellModel& tet = *(cellModeller::lookup("tet"));
101 const cellModel& pyr = *(cellModeller::lookup("pyr"));
102 const cellModel& prism = *(cellModeller::lookup("prism"));
103 const cellModel& wedge = *(cellModeller::lookup("wedge"));
104 const cellModel& hex = *(cellModeller::lookup("hex"));
106 if (!args.optionFound("noPatches"))
108 allPatchNames_ = wordList::subList
110 mesh_.boundaryMesh().names(), mesh_.boundary().size()
111 - mesh_.globalData().processorPatches().size()
114 allPatchProcs_.setSize(allPatchNames_.size());
116 forAll (allPatchProcs_, patchi)
118 if (mesh_.boundary()[patchi].size())
120 allPatchProcs_[patchi].setSize(1);
121 allPatchProcs_[patchi][0] = Pstream::myProcNo();
125 combineReduce(allPatchProcs_, concatPatchProcs());
127 if (args.optionFound("patches"))
129 wordList patchNameList(args.optionLookup("patches")());
131 if (patchNameList.empty())
133 patchNameList = allPatchNames_;
136 forAll (patchNameList, i)
138 patchNames_.insert(patchNameList[i]);
143 if (patchNames_.size())
146 patchPartOffset_ = 1;
151 labelList& tets = meshCellSets_.tets;
152 labelList& pyrs = meshCellSets_.pyrs;
153 labelList& prisms = meshCellSets_.prisms;
154 labelList& wedges = meshCellSets_.wedges;
155 labelList& hexes = meshCellSets_.hexes;
156 labelList& polys = meshCellSets_.polys;
165 forAll(cellShapes, cellI)
167 const cellShape& cellShape = cellShapes[cellI];
168 const cellModel& cellModel = cellShape.model();
170 if (cellModel == tet)
172 tets[nTets++] = cellI;
174 else if (cellModel == pyr)
176 pyrs[nPyrs++] = cellI;
178 else if (cellModel == prism)
180 prisms[nPrisms++] = cellI;
182 else if (cellModel == wedge)
184 wedges[nWedges++] = cellI;
186 else if (cellModel == hex)
188 hexes[nHexes++] = cellI;
192 polys[nPolys++] = cellI;
198 prisms.setSize(nPrisms);
199 wedges.setSize(nWedges);
200 hexes.setSize(nHexes);
201 polys.setSize(nPolys);
203 meshCellSets_.nTets = nTets;
204 reduce(meshCellSets_.nTets, sumOp<label>());
206 meshCellSets_.nPyrs = nPyrs;
207 reduce(meshCellSets_.nPyrs, sumOp<label>());
209 meshCellSets_.nPrisms = nPrisms;
210 reduce(meshCellSets_.nPrisms, sumOp<label>());
212 meshCellSets_.nHexesWedges = nHexes + nWedges;
213 reduce(meshCellSets_.nHexesWedges, sumOp<label>());
215 meshCellSets_.nPolys = nPolys;
216 reduce(meshCellSets_.nPolys, sumOp<label>());
219 if (!args.optionFound("noPatches"))
221 forAll (mesh.boundary(), patchi)
223 if (mesh.boundary()[patchi].size())
225 const polyPatch& p = mesh.boundaryMesh()[patchi];
227 labelList& tris = boundaryFaceSets_[patchi].tris;
228 labelList& quads = boundaryFaceSets_[patchi].quads;
229 labelList& polys = boundaryFaceSets_[patchi].polys;
231 tris.setSize(p.size());
232 quads.setSize(p.size());
233 polys.setSize(p.size());
241 const face& f = p[faceI];
245 tris[nTris++] = faceI;
247 else if (f.size() == 4)
249 quads[nQuads++] = faceI;
253 polys[nPolys++] = faceI;
258 quads.setSize(nQuads);
259 polys.setSize(nPolys);
265 forAll(allPatchNames_, patchi)
267 const word& patchName = allPatchNames_[patchi];
270 if (patchNames_.empty() || patchNames_.found(patchName))
272 if (mesh.boundary()[patchi].size())
274 nfp.nPoints = mesh.boundaryMesh()[patchi].localPoints().size();
275 nfp.nTris = boundaryFaceSets_[patchi].tris.size();
276 nfp.nQuads = boundaryFaceSets_[patchi].quads.size();
277 nfp.nPolys = boundaryFaceSets_[patchi].polys.size();
281 reduce(nfp.nPoints, sumOp<label>());
282 reduce(nfp.nTris, sumOp<label>());
283 reduce(nfp.nQuads, sumOp<label>());
284 reduce(nfp.nPolys, sumOp<label>());
286 nPatchPrims_.insert(patchName, nfp);
291 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
293 Foam::ensightMesh::~ensightMesh()
297 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
299 void Foam::ensightMesh::writePoints
301 const scalarField& pointsComponent,
302 OFstream& ensightGeometryFile
305 forAll(pointsComponent, pointI)
307 ensightGeometryFile<< setw(12) << float(pointsComponent[pointI]) << nl;
312 Foam::cellShapeList Foam::ensightMesh::map
314 const cellShapeList& cellShapes,
315 const labelList& prims
318 cellShapeList mcsl(prims.size());
322 mcsl[i] = cellShapes[prims[i]];
329 Foam::cellShapeList Foam::ensightMesh::map
331 const cellShapeList& cellShapes,
332 const labelList& hexes,
333 const labelList& wedges
336 cellShapeList mcsl(hexes.size() + wedges.size());
340 mcsl[i] = cellShapes[hexes[i]];
343 label offset = hexes.size();
345 const cellModel& hex = *(cellModeller::lookup("hex"));
346 labelList hexLabels(8);
350 const cellShape& cellPoints = cellShapes[wedges[i]];
352 hexLabels[0] = cellPoints[0];
353 hexLabels[1] = cellPoints[1];
354 hexLabels[2] = cellPoints[0];
355 hexLabels[3] = cellPoints[2];
356 hexLabels[4] = cellPoints[3];
357 hexLabels[5] = cellPoints[4];
358 hexLabels[6] = cellPoints[6];
359 hexLabels[7] = cellPoints[5];
361 mcsl[i + offset] = cellShape(hex, hexLabels);
368 void Foam::ensightMesh::writePrims
370 const cellShapeList& cellShapes,
371 const label pointOffset,
372 OFstream& ensightGeometryFile
375 label po = pointOffset + 1;
377 forAll(cellShapes, i)
379 const cellShape& cellPoints = cellShapes[i];
381 forAll(cellPoints, pointI)
383 ensightGeometryFile<< setw(10) << cellPoints[pointI] + po;
385 ensightGeometryFile << nl;
390 void Foam::ensightMesh::writePrimsBinary
392 const cellShapeList& cellShapes,
393 const label pointOffset,
394 std::ofstream& ensightGeometryFile
397 label po = pointOffset + 1;
399 if (cellShapes.size())
401 // All the cellShapes have the same number of elements!
402 int numIntElem = cellShapes.size()*cellShapes[0].size();
403 List<int> temp(numIntElem);
407 forAll(cellShapes, i)
409 const cellShape& cellPoints = cellShapes[i];
411 forAll(cellPoints, pointI)
413 temp[n] = cellPoints[pointI] + po;
418 ensightGeometryFile.write
420 reinterpret_cast<char*>(temp.begin()),
421 numIntElem*sizeof(int)
427 void Foam::ensightMesh::writePolysNFaces
429 const labelList& polys,
430 const cellList& cellFaces,
431 OFstream& ensightGeometryFile
437 << setw(10) << cellFaces[polys[i]].size() << nl;
442 void Foam::ensightMesh::writePolysNPointsPerFace
444 const labelList& polys,
445 const cellList& cellFaces,
446 const faceList& faces,
447 OFstream& ensightGeometryFile
452 const labelList& cf = cellFaces[polys[i]];
457 << setw(10) << faces[cf[faceI]].size() << nl;
463 void Foam::ensightMesh::writePolysPoints
465 const labelList& polys,
466 const cellList& cellFaces,
467 const faceList& faces,
468 const label pointOffset,
469 OFstream& ensightGeometryFile
472 label po = pointOffset + 1;
476 const labelList& cf = cellFaces[polys[i]];
480 const face& f = faces[cf[faceI]];
484 ensightGeometryFile << setw(10) << f[pointI] + po;
486 ensightGeometryFile << nl;
492 void Foam::ensightMesh::writeAllPolys
494 const labelList& pointOffsets,
495 OFstream& ensightGeometryFile
498 if (meshCellSets_.nPolys)
500 const cellList& cellFaces = mesh_.cells();
501 const faceList& faces = mesh_.faces();
503 if (Pstream::master())
506 << "nfaced" << nl << setw(10) << meshCellSets_.nPolys << nl;
509 // Number of faces for each poly cell
510 if (Pstream::master())
520 for (int slave=1; slave<Pstream::nProcs(); slave++)
522 IPstream fromSlave(Pstream::scheduled, slave);
523 labelList polys(fromSlave);
524 cellList cellFaces(fromSlave);
536 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
537 toMaster<< meshCellSets_.polys << cellFaces;
540 // Number of points for each face of the above list
541 if (Pstream::master())
544 writePolysNPointsPerFace
552 for (int slave=1; slave<Pstream::nProcs(); slave++)
554 IPstream fromSlave(Pstream::scheduled, slave);
555 labelList polys(fromSlave);
556 cellList cellFaces(fromSlave);
557 faceList faces(fromSlave);
559 writePolysNPointsPerFace
570 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
571 toMaster<< meshCellSets_.polys << cellFaces << faces;
574 // List of points id for each face of the above list
575 if (Pstream::master())
587 for (int slave=1; slave<Pstream::nProcs(); slave++)
589 IPstream fromSlave(Pstream::scheduled, slave);
590 labelList polys(fromSlave);
591 cellList cellFaces(fromSlave);
592 faceList faces(fromSlave);
599 pointOffsets[slave-1],
606 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
607 toMaster<< meshCellSets_.polys << cellFaces << faces;
613 void Foam::ensightMesh::writePolysNFacesBinary
615 const labelList& polys,
616 const cellList& cellFaces,
617 std::ofstream& ensightGeometryFile
624 cellFaces[polys[i]].size(),
631 void Foam::ensightMesh::writePolysNPointsPerFaceBinary
633 const labelList& polys,
634 const cellList& cellFaces,
635 const faceList& faces,
636 std::ofstream& ensightGeometryFile
641 const labelList& cf = cellFaces[polys[i]];
647 faces[cf[faceI]].size(),
655 void Foam::ensightMesh::writePolysPointsBinary
657 const labelList& polys,
658 const cellList& cellFaces,
659 const faceList& faces,
660 const label pointOffset,
661 std::ofstream& ensightGeometryFile
664 label po = pointOffset + 1;
668 const labelList& cf = cellFaces[polys[i]];
672 const face& f = faces[cf[faceI]];
676 writeEnsDataBinary(f[pointI] + po,ensightGeometryFile);
683 void Foam::ensightMesh::writeAllPolysBinary
685 const labelList& pointOffsets,
686 std::ofstream& ensightGeometryFile
689 if (meshCellSets_.nPolys)
691 const cellList& cellFaces = mesh_.cells();
692 const faceList& faces = mesh_.faces();
694 if (Pstream::master())
696 writeEnsDataBinary("nfaced",ensightGeometryFile);
697 writeEnsDataBinary(meshCellSets_.nPolys,ensightGeometryFile);
700 // Number of faces for each poly cell
701 if (Pstream::master())
704 writePolysNFacesBinary
711 for (int slave=1; slave<Pstream::nProcs(); slave++)
713 IPstream fromSlave(Pstream::scheduled, slave);
714 labelList polys(fromSlave);
715 cellList cellFaces(fromSlave);
717 writePolysNFacesBinary
727 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
728 toMaster<< meshCellSets_.polys << cellFaces;
731 // Number of points for each face of the above list
732 if (Pstream::master())
735 writePolysNPointsPerFaceBinary
743 for (int slave=1; slave<Pstream::nProcs(); slave++)
745 IPstream fromSlave(Pstream::scheduled, slave);
746 labelList polys(fromSlave);
747 cellList cellFaces(fromSlave);
748 faceList faces(fromSlave);
750 writePolysNPointsPerFaceBinary
761 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
762 toMaster<< meshCellSets_.polys << cellFaces << faces;
765 // List of points id for each face of the above list
766 if (Pstream::master())
769 writePolysPointsBinary
778 for (int slave=1; slave<Pstream::nProcs(); slave++)
780 IPstream fromSlave(Pstream::scheduled, slave);
781 labelList polys(fromSlave);
782 cellList cellFaces(fromSlave);
783 faceList faces(fromSlave);
785 writePolysPointsBinary
790 pointOffsets[slave-1],
797 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
798 toMaster<< meshCellSets_.polys << cellFaces << faces;
804 void Foam::ensightMesh::writeAllPrims
808 const cellShapeList& cellShapes,
809 const labelList& pointOffsets,
810 OFstream& ensightGeometryFile
815 if (Pstream::master())
817 ensightGeometryFile << key << nl << setw(10) << nPrims << nl;
819 writePrims(cellShapes, 0, ensightGeometryFile);
821 for (int slave=1; slave<Pstream::nProcs(); slave++)
823 IPstream fromSlave(Pstream::scheduled, slave);
824 cellShapeList cellShapes(fromSlave);
829 pointOffsets[slave-1],
836 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
837 toMaster<< cellShapes;
843 void Foam::ensightMesh::writeAllPrimsBinary
847 const cellShapeList& cellShapes,
848 const labelList& pointOffsets,
849 std::ofstream& ensightGeometryFile
854 if (Pstream::master())
856 writeEnsDataBinary(key,ensightGeometryFile);
857 writeEnsDataBinary(nPrims,ensightGeometryFile);
859 writePrimsBinary(cellShapes, 0, ensightGeometryFile);
861 for (int slave=1; slave<Pstream::nProcs(); slave++)
863 IPstream fromSlave(Pstream::scheduled, slave);
864 cellShapeList cellShapes(fromSlave);
869 pointOffsets[slave-1],
876 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
877 toMaster<< cellShapes;
883 void Foam::ensightMesh::writeFacePrims
885 const faceList& patchFaces,
886 const label pointOffset,
887 OFstream& ensightGeometryFile
890 if (patchFaces.size())
892 label po = pointOffset + 1;
894 forAll(patchFaces, i)
896 const face& patchFace = patchFaces[i];
898 forAll(patchFace, pointI)
900 ensightGeometryFile << setw(10) << patchFace[pointI] + po;
902 ensightGeometryFile << nl;
908 void Foam::ensightMesh::writeFacePrimsBinary
910 const faceList& patchFaces,
911 const label pointOffset,
912 std::ofstream& ensightGeometryFile
915 if (patchFaces.size())
917 label po = pointOffset + 1;
919 forAll(patchFaces, i)
921 const face& patchFace = patchFaces[i];
923 forAll(patchFace, pointI)
927 patchFace[pointI] + po,
936 Foam::faceList Foam::ensightMesh::map
938 const faceList& patchFaces,
939 const labelList& prims
942 faceList ppf(prims.size());
946 ppf[i] = patchFaces[prims[i]];
953 void Foam::ensightMesh::writeAllFacePrims
956 const labelList& prims,
958 const faceList& patchFaces,
959 const labelList& pointOffsets,
960 const labelList& patchProcessors,
961 OFstream& ensightGeometryFile
966 if (Pstream::master())
968 ensightGeometryFile << key << nl << setw(10) << nPrims << nl;
974 map(patchFaces, prims),
980 forAll (patchProcessors, i)
982 if (patchProcessors[i] != 0)
984 label slave = patchProcessors[i];
985 IPstream fromSlave(Pstream::scheduled, slave);
986 faceList patchFaces(fromSlave);
997 else if (&prims != NULL)
999 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1000 toMaster<< map(patchFaces, prims);
1006 void Foam::ensightMesh::writeNSidedNPointsPerFace
1008 const faceList& patchFaces,
1009 OFstream& ensightGeometryFile
1012 forAll(patchFaces, i)
1015 << setw(10) << patchFaces[i].size() << nl;
1020 void Foam::ensightMesh::writeNSidedPoints
1022 const faceList& patchFaces,
1023 const label pointOffset,
1024 OFstream& ensightGeometryFile
1036 void Foam::ensightMesh::writeAllNSided
1038 const labelList& prims,
1040 const faceList& patchFaces,
1041 const labelList& pointOffsets,
1042 const labelList& patchProcessors,
1043 OFstream& ensightGeometryFile
1048 if (Pstream::master())
1051 << "nsided" << nl << setw(10) << nPrims << nl;
1054 // Number of points for each face
1055 if (Pstream::master())
1059 writeNSidedNPointsPerFace
1061 map(patchFaces, prims),
1066 forAll (patchProcessors, i)
1068 if (patchProcessors[i] != 0)
1070 label slave = patchProcessors[i];
1071 IPstream fromSlave(Pstream::scheduled, slave);
1072 faceList patchFaces(fromSlave);
1074 writeNSidedNPointsPerFace
1082 else if (&prims != NULL)
1084 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1085 toMaster<< map(patchFaces, prims);
1088 // List of points id for each face
1089 if (Pstream::master())
1095 map(patchFaces, prims),
1101 forAll (patchProcessors, i)
1103 if (patchProcessors[i] != 0)
1105 label slave = patchProcessors[i];
1106 IPstream fromSlave(Pstream::scheduled, slave);
1107 faceList patchFaces(fromSlave);
1118 else if (&prims != NULL)
1120 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1121 toMaster<< map(patchFaces, prims);
1127 void Foam::ensightMesh::writeNSidedPointsBinary
1129 const faceList& patchFaces,
1130 const label pointOffset,
1131 std::ofstream& ensightGeometryFile
1134 writeFacePrimsBinary
1143 void Foam::ensightMesh::writeNSidedNPointsPerFaceBinary
1145 const faceList& patchFaces,
1146 std::ofstream& ensightGeometryFile
1149 forAll(patchFaces, i)
1153 patchFaces[i].size(),
1160 void Foam::ensightMesh::writeAllNSidedBinary
1162 const labelList& prims,
1164 const faceList& patchFaces,
1165 const labelList& pointOffsets,
1166 const labelList& patchProcessors,
1167 std::ofstream& ensightGeometryFile
1172 if (Pstream::master())
1174 writeEnsDataBinary("nsided",ensightGeometryFile);
1175 writeEnsDataBinary(nPrims,ensightGeometryFile);
1178 // Number of points for each face
1179 if (Pstream::master())
1183 writeNSidedNPointsPerFaceBinary
1185 map(patchFaces, prims),
1190 forAll (patchProcessors, i)
1192 if (patchProcessors[i] != 0)
1194 label slave = patchProcessors[i];
1195 IPstream fromSlave(Pstream::scheduled, slave);
1196 faceList patchFaces(fromSlave);
1198 writeNSidedNPointsPerFaceBinary
1206 else if (&prims != NULL)
1208 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1209 toMaster<< map(patchFaces, prims);
1212 // List of points id for each face
1213 if (Pstream::master())
1217 writeNSidedPointsBinary
1219 map(patchFaces, prims),
1225 forAll (patchProcessors, i)
1227 if (patchProcessors[i] != 0)
1229 label slave = patchProcessors[i];
1230 IPstream fromSlave(Pstream::scheduled, slave);
1231 faceList patchFaces(fromSlave);
1233 writeNSidedPointsBinary
1242 else if (&prims != NULL)
1244 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1245 toMaster<< map(patchFaces, prims);
1251 void Foam::ensightMesh::writeAllFacePrimsBinary
1254 const labelList& prims,
1256 const faceList& patchFaces,
1257 const labelList& pointOffsets,
1258 const labelList& patchProcessors,
1259 std::ofstream& ensightGeometryFile
1264 if (Pstream::master())
1266 writeEnsDataBinary(key,ensightGeometryFile);
1267 writeEnsDataBinary(nPrims,ensightGeometryFile);
1271 writeFacePrimsBinary
1273 map(patchFaces, prims),
1279 forAll (patchProcessors, i)
1281 if (patchProcessors[i] != 0)
1283 label slave = patchProcessors[i];
1284 IPstream fromSlave(Pstream::scheduled, slave);
1285 faceList patchFaces(fromSlave);
1287 writeFacePrimsBinary
1296 else if (&prims != NULL)
1298 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1299 toMaster<< map(patchFaces, prims);
1305 void Foam::ensightMesh::write
1307 const fileName& postProcPath,
1308 const word& prepend,
1309 const label timeIndex,
1310 Ostream& ensightCaseFile
1315 writeBinary(postProcPath, prepend, timeIndex, ensightCaseFile);
1319 writeAscii(postProcPath, prepend, timeIndex, ensightCaseFile);
1324 void Foam::ensightMesh::writeAscii
1326 const fileName& postProcPath,
1327 const word& prepend,
1328 const label timeIndex,
1329 Ostream& ensightCaseFile
1332 const Time& runTime = mesh_.time();
1333 const pointField& points = mesh_.points();
1334 const cellShapeList& cellShapes = mesh_.cellShapes();
1336 word timeFile = prepend;
1342 else if (mesh_.moving())
1344 timeFile += itoa(timeIndex) + '.';
1347 // set the filename of the ensight file
1348 fileName ensightGeometryFileName = timeFile + "mesh";
1350 OFstream *ensightGeometryFilePtr = NULL;
1351 if (Pstream::master())
1353 ensightGeometryFilePtr = new OFstream
1355 postProcPath/ensightGeometryFileName,
1356 ios_base::out|ios_base::trunc,
1357 runTime.writeFormat(),
1358 runTime.writeVersion(),
1359 IOstream::UNCOMPRESSED
1363 OFstream& ensightGeometryFile = *ensightGeometryFilePtr;
1365 if (Pstream::master())
1368 ensightGeometryFile.setf
1370 ios_base::scientific,
1371 ios_base::floatfield
1373 ensightGeometryFile.precision(5);
1376 << "EnSight Geometry File" << nl
1377 << "written from OpenFOAM-" << Foam::FOAMversion << nl
1378 << "node id assign" << nl
1379 << "element id assign" << nl;
1382 labelList pointOffsets(Pstream::nProcs(), 0);
1384 if (patchNames_.empty())
1386 label nPoints = points.size();
1387 Pstream::gather(nPoints, sumOp<label>());
1389 if (Pstream::master())
1393 << setw(10) << 1 << nl
1394 << "internalMesh" << nl
1395 << "coordinates" << nl
1396 << setw(10) << nPoints
1399 for (direction d=0; d<vector::nComponents; d++)
1401 writePoints(points.component(d), ensightGeometryFile);
1402 pointOffsets[0] = points.size();
1404 for (int slave=1; slave<Pstream::nProcs(); slave++)
1406 IPstream fromSlave(Pstream::scheduled, slave);
1407 scalarField pointsComponent(fromSlave);
1408 writePoints(pointsComponent, ensightGeometryFile);
1409 pointOffsets[slave] =
1410 pointOffsets[slave-1]
1411 + pointsComponent.size();
1417 for (direction d=0; d<vector::nComponents; d++)
1419 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1420 toMaster<< points.component(d);
1427 meshCellSets_.nHexesWedges,
1428 map(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
1436 meshCellSets_.nPrisms,
1437 map(cellShapes, meshCellSets_.prisms),
1445 meshCellSets_.nPyrs,
1446 map(cellShapes, meshCellSets_.pyrs),
1454 meshCellSets_.nTets,
1455 map(cellShapes, meshCellSets_.tets),
1468 label ensightPatchI = patchPartOffset_;
1470 forAll(allPatchNames_, patchi)
1472 const word& patchName = allPatchNames_[patchi];
1473 const labelList& patchProcessors = allPatchProcs_[patchi];
1475 if (patchNames_.empty() || patchNames_.found(patchName))
1477 const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
1479 const labelList *trisPtr = NULL;
1480 const labelList *quadsPtr = NULL;
1481 const labelList *polysPtr = NULL;
1483 const pointField *patchPointsPtr = NULL;
1484 const faceList *patchFacesPtr = NULL;
1486 if (mesh_.boundary()[patchi].size())
1488 const polyPatch& p = mesh_.boundaryMesh()[patchi];
1490 trisPtr = &boundaryFaceSets_[patchi].tris;
1491 quadsPtr = &boundaryFaceSets_[patchi].quads;
1492 polysPtr = &boundaryFaceSets_[patchi].polys;
1494 patchPointsPtr = &(p.localPoints());
1495 patchFacesPtr = &(p.localFaces());
1498 const labelList& tris = *trisPtr;
1499 const labelList& quads = *quadsPtr;
1500 const labelList& polys = *polysPtr;
1501 const pointField& patchPoints = *patchPointsPtr;
1502 const faceList& patchFaces = *patchFacesPtr;
1504 if (nfp.nTris || nfp.nQuads || nfp.nPolys)
1506 labelList patchPointOffsets(Pstream::nProcs(), 0);
1508 if (Pstream::master())
1512 << setw(10) << ensightPatchI++ << nl
1514 << "coordinates" << nl
1515 << setw(10) << nfp.nPoints
1518 for (direction d=0; d<vector::nComponents; d++)
1524 patchPoints.component(d),
1529 patchPointOffsets = 0;
1531 forAll (patchProcessors, i)
1533 if (patchProcessors[i] != 0)
1535 label slave = patchProcessors[i];
1536 IPstream fromSlave(Pstream::scheduled, slave);
1537 scalarField patchPointsComponent(fromSlave);
1541 patchPointsComponent,
1545 if (i < Pstream::nProcs()-1)
1547 patchPointOffsets[i+1] =
1548 patchPointOffsets[i]
1549 + patchPointsComponent.size();
1554 if (i < Pstream::nProcs()-1)
1556 patchPointOffsets[i+1] =
1557 patchPointOffsets[i]
1558 + patchPoints.size();
1564 else if (patchPointsPtr)
1566 for (direction d=0; d<vector::nComponents; d++)
1573 toMaster<< patchPoints.component(d);
1612 if (Pstream::master())
1614 delete ensightGeometryFilePtr;
1619 void Foam::ensightMesh::writeBinary
1621 const fileName& postProcPath,
1622 const word& prepend,
1623 const label timeIndex,
1624 Ostream& ensightCaseFile
1627 //const Time& runTime = mesh.time();
1628 const pointField& points = mesh_.points();
1629 const cellShapeList& cellShapes = mesh_.cellShapes();
1631 word timeFile = prepend;
1637 else if (mesh_.moving())
1639 timeFile += itoa(timeIndex) + '.';
1642 // set the filename of the ensight file
1643 fileName ensightGeometryFileName = timeFile + "mesh";
1645 std::ofstream *ensightGeometryFilePtr = NULL;
1647 if (Pstream::master())
1649 ensightGeometryFilePtr = new std::ofstream
1651 (postProcPath/ensightGeometryFileName).c_str(),
1652 ios_base::out | ios_base::binary | ios_base::trunc
1654 // Check on file opened?
1657 std::ofstream& ensightGeometryFile = *ensightGeometryFilePtr;
1659 if (Pstream::master())
1661 writeEnsDataBinary("C binary", ensightGeometryFile);
1662 writeEnsDataBinary("EnSight Geometry File", ensightGeometryFile);
1663 writeEnsDataBinary("written from OpenFOAM", ensightGeometryFile);
1664 writeEnsDataBinary("node id assign", ensightGeometryFile);
1665 writeEnsDataBinary("element id assign", ensightGeometryFile);
1668 labelList pointOffsets(Pstream::nProcs(), 0);
1670 if (patchNames_.empty())
1672 label nPoints = points.size();
1673 Pstream::gather(nPoints, sumOp<label>());
1675 if (Pstream::master())
1677 writeEnsDataBinary("part",ensightGeometryFile);
1678 writeEnsDataBinary(1,ensightGeometryFile);
1679 writeEnsDataBinary("internalMesh",ensightGeometryFile);
1680 writeEnsDataBinary("coordinates",ensightGeometryFile);
1681 writeEnsDataBinary(nPoints,ensightGeometryFile);
1683 for (direction d=0; d<vector::nComponents; d++)
1685 //writePointsBinary(points.component(d), ensightGeometryFile);
1686 writeEnsDataBinary(points.component(d), ensightGeometryFile);
1687 pointOffsets[0] = points.size();
1689 for (int slave=1; slave<Pstream::nProcs(); slave++)
1691 IPstream fromSlave(Pstream::scheduled, slave);
1692 scalarField pointsComponent(fromSlave);
1693 //writePointsBinary(pointsComponent, ensightGeometryFile);
1694 writeEnsDataBinary(pointsComponent, ensightGeometryFile);
1695 pointOffsets[slave] =
1696 pointOffsets[slave-1]
1697 + pointsComponent.size();
1703 for (direction d=0; d<vector::nComponents; d++)
1705 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
1706 toMaster<< points.component(d);
1713 meshCellSets_.nHexesWedges,
1714 map(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
1722 meshCellSets_.nPrisms,
1723 map(cellShapes, meshCellSets_.prisms),
1731 meshCellSets_.nPyrs,
1732 map(cellShapes, meshCellSets_.pyrs),
1740 meshCellSets_.nTets,
1741 map(cellShapes, meshCellSets_.tets),
1754 label ensightPatchI = patchPartOffset_;
1757 forAll(allPatchNames_, patchi)
1760 const word& patchName = allPatchNames_[patchi];
1761 const labelList& patchProcessors = allPatchProcs_[patchi];
1763 if (patchNames_.empty() || patchNames_.found(patchName))
1765 const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
1767 const labelList *trisPtr = NULL;
1768 const labelList *quadsPtr = NULL;
1769 const labelList *polysPtr = NULL;
1771 const pointField *patchPointsPtr = NULL;
1772 const faceList *patchFacesPtr = NULL;
1774 if (mesh_.boundary()[patchi].size())
1776 const polyPatch& p = mesh_.boundaryMesh()[patchi];
1778 trisPtr = &boundaryFaceSets_[patchi].tris;
1779 quadsPtr = &boundaryFaceSets_[patchi].quads;
1780 polysPtr = &boundaryFaceSets_[patchi].polys;
1782 patchPointsPtr = &(p.localPoints());
1783 patchFacesPtr = &(p.localFaces());
1786 const labelList& tris = *trisPtr;
1787 const labelList& quads = *quadsPtr;
1788 const labelList& polys = *polysPtr;
1789 const pointField& patchPoints = *patchPointsPtr;
1790 const faceList& patchFaces = *patchFacesPtr;
1792 if (nfp.nTris || nfp.nQuads || nfp.nPolys)
1794 labelList patchPointOffsets(Pstream::nProcs(), 0);
1796 if (Pstream::master())
1798 writeEnsDataBinary("part",ensightGeometryFile);
1799 writeEnsDataBinary(ensightPatchI++,ensightGeometryFile);
1800 //writeEnsDataBinary(patchName.c_str(),ensightGeometryFile);
1801 writeEnsDataBinary(patchName.c_str(),ensightGeometryFile);
1802 writeEnsDataBinary("coordinates",ensightGeometryFile);
1803 writeEnsDataBinary(nfp.nPoints,ensightGeometryFile);
1805 for (direction d=0; d<vector::nComponents; d++)
1812 patchPoints.component(d),
1817 patchPointOffsets = 0;
1820 forAll (patchProcessors, i)
1822 if (patchProcessors[i] != 0)
1824 label slave = patchProcessors[i];
1825 IPstream fromSlave(Pstream::scheduled, slave);
1826 scalarField patchPointsComponent(fromSlave);
1831 patchPointsComponent,
1835 if (i < Pstream::nProcs()-1)
1837 patchPointOffsets[i+1] =
1838 patchPointOffsets[i]
1839 + patchPointsComponent.size();
1844 if (i < Pstream::nProcs()-1)
1846 patchPointOffsets[i+1] =
1847 patchPointOffsets[i]
1848 + patchPoints.size();
1854 else if (patchPointsPtr)
1856 for (direction d=0; d<vector::nComponents; d++)
1863 toMaster<< patchPoints.component(d);
1867 writeAllFacePrimsBinary
1878 writeAllFacePrimsBinary
1889 writeAllNSidedBinary
1903 if (Pstream::master())
1905 delete ensightGeometryFilePtr;
1910 // ************************************************************************* //