FreeFOAM The Cross-Platform CFD Toolkit
writer.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "writer.H"
27 #include <sampling/coordSet.H>
28 #include <OpenFOAM/OFstream.H>
29 #include <OpenFOAM/OSspecific.H>
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const word& writeType
37 )
38 {
39  typename wordConstructorTable::iterator cstrIter =
40  wordConstructorTablePtr_
41  ->find(writeType);
42 
43  if (cstrIter == wordConstructorTablePtr_->end())
44  {
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  }
54 
55  return autoPtr<writer<Type> >(cstrIter()());
56 }
57 
58 
59 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
60 
61 template<class Type>
63 (
64  const coordSet& points,
65  const wordList& valueSets
66 ) const
67 {
68  fileName fName(points.name());
69 
70  forAll(valueSets, i)
71  {
72  fName += '_' + valueSets[i];
73  }
74 
75  return fName;
76 }
77 
78 
79 template<class Type>
81 (
82  const coordSet& points,
83  const label pointI,
84  Ostream& os
85 ) const
86 {
87  if (points.hasVectorAxis())
88  {
89  write(points.vectorCoord(pointI), os);
90  }
91  else
92  {
93  write(points.scalarCoord(pointI), os);
94  }
95 }
96 
97 
98 template<class Type>
100 (
101  const coordSet& points,
102  const List<Type>& values,
103  Ostream& os
104 ) const
105 {
106  forAll(points, pointI)
107  {
108  writeCoord(points, pointI, os);
109  writeSeparator(os);
110  write(values[pointI], os);
111  os << nl;
112  }
113 }
114 
115 
116 template<class Type>
118 (
119  const coordSet& points,
120  const List<const List<Type>*>& valuesPtrList,
121  Ostream& os
122 ) const
123 {
124  forAll(points, pointI)
125  {
126  writeCoord(points, pointI, os);
127 
128  forAll(valuesPtrList, i)
129  {
130  writeSeparator(os);
131 
132  const List<Type>& values = *valuesPtrList[i];
133  write(values[pointI], os);
134  }
135  os << nl;
136  }
137 }
138 
139 
140 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
141 
142 template<class Type>
144 {}
145 
146 
147 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
148 
149 template<class Type>
151 {}
152 
153 
154 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
155 
156 template<class Type>
158 (
159  const scalar value,
160  Ostream& os
161 ) const
162 {
163  return os << value;
164 }
165 
166 
167 template<class Type>
168 template<class VSType>
170 (
171  const VSType& value,
172  Ostream& os
173 ) const
174 {
175  for (direction d=0; d<VSType::nComponents; d++)
176  {
177  if (d > 0)
178  {
179  writeSeparator(os);
180  }
181 
182  os << value.component(d);
183  }
184  return os;
185 }
186 
187 
188 template<class Type>
190 (
191  Ostream& os
192 ) const
193 {
194  os << token::SPACE << token::TAB;
195 }
196 
197 
198 template<class Type>
200 (
201  const vector& value,
202  Ostream& os
203 ) const
204 {
205  return writeVS(value, os);
206 }
207 
208 
209 template<class Type>
211 (
212  const sphericalTensor& value,
213  Ostream& os
214 ) const
215 {
216  return writeVS(value, os);
217 }
218 
219 
220 template<class Type>
222 (
223  const symmTensor& value,
224  Ostream& os
225 ) const
226 {
227  return writeVS(value, os);
228 }
229 
230 
231 template<class Type>
233 (
234  const tensor& value,
235  Ostream& os
236 ) const
237 {
238  return writeVS(value, os);
239 }
240 
241 
242 // ************************ vim: set sw=4 sts=4 et: ************************ //