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

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