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 #include <OpenFOAM/argList.H>
00027 #include <OpenFOAM/Time.H>
00028 #include "ensightMesh.H"
00029 #include <finiteVolume/fvMesh.H>
00030 #include <OpenFOAM/globalMeshData.H>
00031 #include <OpenFOAM/PstreamCombineReduceOps.H>
00032 #include <OpenFOAM/processorPolyPatch.H>
00033 #include <OpenFOAM/cellModeller.H>
00034 #include <OpenFOAM/IOmanip.H>
00035 #include "itoa.H"
00036 #include "ensightWriteBinary.H"
00037 #include <fstream>
00038
00039
00040
00041 namespace Foam
00042 {
00043
00044 class concatPatchProcs
00045 {
00046
00047 public:
00048
00049 void operator()
00050 (
00051 List<labelList>& x,
00052 const List<labelList>& y
00053 ) const
00054 {
00055 forAll(y, i)
00056 {
00057 const labelList& yPatches = y[i];
00058
00059 if (yPatches.size())
00060 {
00061 labelList& xPatches = x[i];
00062
00063 label offset = xPatches.size();
00064 xPatches.setSize(offset + yPatches.size());
00065
00066 forAll(yPatches, i)
00067 {
00068 xPatches[i + offset] = yPatches[i];
00069 }
00070 }
00071 }
00072 }
00073 };
00074 }
00075
00076
00077
00078
00079 Foam::ensightMesh::ensightMesh
00080 (
00081 const fvMesh& mesh,
00082 const argList& args,
00083 const bool binary
00084 )
00085 :
00086 mesh_(mesh),
00087 binary_(binary),
00088 patchPartOffset_(2),
00089 meshCellSets_(mesh_.nCells()),
00090 boundaryFaceSets_(mesh_.boundary().size()),
00091 allPatchNames_(0),
00092 allPatchProcs_(0),
00093 patchNames_(0),
00094 nPatchPrims_(0)
00095 {
00096 const cellShapeList& cellShapes = mesh.cellShapes();
00097
00098 const cellModel& tet = *(cellModeller::lookup("tet"));
00099 const cellModel& pyr = *(cellModeller::lookup("pyr"));
00100 const cellModel& prism = *(cellModeller::lookup("prism"));
00101 const cellModel& wedge = *(cellModeller::lookup("wedge"));
00102 const cellModel& hex = *(cellModeller::lookup("hex"));
00103
00104 if (!args.optionFound("noPatches"))
00105 {
00106 allPatchNames_ = wordList::subList
00107 (
00108 mesh_.boundaryMesh().names(), mesh_.boundary().size()
00109 - mesh_.globalData().processorPatches().size()
00110 );
00111
00112 allPatchProcs_.setSize(allPatchNames_.size());
00113
00114 forAll (allPatchProcs_, patchi)
00115 {
00116 if (mesh_.boundary()[patchi].size())
00117 {
00118 allPatchProcs_[patchi].setSize(1);
00119 allPatchProcs_[patchi][0] = Pstream::myProcNo();
00120 }
00121 }
00122
00123 combineReduce(allPatchProcs_, concatPatchProcs());
00124
00125 if (args.optionFound("patches"))
00126 {
00127 wordList patchNameList(args.optionLookup("patches")());
00128
00129 if (patchNameList.empty())
00130 {
00131 patchNameList = allPatchNames_;
00132 }
00133
00134 forAll (patchNameList, i)
00135 {
00136 patchNames_.insert(patchNameList[i]);
00137 }
00138 }
00139 }
00140
00141 if (patchNames_.size())
00142 {
00143
00144 patchPartOffset_ = 1;
00145 }
00146 else
00147 {
00148
00149 labelList& tets = meshCellSets_.tets;
00150 labelList& pyrs = meshCellSets_.pyrs;
00151 labelList& prisms = meshCellSets_.prisms;
00152 labelList& wedges = meshCellSets_.wedges;
00153 labelList& hexes = meshCellSets_.hexes;
00154 labelList& polys = meshCellSets_.polys;
00155
00156 label nTets = 0;
00157 label nPyrs = 0;
00158 label nPrisms = 0;
00159 label nWedges = 0;
00160 label nHexes = 0;
00161 label nPolys = 0;
00162
00163 forAll(cellShapes, cellI)
00164 {
00165 const cellShape& cellShape = cellShapes[cellI];
00166 const cellModel& cellModel = cellShape.model();
00167
00168 if (cellModel == tet)
00169 {
00170 tets[nTets++] = cellI;
00171 }
00172 else if (cellModel == pyr)
00173 {
00174 pyrs[nPyrs++] = cellI;
00175 }
00176 else if (cellModel == prism)
00177 {
00178 prisms[nPrisms++] = cellI;
00179 }
00180 else if (cellModel == wedge)
00181 {
00182 wedges[nWedges++] = cellI;
00183 }
00184 else if (cellModel == hex)
00185 {
00186 hexes[nHexes++] = cellI;
00187 }
00188 else
00189 {
00190 polys[nPolys++] = cellI;
00191 }
00192 }
00193
00194 tets.setSize(nTets);
00195 pyrs.setSize(nPyrs);
00196 prisms.setSize(nPrisms);
00197 wedges.setSize(nWedges);
00198 hexes.setSize(nHexes);
00199 polys.setSize(nPolys);
00200
00201 meshCellSets_.nTets = nTets;
00202 reduce(meshCellSets_.nTets, sumOp<label>());
00203
00204 meshCellSets_.nPyrs = nPyrs;
00205 reduce(meshCellSets_.nPyrs, sumOp<label>());
00206
00207 meshCellSets_.nPrisms = nPrisms;
00208 reduce(meshCellSets_.nPrisms, sumOp<label>());
00209
00210 meshCellSets_.nHexesWedges = nHexes + nWedges;
00211 reduce(meshCellSets_.nHexesWedges, sumOp<label>());
00212
00213 meshCellSets_.nPolys = nPolys;
00214 reduce(meshCellSets_.nPolys, sumOp<label>());
00215 }
00216
00217 if (!args.optionFound("noPatches"))
00218 {
00219 forAll (mesh.boundary(), patchi)
00220 {
00221 if (mesh.boundary()[patchi].size())
00222 {
00223 const polyPatch& p = mesh.boundaryMesh()[patchi];
00224
00225 labelList& tris = boundaryFaceSets_[patchi].tris;
00226 labelList& quads = boundaryFaceSets_[patchi].quads;
00227 labelList& polys = boundaryFaceSets_[patchi].polys;
00228
00229 tris.setSize(p.size());
00230 quads.setSize(p.size());
00231 polys.setSize(p.size());
00232
00233 label nTris = 0;
00234 label nQuads = 0;
00235 label nPolys = 0;
00236
00237 forAll(p, faceI)
00238 {
00239 const face& f = p[faceI];
00240
00241 if (f.size() == 3)
00242 {
00243 tris[nTris++] = faceI;
00244 }
00245 else if (f.size() == 4)
00246 {
00247 quads[nQuads++] = faceI;
00248 }
00249 else
00250 {
00251 polys[nPolys++] = faceI;
00252 }
00253 }
00254
00255 tris.setSize(nTris);
00256 quads.setSize(nQuads);
00257 polys.setSize(nPolys);
00258 }
00259 }
00260 }
00261
00262
00263 forAll(allPatchNames_, patchi)
00264 {
00265 const word& patchName = allPatchNames_[patchi];
00266 nFacePrimitives nfp;
00267
00268 if (patchNames_.empty() || patchNames_.found(patchName))
00269 {
00270 if (mesh.boundary()[patchi].size())
00271 {
00272 nfp.nPoints = mesh.boundaryMesh()[patchi].localPoints().size();
00273 nfp.nTris = boundaryFaceSets_[patchi].tris.size();
00274 nfp.nQuads = boundaryFaceSets_[patchi].quads.size();
00275 nfp.nPolys = boundaryFaceSets_[patchi].polys.size();
00276 }
00277 }
00278
00279 reduce(nfp.nPoints, sumOp<label>());
00280 reduce(nfp.nTris, sumOp<label>());
00281 reduce(nfp.nQuads, sumOp<label>());
00282 reduce(nfp.nPolys, sumOp<label>());
00283
00284 nPatchPrims_.insert(patchName, nfp);
00285 }
00286 }
00287
00288
00289
00290
00291 Foam::ensightMesh::~ensightMesh()
00292 {}
00293
00294
00295
00296
00297 void Foam::ensightMesh::writePoints
00298 (
00299 const scalarField& pointsComponent,
00300 OFstream& ensightGeometryFile
00301 ) const
00302 {
00303 forAll(pointsComponent, pointI)
00304 {
00305 ensightGeometryFile<< setw(12) << float(pointsComponent[pointI]) << nl;
00306 }
00307 }
00308
00309
00310 Foam::cellShapeList Foam::ensightMesh::map
00311 (
00312 const cellShapeList& cellShapes,
00313 const labelList& prims
00314 ) const
00315 {
00316 cellShapeList mcsl(prims.size());
00317
00318 forAll(prims, i)
00319 {
00320 mcsl[i] = cellShapes[prims[i]];
00321 }
00322
00323 return mcsl;
00324 }
00325
00326
00327 Foam::cellShapeList Foam::ensightMesh::map
00328 (
00329 const cellShapeList& cellShapes,
00330 const labelList& hexes,
00331 const labelList& wedges
00332 ) const
00333 {
00334 cellShapeList mcsl(hexes.size() + wedges.size());
00335
00336 forAll(hexes, i)
00337 {
00338 mcsl[i] = cellShapes[hexes[i]];
00339 }
00340
00341 label offset = hexes.size();
00342
00343 const cellModel& hex = *(cellModeller::lookup("hex"));
00344 labelList hexLabels(8);
00345
00346 forAll(wedges, i)
00347 {
00348 const cellShape& cellPoints = cellShapes[wedges[i]];
00349
00350 hexLabels[0] = cellPoints[0];
00351 hexLabels[1] = cellPoints[1];
00352 hexLabels[2] = cellPoints[0];
00353 hexLabels[3] = cellPoints[2];
00354 hexLabels[4] = cellPoints[3];
00355 hexLabels[5] = cellPoints[4];
00356 hexLabels[6] = cellPoints[6];
00357 hexLabels[7] = cellPoints[5];
00358
00359 mcsl[i + offset] = cellShape(hex, hexLabels);
00360 }
00361
00362 return mcsl;
00363 }
00364
00365
00366 void Foam::ensightMesh::writePrims
00367 (
00368 const cellShapeList& cellShapes,
00369 const label pointOffset,
00370 OFstream& ensightGeometryFile
00371 ) const
00372 {
00373 label po = pointOffset + 1;
00374
00375 forAll(cellShapes, i)
00376 {
00377 const cellShape& cellPoints = cellShapes[i];
00378
00379 forAll(cellPoints, pointI)
00380 {
00381 ensightGeometryFile<< setw(10) << cellPoints[pointI] + po;
00382 }
00383 ensightGeometryFile << nl;
00384 }
00385 }
00386
00387
00388 void Foam::ensightMesh::writePrimsBinary
00389 (
00390 const cellShapeList& cellShapes,
00391 const label pointOffset,
00392 std::ofstream& ensightGeometryFile
00393 ) const
00394 {
00395 label po = pointOffset + 1;
00396
00397
00398 int numElem;
00399
00400 numElem = cellShapes.size();
00401
00402 if (cellShapes.size())
00403 {
00404
00405 int numIntElem = cellShapes.size()*cellShapes[0].size();
00406 List<int> temp(numIntElem);
00407
00408 int n = 0;
00409
00410 forAll(cellShapes, i)
00411 {
00412 const cellShape& cellPoints = cellShapes[i];
00413
00414 forAll(cellPoints, pointI)
00415 {
00416 temp[n] = cellPoints[pointI] + po;
00417 n++;
00418 }
00419 }
00420
00421 ensightGeometryFile.write
00422 (
00423 reinterpret_cast<char*>(temp.begin()),
00424 numIntElem*sizeof(int)
00425 );
00426 }
00427 }
00428
00429
00430 void Foam::ensightMesh::writePolysNFaces
00431 (
00432 const labelList& polys,
00433 const cellList& cellFaces,
00434 OFstream& ensightGeometryFile
00435 ) const
00436 {
00437 forAll(polys, i)
00438 {
00439 ensightGeometryFile
00440 << setw(10) << cellFaces[polys[i]].size() << nl;
00441 }
00442 }
00443
00444
00445 void Foam::ensightMesh::writePolysNPointsPerFace
00446 (
00447 const labelList& polys,
00448 const cellList& cellFaces,
00449 const faceList& faces,
00450 OFstream& ensightGeometryFile
00451 ) const
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
00465
00466 void Foam::ensightMesh::writePolysPoints
00467 (
00468 const labelList& polys,
00469 const cellList& cellFaces,
00470 const faceList& faces,
00471 const label pointOffset,
00472 OFstream& ensightGeometryFile
00473 ) const
00474 {
00475 label po = pointOffset + 1;
00476
00477 forAll(polys, i)
00478 {
00479 const labelList& cf = cellFaces[polys[i]];
00480
00481 forAll(cf, faceI)
00482 {
00483 const face& f = faces[cf[faceI]];
00484
00485 forAll(f, pointI)
00486 {
00487 ensightGeometryFile << setw(10) << f[pointI] + po;
00488 }
00489 ensightGeometryFile << nl;
00490 }
00491 }
00492 }
00493
00494
00495 void Foam::ensightMesh::writeAllPolys
00496 (
00497 const labelList& pointOffsets,
00498 OFstream& ensightGeometryFile
00499 ) const
00500 {
00501 if (meshCellSets_.nPolys)
00502 {
00503 const cellList& cellFaces = mesh_.cells();
00504 const faceList& faces = mesh_.faces();
00505
00506 if (Pstream::master())
00507 {
00508 ensightGeometryFile
00509 << "nfaced" << nl << setw(10) << meshCellSets_.nPolys << nl;
00510 }
00511
00512
00513 if (Pstream::master())
00514 {
00515
00516 writePolysNFaces
00517 (
00518 meshCellSets_.polys,
00519 cellFaces,
00520 ensightGeometryFile
00521 );
00522
00523 for (int slave=1; slave<Pstream::nProcs(); slave++)
00524 {
00525 IPstream fromSlave(Pstream::scheduled, slave);
00526 labelList polys(fromSlave);
00527 cellList cellFaces(fromSlave);
00528
00529 writePolysNFaces
00530 (
00531 polys,
00532 cellFaces,
00533 ensightGeometryFile
00534 );
00535 }
00536 }
00537 else
00538 {
00539 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00540 toMaster<< meshCellSets_.polys << cellFaces;
00541 }
00542
00543
00544 if (Pstream::master())
00545 {
00546
00547 writePolysNPointsPerFace
00548 (
00549 meshCellSets_.polys,
00550 cellFaces,
00551 faces,
00552 ensightGeometryFile
00553 );
00554
00555 for (int slave=1; slave<Pstream::nProcs(); slave++)
00556 {
00557 IPstream fromSlave(Pstream::scheduled, slave);
00558 labelList polys(fromSlave);
00559 cellList cellFaces(fromSlave);
00560 faceList faces(fromSlave);
00561
00562 writePolysNPointsPerFace
00563 (
00564 polys,
00565 cellFaces,
00566 faces,
00567 ensightGeometryFile
00568 );
00569 }
00570 }
00571 else
00572 {
00573 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00574 toMaster<< meshCellSets_.polys << cellFaces << faces;
00575 }
00576
00577
00578 if (Pstream::master())
00579 {
00580
00581 writePolysPoints
00582 (
00583 meshCellSets_.polys,
00584 cellFaces,
00585 faces,
00586 0,
00587 ensightGeometryFile
00588 );
00589
00590 for (int slave=1; slave<Pstream::nProcs(); slave++)
00591 {
00592 IPstream fromSlave(Pstream::scheduled, slave);
00593 labelList polys(fromSlave);
00594 cellList cellFaces(fromSlave);
00595 faceList faces(fromSlave);
00596
00597 writePolysPoints
00598 (
00599 polys,
00600 cellFaces,
00601 faces,
00602 pointOffsets[slave-1],
00603 ensightGeometryFile
00604 );
00605 }
00606 }
00607 else
00608 {
00609 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00610 toMaster<< meshCellSets_.polys << cellFaces << faces;
00611 }
00612 }
00613 }
00614
00615
00616 void Foam::ensightMesh::writePolysNFacesBinary
00617 (
00618 const labelList& polys,
00619 const cellList& cellFaces,
00620 std::ofstream& ensightGeometryFile
00621 ) const
00622 {
00623 forAll(polys, i)
00624 {
00625 writeEnsDataBinary
00626 (
00627 cellFaces[polys[i]].size(),
00628 ensightGeometryFile
00629 );
00630 }
00631 }
00632
00633
00634 void Foam::ensightMesh::writePolysNPointsPerFaceBinary
00635 (
00636 const labelList& polys,
00637 const cellList& cellFaces,
00638 const faceList& faces,
00639 std::ofstream& ensightGeometryFile
00640 ) const
00641 {
00642 forAll(polys, i)
00643 {
00644 const labelList& cf = cellFaces[polys[i]];
00645
00646 forAll(cf, faceI)
00647 {
00648 writeEnsDataBinary
00649 (
00650 faces[cf[faceI]].size(),
00651 ensightGeometryFile
00652 );
00653 }
00654 }
00655 }
00656
00657
00658 void Foam::ensightMesh::writePolysPointsBinary
00659 (
00660 const labelList& polys,
00661 const cellList& cellFaces,
00662 const faceList& faces,
00663 const label pointOffset,
00664 std::ofstream& ensightGeometryFile
00665 ) const
00666 {
00667 label po = pointOffset + 1;
00668
00669 forAll(polys, i)
00670 {
00671 const labelList& cf = cellFaces[polys[i]];
00672
00673 forAll(cf, faceI)
00674 {
00675 const face& f = faces[cf[faceI]];
00676
00677 forAll(f, pointI)
00678 {
00679 writeEnsDataBinary(f[pointI] + po,ensightGeometryFile);
00680 }
00681 }
00682 }
00683 }
00684
00685
00686 void Foam::ensightMesh::writeAllPolysBinary
00687 (
00688 const labelList& pointOffsets,
00689 std::ofstream& ensightGeometryFile
00690 ) const
00691 {
00692 if (meshCellSets_.nPolys)
00693 {
00694 const cellList& cellFaces = mesh_.cells();
00695 const faceList& faces = mesh_.faces();
00696
00697 if (Pstream::master())
00698 {
00699 writeEnsDataBinary("nfaced",ensightGeometryFile);
00700 writeEnsDataBinary(meshCellSets_.nPolys,ensightGeometryFile);
00701 }
00702
00703
00704 if (Pstream::master())
00705 {
00706
00707 writePolysNFacesBinary
00708 (
00709 meshCellSets_.polys,
00710 cellFaces,
00711 ensightGeometryFile
00712 );
00713
00714 for (int slave=1; slave<Pstream::nProcs(); slave++)
00715 {
00716 IPstream fromSlave(Pstream::scheduled, slave);
00717 labelList polys(fromSlave);
00718 cellList cellFaces(fromSlave);
00719
00720 writePolysNFacesBinary
00721 (
00722 polys,
00723 cellFaces,
00724 ensightGeometryFile
00725 );
00726 }
00727 }
00728 else
00729 {
00730 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00731 toMaster<< meshCellSets_.polys << cellFaces;
00732 }
00733
00734
00735 if (Pstream::master())
00736 {
00737
00738 writePolysNPointsPerFaceBinary
00739 (
00740 meshCellSets_.polys,
00741 cellFaces,
00742 faces,
00743 ensightGeometryFile
00744 );
00745
00746 for (int slave=1; slave<Pstream::nProcs(); slave++)
00747 {
00748 IPstream fromSlave(Pstream::scheduled, slave);
00749 labelList polys(fromSlave);
00750 cellList cellFaces(fromSlave);
00751 faceList faces(fromSlave);
00752
00753 writePolysNPointsPerFaceBinary
00754 (
00755 polys,
00756 cellFaces,
00757 faces,
00758 ensightGeometryFile
00759 );
00760 }
00761 }
00762 else
00763 {
00764 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00765 toMaster<< meshCellSets_.polys << cellFaces << faces;
00766 }
00767
00768
00769 if (Pstream::master())
00770 {
00771
00772 writePolysPointsBinary
00773 (
00774 meshCellSets_.polys,
00775 cellFaces,
00776 faces,
00777 0,
00778 ensightGeometryFile
00779 );
00780
00781 for (int slave=1; slave<Pstream::nProcs(); slave++)
00782 {
00783 IPstream fromSlave(Pstream::scheduled, slave);
00784 labelList polys(fromSlave);
00785 cellList cellFaces(fromSlave);
00786 faceList faces(fromSlave);
00787
00788 writePolysPointsBinary
00789 (
00790 polys,
00791 cellFaces,
00792 faces,
00793 pointOffsets[slave-1],
00794 ensightGeometryFile
00795 );
00796 }
00797 }
00798 else
00799 {
00800 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00801 toMaster<< meshCellSets_.polys << cellFaces << faces;
00802 }
00803 }
00804 }
00805
00806
00807 void Foam::ensightMesh::writeAllPrims
00808 (
00809 const char* key,
00810 const label nPrims,
00811 const cellShapeList& cellShapes,
00812 const labelList& pointOffsets,
00813 OFstream& ensightGeometryFile
00814 ) const
00815 {
00816 if (nPrims)
00817 {
00818 if (Pstream::master())
00819 {
00820 ensightGeometryFile << key << nl << setw(10) << nPrims << nl;
00821
00822 writePrims(cellShapes, 0, ensightGeometryFile);
00823
00824 for (int slave=1; slave<Pstream::nProcs(); slave++)
00825 {
00826 IPstream fromSlave(Pstream::scheduled, slave);
00827 cellShapeList cellShapes(fromSlave);
00828
00829 writePrims
00830 (
00831 cellShapes,
00832 pointOffsets[slave-1],
00833 ensightGeometryFile
00834 );
00835 }
00836 }
00837 else
00838 {
00839 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00840 toMaster<< cellShapes;
00841 }
00842 }
00843 }
00844
00845
00846 void Foam::ensightMesh::writeAllPrimsBinary
00847 (
00848 const char* key,
00849 const label nPrims,
00850 const cellShapeList& cellShapes,
00851 const labelList& pointOffsets,
00852 std::ofstream& ensightGeometryFile
00853 ) const
00854 {
00855 if (nPrims)
00856 {
00857 if (Pstream::master())
00858 {
00859 writeEnsDataBinary(key,ensightGeometryFile);
00860 writeEnsDataBinary(nPrims,ensightGeometryFile);
00861
00862 writePrimsBinary(cellShapes, 0, ensightGeometryFile);
00863
00864 for (int slave=1; slave<Pstream::nProcs(); slave++)
00865 {
00866 IPstream fromSlave(Pstream::scheduled, slave);
00867 cellShapeList cellShapes(fromSlave);
00868
00869 writePrimsBinary
00870 (
00871 cellShapes,
00872 pointOffsets[slave-1],
00873 ensightGeometryFile
00874 );
00875 }
00876 }
00877 else
00878 {
00879 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
00880 toMaster<< cellShapes;
00881 }
00882 }
00883 }
00884
00885
00886 void Foam::ensightMesh::writeFacePrims
00887 (
00888 const faceList& patchFaces,
00889 const label pointOffset,
00890 OFstream& ensightGeometryFile
00891 ) const
00892 {
00893 if (patchFaces.size())
00894 {
00895 label po = pointOffset + 1;
00896
00897 forAll(patchFaces, i)
00898 {
00899 const face& patchFace = patchFaces[i];
00900
00901 forAll(patchFace, pointI)
00902 {
00903 ensightGeometryFile << setw(10) << patchFace[pointI] + po;
00904 }
00905 ensightGeometryFile << nl;
00906 }
00907 }
00908 }
00909
00910
00911 void Foam::ensightMesh::writeFacePrimsBinary
00912 (
00913 const faceList& patchFaces,
00914 const label pointOffset,
00915 std::ofstream& ensightGeometryFile
00916 ) const
00917 {
00918 if (patchFaces.size())
00919 {
00920 label po = pointOffset + 1;
00921
00922 forAll(patchFaces, i)
00923 {
00924 const face& patchFace = patchFaces[i];
00925
00926 forAll(patchFace, pointI)
00927 {
00928 writeEnsDataBinary
00929 (
00930 patchFace[pointI] + po,
00931 ensightGeometryFile
00932 );
00933 }
00934 }
00935 }
00936 }
00937
00938
00939 Foam::faceList Foam::ensightMesh::map
00940 (
00941 const faceList& patchFaces,
00942 const labelList& prims
00943 ) const
00944 {
00945 faceList ppf(prims.size());
00946
00947 forAll (prims, i)
00948 {
00949 ppf[i] = patchFaces[prims[i]];
00950 }
00951
00952 return ppf;
00953 }
00954
00955
00956 void Foam::ensightMesh::writeAllFacePrims
00957 (
00958 const char* key,
00959 const labelList& prims,
00960 const label nPrims,
00961 const faceList& patchFaces,
00962 const labelList& pointOffsets,
00963 const labelList& patchProcessors,
00964 OFstream& ensightGeometryFile
00965 ) const
00966 {
00967 if (nPrims)
00968 {
00969 if (Pstream::master())
00970 {
00971 ensightGeometryFile << key << nl << setw(10) << nPrims << nl;
00972
00973 if (&prims != NULL)
00974 {
00975 writeFacePrims
00976 (
00977 map(patchFaces, prims),
00978 0,
00979 ensightGeometryFile
00980 );
00981 }
00982
00983 forAll (patchProcessors, i)
00984 {
00985 if (patchProcessors[i] != 0)
00986 {
00987 label slave = patchProcessors[i];
00988 IPstream fromSlave(Pstream::scheduled, slave);
00989 faceList patchFaces(fromSlave);
00990
00991 writeFacePrims
00992 (
00993 patchFaces,
00994 pointOffsets[i],
00995 ensightGeometryFile
00996 );
00997 }
00998 }
00999 }
01000 else if (&prims != NULL)
01001 {
01002 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01003 toMaster<< map(patchFaces, prims);
01004 }
01005 }
01006 }
01007
01008
01009 void Foam::ensightMesh::writeNSidedNPointsPerFace
01010 (
01011 const faceList& patchFaces,
01012 OFstream& ensightGeometryFile
01013 ) const
01014 {
01015 forAll(patchFaces, i)
01016 {
01017 ensightGeometryFile
01018 << setw(10) << patchFaces[i].size() << nl;
01019 }
01020 }
01021
01022
01023 void Foam::ensightMesh::writeNSidedPoints
01024 (
01025 const faceList& patchFaces,
01026 const label pointOffset,
01027 OFstream& ensightGeometryFile
01028 ) const
01029 {
01030 writeFacePrims
01031 (
01032 patchFaces,
01033 pointOffset,
01034 ensightGeometryFile
01035 );
01036 }
01037
01038
01039 void Foam::ensightMesh::writeAllNSided
01040 (
01041 const labelList& prims,
01042 const label nPrims,
01043 const faceList& patchFaces,
01044 const labelList& pointOffsets,
01045 const labelList& patchProcessors,
01046 OFstream& ensightGeometryFile
01047 ) const
01048 {
01049 if (nPrims)
01050 {
01051 if (Pstream::master())
01052 {
01053 ensightGeometryFile
01054 << "nsided" << nl << setw(10) << nPrims << nl;
01055 }
01056
01057
01058 if (Pstream::master())
01059 {
01060 if (&prims != NULL)
01061 {
01062 writeNSidedNPointsPerFace
01063 (
01064 map(patchFaces, prims),
01065 ensightGeometryFile
01066 );
01067 }
01068
01069 forAll (patchProcessors, i)
01070 {
01071 if (patchProcessors[i] != 0)
01072 {
01073 label slave = patchProcessors[i];
01074 IPstream fromSlave(Pstream::scheduled, slave);
01075 faceList patchFaces(fromSlave);
01076
01077 writeNSidedNPointsPerFace
01078 (
01079 patchFaces,
01080 ensightGeometryFile
01081 );
01082 }
01083 }
01084 }
01085 else if (&prims != NULL)
01086 {
01087 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01088 toMaster<< map(patchFaces, prims);
01089 }
01090
01091
01092 if (Pstream::master())
01093 {
01094 if (&prims != NULL)
01095 {
01096 writeNSidedPoints
01097 (
01098 map(patchFaces, prims),
01099 0,
01100 ensightGeometryFile
01101 );
01102 }
01103
01104 forAll (patchProcessors, i)
01105 {
01106 if (patchProcessors[i] != 0)
01107 {
01108 label slave = patchProcessors[i];
01109 IPstream fromSlave(Pstream::scheduled, slave);
01110 faceList patchFaces(fromSlave);
01111
01112 writeNSidedPoints
01113 (
01114 patchFaces,
01115 pointOffsets[i],
01116 ensightGeometryFile
01117 );
01118 }
01119 }
01120 }
01121 else if (&prims != NULL)
01122 {
01123 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01124 toMaster<< map(patchFaces, prims);
01125 }
01126 }
01127 }
01128
01129
01130 void Foam::ensightMesh::writeNSidedPointsBinary
01131 (
01132 const faceList& patchFaces,
01133 const label pointOffset,
01134 std::ofstream& ensightGeometryFile
01135 ) const
01136 {
01137 writeFacePrimsBinary
01138 (
01139 patchFaces,
01140 pointOffset,
01141 ensightGeometryFile
01142 );
01143 }
01144
01145
01146 void Foam::ensightMesh::writeNSidedNPointsPerFaceBinary
01147 (
01148 const faceList& patchFaces,
01149 std::ofstream& ensightGeometryFile
01150 ) const
01151 {
01152 forAll(patchFaces, i)
01153 {
01154 writeEnsDataBinary
01155 (
01156 patchFaces[i].size(),
01157 ensightGeometryFile
01158 );
01159 }
01160 }
01161
01162
01163 void Foam::ensightMesh::writeAllNSidedBinary
01164 (
01165 const labelList& prims,
01166 const label nPrims,
01167 const faceList& patchFaces,
01168 const labelList& pointOffsets,
01169 const labelList& patchProcessors,
01170 std::ofstream& ensightGeometryFile
01171 ) const
01172 {
01173 if (nPrims)
01174 {
01175 if (Pstream::master())
01176 {
01177 writeEnsDataBinary("nsided",ensightGeometryFile);
01178 writeEnsDataBinary(nPrims,ensightGeometryFile);
01179 }
01180
01181
01182 if (Pstream::master())
01183 {
01184 if (&prims != NULL)
01185 {
01186 writeNSidedNPointsPerFaceBinary
01187 (
01188 map(patchFaces, prims),
01189 ensightGeometryFile
01190 );
01191 }
01192
01193 forAll (patchProcessors, i)
01194 {
01195 if (patchProcessors[i] != 0)
01196 {
01197 label slave = patchProcessors[i];
01198 IPstream fromSlave(Pstream::scheduled, slave);
01199 faceList patchFaces(fromSlave);
01200
01201 writeNSidedNPointsPerFaceBinary
01202 (
01203 patchFaces,
01204 ensightGeometryFile
01205 );
01206 }
01207 }
01208 }
01209 else if (&prims != NULL)
01210 {
01211 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01212 toMaster<< map(patchFaces, prims);
01213 }
01214
01215
01216 if (Pstream::master())
01217 {
01218 if (&prims != NULL)
01219 {
01220 writeNSidedPointsBinary
01221 (
01222 map(patchFaces, prims),
01223 0,
01224 ensightGeometryFile
01225 );
01226 }
01227
01228 forAll (patchProcessors, i)
01229 {
01230 if (patchProcessors[i] != 0)
01231 {
01232 label slave = patchProcessors[i];
01233 IPstream fromSlave(Pstream::scheduled, slave);
01234 faceList patchFaces(fromSlave);
01235
01236 writeNSidedPointsBinary
01237 (
01238 patchFaces,
01239 pointOffsets[i],
01240 ensightGeometryFile
01241 );
01242 }
01243 }
01244 }
01245 else if (&prims != NULL)
01246 {
01247 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01248 toMaster<< map(patchFaces, prims);
01249 }
01250 }
01251 }
01252
01253
01254 void Foam::ensightMesh::writeAllFacePrimsBinary
01255 (
01256 const char* key,
01257 const labelList& prims,
01258 const label nPrims,
01259 const faceList& patchFaces,
01260 const labelList& pointOffsets,
01261 const labelList& patchProcessors,
01262 std::ofstream& ensightGeometryFile
01263 ) const
01264 {
01265 if (nPrims)
01266 {
01267 if (Pstream::master())
01268 {
01269 writeEnsDataBinary(key,ensightGeometryFile);
01270 writeEnsDataBinary(nPrims,ensightGeometryFile);
01271
01272 if (&prims != NULL)
01273 {
01274 writeFacePrimsBinary
01275 (
01276 map(patchFaces, prims),
01277 0,
01278 ensightGeometryFile
01279 );
01280 }
01281
01282 forAll (patchProcessors, i)
01283 {
01284 if (patchProcessors[i] != 0)
01285 {
01286 label slave = patchProcessors[i];
01287 IPstream fromSlave(Pstream::scheduled, slave);
01288 faceList patchFaces(fromSlave);
01289
01290 writeFacePrimsBinary
01291 (
01292 patchFaces,
01293 pointOffsets[i],
01294 ensightGeometryFile
01295 );
01296 }
01297 }
01298 }
01299 else if (&prims != NULL)
01300 {
01301 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01302 toMaster<< map(patchFaces, prims);
01303 }
01304 }
01305 }
01306
01307
01308 void Foam::ensightMesh::write
01309 (
01310 const fileName& postProcPath,
01311 const word& prepend,
01312 const label timeIndex,
01313 Ostream& ensightCaseFile
01314 ) const
01315 {
01316 if (binary_)
01317 {
01318 writeBinary(postProcPath, prepend, timeIndex, ensightCaseFile);
01319 }
01320 else
01321 {
01322 writeAscii(postProcPath, prepend, timeIndex, ensightCaseFile);
01323 }
01324 }
01325
01326
01327 void Foam::ensightMesh::writeAscii
01328 (
01329 const fileName& postProcPath,
01330 const word& prepend,
01331 const label timeIndex,
01332 Ostream& ensightCaseFile
01333 ) const
01334 {
01335 const Time& runTime = mesh_.time();
01336 const pointField& points = mesh_.points();
01337 const cellShapeList& cellShapes = mesh_.cellShapes();
01338
01339 word timeFile = prepend;
01340
01341 if (timeIndex == 0)
01342 {
01343 timeFile += "000.";
01344 }
01345 else if (mesh_.moving())
01346 {
01347 timeFile += itoa(timeIndex) + '.';
01348 }
01349
01350
01351 fileName ensightGeometryFileName = timeFile + "mesh";
01352
01353 OFstream *ensightGeometryFilePtr = NULL;
01354 if (Pstream::master())
01355 {
01356 ensightGeometryFilePtr = new OFstream
01357 (
01358 postProcPath/ensightGeometryFileName,
01359 runTime.writeFormat(),
01360 runTime.writeVersion(),
01361 IOstream::UNCOMPRESSED
01362 );
01363 }
01364
01365 OFstream& ensightGeometryFile = *ensightGeometryFilePtr;
01366
01367 if (Pstream::master())
01368 {
01369
01370 ensightGeometryFile.setf
01371 (
01372 ios_base::scientific,
01373 ios_base::floatfield
01374 );
01375 ensightGeometryFile.precision(5);
01376
01377 ensightGeometryFile
01378 << "EnSight Geometry File" << nl
01379 << "written from OpenFOAM-" << Foam::FOAMfullVersion << nl
01380 << "node id assign" << nl
01381 << "element id assign" << nl;
01382 }
01383
01384 labelList pointOffsets(Pstream::nProcs(), 0);
01385
01386 if (patchNames_.empty())
01387 {
01388 label nPoints = points.size();
01389 Pstream::gather(nPoints, sumOp<label>());
01390
01391 if (Pstream::master())
01392 {
01393 ensightGeometryFile
01394 << "part" << nl
01395 << setw(10) << 1 << nl
01396 << "internalMesh" << nl
01397 << "coordinates" << nl
01398 << setw(10) << nPoints
01399 << endl;
01400
01401 for (direction d=0; d<vector::nComponents; d++)
01402 {
01403 writePoints(points.component(d), ensightGeometryFile);
01404 pointOffsets[0] = points.size();
01405
01406 for (int slave=1; slave<Pstream::nProcs(); slave++)
01407 {
01408 IPstream fromSlave(Pstream::scheduled, slave);
01409 scalarField pointsComponent(fromSlave);
01410 writePoints(pointsComponent, ensightGeometryFile);
01411 pointOffsets[slave] =
01412 pointOffsets[slave-1]
01413 + pointsComponent.size();
01414 }
01415 }
01416 }
01417 else
01418 {
01419 for (direction d=0; d<vector::nComponents; d++)
01420 {
01421 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01422 toMaster<< points.component(d);
01423 }
01424 }
01425
01426 writeAllPrims
01427 (
01428 "hexa8",
01429 meshCellSets_.nHexesWedges,
01430 map(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
01431 pointOffsets,
01432 ensightGeometryFile
01433 );
01434
01435 writeAllPrims
01436 (
01437 "penta6",
01438 meshCellSets_.nPrisms,
01439 map(cellShapes, meshCellSets_.prisms),
01440 pointOffsets,
01441 ensightGeometryFile
01442 );
01443
01444 writeAllPrims
01445 (
01446 "pyramid5",
01447 meshCellSets_.nPyrs,
01448 map(cellShapes, meshCellSets_.pyrs),
01449 pointOffsets,
01450 ensightGeometryFile
01451 );
01452
01453 writeAllPrims
01454 (
01455 "tetra4",
01456 meshCellSets_.nTets,
01457 map(cellShapes, meshCellSets_.tets),
01458 pointOffsets,
01459 ensightGeometryFile
01460 );
01461
01462 writeAllPolys
01463 (
01464 pointOffsets,
01465 ensightGeometryFile
01466 );
01467 }
01468
01469
01470 label ensightPatchI = patchPartOffset_;
01471
01472 forAll(allPatchNames_, patchi)
01473 {
01474 const word& patchName = allPatchNames_[patchi];
01475 const labelList& patchProcessors = allPatchProcs_[patchi];
01476
01477 if (patchNames_.empty() || patchNames_.found(patchName))
01478 {
01479 const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
01480
01481 const labelList *trisPtr = NULL;
01482 const labelList *quadsPtr = NULL;
01483 const labelList *polysPtr = NULL;
01484
01485 const pointField *patchPointsPtr = NULL;
01486 const faceList *patchFacesPtr = NULL;
01487
01488 if (mesh_.boundary()[patchi].size())
01489 {
01490 const polyPatch& p = mesh_.boundaryMesh()[patchi];
01491
01492 trisPtr = &boundaryFaceSets_[patchi].tris;
01493 quadsPtr = &boundaryFaceSets_[patchi].quads;
01494 polysPtr = &boundaryFaceSets_[patchi].polys;
01495
01496 patchPointsPtr = &(p.localPoints());
01497 patchFacesPtr = &(p.localFaces());
01498 }
01499
01500 const labelList& tris = *trisPtr;
01501 const labelList& quads = *quadsPtr;
01502 const labelList& polys = *polysPtr;
01503 const pointField& patchPoints = *patchPointsPtr;
01504 const faceList& patchFaces = *patchFacesPtr;
01505
01506 if (nfp.nTris || nfp.nQuads || nfp.nPolys)
01507 {
01508 labelList patchPointOffsets(Pstream::nProcs(), 0);
01509
01510 if (Pstream::master())
01511 {
01512 ensightGeometryFile
01513 << "part" << nl
01514 << setw(10) << ensightPatchI++ << nl
01515 << patchName << nl
01516 << "coordinates" << nl
01517 << setw(10) << nfp.nPoints
01518 << endl;
01519
01520 for (direction d=0; d<vector::nComponents; d++)
01521 {
01522 if (patchPointsPtr)
01523 {
01524 writePoints
01525 (
01526 patchPoints.component(d),
01527 ensightGeometryFile
01528 );
01529 }
01530
01531 patchPointOffsets = 0;
01532
01533 forAll (patchProcessors, i)
01534 {
01535 if (patchProcessors[i] != 0)
01536 {
01537 label slave = patchProcessors[i];
01538 IPstream fromSlave(Pstream::scheduled, slave);
01539 scalarField patchPointsComponent(fromSlave);
01540
01541 writePoints
01542 (
01543 patchPointsComponent,
01544 ensightGeometryFile
01545 );
01546
01547 if (i < Pstream::nProcs()-1)
01548 {
01549 patchPointOffsets[i+1] =
01550 patchPointOffsets[i]
01551 + patchPointsComponent.size();
01552 }
01553 }
01554 else
01555 {
01556 if (i < Pstream::nProcs()-1)
01557 {
01558 patchPointOffsets[i+1] =
01559 patchPointOffsets[i]
01560 + patchPoints.size();
01561 }
01562 }
01563 }
01564 }
01565 }
01566 else if (patchPointsPtr)
01567 {
01568 for (direction d=0; d<vector::nComponents; d++)
01569 {
01570 OPstream toMaster
01571 (
01572 Pstream::scheduled,
01573 Pstream::masterNo()
01574 );
01575 toMaster<< patchPoints.component(d);
01576 }
01577 }
01578
01579 writeAllFacePrims
01580 (
01581 "tria3",
01582 tris,
01583 nfp.nTris,
01584 patchFaces,
01585 patchPointOffsets,
01586 patchProcessors,
01587 ensightGeometryFile
01588 );
01589
01590 writeAllFacePrims
01591 (
01592 "quad4",
01593 quads,
01594 nfp.nQuads,
01595 patchFaces,
01596 patchPointOffsets,
01597 patchProcessors,
01598 ensightGeometryFile
01599 );
01600
01601 writeAllNSided
01602 (
01603 polys,
01604 nfp.nPolys,
01605 patchFaces,
01606 patchPointOffsets,
01607 patchProcessors,
01608 ensightGeometryFile
01609 );
01610 }
01611 }
01612 }
01613
01614 if (Pstream::master())
01615 {
01616 delete ensightGeometryFilePtr;
01617 }
01618 }
01619
01620
01621 void Foam::ensightMesh::writeBinary
01622 (
01623 const fileName& postProcPath,
01624 const word& prepend,
01625 const label timeIndex,
01626 Ostream& ensightCaseFile
01627 ) const
01628 {
01629
01630 const pointField& points = mesh_.points();
01631 const cellShapeList& cellShapes = mesh_.cellShapes();
01632
01633 word timeFile = prepend;
01634
01635 if (timeIndex == 0)
01636 {
01637 timeFile += "000.";
01638 }
01639 else if (mesh_.moving())
01640 {
01641 timeFile += itoa(timeIndex) + '.';
01642 }
01643
01644
01645 fileName ensightGeometryFileName = timeFile + "mesh";
01646
01647 std::ofstream *ensightGeometryFilePtr = NULL;
01648
01649 if (Pstream::master())
01650 {
01651 ensightGeometryFilePtr = new std::ofstream
01652 (
01653 (postProcPath/ensightGeometryFileName).c_str(),
01654 ios_base::out | ios_base::binary | ios_base::trunc
01655 );
01656
01657 }
01658
01659 std::ofstream& ensightGeometryFile = *ensightGeometryFilePtr;
01660
01661 if (Pstream::master())
01662 {
01663 writeEnsDataBinary("C binary", ensightGeometryFile);
01664 writeEnsDataBinary("EnSight Geometry File", ensightGeometryFile);
01665 writeEnsDataBinary("written from OpenFOAM", ensightGeometryFile);
01666 writeEnsDataBinary("node id assign", ensightGeometryFile);
01667 writeEnsDataBinary("element id assign", ensightGeometryFile);
01668 }
01669
01670 labelList pointOffsets(Pstream::nProcs(), 0);
01671
01672 if (patchNames_.empty())
01673 {
01674 label nPoints = points.size();
01675 Pstream::gather(nPoints, sumOp<label>());
01676
01677 if (Pstream::master())
01678 {
01679 writeEnsDataBinary("part",ensightGeometryFile);
01680 writeEnsDataBinary(1,ensightGeometryFile);
01681 writeEnsDataBinary("internalMesh",ensightGeometryFile);
01682 writeEnsDataBinary("coordinates",ensightGeometryFile);
01683 writeEnsDataBinary(nPoints,ensightGeometryFile);
01684
01685 for (direction d=0; d<vector::nComponents; d++)
01686 {
01687
01688 writeEnsDataBinary(points.component(d), ensightGeometryFile);
01689 pointOffsets[0] = points.size();
01690
01691 for (int slave=1; slave<Pstream::nProcs(); slave++)
01692 {
01693 IPstream fromSlave(Pstream::scheduled, slave);
01694 scalarField pointsComponent(fromSlave);
01695
01696 writeEnsDataBinary(pointsComponent, ensightGeometryFile);
01697 pointOffsets[slave] =
01698 pointOffsets[slave-1]
01699 + pointsComponent.size();
01700 }
01701 }
01702 }
01703 else
01704 {
01705 for (direction d=0; d<vector::nComponents; d++)
01706 {
01707 OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
01708 toMaster<< points.component(d);
01709 }
01710 }
01711
01712 writeAllPrimsBinary
01713 (
01714 "hexa8",
01715 meshCellSets_.nHexesWedges,
01716 map(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
01717 pointOffsets,
01718 ensightGeometryFile
01719 );
01720
01721 writeAllPrimsBinary
01722 (
01723 "penta6",
01724 meshCellSets_.nPrisms,
01725 map(cellShapes, meshCellSets_.prisms),
01726 pointOffsets,
01727 ensightGeometryFile
01728 );
01729
01730 writeAllPrimsBinary
01731 (
01732 "pyramid5",
01733 meshCellSets_.nPyrs,
01734 map(cellShapes, meshCellSets_.pyrs),
01735 pointOffsets,
01736 ensightGeometryFile
01737 );
01738
01739 writeAllPrimsBinary
01740 (
01741 "tetra4",
01742 meshCellSets_.nTets,
01743 map(cellShapes, meshCellSets_.tets),
01744 pointOffsets,
01745 ensightGeometryFile
01746 );
01747
01748 writeAllPolysBinary
01749 (
01750 pointOffsets,
01751 ensightGeometryFile
01752 );
01753
01754 }
01755
01756 label ensightPatchI = patchPartOffset_;
01757 label iCount = 0;
01758
01759 forAll(allPatchNames_, patchi)
01760 {
01761 iCount ++;
01762 const word& patchName = allPatchNames_[patchi];
01763 const labelList& patchProcessors = allPatchProcs_[patchi];
01764
01765 if (patchNames_.empty() || patchNames_.found(patchName))
01766 {
01767 const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
01768
01769 const labelList *trisPtr = NULL;
01770 const labelList *quadsPtr = NULL;
01771 const labelList *polysPtr = NULL;
01772
01773 const pointField *patchPointsPtr = NULL;
01774 const faceList *patchFacesPtr = NULL;
01775
01776 if (mesh_.boundary()[patchi].size())
01777 {
01778 const polyPatch& p = mesh_.boundaryMesh()[patchi];
01779
01780 trisPtr = &boundaryFaceSets_[patchi].tris;
01781 quadsPtr = &boundaryFaceSets_[patchi].quads;
01782 polysPtr = &boundaryFaceSets_[patchi].polys;
01783
01784 patchPointsPtr = &(p.localPoints());
01785 patchFacesPtr = &(p.localFaces());
01786 }
01787
01788 const labelList& tris = *trisPtr;
01789 const labelList& quads = *quadsPtr;
01790 const labelList& polys = *polysPtr;
01791 const pointField& patchPoints = *patchPointsPtr;
01792 const faceList& patchFaces = *patchFacesPtr;
01793
01794 if (nfp.nTris || nfp.nQuads || nfp.nPolys)
01795 {
01796 labelList patchPointOffsets(Pstream::nProcs(), 0);
01797
01798 if (Pstream::master())
01799 {
01800 writeEnsDataBinary("part",ensightGeometryFile);
01801 writeEnsDataBinary(ensightPatchI++,ensightGeometryFile);
01802
01803 writeEnsDataBinary(patchName.c_str(),ensightGeometryFile);
01804 writeEnsDataBinary("coordinates",ensightGeometryFile);
01805 writeEnsDataBinary(nfp.nPoints,ensightGeometryFile);
01806
01807 for (direction d=0; d<vector::nComponents; d++)
01808 {
01809 if (patchPointsPtr)
01810 {
01811
01812 writeEnsDataBinary
01813 (
01814 patchPoints.component(d),
01815 ensightGeometryFile
01816 );
01817 }
01818
01819 patchPointOffsets = 0;
01820
01821
01822 forAll (patchProcessors, i)
01823 {
01824 if (patchProcessors[i] != 0)
01825 {
01826 label slave = patchProcessors[i];
01827 IPstream fromSlave(Pstream::scheduled, slave);
01828 scalarField patchPointsComponent(fromSlave);
01829
01830
01831 writeEnsDataBinary
01832 (
01833 patchPointsComponent,
01834 ensightGeometryFile
01835 );
01836
01837 if (i < Pstream::nProcs()-1)
01838 {
01839 patchPointOffsets[i+1] =
01840 patchPointOffsets[i]
01841 + patchPointsComponent.size();
01842 }
01843 }
01844 else
01845 {
01846 if (i < Pstream::nProcs()-1)
01847 {
01848 patchPointOffsets[i+1] =
01849 patchPointOffsets[i]
01850 + patchPoints.size();
01851 }
01852 }
01853 }
01854 }
01855 }
01856 else if (patchPointsPtr)
01857 {
01858 for (direction d=0; d<vector::nComponents; d++)
01859 {
01860 OPstream toMaster
01861 (
01862 Pstream::scheduled,
01863 Pstream::masterNo()
01864 );
01865 toMaster<< patchPoints.component(d);
01866 }
01867 }
01868
01869 writeAllFacePrimsBinary
01870 (
01871 "tria3",
01872 tris,
01873 nfp.nTris,
01874 patchFaces,
01875 patchPointOffsets,
01876 patchProcessors,
01877 ensightGeometryFile
01878 );
01879
01880 writeAllFacePrimsBinary
01881 (
01882 "quad4",
01883 quads,
01884 nfp.nQuads,
01885 patchFaces,
01886 patchPointOffsets,
01887 patchProcessors,
01888 ensightGeometryFile
01889 );
01890
01891 writeAllNSidedBinary
01892 (
01893 polys,
01894 nfp.nPolys,
01895 patchFaces,
01896 patchPointOffsets,
01897 patchProcessors,
01898 ensightGeometryFile
01899 );
01900 }
01901 }
01902 }
01903
01904
01905 if (Pstream::master())
01906 {
01907 delete ensightGeometryFilePtr;
01908 }
01909 }
01910
01911
01912