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

foamToVTK.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 Application
00026     foamToVTK
00027 
00028 Description
00029     Legacy VTK file format writer.
00030 
00031     - handles volScalar, volVector, pointScalar, pointVector, surfaceScalar
00032       fields.
00033     - mesh topo changes.
00034     - both ascii and binary.
00035     - single time step writing.
00036     - write subset only.
00037     - automatic decomposition of cells; polygons on boundary undecomposed since
00038       handled by vtk.
00039 
00040 Usage
00041 
00042     - foamToVTK [OPTION]
00043 
00044 
00045     @param -ascii \n
00046     Write VTK data in ASCII format instead of binary.
00047 
00048     @param -mesh <name>\n
00049     Use a different mesh name (instead of -region)
00050 
00051     @param -fields <fields>\n
00052     Convert selected fields only. For example,
00053     @verbatim
00054          -fields "( p T U )"
00055     @endverbatim
00056     The quoting is required to avoid shell expansions and to pass the
00057     information as a single argument.
00058 
00059     @param -surfaceFields \n
00060     Write surfaceScalarFields (e.g., phi)
00061 
00062     @param -cellSet <name>\n
00063     @param -faceSet <name>\n
00064     @param -pointSet <name>\n
00065     Restrict conversion to the cellSet, faceSet or pointSet.
00066 
00067     @param -nearCellValue \n
00068     Output cell value on patches instead of patch value itself
00069 
00070     @param -noInternal \n
00071     Do not generate file for mesh, only for patches
00072 
00073     @param -noPointValues \n
00074     No pointFields
00075 
00076     @param -noFaceZones \n
00077     No faceZones
00078 
00079     @param -noLinks \n
00080     (in parallel) do not link processor files to master
00081 
00082     @param -allPatches \n
00083     Combine all patches into a single file
00084 
00085     @param -excludePatches <patchNames>\n
00086     Specify patches to exclude. For example,
00087     @verbatim
00088          -excludePatches "( inlet_1 inlet_2 )"
00089     @endverbatim
00090     The quoting is required to avoid shell expansions and to pass the
00091     information as a single argument.
00092 
00093     @param -useTimeName \n
00094     use the time index in the VTK file name instead of the time index
00095 
00096 Note
00097     mesh subset is handled by vtkMesh. Slight inconsistency in
00098     interpolation: on the internal field it interpolates the whole volfield
00099     to the whole-mesh pointField and then selects only those values it
00100     needs for the subMesh (using the fvMeshSubset cellMap(), pointMap()
00101     functions). For the patches however it uses the
00102     fvMeshSubset.interpolate function to directly interpolate the
00103     whole-mesh values onto the subset patch.
00104 
00105 Note
00106     new file format: \n
00107     no automatic timestep recognition.
00108     However can have .pvd file format which refers to time simulation
00109     if XML *.vtu files are available:
00110 
00111     @verbatim
00112       <?xml version="1.0"?>
00113       <VTKFile type="Collection" version="0.1" byte_order="LittleEndian" compressor="vtkZLibDataCompressor">
00114         <Collection>
00115           <DataSet timestep="50" file="pitzDaily_2.vtu"/>
00116           <DataSet timestep="100" file="pitzDaily_3.vtu"/>
00117           <DataSet timestep="150" file="pitzDaily_4.vtu"/>
00118           <DataSet timestep="200" file="pitzDaily_5.vtu"/>
00119           <DataSet timestep="250" file="pitzDaily_6.vtu"/>
00120           <DataSet timestep="300" file="pitzDaily_7.vtu"/>
00121           <DataSet timestep="350" file="pitzDaily_8.vtu"/>
00122           <DataSet timestep="400" file="pitzDaily_9.vtu"/>
00123           <DataSet timestep="450" file="pitzDaily_10.vtu"/>
00124           <DataSet timestep="500" file="pitzDaily_11.vtu"/>
00125         </Collection>
00126       </VTKFile>
00127     @endverbatim
00128 
00129 \*---------------------------------------------------------------------------*/
00130 
00131 #include "fvCFD.H"
00132 #include "pointMesh.H"
00133 #include "volPointInterpolation.H"
00134 #include "emptyPolyPatch.H"
00135 #include "labelIOField.H"
00136 #include "scalarIOField.H"
00137 #include "sphericalTensorIOField.H"
00138 #include "symmTensorIOField.H"
00139 #include "tensorIOField.H"
00140 #include "faceZoneMesh.H"
00141 #include "Cloud.H"
00142 #include "passiveParticle.H"
00143 
00144 #include "vtkMesh.H"
00145 #include "readFields.H"
00146 #include "writeFuns.H"
00147 
00148 #include "internalWriter.H"
00149 #include "patchWriter.H"
00150 #include "lagrangianWriter.H"
00151 
00152 #include "writeFaceSet.H"
00153 #include "writePointSet.H"
00154 #include "writePatchGeom.H"
00155 #include "writeSurfFields.H"
00156 
00157 
00158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00159 
00160 
00161 static const label VTK_TETRA      = 10;
00162 static const label VTK_PYRAMID    = 14;
00163 static const label VTK_WEDGE      = 13;
00164 static const label VTK_HEXAHEDRON = 12;
00165 
00166 
00167 template<class GeoField>
00168 void print(const char* msg, Ostream& os, const PtrList<GeoField>& flds)
00169 {
00170     if (flds.size())
00171     {
00172         os << msg;
00173         forAll(flds, i)
00174         {
00175             os<< ' ' << flds[i].name();
00176         }
00177         os << endl;
00178     }
00179 }
00180 
00181 
00182 void print(Ostream& os, const wordList& flds)
00183 {
00184     forAll(flds, i)
00185     {
00186         os<< ' ' << flds[i];
00187     }
00188     os << endl;
00189 }
00190 
00191 
00192 labelList getSelectedPatches
00193 (
00194     const polyBoundaryMesh& patches,
00195     const HashSet<word>& excludePatches
00196 )
00197 {
00198     DynamicList<label> patchIDs(patches.size());
00199 
00200     Info<< "Combining patches:" << endl;
00201 
00202     forAll(patches, patchI)
00203     {
00204         const polyPatch& pp = patches[patchI];
00205 
00206         if
00207         (
00208             isType<emptyPolyPatch>(pp)
00209             || (Pstream::parRun() && isType<processorPolyPatch>(pp))
00210         )
00211         {
00212             Info<< "    discarding empty/processor patch " << patchI
00213                 << " " << pp.name() << endl;
00214         }
00215         else if (!excludePatches.found(pp.name()))
00216         {
00217             patchIDs.append(patchI);
00218             Info<< "    patch " << patchI << " " << pp.name() << endl;
00219         }
00220     }
00221     return patchIDs.shrink();
00222 }
00223 
00224 
00225 
00226 
00227 // Main program:
00228 
00229 int main(int argc, char *argv[])
00230 {
00231     timeSelector::addOptions();
00232 
00233 #   include "addRegionOption.H"
00234 
00235     argList::validOptions.insert("fields", "fields");
00236     argList::validOptions.insert("cellSet", "cellSet name");
00237     argList::validOptions.insert("faceSet", "faceSet name");
00238     argList::validOptions.insert("pointSet", "pointSet name");
00239     argList::validOptions.insert("ascii","");
00240     argList::validOptions.insert("surfaceFields","");
00241     argList::validOptions.insert("nearCellValue","");
00242     argList::validOptions.insert("noInternal","");
00243     argList::validOptions.insert("noPointValues","");
00244     argList::validOptions.insert("allPatches","");
00245     argList::validOptions.insert("excludePatches","patches to exclude");
00246     argList::validOptions.insert("noFaceZones","");
00247     argList::validOptions.insert("noLinks","");
00248     argList::validOptions.insert("useTimeName","");
00249 
00250 #   include "setRootCase.H"
00251 #   include "createTime.H"
00252 
00253     bool doWriteInternal = !args.optionFound("noInternal");
00254     bool doFaceZones     = !args.optionFound("noFaceZones");
00255     bool doLinks         = !args.optionFound("noLinks");
00256     bool binary          = !args.optionFound("ascii");
00257     bool useTimeName     = args.optionFound("useTimeName");
00258 
00259     if (binary && (sizeof(floatScalar) != 4 || sizeof(label) != 4))
00260     {
00261         FatalErrorIn(args.executable())
00262             << "floatScalar and/or label are not 4 bytes in size" << nl
00263             << "Hence cannot use binary VTK format. Please use -ascii"
00264             << exit(FatalError);
00265     }
00266 
00267     bool nearCellValue = args.optionFound("nearCellValue");
00268 
00269     if (nearCellValue)
00270     {
00271         WarningIn(args.executable())
00272             << "Using neighbouring cell value instead of patch value"
00273             << nl << endl;
00274     }
00275 
00276     bool noPointValues = args.optionFound("noPointValues");
00277 
00278     if (noPointValues)
00279     {
00280         WarningIn(args.executable())
00281             << "Outputting cell values only" << nl << endl;
00282     }
00283 
00284     bool allPatches = args.optionFound("allPatches");
00285 
00286     HashSet<word> excludePatches;
00287     if (args.optionFound("excludePatches"))
00288     {
00289         args.optionLookup("excludePatches")() >> excludePatches;
00290 
00291         Info<< "Not including patches " << excludePatches << nl << endl;
00292     }
00293 
00294     word cellSetName;
00295     string vtkName;
00296 
00297     if (args.optionFound("cellSet"))
00298     {
00299         cellSetName = args.option("cellSet");
00300         vtkName = cellSetName;
00301     }
00302     else if (Pstream::parRun())
00303     {
00304         // Strip off leading casename, leaving just processor_DDD ending.
00305         vtkName = runTime.caseName();
00306 
00307         string::size_type i = vtkName.rfind("processor");
00308 
00309         if (i != string::npos)
00310         {
00311             vtkName = vtkName.substr(i);
00312         }
00313     }
00314     else
00315     {
00316         vtkName = runTime.caseName();
00317     }
00318 
00319 
00320     instantList timeDirs = timeSelector::select0(runTime, args);
00321 
00322 #   include "createNamedMesh.H"
00323 
00324     // VTK/ directory in the case
00325     fileName fvPath(runTime.path()/"VTK");
00326     // Directory of mesh (region0 gets filtered out)
00327     fileName regionPrefix = "";
00328 
00329     if (regionName != polyMesh::defaultRegion)
00330     {
00331         fvPath = fvPath/regionName;
00332         regionPrefix = regionName;
00333     }
00334 
00335     if (isDir(fvPath))
00336     {
00337         if
00338         (
00339             args.optionFound("time")
00340          || args.optionFound("latestTime")
00341          || cellSetName.size()
00342          || regionName != polyMesh::defaultRegion
00343         )
00344         {
00345             Info<< "Keeping old VTK files in " << fvPath << nl << endl;
00346         }
00347         else
00348         {
00349             Info<< "Deleting old VTK files in " << fvPath << nl << endl;
00350 
00351             rmDir(fvPath);
00352         }
00353     }
00354 
00355     mkDir(fvPath);
00356 
00357 
00358     // mesh wrapper; does subsetting and decomposition
00359     vtkMesh vMesh(mesh, cellSetName);
00360 
00361     forAll(timeDirs, timeI)
00362     {
00363         runTime.setTime(timeDirs[timeI], timeI);
00364 
00365         Info<< "Time: " << runTime.timeName() << endl;
00366 
00367         word timeDesc = "";
00368         if (useTimeName)
00369         {
00370             timeDesc = runTime.timeName();
00371         }
00372         else
00373         {
00374             timeDesc = name(runTime.timeIndex());
00375         }
00376 
00377         // Check for new polyMesh/ and update mesh, fvMeshSubset and cell
00378         // decomposition.
00379         polyMesh::readUpdateState meshState = vMesh.readUpdate();
00380 
00381         const fvMesh& mesh = vMesh.mesh();
00382 
00383         if
00384         (
00385             meshState == polyMesh::TOPO_CHANGE
00386          || meshState == polyMesh::TOPO_PATCH_CHANGE
00387         )
00388         {
00389             Info<< "    Read new mesh" << nl << endl;
00390         }
00391 
00392 
00393         // If faceSet: write faceSet only (as polydata)
00394         if (args.optionFound("faceSet"))
00395         {
00396             // Load the faceSet
00397             faceSet set(mesh, args.option("faceSet"));
00398 
00399             // Filename as if patch with same name.
00400             mkDir(fvPath/set.name());
00401 
00402             fileName patchFileName
00403             (
00404                 fvPath/set.name()/set.name()
00405               + "_"
00406               + timeDesc
00407               + ".vtk"
00408             );
00409 
00410             Info<< "    FaceSet   : " << patchFileName << endl;
00411 
00412             writeFaceSet(binary, vMesh, set, patchFileName);
00413 
00414             continue;
00415         }
00416         // If pointSet: write pointSet only (as polydata)
00417         if (args.optionFound("pointSet"))
00418         {
00419             // Load the pointSet
00420             pointSet set(mesh, args.option("pointSet"));
00421 
00422             // Filename as if patch with same name.
00423             mkDir(fvPath/set.name());
00424 
00425             fileName patchFileName
00426             (
00427                 fvPath/set.name()/set.name()
00428               + "_"
00429               + timeDesc
00430               + ".vtk"
00431             );
00432 
00433             Info<< "    pointSet   : " << patchFileName << endl;
00434 
00435             writePointSet(binary, vMesh, set, patchFileName);
00436 
00437             continue;
00438         }
00439 
00440 
00441         // Search for list of objects for this time
00442         IOobjectList objects(mesh, runTime.timeName());
00443 
00444         HashSet<word> selectedFields;
00445         if (args.optionFound("fields"))
00446         {
00447             args.optionLookup("fields")() >> selectedFields;
00448         }
00449 
00450         // Construct the vol fields (on the original mesh if subsetted)
00451 
00452         PtrList<volScalarField> vsf;
00453         readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vsf);
00454         print("    volScalarFields            :", Info, vsf);
00455 
00456         PtrList<volVectorField> vvf;
00457         readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vvf);
00458         print("    volVectorFields            :", Info, vvf);
00459 
00460         PtrList<volSphericalTensorField> vSpheretf;
00461         readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vSpheretf);
00462         print("    volSphericalTensorFields   :", Info, vSpheretf);
00463 
00464         PtrList<volSymmTensorField> vSymmtf;
00465         readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vSymmtf);
00466         print("    volSymmTensorFields        :", Info, vSymmtf);
00467 
00468         PtrList<volTensorField> vtf;
00469         readFields(vMesh, vMesh.baseMesh(), objects, selectedFields, vtf);
00470         print("    volTensorFields            :", Info, vtf);
00471 
00472         label nVolFields =
00473                 vsf.size()
00474               + vvf.size()
00475               + vSpheretf.size()
00476               + vSymmtf.size()
00477               + vtf.size();
00478 
00479 
00480         // Construct pointMesh only if nessecary since constructs edge
00481         // addressing (expensive on polyhedral meshes)
00482         if (noPointValues)
00483         {
00484             Info<< "    pointScalarFields : switched off"
00485                 << " (\"-noPointValues\" option)\n";
00486             Info<< "    pointVectorFields : switched off"
00487                 << " (\"-noPointValues\" option)\n";
00488         }
00489 
00490         PtrList<pointScalarField> psf;
00491         PtrList<pointVectorField> pvf;
00492         PtrList<pointSphericalTensorField> pSpheretf;
00493         PtrList<pointSymmTensorField> pSymmtf;
00494         PtrList<pointTensorField> ptf;
00495 
00496         if (!noPointValues)
00497         {
00498             readFields
00499             (
00500                 vMesh,
00501                 pointMesh::New(vMesh.baseMesh()),
00502                 objects,
00503                 selectedFields,
00504                 psf
00505             );
00506             print("    pointScalarFields          :", Info, psf);
00507 
00508             readFields
00509             (
00510                 vMesh,
00511                 pointMesh::New(vMesh.baseMesh()),
00512                 objects,
00513                 selectedFields,
00514                 pvf
00515             );
00516             print("    pointVectorFields          :", Info, pvf);
00517 
00518             readFields
00519             (
00520                 vMesh,
00521                 pointMesh::New(vMesh.baseMesh()),
00522                 objects,
00523                 selectedFields,
00524                 pSpheretf
00525             );
00526             print("    pointSphericalTensorFields :", Info, pSpheretf);
00527 
00528             readFields
00529             (
00530                 vMesh,
00531                 pointMesh::New(vMesh.baseMesh()),
00532                 objects,
00533                 selectedFields,
00534                 pSymmtf
00535             );
00536             print("    pointSymmTensorFields      :", Info, pSymmtf);
00537 
00538             readFields
00539             (
00540                 vMesh,
00541                 pointMesh::New(vMesh.baseMesh()),
00542                 objects,
00543                 selectedFields,
00544                 ptf
00545             );
00546             print("    pointTensorFields          :", Info, ptf);
00547         }
00548         Info<< endl;
00549 
00550         label nPointFields =
00551             psf.size()
00552           + pvf.size()
00553           + pSpheretf.size()
00554           + pSymmtf.size()
00555           + ptf.size();
00556 
00557         if (doWriteInternal)
00558         {
00559             //
00560             // Create file and write header
00561             //
00562             fileName vtkFileName
00563             (
00564                 fvPath/vtkName
00565               + "_"
00566               + timeDesc
00567               + ".vtk"
00568             );
00569 
00570             Info<< "    Internal  : " << vtkFileName << endl;
00571 
00572             // Write mesh
00573             internalWriter writer(vMesh, binary, vtkFileName);
00574 
00575             // VolFields + cellID
00576             writeFuns::writeCellDataHeader
00577             (
00578                 writer.os(),
00579                 vMesh.nFieldCells(),
00580                 1+nVolFields
00581             );
00582 
00583             // Write cellID field
00584             writer.writeCellIDs();
00585 
00586             // Write volFields
00587             writer.write(vsf);
00588             writer.write(vvf);
00589             writer.write(vSpheretf);
00590             writer.write(vSymmtf);
00591             writer.write(vtf);
00592 
00593             if (!noPointValues)
00594             {
00595                 writeFuns::writePointDataHeader
00596                 (
00597                     writer.os(),
00598                     vMesh.nFieldPoints(),
00599                     nVolFields+nPointFields
00600                 );
00601 
00602                 // pointFields
00603                 writer.write(psf);
00604                 writer.write(pvf);
00605                 writer.write(pSpheretf);
00606                 writer.write(pSymmtf);
00607                 writer.write(ptf);
00608 
00609                 // Interpolated volFields
00610                 volPointInterpolation pInterp(mesh);
00611                 writer.write(pInterp, vsf);
00612                 writer.write(pInterp, vvf);
00613                 writer.write(pInterp, vSpheretf);
00614                 writer.write(pInterp, vSymmtf);
00615                 writer.write(pInterp, vtf);
00616             }
00617         }
00618 
00619         //---------------------------------------------------------------------
00620         //
00621         // Write surface fields
00622         //
00623         //---------------------------------------------------------------------
00624 
00625         if (args.optionFound("surfaceFields"))
00626         {
00627             PtrList<surfaceScalarField> ssf;
00628             readFields
00629             (
00630                 vMesh,
00631                 vMesh.baseMesh(),
00632                 objects,
00633                 selectedFields,
00634                 ssf
00635             );
00636             print("    surfScalarFields  :", Info, ssf);
00637 
00638             PtrList<surfaceVectorField> svf;
00639             readFields
00640             (
00641                 vMesh,
00642                 vMesh.baseMesh(),
00643                 objects,
00644                 selectedFields,
00645                 svf
00646             );
00647             print("    surfVectorFields  :", Info, svf);
00648 
00649             if (ssf.size() + svf.size() > 0)
00650             {
00651                 // Rework the scalar fields into vectorfields.
00652                 label sz = svf.size();
00653 
00654                 svf.setSize(sz+ssf.size());
00655 
00656                 surfaceVectorField n(mesh.Sf()/mesh.magSf());
00657 
00658                 forAll(ssf, i)
00659                 {
00660                     svf.set(sz+i, ssf[i]*n);
00661                     svf[sz+i].rename(ssf[i].name());
00662                 }
00663                 ssf.clear();
00664 
00665                 mkDir(fvPath / "surfaceFields");
00666 
00667                 fileName surfFileName
00668                 (
00669                     fvPath
00670                    /"surfaceFields"
00671                    /"surfaceFields"
00672                    + "_"
00673                    + timeDesc
00674                    + ".vtk"
00675                 );
00676 
00677                 writeSurfFields
00678                 (
00679                     binary,
00680                     vMesh,
00681                     surfFileName,
00682                     svf
00683                 );
00684             }
00685         }
00686 
00687 
00688         //---------------------------------------------------------------------
00689         //
00690         // Write patches (POLYDATA file, one for each patch)
00691         //
00692         //---------------------------------------------------------------------
00693 
00694         const polyBoundaryMesh& patches = mesh.boundaryMesh();
00695 
00696         if (allPatches)
00697         {
00698             mkDir(fvPath/"allPatches");
00699 
00700             fileName patchFileName;
00701 
00702             if (vMesh.useSubMesh())
00703             {
00704                 patchFileName =
00705                     fvPath/"allPatches"/cellSetName
00706                   + "_"
00707                   + timeDesc
00708                   + ".vtk";
00709             }
00710             else
00711             {
00712                 patchFileName =
00713                     fvPath/"allPatches"/"allPatches"
00714                   + "_"
00715                   + timeDesc
00716                   + ".vtk";
00717             }
00718 
00719             Info<< "    Combined patches     : " << patchFileName << endl;
00720 
00721             patchWriter writer
00722             (
00723                 vMesh,
00724                 binary,
00725                 nearCellValue,
00726                 patchFileName,
00727                 getSelectedPatches(patches, excludePatches)
00728             );
00729 
00730             // VolFields + patchID
00731             writeFuns::writeCellDataHeader
00732             (
00733                 writer.os(),
00734                 writer.nFaces(),
00735                 1+nVolFields
00736             );
00737 
00738             // Write patchID field
00739             writer.writePatchIDs();
00740 
00741             // Write volFields
00742             writer.write(vsf);
00743             writer.write(vvf);
00744             writer.write(vSpheretf);
00745             writer.write(vSymmtf);
00746             writer.write(vtf);
00747 
00748             if (!noPointValues)
00749             {
00750                 writeFuns::writePointDataHeader
00751                 (
00752                     writer.os(),
00753                     writer.nPoints(),
00754                     nPointFields
00755                 );
00756 
00757                 // Write pointFields
00758                 writer.write(psf);
00759                 writer.write(pvf);
00760                 writer.write(pSpheretf);
00761                 writer.write(pSymmtf);
00762                 writer.write(ptf);
00763 
00764                 // no interpolated volFields since I cannot be bothered to
00765                 // create the patchInterpolation for all subpatches.
00766             }
00767         }
00768         else
00769         {
00770             forAll(patches, patchI)
00771             {
00772                 const polyPatch& pp = patches[patchI];
00773 
00774                 if (!excludePatches.found(pp.name()))
00775                 {
00776                     mkDir(fvPath/pp.name());
00777 
00778                     fileName patchFileName;
00779 
00780                     if (vMesh.useSubMesh())
00781                     {
00782                         patchFileName =
00783                             fvPath/pp.name()/cellSetName
00784                           + "_"
00785                           + timeDesc
00786                           + ".vtk";
00787                     }
00788                     else
00789                     {
00790                         patchFileName =
00791                             fvPath/pp.name()/pp.name()
00792                           + "_"
00793                           + timeDesc
00794                           + ".vtk";
00795                     }
00796 
00797                     Info<< "    Patch     : " << patchFileName << endl;
00798 
00799                     patchWriter writer
00800                     (
00801                         vMesh,
00802                         binary,
00803                         nearCellValue,
00804                         patchFileName,
00805                         labelList(1, patchI)
00806                     );
00807 
00808                     if (!isType<emptyPolyPatch>(pp))
00809                     {
00810                         // VolFields + patchID
00811                         writeFuns::writeCellDataHeader
00812                         (
00813                             writer.os(),
00814                             writer.nFaces(),
00815                             1+nVolFields
00816                         );
00817 
00818                         // Write patchID field
00819                         writer.writePatchIDs();
00820 
00821                         // Write volFields
00822                         writer.write(vsf);
00823                         writer.write(vvf);
00824                         writer.write(vSpheretf);
00825                         writer.write(vSymmtf);
00826                         writer.write(vtf);
00827 
00828                         if (!noPointValues)
00829                         {
00830                             writeFuns::writePointDataHeader
00831                             (
00832                                 writer.os(),
00833                                 writer.nPoints(),
00834                                 nVolFields
00835                               + nPointFields
00836                             );
00837 
00838                             // Write pointFields
00839                             writer.write(psf);
00840                             writer.write(pvf);
00841                             writer.write(pSpheretf);
00842                             writer.write(pSymmtf);
00843                             writer.write(ptf);
00844 
00845                             PrimitivePatchInterpolation<primitivePatch> pInter
00846                             (
00847                                 pp
00848                             );
00849 
00850                             // Write interpolated volFields
00851                             writer.write(pInter, vsf);
00852                             writer.write(pInter, vvf);
00853                             writer.write(pInter, vSpheretf);
00854                             writer.write(pInter, vSymmtf);
00855                             writer.write(pInter, vtf);
00856                         }
00857                     }
00858                 }
00859             }
00860         }
00861 
00862         //---------------------------------------------------------------------
00863         //
00864         // Write faceZones (POLYDATA file, one for each zone)
00865         //
00866         //---------------------------------------------------------------------
00867 
00868         if (doFaceZones)
00869         {
00870             const faceZoneMesh& zones = mesh.faceZones();
00871 
00872             forAll(zones, zoneI)
00873             {
00874                 const faceZone& pp = zones[zoneI];
00875 
00876                 mkDir(fvPath/pp.name());
00877 
00878                 fileName patchFileName;
00879 
00880                 if (vMesh.useSubMesh())
00881                 {
00882                     patchFileName =
00883                         fvPath/pp.name()/cellSetName
00884                       + "_"
00885                       + timeDesc
00886                       + ".vtk";
00887                 }
00888                 else
00889                 {
00890                     patchFileName =
00891                         fvPath/pp.name()/pp.name()
00892                       + "_"
00893                       + timeDesc
00894                       + ".vtk";
00895                 }
00896 
00897                 Info<< "    FaceZone  : " << patchFileName << endl;
00898 
00899                 std::ofstream str(patchFileName.c_str());
00900 
00901                 writeFuns::writeHeader(str, binary, pp.name());
00902                 str << "DATASET POLYDATA" << std::endl;
00903 
00904                 writePatchGeom
00905                 (
00906                     binary,
00907                     pp().localFaces(),
00908                     pp().localPoints(),
00909                     str
00910                 );
00911             }
00912         }
00913 
00914 
00915 
00916         //---------------------------------------------------------------------
00917         //
00918         // Write lagrangian data
00919         //
00920         //---------------------------------------------------------------------
00921 
00922         fileNameList cloudDirs
00923         (
00924             readDir
00925             (
00926                 runTime.timePath()/regionPrefix/cloud::prefix,
00927                 fileName::DIRECTORY
00928             )
00929         );
00930 
00931         forAll(cloudDirs, i)
00932         {
00933             IOobjectList sprayObjs
00934             (
00935                 mesh,
00936                 runTime.timeName(),
00937                 cloud::prefix/cloudDirs[i]
00938             );
00939 
00940             IOobject* positionsPtr = sprayObjs.lookup("positions");
00941 
00942             if (positionsPtr)
00943             {
00944                 mkDir(fvPath/cloud::prefix/cloudDirs[i]);
00945 
00946                 fileName lagrFileName
00947                 (
00948                     fvPath/cloud::prefix/cloudDirs[i]/cloudDirs[i]
00949                   + "_" + timeDesc + ".vtk"
00950                 );
00951 
00952                 Info<< "    Lagrangian: " << lagrFileName << endl;
00953 
00954                 wordList labelNames(sprayObjs.names(labelIOField::typeName));
00955                 Info<< "        labels            :";
00956                 print(Info, labelNames);
00957 
00958                 wordList scalarNames(sprayObjs.names(scalarIOField::typeName));
00959                 Info<< "        scalars           :";
00960                 print(Info, scalarNames);
00961 
00962                 wordList vectorNames(sprayObjs.names(vectorIOField::typeName));
00963                 Info<< "        vectors           :";
00964                 print(Info, vectorNames);
00965 
00966                 wordList sphereNames
00967                 (
00968                     sprayObjs.names
00969                     (
00970                         sphericalTensorIOField::typeName
00971                     )
00972                 );
00973                 Info<< "        spherical tensors :";
00974                 print(Info, sphereNames);
00975 
00976                 wordList symmNames
00977                 (
00978                     sprayObjs.names
00979                     (
00980                         symmTensorIOField::typeName
00981                     )
00982                 );
00983                 Info<< "        symm tensors      :";
00984                 print(Info, symmNames);
00985 
00986                 wordList tensorNames(sprayObjs.names(tensorIOField::typeName));
00987                 Info<< "        tensors           :";
00988                 print(Info, tensorNames);
00989 
00990                 lagrangianWriter writer
00991                 (
00992                     vMesh,
00993                     binary,
00994                     lagrFileName,
00995                     cloudDirs[i]
00996                 );
00997 
00998                 // Write number of fields
00999                 writer.writeParcelHeader
01000                 (
01001                     labelNames.size()
01002                 + scalarNames.size()
01003                 + vectorNames.size()
01004                 + sphereNames.size()
01005                 + symmNames.size()
01006                 + tensorNames.size()
01007                 );
01008 
01009                 // Fields
01010                 writer.writeIOField<label>(labelNames);
01011                 writer.writeIOField<scalar>(scalarNames);
01012                 writer.writeIOField<vector>(vectorNames);
01013                 writer.writeIOField<vector>(sphereNames);
01014                 writer.writeIOField<vector>(symmNames);
01015                 writer.writeIOField<vector>(tensorNames);
01016             }
01017         }
01018     }
01019 
01020 
01021     //---------------------------------------------------------------------
01022     //
01023     // Link parallel outputs back to undecomposed case for ease of loading
01024     //
01025     //---------------------------------------------------------------------
01026 
01027     if (Pstream::parRun() && doLinks)
01028     {
01029         mkDir(runTime.path()/".."/"VTK");
01030         chDir(runTime.path()/".."/"VTK");
01031 
01032         Info<< "Linking all processor files to " << runTime.path()/".."/"VTK"
01033             << endl;
01034 
01035         // Get list of vtk files
01036         fileName procVTK
01037         (
01038             fileName("..")
01039            /"processor" + name(Pstream::myProcNo())
01040            /"VTK"
01041         );
01042 
01043         fileNameList dirs(readDir(procVTK, fileName::DIRECTORY));
01044         label sz = dirs.size();
01045         dirs.setSize(sz+1);
01046         dirs[sz] = ".";
01047 
01048         forAll(dirs, i)
01049         {
01050             fileNameList subFiles(readDir(procVTK/dirs[i], fileName::FILE));
01051 
01052             forAll(subFiles, j)
01053             {
01054                 fileName procFile(procVTK/dirs[i]/subFiles[j]);
01055 
01056                 if (exists(procFile))
01057                 {
01058                     string cmd
01059                     (
01060                         "ln -s "
01061                       + procFile
01062                       + " "
01063                       + "processor"
01064                       + name(Pstream::myProcNo())
01065                       + "_"
01066                       + procFile.name()
01067                     );
01068                     system(cmd.c_str());
01069                 }
01070             }
01071         }
01072     }
01073 
01074     Info<< "End\n" << endl;
01075 
01076     return 0;
01077 }
01078 
01079 
01080 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd