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

foamFileSurfaceWriter.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 "foamFileSurfaceWriter.H"
00027 
00028 #include <OpenFOAM/OFstream.H>
00029 #include <OpenFOAM/OSspecific.H>
00030 
00031 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00032 
00033 template<class Type>
00034 Foam::foamFileSurfaceWriter<Type>::foamFileSurfaceWriter()
00035 :
00036     surfaceWriter<Type>()
00037 {}
00038 
00039 
00040 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00041 
00042 template<class Type>
00043 Foam::foamFileSurfaceWriter<Type>::~foamFileSurfaceWriter()
00044 {}
00045 
00046 
00047 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00048 
00049 template<class Type>
00050 void Foam::foamFileSurfaceWriter<Type>::write
00051 (
00052     const fileName& outputDir,
00053     const fileName& surfaceName,
00054     const pointField& points,
00055     const faceList& faces,
00056     const bool verbose
00057 ) const
00058 {
00059     fileName surfaceDir(outputDir/surfaceName);
00060 
00061     if (!isDir(surfaceDir))
00062     {
00063         mkDir(surfaceDir);
00064     }
00065 
00066     if (verbose)
00067     {
00068         Info<< "Writing geometry to " << surfaceDir << endl;
00069     }
00070 
00071     // Points
00072     OFstream(surfaceDir/"points")() << points;
00073 
00074     // Faces
00075     OFstream(surfaceDir/"faces")() << faces;
00076 
00077     // Face centers. Not really necessary but very handy when reusing as inputs
00078     // for e.g. timeVaryingMapped bc.
00079     pointField faceCentres(faces.size(),point::zero);
00080 
00081     forAll (faces, faceI)
00082     {
00083         faceCentres[faceI] = faces[faceI].centre(points);
00084     }
00085 
00086     OFstream(surfaceDir/"faceCentres")() << faceCentres;
00087 }
00088 
00089 
00090 template<class Type>
00091 void Foam::foamFileSurfaceWriter<Type>::write
00092 (
00093     const fileName& outputDir,
00094     const fileName& surfaceName,
00095     const pointField& points,
00096     const faceList& faces,
00097     const fileName& fieldName,
00098     const Field<Type>& values,
00099     const bool verbose
00100 ) const
00101 {
00102     fileName surfaceDir(outputDir/surfaceName);
00103 
00104     if (!isDir(surfaceDir))
00105     {
00106         mkDir(surfaceDir);
00107     }
00108 
00109     if (verbose)
00110     {
00111         Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
00112     }
00113 
00114     // geometry should already have been written
00115 
00116     // Values to separate directory (e.g. "scalarField/p")
00117 
00118     fileName foamName(pTraits<Type>::typeName);
00119     fileName valuesDir(surfaceDir  / (foamName + Field<Type>::typeName));
00120 
00121     if (!isDir(valuesDir))
00122     {
00123         mkDir(valuesDir);
00124     }
00125 
00126     // values
00127     OFstream(valuesDir/fieldName)() << values;
00128 }
00129 
00130 
00131 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines