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

writer.H

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 Class
00026     Foam::writer
00027 
00028 Description
00029     Base class for graphics format writing. Entry points are
00030     - write(..). \n
00031       Write to an Ostream a table of points with corresponding values.
00032     - write(scalar/vector/sphericalTensor/symmTensor/tensor). \n
00033       Write single scalar/vector/sphericalTensor/symmTensor/tensor.
00034       Default is to write space separated components.
00035 
00036     Example:
00037     @verbatim
00038         // Construct writer of xmgr type
00039         autoPtr<writer<scalar> > scalarFormatter(writer<scalar>::New("xmgr"));
00040 
00041         // Output list of points and corresponding values
00042         scalarFormatter().write
00043         (
00044             coordSet
00045             (
00046                 points,         // sample coordinates
00047                 "someLine",     // name of coordSet
00048                 "distance",     // write coordinates as distance to refPoint
00049                 points[0]       // reference point
00050             ),
00051             "U.component(0)",   // name of values
00052             vals                // values
00053         );
00054     @endverbatim
00055 
00056 SourceFiles
00057     writer.C
00058 
00059 \*---------------------------------------------------------------------------*/
00060 
00061 #ifndef writer_H
00062 #define writer_H
00063 
00064 #include "fileName.H"
00065 #include "wordList.H"
00066 #include "vector.H"
00067 #include "tensor.H"
00068 #include "typeInfo.H"
00069 #include "runTimeSelectionTables.H"
00070 #include "autoPtr.H"
00071 #include "Field.H"
00072 
00073 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00074 
00075 namespace Foam
00076 {
00077 
00078 // Forward declaration of classes
00079 class coordSet;
00080 
00081 /*---------------------------------------------------------------------------*\
00082                            Class writer Declaration
00083 \*---------------------------------------------------------------------------*/
00084 
00085 template<class Type>
00086 class writer
00087 {
00088 
00089 protected:
00090 
00091     //- Generates filename from coordSet and sampled fields
00092     fileName getBaseName(const coordSet&, const wordList&) const;
00093 
00094     void writeCoord(const coordSet&, const label sampleI, Ostream&) const;
00095 
00096     //- Writes single-column ascii write. Column 1 is coordSet coordinate,
00097     //  columns 2 is the value. Uses write() function
00098     //  to write coordinate in correct format.
00099     void writeTable(const coordSet&, const List<Type>&, Ostream&) const;
00100 
00101     //- Writes multi-column ascii write. Column 1 is coordSet coordinate,
00102     //  columns 2..n are the values. Uses write() function
00103     //  to write coordinate in correct format.
00104     void writeTable
00105     (
00106         const coordSet&,
00107         const List<const List<Type>*>&,
00108         Ostream& os
00109     ) const;
00110 
00111 
00112 public:
00113 
00114     //- Runtime type information
00115     TypeName("writer");
00116 
00117     // Declare run-time constructor selection table
00118 
00119         declareRunTimeSelectionTable
00120         (
00121             autoPtr,
00122             writer,
00123             word,
00124             (),
00125             ()
00126         );
00127 
00128 
00129     // Selectors
00130 
00131         //- Return a reference to the selected writer
00132         static autoPtr<writer> New(const word& writeFormat);
00133 
00134 
00135     // Constructors
00136 
00137         //- Construct null
00138         writer();
00139 
00140 
00141     //- Destructor
00142     virtual ~writer() = 0;
00143 
00144 
00145     // Member Functions
00146 
00147         //- Generate file name with correct extension
00148         virtual fileName getFileName
00149         (
00150             const coordSet&,
00151             const wordList&
00152         ) const = 0;
00153 
00154         //- General entry point for writing.
00155         //  The data is organized in a set of point with one or more values
00156         //  per point
00157         virtual void write
00158         (
00159             const coordSet&,
00160             const wordList&,
00161             const List<const Field<Type>*>&,
00162             Ostream&
00163         ) const = 0;
00164 
00165         //- Write scalar as ascii
00166         virtual Ostream& write(const scalar, Ostream&) const;
00167 
00168         template<class VSType>
00169         Ostream& writeVS(const VSType&, Ostream&) const;
00170 
00171         //- Write vector. Tab separated ascii
00172         virtual Ostream& write(const vector&, Ostream&) const;
00173 
00174         //- Write sphericalTensor. Tab separated ascii
00175         virtual Ostream& write(const sphericalTensor&, Ostream&) const;
00176 
00177         //- Write symmTensor. Tab separated ascii
00178         virtual Ostream& write(const symmTensor&, Ostream&) const;
00179 
00180         //- Write tensor. Tab separated ascii
00181         virtual Ostream& write(const tensor&, Ostream&) const;
00182 };
00183 
00184 
00185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00186 
00187 } // End namespace Foam
00188 
00189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00190 
00191 #ifdef NoRepository
00192 #   include "writer.C"
00193 #endif
00194 
00195 
00196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00197 
00198 #endif
00199 
00200 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd