initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / sampling / sampledSet / writers / writer / writer.C
blobb16cbd214f9f70511af3a1cd70e4e77977854e51
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 \*---------------------------------------------------------------------------*/
27 #include "writer.H"
28 #include "coordSet.H"
29 #include "OFstream.H"
30 #include "OSspecific.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 template<class Type>
35 Foam::autoPtr<Foam::writer<Type> > Foam::writer<Type>::New
37     const word& writeType
40     typename wordConstructorTable::iterator cstrIter =
41         wordConstructorTablePtr_
42             ->find(writeType);
44     if (cstrIter == wordConstructorTablePtr_->end())
45     {
46         FatalErrorIn
47         (
48             "writer::New(const word&)"
49         )   << "Unknown write type " << writeType
50             << endl << endl
51             << "Valid write types : " << endl
52             << wordConstructorTablePtr_->toc()
53             << exit(FatalError);
54     }
56     return autoPtr<writer<Type> >(cstrIter()());
60 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
62 template<class Type>
63 Foam::fileName Foam::writer<Type>::getBaseName
65     const coordSet& points,
66     const wordList& valueSets
67 ) const
69     fileName fName(points.name());
71     forAll(valueSets, i)
72     {
73         fName += '_' + valueSets[i];
74     }
76     return fName;
80 template<class Type>
81 void Foam::writer<Type>::writeCoord
83     const coordSet& points,
84     const label pointI,
85     Ostream& os
86 ) const
88     if (points.hasVectorAxis())
89     {
90         write(points.vectorCoord(pointI), os);
91     }
92     else
93     {
94         write(points.scalarCoord(pointI), os);
95     }
99 template<class Type>
100 void Foam::writer<Type>::writeTable
102     const coordSet& points,
103     const List<Type>& values,
104     Ostream& os
105 ) const
107     forAll(points, pointI)
108     {
109         writeCoord(points, pointI, os);
111         os << token::SPACE;
112         write(values[pointI], os);
113         os << endl;
114     }
118 template<class Type>
119 void Foam::writer<Type>::writeTable
121     const coordSet& points,
122     const List<const List<Type>*>& valuesPtrList,
123     Ostream& os
124 ) const
126     forAll(points, pointI)
127     {
128         writeCoord(points, pointI, os);
130         forAll(valuesPtrList, i)
131         {
132             os << token::SPACE;
133             const List<Type>& values = *valuesPtrList[i];
134             write(values[pointI], os);
135         }
136         os << endl;
137     }
141 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
143 template<class Type>
144 Foam::writer<Type>::writer()
148 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
150 template<class Type>
151 Foam::writer<Type>::~writer()
155 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
157 template<class Type>
158 Foam::Ostream& Foam::writer<Type>::write
160     const scalar value,
161     Ostream& os
162 ) const
164     return os << value;
168 template<class Type>
169 template<class VSType>
170 Foam::Ostream& Foam::writer<Type>::writeVS
172     const VSType& value,
173     Ostream& os
174 ) const
176     for (direction d=0; d<VSType::nComponents; d++)
177     {
178         os << value.component(d);
180         if (d <= VSType::nComponents-1)
181         {
182             os << token::TAB;
183         }
184     }
185     return os;
189 template<class Type>
190 Foam::Ostream& Foam::writer<Type>::write
192     const vector& value,
193     Ostream& os
194 ) const
196     return writeVS(value, os);
200 template<class Type>
201 Foam::Ostream& Foam::writer<Type>::write
203     const sphericalTensor& value,
204     Ostream& os
205 ) const
207     return writeVS(value, os);
211 template<class Type>
212 Foam::Ostream& Foam::writer<Type>::write
214     const symmTensor& value,
215     Ostream& os
216 ) const
218     return writeVS(value, os);
222 template<class Type>
223 Foam::Ostream& Foam::writer<Type>::write
225     const tensor& value,
226     Ostream& os
227 ) const
229     return writeVS(value, os);
233 // ************************************************************************* //