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

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-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 "foamFileSurfaceWriter.H"
00028 
00029 #include "OFstream.H"
00030 #include "OSspecific.H"
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 template<class Type>
00035 Foam::foamFileSurfaceWriter<Type>::foamFileSurfaceWriter()
00036 :
00037     surfaceWriter<Type>()
00038 {}
00039 
00040 
00041 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00042 
00043 template<class Type>
00044 Foam::foamFileSurfaceWriter<Type>::~foamFileSurfaceWriter()
00045 {}
00046 
00047 
00048 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00049 
00050 template<class Type>
00051 void Foam::foamFileSurfaceWriter<Type>::write
00052 (
00053     const fileName& outputDir,
00054     const fileName& surfaceName,
00055     const pointField& points,
00056     const faceList& faces,
00057     const bool verbose
00058 ) const
00059 {
00060     fileName surfaceDir(outputDir/surfaceName);
00061 
00062     if (!isDir(surfaceDir))
00063     {
00064         mkDir(surfaceDir);
00065     }
00066 
00067     if (verbose)
00068     {
00069         Info<< "Writing geometry to " << surfaceDir << endl;
00070     }
00071 
00072     // Points
00073     OFstream(surfaceDir/"points")() << points;
00074 
00075     // Faces
00076     OFstream(surfaceDir/"faces")() << faces;
00077 }
00078 
00079 
00080 template<class Type>
00081 void Foam::foamFileSurfaceWriter<Type>::write
00082 (
00083     const fileName& outputDir,
00084     const fileName& surfaceName,
00085     const pointField& points,
00086     const faceList& faces,
00087     const fileName& fieldName,
00088     const Field<Type>& values,
00089     const bool verbose
00090 ) const
00091 {
00092     fileName surfaceDir(outputDir/surfaceName);
00093 
00094     if (!isDir(surfaceDir))
00095     {
00096         mkDir(surfaceDir);
00097     }
00098 
00099     if (verbose)
00100     {
00101         Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
00102     }
00103 
00104     // geometry should already have been written
00105 
00106     // Values to separate directory (e.g. "scalarField/p")
00107 
00108     fileName foamName(pTraits<Type>::typeName);
00109     fileName valuesDir(surfaceDir  / (foamName + Field<Type>::typeName));
00110 
00111     if (!isDir(valuesDir))
00112     {
00113         mkDir(valuesDir);
00114     }
00115 
00116     // values
00117     OFstream(valuesDir/fieldName)() << values;
00118 }
00119 
00120 
00121 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd