Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / sampling / sampledSet / writers / writer.C
blobb2286998b47719a8816e002c4c2a19528d2ee990
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2011 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "writer.H"
27 #include "coordSet.H"
28 #include "OFstream.H"
29 #include "OSspecific.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 template<class Type>
34 Foam::autoPtr< Foam::writer<Type> > Foam::writer<Type>::New
36     const word& writeType
39     typename wordConstructorTable::iterator cstrIter =
40         wordConstructorTablePtr_->find(writeType);
42     if (cstrIter == wordConstructorTablePtr_->end())
43     {
44         FatalErrorIn
45         (
46             "writer::New(const word&)"
47         )   << "Unknown write type "
48             << writeType << nl << nl
49             << "Valid write types : " << endl
50             << wordConstructorTablePtr_->sortedToc()
51             << exit(FatalError);
52     }
54     return autoPtr<writer<Type> >(cstrIter()());
58 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
60 template<class Type>
61 Foam::fileName Foam::writer<Type>::getBaseName
63     const coordSet& points,
64     const wordList& valueSets
65 ) const
67     fileName fName(points.name());
69     forAll(valueSets, i)
70     {
71         fName += '_' + valueSets[i];
72     }
74     return fName;
78 template<class Type>
79 void Foam::writer<Type>::writeCoord
81     const coordSet& points,
82     const label pointI,
83     Ostream& os
84 ) const
86     if (points.hasVectorAxis())
87     {
88         write(points.vectorCoord(pointI), os);
89     }
90     else
91     {
92         write(points.scalarCoord(pointI), os);
93     }
97 template<class Type>
98 void Foam::writer<Type>::writeTable
100     const coordSet& points,
101     const List<Type>& values,
102     Ostream& os
103 ) const
105     forAll(points, pointI)
106     {
107         writeCoord(points, pointI, os);
108         writeSeparator(os);
109         write(values[pointI], os);
110         os << nl;
111     }
115 template<class Type>
116 void Foam::writer<Type>::writeTable
118     const coordSet& points,
119     const List<const List<Type>*>& valuesPtrList,
120     Ostream& os
121 ) const
123     forAll(points, pointI)
124     {
125         writeCoord(points, pointI, os);
127         forAll(valuesPtrList, i)
128         {
129             writeSeparator(os);
131             const List<Type>& values = *valuesPtrList[i];
132             write(values[pointI], os);
133         }
134         os << nl;
135     }
139 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
141 template<class Type>
142 Foam::writer<Type>::writer()
146 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
148 template<class Type>
149 Foam::writer<Type>::~writer()
153 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
155 template<class Type>
156 Foam::Ostream& Foam::writer<Type>::write
158     const scalar value,
159     Ostream& os
160 ) const
162     return os << value;
166 template<class Type>
167 template<class VSType>
168 Foam::Ostream& Foam::writer<Type>::writeVS
170     const VSType& value,
171     Ostream& os
172 ) const
174     for (direction d=0; d<VSType::nComponents; d++)
175     {
176         if (d > 0)
177         {
178             writeSeparator(os);
179         }
181         os << value.component(d);
182     }
183     return os;
187 template<class Type>
188 void Foam::writer<Type>::writeSeparator
190     Ostream& os
191 ) const
193     os << token::SPACE << token::TAB;
197 template<class Type>
198 Foam::Ostream& Foam::writer<Type>::write
200     const vector& value,
201     Ostream& os
202 ) const
204     return writeVS(value, os);
208 template<class Type>
209 Foam::Ostream& Foam::writer<Type>::write
211     const sphericalTensor& value,
212     Ostream& os
213 ) const
215     return writeVS(value, os);
219 template<class Type>
220 Foam::Ostream& Foam::writer<Type>::write
222     const symmTensor& value,
223     Ostream& os
224 ) const
226     return writeVS(value, os);
230 template<class Type>
231 Foam::Ostream& Foam::writer<Type>::write
233     const tensor& value,
234     Ostream& os
235 ) const
237     return writeVS(value, os);
241 // ************************************************************************* //