initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / sampling / sampledSet / writers / writer / writer.H
blob73fe2fd10fa8f95d181c0400bc03ad221a1cc5b3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::writer
28 Description
29     Base class for graphics format writing. Entry points are
30     - write(..). \n
31       Write to an Ostream a table of points with corresponding values.
32     - write(scalar/vector/sphericalTensor/symmTensor/tensor). \n
33       Write single scalar/vector/sphericalTensor/symmTensor/tensor.
34       Default is to write space separated components.
36     Example:
37     @verbatim
38         // Construct writer of xmgr type
39         autoPtr<writer<scalar> > scalarFormatter(writer<scalar>::New("xmgr"));
41         // Output list of points and corresponding values
42         scalarFormatter().write
43         (
44             coordSet
45             (
46                 points,         // sample coordinates
47                 "someLine",     // name of coordSet
48                 "distance",     // write coordinates as distance to refPoint
49                 points[0]       // reference point
50             ),
51             "U.component(0)",   // name of values
52             vals                // values
53         );
54     @endverbatim
56 SourceFiles
57     writer.C
59 \*---------------------------------------------------------------------------*/
61 #ifndef writer_H
62 #define writer_H
64 #include "fileName.H"
65 #include "wordList.H"
66 #include "vector.H"
67 #include "tensor.H"
68 #include "typeInfo.H"
69 #include "runTimeSelectionTables.H"
70 #include "autoPtr.H"
71 #include "Field.H"
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
75 namespace Foam
78 // Forward declaration of classes
79 class coordSet;
81 /*---------------------------------------------------------------------------*\
82                            Class writer Declaration
83 \*---------------------------------------------------------------------------*/
85 template<class Type>
86 class writer
89 protected:
91     //- Generates filename from coordSet and sampled fields
92     fileName getBaseName(const coordSet&, const wordList&) const;
94     void writeCoord
95     (
96         const coordSet& samples,
97         const label sampleI,
98         Ostream& os
99     ) const;
101     //- Writes single-column ascii write. Column 1 is coordSet coordinate,
102     //  columns 2 is the value. Uses write() function
103     //  to write coordinate in correct format.
104     void writeTable
105     (
106         const coordSet&,
107         const List<Type>&,
108         Ostream& os
109     ) const;
111     //- Writes multi-column ascii write. Column 1 is coordSet coordinate,
112     //  columns 2..n are the values. Uses write() function
113     //  to write coordinate in correct format.
114     void writeTable
115     (
116         const coordSet&,
117         const List<const List<Type>*>&,
118         Ostream& os
119     ) const;
122 public:
124     //- Runtime type information
125     TypeName("writer");
127     // Declare run-time constructor selection table
129         declareRunTimeSelectionTable
130         (
131             autoPtr,
132             writer,
133             word,
134             (),
135             ()
136         );
139     // Selectors
141         //- Return a reference to the selected writer
142         static autoPtr<writer> New
143         (
144             const word& writeFormat
145         );
148     // Constructors
150         //- Construct null
151         writer();
154     //- Destructor
155     virtual ~writer() = 0;
158     // Member Functions
160         //- Generate file name with correct extension
161         virtual fileName getFileName
162         (
163             const coordSet&,
164             const wordList&
165         ) const = 0;
167         //- General entry point for writing.
168         //  The data is organized in a set of point with one or
169         //  more values per point
170         virtual void write
171         (
172             const coordSet&,
173             const wordList&,
174             const List<const Field<Type>*>&,
175             Ostream&
176         ) const = 0;
178         //- Write scalar as ascii
179         virtual Ostream& write(const scalar, Ostream&) const;
181         template<class VSType>
182         Ostream& writeVS(const VSType& value, Ostream& os) const;
184         //- Write vector. Tab separated ascii
185         virtual Ostream& write(const vector&, Ostream&) const;
187         //- Write sphericalTensor. Tab separated ascii
188         virtual Ostream& write(const sphericalTensor&, Ostream&) const;
190         //- Write symmTensor. Tab separated ascii
191         virtual Ostream& write(const symmTensor&, Ostream&) const;
193         //- Write tensor. Tab separated ascii
194         virtual Ostream& write(const tensor&, Ostream&) const;
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 } // End namespace Foam
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 #ifdef NoRepository
205 #   include "writer.C"
206 #endif
208 // Only used internally
209 #define makeTypeWritersTypeName(type)                                         \
210                                                                               \
211 defineNamedTemplateTypeNameAndDebug(type, 0);
213 // Used externally sometimes
214 #define makeWritersTypeName(typeWriter)                                       \
215                                                                               \
216 makeTypeWritersTypeName(typeWriter##ScalarWriter);                            \
217 makeTypeWritersTypeName(typeWriter##VectorWriter);                            \
218 makeTypeWritersTypeName(typeWriter##SphericalTensorWriter);                   \
219 makeTypeWritersTypeName(typeWriter##SymmTensorWriter);                        \
220 makeTypeWritersTypeName(typeWriter##TensorWriter);
222 // Define type info for single template instantiation (e.g. vector)
223 #define makeWriterTypes(WriterType, type)                                     \
224                                                                               \
225 defineNamedTemplateTypeNameAndDebug(type, 0);                                 \
226                                                                               \
227 addToRunTimeSelectionTable                                                    \
228 (                                                                             \
229     WriterType, type, word                                                    \
233 // Define type info info for scalar, vector etc. instantiations
234 #define makeWriters(typeWriter)                                               \
235                                                                               \
236 makeWriterTypes(writerScalarWriter, typeWriter##ScalarWriter);                \
237 makeWriterTypes(writerVectorWriter, typeWriter##VectorWriter);                \
238 makeWriterTypes(writerSphericalTensorWriter, typeWriter##SphericalTensorWriter);\
239 makeWriterTypes(writerSymmTensorWriter, typeWriter##SymmTensorWriter);        \
240 makeWriterTypes(writerTensorWriter, typeWriter##TensorWriter);
243 #define makeWritersTypedefs(typeWriter)                                       \
244                                                                               \
245 typedef typeWriter<scalar> typeWriter##ScalarWriter;                          \
246 typedef typeWriter<vector> typeWriter##VectorWriter;                          \
247 typedef typeWriter<sphericalTensor> typeWriter##SphericalTensorWriter;        \
248 typedef typeWriter<symmTensor> typeWriter##SymmTensorWriter;                  \
249 typedef typeWriter<tensor> typeWriter##TensorWriter;
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 #endif
256 // ************************************************************************* //