FreeFOAM The Cross-Platform CFD Toolkit
ensightPartIO.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-2010 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 Description
25  Output for ensightPart
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "ensightPart.H"
30 #include <OpenFOAM/dictionary.H>
31 #include <OpenFOAM/IOstreams.H>
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
36 (
37  ensightFile& os,
38  bool withDescription
39 ) const
40 {
41  os.write("part");
42  os.newline();
43 
44  os.write(number() + 1); // Ensight starts with 1
45  os.newline();
46 
47  if (withDescription)
48  {
49  os.write(name());
50  os.newline();
51  }
52 }
53 
54 
56 (
57  ensightFile& os,
58  const List<scalar>& field,
59  const List<label>& idList
60 ) const
61 {
62  forAll(idList, i)
63  {
64  if (idList[i] >= field.size() || std::isnan(field[idList[i]]))
65  {
66  os.writeUndef();
67  }
68  else
69  {
70  os.write(field[idList[i]]);
71  }
72 
73  os.newline();
74  }
75 }
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
81 {
82  os << indent << type() << nl
84 
85  // Ensight starts with 1
86  os.writeKeyword("id") << (number() + 1) << token::END_STATEMENT << nl;
87  os.writeKeyword("name") << name() << token::END_STATEMENT << nl;
88  os.writeKeyword("offset") << offset() << token::END_STATEMENT << nl;
89  os.writeKeyword("size") << size() << token::END_STATEMENT << nl;
90 
91  os << decrIndent << indent << token::END_BLOCK << nl << endl;
92 
93  return true;
94 }
95 
96 
98 {
99  os << indent << type() << nl
101 
102  os.writeKeyword("id") << number() << token::END_STATEMENT << nl;
103  os.writeKeyword("name") << name() << token::END_STATEMENT << nl;
104  os.writeKeyword("offset") << offset() << token::END_STATEMENT << nl;
105 
106  forAll(elementTypes(), typeI)
107  {
108  word key(elementTypes()[typeI]);
109  if (elemLists_[typeI].size())
110  {
111  elemLists_[typeI].writeEntry(key, os);
112  }
113  }
114 
115  os << decrIndent << indent << token::END_BLOCK << nl << endl;
116 
117  return true;
118 }
119 
120 
122 {
123  if (size() && meshPtr_)
124  {
125  const polyMesh& mesh = *meshPtr_;
126  const pointField& meshPoints = mesh.points();
127 
128  localPoints ptList = calcLocalPoints();
129  labelList& pointMap = ptList.list;
130 
131  writeHeader(os, true);
132 
133  // write points
134  os.writeKeyword("coordinates");
135  os.write(ptList.nPoints);
136  os.newline();
137 
138  for (direction cmpt=0; cmpt < vector::nComponents; cmpt++)
139  {
140  forAll(pointMap, ptI)
141  {
142  if (pointMap[ptI] > -1)
143  {
144  os.write( meshPoints[ptI].component(cmpt) );
145  os.newline();
146  }
147  }
148  }
149 
150  // write parts
151  forAll(elementTypes(), elemI)
152  {
153  if (elemLists_[elemI].size())
154  {
155  writeConnectivity
156  (
157  os,
158  elementTypes()[elemI],
159  elemLists_[elemI],
160  pointMap
161  );
162  }
163  }
164  }
165 }
166 
167 
169 (
170  ensightFile& os,
171  const List<scalar>& field
172 ) const
173 {
174  if (size() && field.size() && (os.allowUndef() || isFieldDefined(field)))
175  {
176  writeHeader(os);
177 
178  forAll(elementTypes(), elemI)
179  {
180  const labelList& idList = elemLists_[elemI];
181 
182  if (idList.size())
183  {
184  os.writeKeyword( elementTypes()[elemI] );
185  writeFieldList(os, field, idList);
186  }
187  }
188  }
189 }
190 
191 
193 (
194  ensightFile& os,
195  const List<scalar>& field0,
196  const List<scalar>& field1,
197  const List<scalar>& field2
198 ) const
199 {
200  if (size() && field0.size() && (os.allowUndef() || isFieldDefined(field0)))
201  {
202  writeHeader(os);
203 
204  forAll(elementTypes(), elemI)
205  {
206  const labelList& idList = elemLists_[elemI];
207 
208  if (idList.size())
209  {
210  os.writeKeyword( elementTypes()[elemI] );
211  writeFieldList(os, field0, idList);
212  writeFieldList(os, field1, idList);
213  writeFieldList(os, field2, idList);
214  }
215  }
216  }
217 }
218 
219 
220 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
221 
222 Foam::Ostream& Foam::operator<<
223 (
224  Ostream& os,
225  const ensightPart& part
226 )
227 {
228  part.writeData(os);
229  return os;
230 }
231 
232 
233 Foam::ensightGeoFile& Foam::operator<<
234 (
235  ensightGeoFile& os,
236  const ensightPart& part
237 )
238 {
239  part.writeGeometry(os);
240  return os;
241 }
242 
243 
244 // ************************ vim: set sw=4 sts=4 et: ************************ //