OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

foamToFieldview9.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Write out the OpenFOAM mesh in Version 3.0 Fieldview-UNS format (binary).
00027 
00028     See Fieldview Release 9 Reference Manual - Appendix D
00029     (Unstructured Data Format)
00030     Borrows various from uns/write_binary_uns.c from FieldView dist.
00031 
00032 \*---------------------------------------------------------------------------*/
00033 
00034 #include "argList.H"
00035 #include "timeSelector.H"
00036 #include "volFields.H"
00037 #include "surfaceFields.H"
00038 #include "pointFields.H"
00039 #include "scalarIOField.H"
00040 #include "volPointInterpolation.H"
00041 #include "wallFvPatch.H"
00042 #include "symmetryFvPatch.H"
00043 
00044 #include "Cloud.H"
00045 #include "passiveParticle.H"
00046 
00047 #include "IOobjectList.H"
00048 #include "boolList.H"
00049 #include "stringList.H"
00050 #include "cellModeller.H"
00051 
00052 #include "floatScalar.H"
00053 #include "calcFaceAddressing.H"
00054 #include "writeFunctions.H"
00055 #include "fieldviewTopology.H"
00056 
00057 #include <fstream>
00058 
00059 #include "fv_reader_tags.h"
00060 
00061 extern "C"
00062 {
00063     unsigned int fv_encode_elem_header(int elem_type, int wall_info[]);
00064 }
00065 
00066 using namespace Foam;
00067 
00068 typedef Field<floatScalar> floatField;
00069 
00070 
00071 static HashTable<word> FieldviewNames;
00072 
00073 
00074 static word getFieldViewName(const word& foamName)
00075 {
00076     if (FieldviewNames.found(foamName))
00077     {
00078         return FieldviewNames[foamName];
00079     }
00080     else
00081     {
00082         return foamName;
00083     }
00084 }
00085 
00086 
00087 static void printNames(const wordList& names, Ostream& os)
00088 {
00089     forAll(names, fieldI)
00090     {
00091         Info<< " " << names[fieldI] << '/' << getFieldViewName(names[fieldI]);
00092     }
00093 }
00094 
00095 
00096 // Count number of vertices used by celli
00097 static label countVerts(const primitiveMesh& mesh, const label celli)
00098 {
00099     const cell& cll = mesh.cells()[celli];
00100 
00101     // Count number of vertices used
00102     labelHashSet usedVerts(10*cll.size());
00103 
00104     forAll(cll, cellFacei)
00105     {
00106         const face& f = mesh.faces()[cll[cellFacei]];
00107 
00108         forAll(f, fp)
00109         {
00110             if (!usedVerts.found(f[fp]))
00111             {
00112                 usedVerts.insert(f[fp]);
00113             }
00114         }
00115     }
00116     return usedVerts.toc().size();
00117 }
00118 
00119 
00120 static void writeFaceData
00121 (
00122     const polyMesh& mesh,
00123     const fieldviewTopology& topo,
00124     const label patchI,
00125     const scalarField& patchField,
00126     const bool writePolyFaces,
00127     std::ofstream& fvFile
00128 )
00129 {
00130     const polyPatch& pp = mesh.boundaryMesh()[patchI];
00131 
00132     // Start off with dummy value.
00133     if (writePolyFaces)
00134     {
00135         floatField fField(topo.nPolyFaces()[patchI], 0.0);
00136 
00137         // Fill selected faces with field values
00138         label polyFaceI = 0;
00139         forAll(patchField, faceI)
00140         {
00141             if (pp[faceI].size() > 4)
00142             {
00143                 fField[polyFaceI++] = float(patchField[faceI]);
00144             }
00145         }
00146 
00147         fvFile.write
00148         (
00149             reinterpret_cast<char*>(fField.begin()), fField.size()*sizeof(float)
00150         );
00151     }
00152     else
00153     {
00154         floatField fField(pp.size() - topo.nPolyFaces()[patchI], 0.0);
00155 
00156         // Fill selected faces with field values
00157         label quadFaceI = 0;
00158         forAll(patchField, faceI)
00159         {
00160             if (pp[faceI].size() <= 4)
00161             {
00162                 fField[quadFaceI++] = float(patchField[faceI]);
00163             }
00164         }
00165 
00166         fvFile.write
00167         (
00168             reinterpret_cast<char*>(fField.begin()), fField.size()*sizeof(float)
00169         );
00170     }
00171 }
00172 
00173 
00174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00175 // Main program:
00176 
00177 int main(int argc, char *argv[])
00178 {
00179     argList::noParallel();
00180     argList::validOptions.insert("noWall", "");
00181     timeSelector::addOptions(true, false);
00182 
00183 #   include "setRootCase.H"
00184 #   include "createTime.H"
00185 
00186     instantList timeDirs = timeSelector::select0(runTime, args);
00187 
00188 #   include "createMesh.H"
00189 
00190     // Initialize name mapping table
00191     FieldviewNames.insert("alpha", "aalpha");
00192     FieldviewNames.insert("Alpha", "AAlpha");
00193     FieldviewNames.insert("fsmach", "ffsmach");
00194     FieldviewNames.insert("FSMach", "FFSMach");
00195     FieldviewNames.insert("re", "rre");
00196     FieldviewNames.insert("Re", "RRe");
00197     FieldviewNames.insert("time", "ttime");
00198     FieldviewNames.insert("Time", "TTime");
00199     FieldviewNames.insert("pi", "ppi");
00200     FieldviewNames.insert("PI", "PPI");
00201     FieldviewNames.insert("x", "xx");
00202     FieldviewNames.insert("X", "XX");
00203     FieldviewNames.insert("y", "yy");
00204     FieldviewNames.insert("Y", "YY");
00205     FieldviewNames.insert("z", "zz");
00206     FieldviewNames.insert("Z", "ZZ");
00207     FieldviewNames.insert("rcyl", "rrcyl");
00208     FieldviewNames.insert("Rcyl", "RRcyl");
00209     FieldviewNames.insert("theta", "ttheta");
00210     FieldviewNames.insert("Theta", "TTheta");
00211     FieldviewNames.insert("rsphere", "rrsphere");
00212     FieldviewNames.insert("Rsphere", "RRsphere");
00213     FieldviewNames.insert("k", "kk");
00214     FieldviewNames.insert("K", "KK");
00215 
00216 
00217     // Scan for all available fields, in all timesteps
00218     //     volScalarNames  : all scalar fields
00219     //     volVectorNames  : ,,  vector ,,
00220     //     surfScalarNames : surface fields
00221     //     surfVectorNames : ,,
00222     //     sprayScalarNames: spray fields
00223     //     sprayVectorNames: ,,
00224 #   include "getFieldNames.H"
00225 
00226     bool hasLagrangian = false;
00227     if (sprayScalarNames.size() || sprayVectorNames.size())
00228     {
00229         hasLagrangian = true;
00230     }
00231 
00232     Info<< "All fields:   Foam/Fieldview" << endl;
00233     Info<< "    volScalar   :";
00234     printNames(volScalarNames, Info);
00235     Info<< endl;
00236     Info<< "    volVector   :";
00237     printNames(volVectorNames, Info);
00238     Info<< endl;
00239     Info<< "    surfScalar  :";
00240     printNames(surfScalarNames, Info);
00241     Info<< endl;
00242     Info<< "    surfVector  :";
00243     printNames(surfVectorNames, Info);
00244     Info<< endl;
00245     Info<< "    sprayScalar :";
00246     printNames(sprayScalarNames, Info);
00247     Info<< endl;
00248     Info<< "    sprayVector :";
00249     printNames(sprayVectorNames, Info);
00250     Info<< endl;
00251 
00252 
00253     //
00254     // Start writing
00255     //
00256 
00257     // make a directory called FieldView in the case
00258     fileName fvPath(runTime.path()/"Fieldview");
00259 
00260     if (isDir(fvPath))
00261     {
00262         rmDir(fvPath);
00263     }
00264 
00265     mkDir(fvPath);
00266 
00267     fileName fvParticleFileName(fvPath/runTime.caseName() + ".fvp");
00268     if (hasLagrangian)
00269     {
00270         Info<< "Opening particle file " << fvParticleFileName << endl;
00271     }
00272     std::ofstream fvParticleFile(fvParticleFileName.c_str());
00273 
00274     // Write spray file header
00275     if (hasLagrangian)
00276     {
00277 #       include "writeSprayHeader.H"
00278     }
00279 
00280     // Current mesh. Start off from unloaded mesh.
00281     autoPtr<fieldviewTopology> topoPtr(NULL);
00282 
00283     label fieldViewTime = 0;
00284 
00285     forAll(timeDirs, timeI)
00286     {
00287         runTime.setTime(timeDirs[timeI], timeI);
00288         Info<< "Time: " << runTime.timeName() << endl;
00289 
00290         fvMesh::readUpdateState state = mesh.readUpdate();
00291 
00292         if
00293         (
00294             timeI == 0
00295          || state == fvMesh::TOPO_CHANGE
00296          || state == fvMesh::TOPO_PATCH_CHANGE
00297         )
00298         {
00299             // Mesh topo changed. Update Fieldview topo.
00300 
00301             topoPtr.reset
00302             (
00303                 new fieldviewTopology
00304                 (
00305                     mesh,
00306                     !args.optionFound("noWall")
00307                 )
00308             );
00309 
00310             Info<< "    Mesh read:" << endl
00311                 << "        tet   : " << topoPtr().nTet() << endl
00312                 << "        hex   : " << topoPtr().nHex() << endl
00313                 << "        prism : " << topoPtr().nPrism() << endl
00314                 << "        pyr   : " << topoPtr().nPyr() << endl
00315                 << "        poly  : " << topoPtr().nPoly() << endl
00316                 << endl;
00317         }
00318         else if (state == fvMesh::POINTS_MOVED)
00319         {
00320             // points exists for time step, let's read them
00321             Info<< "    Points file detected - updating points" << endl;
00322         }
00323 
00324         const fieldviewTopology& topo = topoPtr();
00325 
00326 
00327         //
00328         // Create file and write header
00329         //
00330 
00331         fileName fvFileName
00332         (
00333             fvPath/runTime.caseName() + "_" + Foam::name(timeI) + ".uns"
00334         );
00335 
00336         Info<< "    file:" << fvFileName.c_str() << endl;
00337 
00338 
00339         std::ofstream fvFile(fvFileName.c_str());
00340 
00341         //Info<< "Writing header ..." << endl;
00342 
00343         // Output the magic number.
00344         writeInt(fvFile, FV_MAGIC);
00345 
00346         // Output file header and version number.
00347         writeStr80(fvFile, "FIELDVIEW");
00348 
00349         // This version of the FIELDVIEW unstructured file is "3.0".
00350         // This is written as two integers.
00351         writeInt(fvFile, 3);
00352         writeInt(fvFile, 0);
00353 
00354 
00355         // File type code. Grid and results.
00356         writeInt(fvFile, FV_COMBINED_FILE);
00357 
00358         // Reserved field, always zero
00359         writeInt(fvFile, 0);
00360 
00361         // Output constants for time, fsmach, alpha and re.
00362         float fBuf[4];
00363         fBuf[0] = runTime.value();
00364         fBuf[1] = 0.0;
00365         fBuf[2] = 0.0;
00366         fBuf[3] = 1.0;
00367         fvFile.write(reinterpret_cast<char*>(fBuf), 4*sizeof(float));
00368 
00369 
00370         // Output the number of grids
00371         writeInt(fvFile, 1);
00372 
00373 
00374         //
00375         //  Boundary table
00376         //
00377         //Info<< "Writing boundary table ..." << endl;
00378 
00379         // num patches
00380         writeInt(fvFile, mesh.boundary().size());
00381 
00382         forAll (mesh.boundary(), patchI)
00383         {
00384             const fvPatch& currPatch = mesh.boundary()[patchI];
00385 
00386             writeInt(fvFile, 1);   // data present
00387             writeInt(fvFile, 1);   // normals ok
00388 
00389             // name
00390             writeStr80(fvFile, currPatch.name().c_str());
00391         }
00392 
00393 
00394         //
00395         // Create fields:
00396         //     volFieldPtrs     : List of ptrs to all volScalar/Vector fields
00397         //                        (null if field not present at current time)
00398         //     volFieldNames    : FieldView compatible names of volFields
00399         //     surfFieldPtrs    : same for surfaceScalar/Vector
00400         //     surfFieldNames
00401 #       include "createFields.H"
00402 
00403 
00404 
00405         //
00406         // Write Variables table
00407         //
00408 
00409         //Info<< "Writing variables table ..." << endl;
00410 
00411         writeInt(fvFile, volFieldNames.size());
00412         forAll(volFieldNames, fieldI)
00413         {
00414             if (volFieldPtrs[fieldI] == NULL)
00415             {
00416                 Info<< "    dummy field for "
00417                     << volFieldNames[fieldI].c_str() << endl;
00418             }
00419 
00420             writeStr80(fvFile, volFieldNames[fieldI].c_str());
00421         }
00422 
00423         //
00424         // Write Boundary Variables table = vol + surface fields
00425         //
00426 
00427         //Info<< "Writing boundary variables table ..." << endl;
00428 
00429         writeInt
00430         (
00431             fvFile,
00432             volFieldNames.size() + surfFieldNames.size()
00433         );
00434         forAll(volFieldNames, fieldI)
00435         {
00436             writeStr80(fvFile, volFieldNames[fieldI].c_str());
00437         }
00438         forAll(surfFieldNames, fieldI)
00439         {
00440             if (surfFieldPtrs[fieldI] == NULL)
00441             {
00442                 Info<< "    dummy surface field for "
00443                     << surfFieldNames[fieldI].c_str() << endl;
00444             }
00445 
00446             writeStr80(fvFile, surfFieldNames[fieldI].c_str());
00447         }
00448 
00449 
00450         // Output grid data.
00451 
00452         //
00453         // Nodes
00454         //
00455 
00456         //Info<< "Writing points ..." << endl;
00457 
00458         const pointField& points = mesh.points();
00459         label nPoints = points.size();
00460 
00461         writeInt(fvFile, FV_NODES);
00462         writeInt(fvFile, nPoints);
00463 
00464         for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
00465         {
00466             floatField fField(nPoints);
00467 
00468             for (label pointi = 0; pointi<nPoints; pointi++)
00469             {
00470                 fField[pointi] = float(points[pointi][cmpt]);
00471             }
00472 
00473             fvFile.write
00474             (
00475                 reinterpret_cast<char*>(fField.begin()),
00476                 fField.size()*sizeof(float)
00477             );
00478         }
00479 
00480         //
00481         // Boundary Faces - regular
00482         //
00483 
00484         //Info<< "Writing regular boundary faces ..." << endl;
00485 
00486         forAll(mesh.boundary(), patchI)
00487         {
00488             label nQuadFaces = topo.quadFaceLabels()[patchI].size()/4;
00489 
00490             if (nQuadFaces != 0)
00491             {
00492                 writeInt(fvFile, FV_FACES);
00493                 writeInt(fvFile, patchI + 1);  // patch number
00494                 writeInt(fvFile, nQuadFaces);  // number of faces in patch
00495                 fvFile.write
00496                 (
00497                     reinterpret_cast<const char*>
00498                         (topo.quadFaceLabels()[patchI].begin()),
00499                     nQuadFaces*4*sizeof(int)
00500                 );
00501             }
00502         }
00503 
00504         //
00505         // Boundary Faces - arbitrary polygon
00506         //
00507 
00508         //Info<< "Write polygonal boundary faces ..." << endl;
00509 
00510         forAll(mesh.boundary(), patchI)
00511         {
00512             if (topo.nPolyFaces()[patchI] > 0)
00513             {
00514                 writeInt(fvFile, FV_ARB_POLY_FACES);
00515                 writeInt(fvFile, patchI + 1);
00516 
00517                 // number of arb faces in patch
00518                 writeInt(fvFile, topo.nPolyFaces()[patchI]);
00519 
00520                 const polyPatch& patchFaces = mesh.boundary()[patchI].patch();
00521 
00522                 forAll(patchFaces, faceI)
00523                 {
00524                     const face& f = patchFaces[faceI];
00525 
00526                     if (f.size() > 4)
00527                     {
00528                         writeInt(fvFile, f.size());
00529 
00530                         forAll(f, fp)
00531                         {
00532                             writeInt(fvFile, f[fp] + 1);
00533                         }
00534                     }
00535                 }
00536             }
00537         }
00538 
00539 
00540         //
00541         // Write regular topology
00542         //
00543 
00544         //Info<< "Writing regular elements ..." << endl;
00545 
00546         writeInt(fvFile, FV_ELEMENTS);
00547         writeInt(fvFile, topo.nTet());
00548         writeInt(fvFile, topo.nHex());
00549         writeInt(fvFile, topo.nPrism());
00550         writeInt(fvFile, topo.nPyr());
00551         fvFile.write
00552         (
00553             reinterpret_cast<const char*>(topo.tetLabels().begin()),
00554             topo.nTet()*(1+4)*sizeof(int)
00555         );
00556         fvFile.write
00557         (
00558             reinterpret_cast<const char*>(topo.hexLabels().begin()),
00559             topo.nHex()*(1+8)*sizeof(int)
00560         );
00561         fvFile.write
00562         (
00563             reinterpret_cast<const char*>(topo.prismLabels().begin()),
00564             topo.nPrism()*(1+6)*sizeof(int)
00565         );
00566         fvFile.write
00567         (
00568             reinterpret_cast<const char*>(topo.pyrLabels().begin()),
00569             topo.nPyr()*(1+5)*sizeof(int)
00570         );
00571 
00572 
00573         //
00574         // Write arbitrary polyhedra
00575         //
00576 
00577         //Info<< "Writing polyhedral elements ..." << endl;
00578 
00579 
00580         const cellShapeList& cellShapes = mesh.cellShapes();
00581         const cellModel& unknown = *(cellModeller::lookup("unknown"));
00582 
00583         if (topo.nPoly() > 0)
00584         {
00585             writeInt(fvFile, FV_ARB_POLY_ELEMENTS);
00586             writeInt(fvFile, topo.nPoly());
00587 
00588             forAll(cellShapes, celli)
00589             {
00590                 if (cellShapes[celli].model() == unknown)
00591                 {
00592                     const cell& cll = mesh.cells()[celli];
00593 
00594                     // number of faces
00595                     writeInt(fvFile, cll.size());
00596                     // number of vertices used (no cell centre)
00597                     writeInt(fvFile, countVerts(mesh, celli));
00598                     // cell centre node id
00599                     writeInt(fvFile, -1);
00600 
00601                     forAll(cll, cellFacei)
00602                     {
00603                         label faceI = cll[cellFacei];
00604 
00605                         const face& f = mesh.faces()[faceI];
00606 
00607                         // Not a wall for now
00608                         writeInt(fvFile, NOT_A_WALL);
00609 
00610                         writeInt(fvFile, f.size());
00611 
00612                         if (mesh.faceOwner()[faceI] == celli)
00613                         {
00614                             forAll(f, fp)
00615                             {
00616                                 writeInt(fvFile, f[fp]+1);
00617                             }
00618                         }
00619                         else
00620                         {
00621                             for (label fp = f.size()-1; fp >= 0; fp--)
00622                             {
00623                                 writeInt(fvFile, f[fp]+1);
00624                             }
00625                         }
00626 
00627                         // Number of hanging nodes
00628                         writeInt(fvFile, 0);
00629                     }
00630                 }
00631             }
00632         }
00633 
00634 
00635         //
00636         // Variables data
00637         //
00638 
00639         //Info<< "Writing variables data ..." << endl;
00640 
00641         volPointInterpolation pInterp(mesh);
00642 
00643         writeInt(fvFile, FV_VARIABLES);
00644 
00645 
00646         forAll(volFieldPtrs, fieldI)
00647         {
00648             if (volFieldPtrs[fieldI] != NULL)
00649             {
00650                 const volScalarField& vField = *volFieldPtrs[fieldI];
00651 
00652                 // Interpolate to points
00653                 pointScalarField psf(pInterp.interpolate(vField));
00654 
00655                 floatField fField(nPoints);
00656 
00657                 for (label pointi = 0; pointi<nPoints; pointi++)
00658                 {
00659                     fField[pointi] = float(psf[pointi]);
00660                 }
00661 
00662                 fvFile.write
00663                 (
00664                     reinterpret_cast<char*>(fField.begin()),
00665                     fField.size()*sizeof(float)
00666                 );
00667             }
00668             else
00669             {
00670                 // Create dummy field
00671                 floatField dummyField(nPoints, 0.0);
00672 
00673                 fvFile.write
00674                 (
00675                     reinterpret_cast<char*>(dummyField.begin()),
00676                     dummyField.size()*sizeof(float)
00677                 );
00678             }
00679         }
00680 
00681 
00682         //
00683         // Boundary variables data
00684         //     1. volFields
00685         //     2. surfFields
00686 
00687         //Info<< "Writing regular boundary elements data ..." << endl;
00688 
00689         writeInt(fvFile, FV_BNDRY_VARS);
00690 
00691         forAll(volFieldPtrs, fieldI)
00692         {
00693             if (volFieldPtrs[fieldI] != NULL)
00694             {
00695                 const volScalarField& vsf = *volFieldPtrs[fieldI];
00696 
00697                 forAll (mesh.boundary(), patchI)
00698                 {
00699                     writeFaceData
00700                     (
00701                         mesh,
00702                         topo,
00703                         patchI,
00704                         vsf.boundaryField()[patchI],
00705                         false,
00706                         fvFile
00707                     );
00708                 }
00709             }
00710             else
00711             {
00712                 forAll (mesh.boundaryMesh(), patchI)
00713                 {
00714                     // Dummy value.
00715                     floatField fField
00716                     (
00717                         mesh.boundaryMesh()[patchI].size()
00718                       - topo.nPolyFaces()[patchI],
00719                         0.0
00720                     );
00721 
00722                     fvFile.write
00723                     (
00724                         reinterpret_cast<char*>(fField.begin()),
00725                         fField.size()*sizeof(float)
00726                     );
00727                 }
00728             }
00729         }
00730 
00731         // surfFields
00732         forAll(surfFieldPtrs, fieldI)
00733         {
00734             if (surfFieldPtrs[fieldI] != NULL)
00735             {
00736                 const surfaceScalarField& ssf = *surfFieldPtrs[fieldI];
00737 
00738                 forAll (mesh.boundary(), patchI)
00739                 {
00740                     writeFaceData
00741                     (
00742                         mesh,
00743                         topo,
00744                         patchI,
00745                         ssf.boundaryField()[patchI],
00746                         false,
00747                         fvFile
00748                     );
00749                 }
00750             }
00751             else
00752             {
00753                 forAll (mesh.boundaryMesh(), patchI)
00754                 {
00755                     // Dummy value.
00756                     floatField fField
00757                     (
00758                         mesh.boundaryMesh()[patchI].size()
00759                       - topo.nPolyFaces()[patchI],
00760                         0.0
00761                     );
00762 
00763                     fvFile.write
00764                     (
00765                         reinterpret_cast<char*>(fField.begin()),
00766                         fField.size()*sizeof(float)
00767                     );
00768                 }
00769             }
00770         }
00771 
00772         //
00773         // Polygonal faces boundary data
00774         //     1. volFields
00775         //     2. surfFields
00776 
00777         //Info<< "Writing polygonal boundary elements data ..." << endl;
00778 
00779         writeInt(fvFile, FV_ARB_POLY_BNDRY_VARS);
00780         forAll(volFieldPtrs, fieldI)
00781         {
00782             if (volFieldPtrs[fieldI] != NULL)
00783             {
00784                 const volScalarField& vsf = *volFieldPtrs[fieldI];
00785 
00786                 // All non-empty patches
00787                 forAll (mesh.boundary(), patchI)
00788                 {
00789                     writeFaceData
00790                     (
00791                         mesh,
00792                         topo,
00793                         patchI,
00794                         vsf.boundaryField()[patchI],
00795                         true,
00796                         fvFile
00797                     );
00798                 }
00799             }
00800             else
00801             {
00802                 forAll (mesh.boundary(), patchI)
00803                 {
00804                     // Dummy value.
00805                     floatField fField(topo.nPolyFaces()[patchI], 0.0);
00806 
00807                     fvFile.write
00808                     (
00809                         reinterpret_cast<char*>(fField.begin()),
00810                         fField.size()*sizeof(float)
00811                     );
00812                 }
00813             }
00814         }
00815 
00816         // surfFields
00817         forAll(surfFieldPtrs, fieldI)
00818         {
00819             if (surfFieldPtrs[fieldI] != NULL)
00820             {
00821                 const surfaceScalarField& ssf = *surfFieldPtrs[fieldI];
00822 
00823                 // All non-empty patches
00824                 forAll(mesh.boundary(), patchI)
00825                 {
00826                     writeFaceData
00827                     (
00828                         mesh,
00829                         topo,
00830                         patchI,
00831                         ssf.boundaryField()[patchI],
00832                         true,
00833                         fvFile
00834                     );
00835                 }
00836             }
00837             else
00838             {
00839                 forAll (mesh.boundaryMesh(), patchI)
00840                 {
00841                     // Dummy value.
00842                     floatField fField
00843                     (
00844                         mesh.boundaryMesh()[patchI].size()
00845                       - topo.nPolyFaces()[patchI],
00846                         0.0
00847                     );
00848 
00849                     fvFile.write
00850                     (
00851                         reinterpret_cast<char*>(fField.begin()),
00852                         fField.size()*sizeof(float)
00853                     );
00854                 }
00855             }
00856         }
00857 
00858 
00859         //
00860         // Cleanup volume and surface fields
00861         //
00862         forAll(volFieldPtrs, fieldI)
00863         {
00864             delete volFieldPtrs[fieldI];
00865         }
00866         forAll(surfFieldPtrs, fieldI)
00867         {
00868             delete surfFieldPtrs[fieldI];
00869         }
00870 
00871 
00872 
00873 
00874         //
00875         // Spray
00876         //
00877         if (hasLagrangian)
00878         {
00879             // Read/create fields:
00880             //     sprayScalarFieldPtrs: List of ptrs to lagrangian scalfields
00881             //     sprayVectorFieldPtrs:               ,,           vec  ,,
00882 #           include "createSprayFields.H"
00883 
00884 
00885             // Write time header
00886 
00887             // Time index (FieldView: has to start from 1)
00888             writeInt(fvParticleFile, fieldViewTime + 1);
00889 
00890             // Time value
00891             writeFloat(fvParticleFile, runTime.value());
00892 
00893             // Read particles
00894             Cloud<passiveParticle> parcels(mesh);
00895 
00896             // Num particles
00897             writeInt(fvParticleFile, parcels.size());
00898 
00899             Info<< "    Writing " << parcels.size() << " particles." << endl;
00900 
00901 
00902             //
00903             // Output data parcelwise
00904             //
00905 
00906             label parcelNo = 0;
00907 
00908 
00909             for
00910             (
00911                 Cloud<passiveParticle>::iterator elmnt = parcels.begin();
00912                 elmnt != parcels.end();
00913                 ++elmnt, parcelNo++
00914             )
00915             {
00916                 writeInt(fvParticleFile, parcelNo+1);
00917 
00918                 writeFloat(fvParticleFile, elmnt().position().x());
00919                 writeFloat(fvParticleFile, elmnt().position().y());
00920                 writeFloat(fvParticleFile, elmnt().position().z());
00921 
00922                 forAll(sprayScalarFieldPtrs, fieldI)
00923                 {
00924                     if (sprayScalarFieldPtrs[fieldI] != NULL)
00925                     {
00926                         const IOField<scalar>& sprayField =
00927                             *sprayScalarFieldPtrs[fieldI];
00928                         writeFloat
00929                         (
00930                             fvParticleFile,
00931                             sprayField[parcelNo]
00932                         );
00933                     }
00934                     else
00935                     {
00936                         writeFloat(fvParticleFile, 0.0);
00937                     }
00938                 }
00939                 forAll(sprayVectorFieldPtrs, fieldI)
00940                 {
00941                     if (sprayVectorFieldPtrs[fieldI] != NULL)
00942                     {
00943                         const IOField<vector>& sprayVectorField =
00944                             *sprayVectorFieldPtrs[fieldI];
00945                         const vector& val =
00946                             sprayVectorField[parcelNo];
00947 
00948                         writeFloat(fvParticleFile, val.x());
00949                         writeFloat(fvParticleFile, val.y());
00950                         writeFloat(fvParticleFile, val.z());
00951                     }
00952                     else
00953                     {
00954                         writeFloat(fvParticleFile, 0.0);
00955                         writeFloat(fvParticleFile, 0.0);
00956                         writeFloat(fvParticleFile, 0.0);
00957                     }
00958                 }
00959             }
00960 
00961             // increment fieldView particle time
00962             fieldViewTime++;
00963 
00964 
00965             //
00966             // Cleanup spray fields
00967             //
00968             forAll(sprayScalarFieldPtrs, fieldI)
00969             {
00970                 delete sprayScalarFieldPtrs[fieldI];
00971             }
00972             forAll(sprayVectorFieldPtrs, fieldI)
00973             {
00974                 delete sprayVectorFieldPtrs[fieldI];
00975             }
00976 
00977         } // end of hasLagrangian
00978     }
00979 
00980     if (!hasLagrangian)
00981     {
00982         rm(fvParticleFileName);
00983     }
00984 
00985     Info << "End\n" << endl;
00986 
00987     return 0;
00988 }
00989 
00990 
00991 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd