FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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