ENH: RASModel.C: clipping input to log
[OpenFOAM-1.7.x.git] / src / sampling / sampledSet / writers / writer.C
blob45cd8502f784af2d827c54beaf59e16e361a8891
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-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_
41             ->find(writeType);
43     if (cstrIter == wordConstructorTablePtr_->end())
44     {
45         FatalErrorIn
46         (
47             "writer::New(const word&)"
48         )   << "Unknown write type " << writeType
49             << nl << nl
50             << "Valid write types : " << nl
51             << wordConstructorTablePtr_->sortedToc()
52             << exit(FatalError);
53     }
55     return autoPtr<writer<Type> >(cstrIter()());
59 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
61 template<class Type>
62 Foam::fileName Foam::writer<Type>::getBaseName
64     const coordSet& points,
65     const wordList& valueSets
66 ) const
68     fileName fName(points.name());
70     forAll(valueSets, i)
71     {
72         fName += '_' + valueSets[i];
73     }
75     return fName;
79 template<class Type>
80 void Foam::writer<Type>::writeCoord
82     const coordSet& points,
83     const label pointI,
84     Ostream& os
85 ) const
87     if (points.hasVectorAxis())
88     {
89         write(points.vectorCoord(pointI), os);
90     }
91     else
92     {
93         write(points.scalarCoord(pointI), os);
94     }
98 template<class Type>
99 void Foam::writer<Type>::writeTable
101     const coordSet& points,
102     const List<Type>& values,
103     Ostream& os
104 ) const
106     forAll(points, pointI)
107     {
108         writeCoord(points, pointI, os);
109         writeSeparator(os);
110         write(values[pointI], os);
111         os << nl;
112     }
116 template<class Type>
117 void Foam::writer<Type>::writeTable
119     const coordSet& points,
120     const List<const List<Type>*>& valuesPtrList,
121     Ostream& os
122 ) const
124     forAll(points, pointI)
125     {
126         writeCoord(points, pointI, os);
128         forAll(valuesPtrList, i)
129         {
130             writeSeparator(os);
132             const List<Type>& values = *valuesPtrList[i];
133             write(values[pointI], os);
134         }
135         os << nl;
136     }
140 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
142 template<class Type>
143 Foam::writer<Type>::writer()
147 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
149 template<class Type>
150 Foam::writer<Type>::~writer()
154 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
156 template<class Type>
157 Foam::Ostream& Foam::writer<Type>::write
159     const scalar value,
160     Ostream& os
161 ) const
163     return os << value;
167 template<class Type>
168 template<class VSType>
169 Foam::Ostream& Foam::writer<Type>::writeVS
171     const VSType& value,
172     Ostream& os
173 ) const
175     for (direction d=0; d<VSType::nComponents; d++)
176     {
177         if (d > 0)
178         {
179             writeSeparator(os);
180         }
182         os << value.component(d);
183     }
184     return os;
188 template<class Type>
189 void Foam::writer<Type>::writeSeparator
191     Ostream& os
192 ) const
194     os << token::SPACE << token::TAB;
198 template<class Type>
199 Foam::Ostream& Foam::writer<Type>::write
201     const vector& value,
202     Ostream& os
203 ) const
205     return writeVS(value, os);
209 template<class Type>
210 Foam::Ostream& Foam::writer<Type>::write
212     const sphericalTensor& value,
213     Ostream& os
214 ) const
216     return writeVS(value, os);
220 template<class Type>
221 Foam::Ostream& Foam::writer<Type>::write
223     const symmTensor& value,
224     Ostream& os
225 ) const
227     return writeVS(value, os);
231 template<class Type>
232 Foam::Ostream& Foam::writer<Type>::write
234     const tensor& value,
235     Ostream& os
236 ) const
238     return writeVS(value, os);
242 // ************************************************************************* //