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

writeSurfFields.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "writeSurfFields.H"
00028 #include "OFstream.H"
00029 #include "floatScalar.H"
00030 #include "writeFuns.H"
00031 #include "emptyFvsPatchFields.H"
00032 #include "fvsPatchFields.H"
00033 
00034 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038 
00039 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00040 
00041 void writeSurfFields
00042 (
00043     const bool binary,
00044     const vtkMesh& vMesh,
00045     const fileName& fileName,
00046     const PtrList<surfaceVectorField>& surfVectorFields
00047 )
00048 {
00049     const fvMesh& mesh = vMesh.mesh();
00050 
00051     std::ofstream str(fileName.c_str());
00052 
00053     str << "# vtk DataFile Version 2.0" << std::endl
00054         << "surfaceFields" << std::endl;
00055 
00056     if (binary)
00057     {
00058         str << "BINARY" << std::endl;
00059     }
00060     else
00061     {
00062         str << "ASCII" << std::endl;
00063     }
00064     str << "DATASET POLYDATA" << std::endl;
00065 
00066     const pointField& fc = mesh.faceCentres();
00067 
00068     str << "POINTS " << mesh.nFaces() << " float" << std::endl;
00069 
00070     DynamicList<floatScalar> pField(3*mesh.nFaces());
00071 
00072     for (label faceI = 0; faceI < mesh.nFaces(); faceI++)
00073     {
00074         writeFuns::insert(fc[faceI], pField);   
00075     }
00076 
00077     writeFuns::write(str, binary, pField);
00078 
00079     str << "POINT_DATA " << mesh.nFaces() << std::endl
00080         << "FIELD attributes " << surfVectorFields.size() << std::endl;
00081 
00082     // surfVectorFields
00083     forAll(surfVectorFields, fieldI)
00084     {
00085         const surfaceVectorField& svf = surfVectorFields[fieldI];
00086 
00087         str << svf.name() << " 3 "
00088             << mesh.nFaces() << " float" << std::endl;
00089 
00090         DynamicList<floatScalar> fField(3*mesh.nFaces());
00091 
00092         for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
00093         {
00094             writeFuns::insert(svf[faceI], fField);
00095         }
00096 
00097         forAll(svf.boundaryField(), patchI)
00098         {
00099             const fvsPatchVectorField& pf = svf.boundaryField()[patchI];
00100 
00101             const fvPatch& pp = mesh.boundary()[patchI];
00102 
00103             if (isA<emptyFvsPatchVectorField>(pf))
00104             {
00105                 // Note: loop over polypatch size, not fvpatch size.
00106                 forAll(pp.patch(), i)
00107                 {
00108                     writeFuns::insert(vector::zero, fField);
00109                 }
00110             }
00111             else
00112             {
00113                 forAll(pf, i)
00114                 {
00115                     writeFuns::insert(pf[i], fField);
00116                 }
00117             }
00118         }
00119 
00120         writeFuns::write(str, binary, fField);
00121     }
00122 }
00123 
00124 
00125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00126 
00127 } // End namespace Foam
00128 
00129 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd