00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "argList.H"
00028 #include "Time.H"
00029 #include "ensightMesh.H"
00030 #include "fvMesh.H"
00031 #include "globalMeshData.H"
00032 #include "PstreamCombineReduceOps.H"
00033 #include "processorPolyPatch.H"
00034 #include "cellModeller.H"
00035 #include "IOmanip.H"
00036 #include "itoa.H"
00037 #include "ensightWriteBinary.H"
00038 #include <fstream>
00039
00040
00041
00042 namespace Foam
00043 {
00044
00045 class concatPatchProcs
00046 {
00047
00048 public:
00049
00050 void operator()
00051 (
00052 List<labelList>& x,
00053 const List<labelList>& y
00054 ) const
00055 {
00056 forAll(y, i)
00057 {
00058 const labelList& yPatches = y[i];
00059
00060 if (yPatches.size())
00061 {
00062 labelList& xPatches = x[i];
00063
00064 label offset = xPatches.size();
00065 xPatches.setSize(offset + yPatches.size());
00066
00067 forAll(yPatches, i)
00068 {
00069 xPatches[i + offset] = yPatches[i];
00070 }
00071 }
00072 }
00073 }
00074 };
00075 }
00076
00077
00078
00079
00080 Foam::ensightMesh::ensightMesh
00081 (
00082 const fvMesh& mesh,
00083 const argList& args,
00084 const bool binary
00085 )
00086 :
00087 mesh_(mesh),
00088 binary_(binary),
00089 patchPartOffset_(2),
00090 meshCellSets_(mesh_.nCells()),
00091 boundaryFaceSets_(mesh_.boundary().size()),
00092 allPatchNames_(0),
00093 allPatchProcs_(0),
00094 patchNames_(0),
00095 nPatchPrims_(0)
00096 {
00097 const cellShapeList& cellShapes = mesh.cellShapes();
00098
00099 const cellModel& tet = *(cellModeller::lookup("tet"));
00100 const cellModel& pyr = *(cellModeller::lookup("pyr"));
00101 const cellModel& prism = *(cellModeller::lookup("prism"));
00102 const cellModel& wedge = *(cellModeller::lookup("wedge"));
00103 const cellModel& hex = *(cellModeller::lookup("hex"));
00104
00105 if (!args.optionFound("noPatches"))
00106 {
00107 allPatchNames_ = wordList::subList
00108 (
00109 mesh_.boundaryMesh().names(), mesh_.boundary().size()
00110 - mesh_.globalData().processorPatches().size()
00111 );
00112
00113 allPatchProcs_.setSize(allPatchNames_.size());
00114
00115 forAll (allPatchProcs_, patchi)
00116 {
00117 if (mesh_.boundary()[patchi].size())
00118 {
00119 allPatchProcs_[patchi].setSize(1);
00120 allPatchProcs_[patchi][0] = Pstream::myProcNo();
00121 }
00122 }
00123
00124 combineReduce(allPatchProcs_, concatPatchProcs());
00125
00126 if (args.optionFound("patches"))
00127 {
00128 wordList patchNameList(args.optionLookup("patches")());
00129
00130 if (patchNameList.empty())
00131 {
00132 patchNameList = allPatchNames_;
00133 }
00134
00135 forAll (patchNameList, i)
00136 {
00137 patchNames_.insert(patchNameList[i]);
00138 }
00139 }
00140 }
00141
00142 if (patchNames_.size())
00143 {
00144
00145 patchPartOffset_ = 1;
00146 }
00147 else
00148 {
00149
00150 labelList& tets = meshCellSets_.tets;
00151 labelList& pyrs = meshCellSets_.pyrs;
00152 labelList& prisms = meshCellSets_.prisms;
00153 labelList& wedges = meshCellSets_.wedges;
00154 labelList& hexes = meshCellSets_.hexes;
00155 labelList& polys = meshCellSets_.polys;
00156
00157 label nTets = 0;
00158 label nPyrs = 0;
00159 label nPrisms = 0;
00160 label nWedges = 0;
00161 label nHexes = 0;
00162 label nPolys = 0;
00163
00164 forAll(cellShapes, cellI)
00165 {
00166 const cellShape& cellShape = cellShapes[cellI];
00167 const cellModel& cellModel = cellShape.model();
00168
00169 if (cellModel == tet)
00170 {
00171 tets[nTets++] = cellI;
00172 }
00173 else if (cellModel == pyr)
00174 {
00175 pyrs[nPyrs++] = cellI;
00176 }
00177 else if (cellModel == prism)
00178 {
00179 prisms[nPrisms++] = cellI;
00180 }
00181 else if (cellModel == wedge)
00182 {
00183 wedges[nWedges++] = cellI;
00184 }
00185 else if (cellModel == hex)
00186 {
00187 hexes[nHexes++] = cellI;
00188 }
00189 else
00190 {
00191 polys[nPolys++] = cellI;
00192 }
00193 }
00194
00195 tets.setSize(nTets);
00196 pyrs.setSize(nPyrs);
00197 prisms.setSize(nPrisms);
00198 wedges.setSize(nWedges);
00199 hexes.setSize(nHexes);
00200 polys.setSize(nPolys);
00201
00202 meshCellSets_.nTets = nTets;
00203 reduce(meshCellSets_.nTets, sumOp<label>());
00204
00205 meshCellSets_.nPyrs = nPyrs;
00206 reduce(meshCellSets_.nPyrs, sumOp<label>());
00207
00208 meshCellSets_.nPrisms = nPrisms;
00209 reduce(meshCellSets_.nPrisms, sumOp<label>());
00210
00211 meshCellSets_.nHexesWedges = nHexes + nWedges;
00212 reduce(meshCellSets_.nHexesWedges, sumOp<label>());
00213
00214 meshCellSets_.nPolys = nPolys;
00215 reduce(meshCellSets_.nPolys, sumOp<label>());
00216 }
00217
00218 if (!args.optionFound("noPatches"))
00219 {
00220 forAll (mesh.boundary(), patchi)
00221 {
00222 if (mesh.boundary()[patchi].size())
00223 {
00224 const polyPatch& p = mesh.boundaryMesh()[patchi];
00225
00226 labelList& tris = boundaryFaceSets_[patchi].tris;
00227 labelList& quads = boundaryFaceSets_[patchi].quads;
00228 labelList& polys = boundaryFaceSets_[patchi].polys;
00229
00230 tris.setSize(p.size());
00231 quads.setSize(p.size());
00232 polys.setSize(p.size());
00233
00234 label nTris = 0;
00235 label nQuads = 0;
00236 label nPolys = 0;
00237
00238 forAll(p, faceI)
00239 {
00240 const face& f = p[faceI];
00241
00242 if (f.size() == 3)
00243 {
00244 tris[nTris++] = faceI;
00245 }
00246 else if (f.size() == 4)
00247 {
00248 quads[nQuads++] = faceI;
00249 }
00250 else
00251 {
00252 polys[nPolys++] = faceI;
00253 }
00254 }
00255
00256 tris.setSize(nTris);
00257 quads.setSize(nQuads);
00258 polys.setSize(nPolys);
00259 }
00260 }
00261 }
00262
00263
00264 forAll(allPatchNames_, patchi)
00265 {
00266 const word& patchName = allPatchNames_[patchi];
00267 nFacePrimitives nfp;
00268
00269 if (patchNames_.empty() || patchNames_.found(patchName))
00270 {
00271 if (mesh.boundary()[patchi].size())
00272 {
00273 nfp.nPoints = mesh.boundaryMesh()[patchi].localPoints().size();
00274 nfp.nTris = boundaryFaceSets_[patchi].tris.size();
00275 nfp.nQuads = boundaryFaceSets_[patchi].quads.size();
00276 nfp.nPolys = boundaryFaceSets_[patchi].polys.size();
00277 }
00278 }
00279
00280 reduce(nfp.nPoints, sumOp<label>());
00281 reduce(nfp.nTris, sumOp<label>());
00282 reduce(nfp.nQuads, sumOp<label>());
00283 reduce(nfp.nPolys, sumOp<label>());
00284
00285 nPatchPrims_.insert(patchName, nfp);
00286 }
00287 }
00288
00289
00290
00291
00292 Foam::ensightMesh::~ensightMesh()
00293 {}
00294
00295
00296
00297
00298 void Foam::ensightMesh::writePoints
00299 (
00300 const scalarField& pointsComponent,
00301 OFstream& ensightGeometryFile
00302 ) const
00303 {
00304 forAll(pointsComponent, pointI)
00305 {
00306 ensightGeometryFile<< setw(12) << float(pointsComponent[pointI]) << nl;
00307 }
00308 }
00309
00310
00311 Foam::cellShapeList Foam::ensightMesh::map
00312 (
00313 const cellShapeList& cellShapes,
00314 const labelList& prims
00315 ) const
00316 {
00317 cellShapeList mcsl(prims.size());
00318
00319 forAll(prims, i)
00320 {
00321 mcsl[i] = cellShapes[prims[i]];
00322 }
00323
00324 return mcsl;
00325 }
00326
00327
00328 Foam::cellShapeList Foam::ensightMesh::map
00329 (
00330 const cellShapeList& cellShapes,
00331 const labelList& hexes,
00332 const labelList& wedges
00333 ) const
00334 {
00335 cellShapeList mcsl(hexes.size() + wedges.size());
00336
00337 forAll(hexes, i)
00338 {
00339 mcsl[i] = cellShapes[hexes[i]];
00340 }
00341
00342 label offset = hexes.size();
00343
00344 const cellModel& hex = *(cellModeller::lookup("hex"));
00345 labelList hexLabels(8);
00346
00347 forAll(wedges, i)
00348 {
00349 const cellShape& cellPoints = cellShapes[wedges[i]];
00350
00351 hexLabels[0] = cellPoints[0];
00352 hexLabels[1] = cellPoints[1];
00353 hexLabels[2] = cellPoints[0];
00354 hexLabels[3] = cellPoints[2];
00355 hexLabels[4] = cellPoints[3];
00356 hexLabels[5] = cellPoints[4];
00357 hexLabels[6] = cellPoints[6];
00358 hexLabels[7] = cellPoints[5];
00359
00360 mcsl[i + offset] = cellShape(hex, hexLabels);
00361 }
00362
00363 return mcsl;
00364 }
00365
00366
00367 void Foam::ensightMesh::writePrims
00368 (
00369 const cellShapeList& cellShapes,
00370 const label pointOffset,
00371 OFstream& ensightGeometryFile
00372 ) const
00373 {
00374 label po = pointOffset + 1;
00375
00376 forAll(cellShapes, i)
00377 {
00378 const cellShape& cellPoints = cellShapes[i];
00379
00380 forAll(cellPoints, pointI)
00381 {
00382 ensightGeometryFile<< setw(10) << cellPoints[pointI] + po;
00383 }
00384 ensightGeometryFile << nl;
00385 }
00386 }
00387
00388
00389 void Foam::ensightMesh::writePrimsBinary
00390 (
00391 const cellShapeList& cellShapes,
00392 const label pointOffset,
00393 std::ofstream& ensightGeometryFile
00394 ) const
00395 {
00396 label po = pointOffset + 1;
00397
00398
00399 int numElem;
00400
00401 numElem = cellShapes.size();
00402
00403 if (cellShapes.size())
00404 {
00405
00406 int numIntElem = cellShapes.size()*cellShapes[0].size();
00407 List<int> temp(numIntElem);
00408
00409 int n = 0;
00410
00411 forAll(cellShapes, i)
00412 {
00413 const cellShape& cellPoints = cellShapes[i];
00414
00415 forAll(cellPoints, pointI)
00416 {
00417 temp[n] = cellPoints[pointI] + po;
00418 n++;
00419 }
00420 }
00421
00422 ensightGeometryFile.write
00423 (
00424 reinterpret_cast<char*>(temp.begin()),
00425 numIntElem*sizeof(int)
00426 );
00427 }
00428 }
00429
00430
00431 void Foam::ensightMesh::writePolys
00432 (
00433 const labelList& polys,
00434 const cellList& cellFaces,
00435 const faceList& faces,
00436 const label pointOffset,
00437 OFstream& ensightGeometryFile
00438 ) const
00439 {
00440 if (polys.size())
00441 {
00442 ensightGeometryFile
00443 << "nfaced" << nl << setw(10) << polys.size() << nl;
00444
00445 label po = pointOffset + 1;
00446
00447 forAll(polys, i)
00448 {
00449 ensightGeometryFile
00450 << setw(10) << cellFaces[polys[i]].size() << nl;
00451 }
00452
00453 forAll(polys, i)
00454 {
00455 const labelList& cf = cellFaces[polys[i]];
00456
00457 forAll(cf, faceI)
00458 {
00459 ensightGeometryFile
00460 << setw(10) << faces[cf[faceI]].size() << nl;
00461 }
00462 }
00463
00464 forAll(polys, i)
00465 {
00466 const labelList& cf = cellFaces[polys[i]];
00467
00468 forAll(cf, faceI)
00469 {
00470 const face& f = faces[cf[faceI]];
00471
00472 forAll(f, pointI)
00473 {
00474 ensightGeometryFile << setw(10) << f[pointI] + po;
00475 }
00476 ensightGeometryFile << nl;
00477 }
00478 }
00479 }
00480 }
00481
00482
00483 void Foam::ensightMesh::writePolysBinary
00484 (
00485 const labelList& polys,
00486 const cellList& cellFaces,
00487 const faceList& faces,
00488 const label pointOffset,
00489 std::ofstream& ensightGeometryFile
00490 ) const
00491 {
00492 if (polys.size())
00493 {
00494 writeEnsDataBinary("nfaced",ensightGeometryFile);
00495 writeEnsDataBinary(polys.size(),ensightGeometryFile);
00496
00497 label po = pointOffset + 1;
00498
00499
00500 forAll(polys, i)
00501 {
00502 writeEnsDataBinary
00503 (
00504 cellFaces[polys[i]].size(),
00505 ensightGeometryFile
00506 );
00507 }
00508
00509 forAll(polys, i)
00510 {
00511 const labelList& cf = cellFaces[polys[i]];
00512
00513 forAll(cf, faceI)
00514 {
00515 writeEnsDataBinary
00516 (
00517 faces[cf[faceI]].size(),
00518 ensightGeometryFile
00519 );
00520 }
00521 }
00522
00523 forAll(polys, i)
00524 {
00525 const labelList& cf = cellFaces[polys[i]];
00526
00527 forAll(cf, faceI)
00528 {
00529 const face& f = faces[cf[faceI]];
00530
00531 forAll(f, pointI)
00532 {
00533 writeEnsDataBinary(f[pointI] + po,ensightGeometryFile);
00534 }
00535 }
00536 }
00537 }
00538 }
00539
00540
00541 void Foam::ensightMesh::writeAllPrims
00542 (
00543 const char* key,
00544 const label nPrims,
00545 const cellShapeList& cellShapes,
00546 const labelList& pointOffsets,
00547 OFstream& ensightGeometryFile
00548 ) const
00549 {
00550 if (nPrims)
00551 {
00552 if (Pstream::master())
00553 {
00554 ensightGeometryFile << key << nl << setw(10) << nPrims << nl;
00555
00556 writePrims(cellShapes, 0, ensightGeometryFile);
00557
00558 for (int slave=1; slave<Pstream::nProcs(); slave++)
00559 {
00560 IPstream fromSlave(Pstream::scheduled, slave);
00561 cellShapeList cellShapes(fromSlave);
00562
00563 writePrims
00564 (
00565 cellShapes,
00566 pointOffsets[slave-1],
00567 ensightGeometryFile
00568 );
00569 }
00570 }
00571 else
00572 {
00573 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00574 toMaster<< cellShapes;
00575 }
00576 }
00577 }
00578
00579
00580 void Foam::ensightMesh::writeAllPrimsBinary
00581 (
00582 const char* key,
00583 const label nPrims,
00584 const cellShapeList& cellShapes,
00585 const labelList& pointOffsets,
00586 std::ofstream& ensightGeometryFile
00587 ) const
00588 {
00589 if (nPrims)
00590 {
00591 if (Pstream::master())
00592 {
00593 writeEnsDataBinary(key,ensightGeometryFile);
00594 writeEnsDataBinary(nPrims,ensightGeometryFile);
00595
00596 writePrimsBinary(cellShapes, 0, ensightGeometryFile);
00597
00598 for (int slave=1; slave<Pstream::nProcs(); slave++)
00599 {
00600 IPstream fromSlave(Pstream::scheduled, slave);
00601 cellShapeList cellShapes(fromSlave);
00602
00603 writePrimsBinary
00604 (
00605 cellShapes,
00606 pointOffsets[slave-1],
00607 ensightGeometryFile
00608 );
00609 }
00610 }
00611 else
00612 {
00613 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00614 toMaster<< cellShapes;
00615 }
00616 }
00617 }
00618
00619
00620 void Foam::ensightMesh::writeFacePrims
00621 (
00622 const char* key,
00623 const faceList& patchFaces,
00624 const label pointOffset,
00625 OFstream& ensightGeometryFile
00626 ) const
00627 {
00628 if (patchFaces.size())
00629 {
00630 if (word(key) == "nsided")
00631 {
00632 ensightGeometryFile
00633 << key << nl << setw(10) << patchFaces.size() << nl;
00634
00635 forAll(patchFaces, i)
00636 {
00637 ensightGeometryFile
00638 << setw(10) << patchFaces[i].size() << nl;
00639 }
00640 }
00641
00642 label po = pointOffset + 1;
00643
00644 forAll(patchFaces, i)
00645 {
00646 const face& patchFace = patchFaces[i];
00647
00648 forAll(patchFace, pointI)
00649 {
00650 ensightGeometryFile << setw(10) << patchFace[pointI] + po;
00651 }
00652 ensightGeometryFile << nl;
00653 }
00654 }
00655 }
00656
00657
00658 void Foam::ensightMesh::writeFacePrimsBinary
00659 (
00660 const char* key,
00661 const faceList& patchFaces,
00662 const label pointOffset,
00663 std::ofstream& ensightGeometryFile
00664 ) const
00665 {
00666 if (patchFaces.size())
00667 {
00668
00669 if (word(key) == "nsided")
00670 {
00671 writeEnsDataBinary(key,ensightGeometryFile);
00672 writeEnsDataBinary(patchFaces.size(),ensightGeometryFile);
00673
00674 forAll(patchFaces, i)
00675 {
00676 writeEnsDataBinary
00677 (
00678 patchFaces[i].size(),
00679 ensightGeometryFile
00680 );
00681 }
00682 }
00683
00684 label po = pointOffset + 1;
00685
00686 forAll(patchFaces, i)
00687 {
00688 const face& patchFace = patchFaces[i];
00689
00690 forAll(patchFace, pointI)
00691 {
00692 writeEnsDataBinary
00693 (
00694 patchFace[pointI] + po,
00695 ensightGeometryFile
00696 );
00697 }
00698 }
00699 }
00700 }
00701
00702
00703 Foam::faceList Foam::ensightMesh::map
00704 (
00705 const faceList& patchFaces,
00706 const labelList& prims
00707 ) const
00708 {
00709 faceList ppf(prims.size());
00710
00711 forAll (prims, i)
00712 {
00713 ppf[i] = patchFaces[prims[i]];
00714 }
00715
00716 return ppf;
00717 }
00718
00719
00720 void Foam::ensightMesh::writeAllFacePrims
00721 (
00722 const char* key,
00723 const labelList& prims,
00724 const label nPrims,
00725 const faceList& patchFaces,
00726 const labelList& pointOffsets,
00727 const labelList& patchProcessors,
00728 OFstream& ensightGeometryFile
00729 ) const
00730 {
00731 if (nPrims)
00732 {
00733 if (Pstream::master())
00734 {
00735 if (word(key) != "nsided")
00736 {
00737 ensightGeometryFile << key << nl << setw(10) << nPrims << nl;
00738 }
00739
00740 if (&prims != NULL)
00741 {
00742 writeFacePrims
00743 (
00744 key,
00745 map(patchFaces, prims),
00746 0,
00747 ensightGeometryFile
00748 );
00749 }
00750
00751 forAll (patchProcessors, i)
00752 {
00753 if (patchProcessors[i] != 0)
00754 {
00755 label slave = patchProcessors[i];
00756 IPstream fromSlave(Pstream::scheduled, slave);
00757 faceList patchFaces(fromSlave);
00758
00759 writeFacePrims
00760 (
00761 key,
00762 patchFaces,
00763 pointOffsets[i],
00764 ensightGeometryFile
00765 );
00766 }
00767 }
00768 }
00769 else if (&prims != NULL)
00770 {
00771 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00772 toMaster<< map(patchFaces, prims);
00773 }
00774 }
00775 }
00776
00777
00778 void Foam::ensightMesh::writeAllFacePrimsBinary
00779 (
00780 const char* key,
00781 const labelList& prims,
00782 const label nPrims,
00783 const faceList& patchFaces,
00784 const labelList& pointOffsets,
00785 const labelList& patchProcessors,
00786 std::ofstream& ensightGeometryFile
00787 ) const
00788 {
00789 if (nPrims)
00790 {
00791 if (Pstream::master())
00792 {
00793 if (word(key) != "nsided")
00794 {
00795 writeEnsDataBinary(key,ensightGeometryFile);
00796 writeEnsDataBinary(nPrims,ensightGeometryFile);
00797 }
00798
00799 if (&prims != NULL)
00800 {
00801 writeFacePrimsBinary
00802 (
00803 key,
00804 map(patchFaces, prims),
00805 0,
00806 ensightGeometryFile
00807 );
00808 }
00809
00810 forAll (patchProcessors, i)
00811 {
00812 if (patchProcessors[i] != 0)
00813 {
00814 label slave = patchProcessors[i];
00815 IPstream fromSlave(Pstream::scheduled, slave);
00816 faceList patchFaces(fromSlave);
00817
00818 writeFacePrimsBinary
00819 (
00820 key,
00821 patchFaces,
00822 pointOffsets[i],
00823 ensightGeometryFile
00824 );
00825 }
00826 }
00827 }
00828 else if (&prims != NULL)
00829 {
00830 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00831 toMaster<< map(patchFaces, prims);
00832 }
00833 }
00834 }
00835
00836
00837 void Foam::ensightMesh::write
00838 (
00839 const fileName& postProcPath,
00840 const word& prepend,
00841 const label timeIndex,
00842 Ostream& ensightCaseFile
00843 ) const
00844 {
00845 if (binary_)
00846 {
00847 writeBinary(postProcPath, prepend, timeIndex, ensightCaseFile);
00848 }
00849 else
00850 {
00851 writeAscii(postProcPath, prepend, timeIndex, ensightCaseFile);
00852 }
00853 }
00854
00855
00856 void Foam::ensightMesh::writeAscii
00857 (
00858 const fileName& postProcPath,
00859 const word& prepend,
00860 const label timeIndex,
00861 Ostream& ensightCaseFile
00862 ) const
00863 {
00864 const Time& runTime = mesh_.time();
00865 const pointField& points = mesh_.points();
00866 const cellList& cellFaces = mesh_.cells();
00867 const faceList& faces = mesh_.faces();
00868 const cellShapeList& cellShapes = mesh_.cellShapes();
00869
00870 word timeFile = prepend;
00871
00872 if (timeIndex == 0)
00873 {
00874 timeFile += "000.";
00875 }
00876 else if (mesh_.moving())
00877 {
00878 timeFile += itoa(timeIndex) + '.';
00879 }
00880
00881
00882 fileName ensightGeometryFileName = timeFile + "mesh";
00883
00884 OFstream *ensightGeometryFilePtr = NULL;
00885 if (Pstream::master())
00886 {
00887 ensightGeometryFilePtr = new OFstream
00888 (
00889 postProcPath/ensightGeometryFileName,
00890 runTime.writeFormat(),
00891 runTime.writeVersion(),
00892 IOstream::UNCOMPRESSED
00893 );
00894 }
00895
00896 OFstream& ensightGeometryFile = *ensightGeometryFilePtr;
00897
00898 if (Pstream::master())
00899 {
00900
00901 ensightGeometryFile.setf
00902 (
00903 ios_base::scientific,
00904 ios_base::floatfield
00905 );
00906 ensightGeometryFile.precision(5);
00907
00908 ensightGeometryFile
00909 << "EnSight Geometry File" << nl
00910 << "written from OpenFOAM-" << Foam::FOAMversion << nl
00911 << "node id assign" << nl
00912 << "element id assign" << nl;
00913 }
00914
00915 labelList pointOffsets(Pstream::nProcs(), 0);
00916
00917 if (patchNames_.empty())
00918 {
00919 label nPoints = points.size();
00920 Pstream::gather(nPoints, sumOp<label>());
00921
00922 if (Pstream::master())
00923 {
00924 ensightGeometryFile
00925 << "part" << nl
00926 << setw(10) << 1 << nl
00927 << "internalMesh" << nl
00928 << "coordinates" << nl
00929 << setw(10) << nPoints
00930 << endl;
00931
00932 for (direction d=0; d<vector::nComponents; d++)
00933 {
00934 writePoints(points.component(d), ensightGeometryFile);
00935 pointOffsets[0] = points.size();
00936
00937 for (int slave=1; slave<Pstream::nProcs(); slave++)
00938 {
00939 IPstream fromSlave(Pstream::scheduled, slave);
00940 scalarField pointsComponent(fromSlave);
00941 writePoints(pointsComponent, ensightGeometryFile);
00942 pointOffsets[slave] =
00943 pointOffsets[slave-1]
00944 + pointsComponent.size();
00945 }
00946 }
00947 }
00948 else
00949 {
00950 for (direction d=0; d<vector::nComponents; d++)
00951 {
00952 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00953 toMaster<< points.component(d);
00954 }
00955 }
00956
00957 writeAllPrims
00958 (
00959 "hexa8",
00960 meshCellSets_.nHexesWedges,
00961 map(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
00962 pointOffsets,
00963 ensightGeometryFile
00964 );
00965
00966 writeAllPrims
00967 (
00968 "penta6",
00969 meshCellSets_.nPrisms,
00970 map(cellShapes, meshCellSets_.prisms),
00971 pointOffsets,
00972 ensightGeometryFile
00973 );
00974
00975 writeAllPrims
00976 (
00977 "pyramid5",
00978 meshCellSets_.nPyrs,
00979 map(cellShapes, meshCellSets_.pyrs),
00980 pointOffsets,
00981 ensightGeometryFile
00982 );
00983
00984 writeAllPrims
00985 (
00986 "tetra4",
00987 meshCellSets_.nTets,
00988 map(cellShapes, meshCellSets_.tets),
00989 pointOffsets,
00990 ensightGeometryFile
00991 );
00992
00993
00994 if (meshCellSets_.nPolys)
00995 {
00996 if (Pstream::master())
00997 {
00998
00999
01000
01001
01002
01003 writePolys
01004 (
01005 meshCellSets_.polys,
01006 cellFaces,
01007 faces,
01008 0,
01009 ensightGeometryFile
01010 );
01011
01012 for (int slave=1; slave<Pstream::nProcs(); slave++)
01013 {
01014 IPstream fromSlave(Pstream::scheduled, slave);
01015 labelList polys(fromSlave);
01016 cellList cellFaces(fromSlave);
01017 faceList faces(fromSlave);
01018
01019 writePolys
01020 (
01021 polys,
01022 cellFaces,
01023 faces,
01024 pointOffsets[slave-1],
01025 ensightGeometryFile
01026 );
01027 }
01028 }
01029 else
01030 {
01031 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01032 toMaster<< meshCellSets_.polys << cellFaces << faces;
01033 }
01034 }
01035 }
01036
01037
01038 label ensightPatchI = patchPartOffset_;
01039
01040 forAll(allPatchNames_, patchi)
01041 {
01042 const word& patchName = allPatchNames_[patchi];
01043 const labelList& patchProcessors = allPatchProcs_[patchi];
01044
01045 if (patchNames_.empty() || patchNames_.found(patchName))
01046 {
01047 const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
01048
01049 const labelList *trisPtr = NULL;
01050 const labelList *quadsPtr = NULL;
01051 const labelList *polysPtr = NULL;
01052
01053 const pointField *patchPointsPtr = NULL;
01054 const faceList *patchFacesPtr = NULL;
01055
01056 if (mesh_.boundary()[patchi].size())
01057 {
01058 const polyPatch& p = mesh_.boundaryMesh()[patchi];
01059
01060 trisPtr = &boundaryFaceSets_[patchi].tris;
01061 quadsPtr = &boundaryFaceSets_[patchi].quads;
01062 polysPtr = &boundaryFaceSets_[patchi].polys;
01063
01064 patchPointsPtr = &(p.localPoints());
01065 patchFacesPtr = &(p.localFaces());
01066 }
01067
01068 const labelList& tris = *trisPtr;
01069 const labelList& quads = *quadsPtr;
01070 const labelList& polys = *polysPtr;
01071 const pointField& patchPoints = *patchPointsPtr;
01072 const faceList& patchFaces = *patchFacesPtr;
01073
01074 if (nfp.nTris || nfp.nQuads || nfp.nPolys)
01075 {
01076 labelList patchPointOffsets(Pstream::nProcs(), 0);
01077
01078 if (Pstream::master())
01079 {
01080 ensightGeometryFile
01081 << "part" << nl
01082 << setw(10) << ensightPatchI++ << nl
01083 << patchName << nl
01084 << "coordinates" << nl
01085 << setw(10) << nfp.nPoints
01086 << endl;
01087
01088 for (direction d=0; d<vector::nComponents; d++)
01089 {
01090 if (patchPointsPtr)
01091 {
01092 writePoints
01093 (
01094 patchPoints.component(d),
01095 ensightGeometryFile
01096 );
01097 }
01098
01099 patchPointOffsets = 0;
01100
01101 forAll (patchProcessors, i)
01102 {
01103 if (patchProcessors[i] != 0)
01104 {
01105 label slave = patchProcessors[i];
01106 IPstream fromSlave(Pstream::scheduled, slave);
01107 scalarField patchPointsComponent(fromSlave);
01108
01109 writePoints
01110 (
01111 patchPointsComponent,
01112 ensightGeometryFile
01113 );
01114
01115 if (i < Pstream::nProcs()-1)
01116 {
01117 patchPointOffsets[i+1] =
01118 patchPointOffsets[i]
01119 + patchPointsComponent.size();
01120 }
01121 }
01122 else
01123 {
01124 if (i < Pstream::nProcs()-1)
01125 {
01126 patchPointOffsets[i+1] =
01127 patchPointOffsets[i]
01128 + patchPoints.size();
01129 }
01130 }
01131 }
01132 }
01133 }
01134 else if (patchPointsPtr)
01135 {
01136 for (direction d=0; d<vector::nComponents; d++)
01137 {
01138 OPstream toMaster
01139 (
01140 Pstream::scheduled,
01141 Pstream::masterNo()
01142 );
01143 toMaster<< patchPoints.component(d);
01144 }
01145 }
01146
01147 writeAllFacePrims
01148 (
01149 "tria3",
01150 tris,
01151 nfp.nTris,
01152 patchFaces,
01153 patchPointOffsets,
01154 patchProcessors,
01155 ensightGeometryFile
01156 );
01157
01158 writeAllFacePrims
01159 (
01160 "quad4",
01161 quads,
01162 nfp.nQuads,
01163 patchFaces,
01164 patchPointOffsets,
01165 patchProcessors,
01166 ensightGeometryFile
01167 );
01168
01169 writeAllFacePrims
01170 (
01171 "nsided",
01172 polys,
01173 nfp.nPolys,
01174 patchFaces,
01175 patchPointOffsets,
01176 patchProcessors,
01177 ensightGeometryFile
01178 );
01179 }
01180 }
01181 }
01182
01183 if (Pstream::master())
01184 {
01185 delete ensightGeometryFilePtr;
01186 }
01187 }
01188
01189
01190 void Foam::ensightMesh::writeBinary
01191 (
01192 const fileName& postProcPath,
01193 const word& prepend,
01194 const label timeIndex,
01195 Ostream& ensightCaseFile
01196 ) const
01197 {
01198
01199 const pointField& points = mesh_.points();
01200 const cellList& cellFaces = mesh_.cells();
01201 const faceList& faces = mesh_.faces();
01202 const cellShapeList& cellShapes = mesh_.cellShapes();
01203
01204 word timeFile = prepend;
01205
01206 if (timeIndex == 0)
01207 {
01208 timeFile += "000.";
01209 }
01210 else if (mesh_.moving())
01211 {
01212 timeFile += itoa(timeIndex) + '.';
01213 }
01214
01215
01216 fileName ensightGeometryFileName = timeFile + "mesh";
01217
01218 std::ofstream *ensightGeometryFilePtr = NULL;
01219
01220 if (Pstream::master())
01221 {
01222 ensightGeometryFilePtr = new std::ofstream
01223 (
01224 (postProcPath/ensightGeometryFileName).c_str(),
01225 ios_base::out | ios_base::binary | ios_base::trunc
01226 );
01227
01228 }
01229
01230 std::ofstream& ensightGeometryFile = *ensightGeometryFilePtr;
01231
01232 if (Pstream::master())
01233 {
01234 writeEnsDataBinary("C binary", ensightGeometryFile);
01235 writeEnsDataBinary("EnSight Geometry File", ensightGeometryFile);
01236 writeEnsDataBinary("written from OpenFOAM", ensightGeometryFile);
01237 writeEnsDataBinary("node id assign", ensightGeometryFile);
01238 writeEnsDataBinary("element id assign", ensightGeometryFile);
01239 }
01240
01241 labelList pointOffsets(Pstream::nProcs(), 0);
01242
01243 if (patchNames_.empty())
01244 {
01245 label nPoints = points.size();
01246 Pstream::gather(nPoints, sumOp<label>());
01247
01248 if (Pstream::master())
01249 {
01250 writeEnsDataBinary("part",ensightGeometryFile);
01251 writeEnsDataBinary(1,ensightGeometryFile);
01252 writeEnsDataBinary("internalMesh",ensightGeometryFile);
01253 writeEnsDataBinary("coordinates",ensightGeometryFile);
01254 writeEnsDataBinary(nPoints,ensightGeometryFile);
01255
01256 for (direction d=0; d<vector::nComponents; d++)
01257 {
01258
01259 writeEnsDataBinary(points.component(d), ensightGeometryFile);
01260 pointOffsets[0] = points.size();
01261
01262 for (int slave=1; slave<Pstream::nProcs(); slave++)
01263 {
01264 IPstream fromSlave(Pstream::scheduled, slave);
01265 scalarField pointsComponent(fromSlave);
01266
01267 writeEnsDataBinary(pointsComponent, ensightGeometryFile);
01268 pointOffsets[slave] =
01269 pointOffsets[slave-1]
01270 + pointsComponent.size();
01271 }
01272 }
01273 }
01274 else
01275 {
01276 for (direction d=0; d<vector::nComponents; d++)
01277 {
01278 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01279 toMaster<< points.component(d);
01280 }
01281 }
01282
01283 writeAllPrimsBinary
01284 (
01285 "hexa8",
01286 meshCellSets_.nHexesWedges,
01287 map(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
01288 pointOffsets,
01289 ensightGeometryFile
01290 );
01291
01292 writeAllPrimsBinary
01293 (
01294 "penta6",
01295 meshCellSets_.nPrisms,
01296 map(cellShapes, meshCellSets_.prisms),
01297 pointOffsets,
01298 ensightGeometryFile
01299 );
01300
01301 writeAllPrimsBinary
01302 (
01303 "pyramid5",
01304 meshCellSets_.nPyrs,
01305 map(cellShapes, meshCellSets_.pyrs),
01306 pointOffsets,
01307 ensightGeometryFile
01308 );
01309
01310 writeAllPrimsBinary
01311 (
01312 "tetra4",
01313 meshCellSets_.nTets,
01314 map(cellShapes, meshCellSets_.tets),
01315 pointOffsets,
01316 ensightGeometryFile
01317 );
01318
01319 if (meshCellSets_.nPolys)
01320 {
01321 if (Pstream::master())
01322 {
01323
01324
01325
01326
01327
01328 writePolysBinary
01329 (
01330 meshCellSets_.polys,
01331 cellFaces,
01332 faces,
01333 0,
01334 ensightGeometryFile
01335 );
01336
01337 for (int slave=1; slave<Pstream::nProcs(); slave++)
01338 {
01339 IPstream fromSlave(Pstream::scheduled, slave);
01340 labelList polys(fromSlave);
01341 cellList cellFaces(fromSlave);
01342 faceList faces(fromSlave);
01343
01344 writePolysBinary
01345 (
01346 polys,
01347 cellFaces,
01348 faces,
01349 pointOffsets[slave-1],
01350 ensightGeometryFile
01351 );
01352 }
01353 }
01354 else
01355 {
01356 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01357 toMaster<< meshCellSets_.polys << cellFaces << faces;
01358 }
01359 }
01360
01361 }
01362
01363 label ensightPatchI = patchPartOffset_;
01364 label iCount = 0;
01365
01366 forAll(allPatchNames_, patchi)
01367 {
01368 iCount ++;
01369 const word& patchName = allPatchNames_[patchi];
01370 const labelList& patchProcessors = allPatchProcs_[patchi];
01371
01372 if (patchNames_.empty() || patchNames_.found(patchName))
01373 {
01374 const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
01375
01376 const labelList *trisPtr = NULL;
01377 const labelList *quadsPtr = NULL;
01378 const labelList *polysPtr = NULL;
01379
01380 const pointField *patchPointsPtr = NULL;
01381 const faceList *patchFacesPtr = NULL;
01382
01383 if (mesh_.boundary()[patchi].size())
01384 {
01385 const polyPatch& p = mesh_.boundaryMesh()[patchi];
01386
01387 trisPtr = &boundaryFaceSets_[patchi].tris;
01388 quadsPtr = &boundaryFaceSets_[patchi].quads;
01389 polysPtr = &boundaryFaceSets_[patchi].polys;
01390
01391 patchPointsPtr = &(p.localPoints());
01392 patchFacesPtr = &(p.localFaces());
01393 }
01394
01395 const labelList& tris = *trisPtr;
01396 const labelList& quads = *quadsPtr;
01397 const labelList& polys = *polysPtr;
01398 const pointField& patchPoints = *patchPointsPtr;
01399 const faceList& patchFaces = *patchFacesPtr;
01400
01401 if (nfp.nTris || nfp.nQuads || nfp.nPolys)
01402 {
01403 labelList patchPointOffsets(Pstream::nProcs(), 0);
01404
01405 if (Pstream::master())
01406 {
01407 writeEnsDataBinary("part",ensightGeometryFile);
01408 writeEnsDataBinary(ensightPatchI++,ensightGeometryFile);
01409
01410 writeEnsDataBinary(patchName.c_str(),ensightGeometryFile);
01411 writeEnsDataBinary("coordinates",ensightGeometryFile);
01412 writeEnsDataBinary(nfp.nPoints,ensightGeometryFile);
01413
01414 for (direction d=0; d<vector::nComponents; d++)
01415 {
01416 if (patchPointsPtr)
01417 {
01418
01419 writeEnsDataBinary
01420 (
01421 patchPoints.component(d),
01422 ensightGeometryFile
01423 );
01424 }
01425
01426 patchPointOffsets = 0;
01427
01428
01429 forAll (patchProcessors, i)
01430 {
01431 if (patchProcessors[i] != 0)
01432 {
01433 label slave = patchProcessors[i];
01434 IPstream fromSlave(Pstream::scheduled, slave);
01435 scalarField patchPointsComponent(fromSlave);
01436
01437
01438 writeEnsDataBinary
01439 (
01440 patchPointsComponent,
01441 ensightGeometryFile
01442 );
01443
01444 if (i < Pstream::nProcs()-1)
01445 {
01446 patchPointOffsets[i+1] =
01447 patchPointOffsets[i]
01448 + patchPointsComponent.size();
01449 }
01450 }
01451 else
01452 {
01453 if (i < Pstream::nProcs()-1)
01454 {
01455 patchPointOffsets[i+1] =
01456 patchPointOffsets[i]
01457 + patchPoints.size();
01458 }
01459 }
01460 }
01461 }
01462 }
01463 else if (patchPointsPtr)
01464 {
01465 for (direction d=0; d<vector::nComponents; d++)
01466 {
01467 OPstream toMaster
01468 (
01469 Pstream::scheduled,
01470 Pstream::masterNo()
01471 );
01472 toMaster<< patchPoints.component(d);
01473 }
01474 }
01475
01476 writeAllFacePrimsBinary
01477 (
01478 "tria3",
01479 tris,
01480 nfp.nTris,
01481 patchFaces,
01482 patchPointOffsets,
01483 patchProcessors,
01484 ensightGeometryFile
01485 );
01486
01487 writeAllFacePrimsBinary
01488 (
01489 "quad4",
01490 quads,
01491 nfp.nQuads,
01492 patchFaces,
01493 patchPointOffsets,
01494 patchProcessors,
01495 ensightGeometryFile
01496 );
01497
01498 writeAllFacePrimsBinary
01499 (
01500 "nsided",
01501 polys,
01502 nfp.nPolys,
01503 patchFaces,
01504 patchPointOffsets,
01505 patchProcessors,
01506 ensightGeometryFile
01507 );
01508 }
01509 }
01510 }
01511
01512
01513 if (Pstream::master())
01514 {
01515 delete ensightGeometryFilePtr;
01516 }
01517 }
01518
01519