writeDX.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend 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 3 of the License, or (at your
14  option) any later version.
15 
16  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  OpenDX format. Both data-only and scalar/vector data.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "triSurface.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 
38 // Geometry (positions + connections)
39 // writeSorted: sort acc. to patch
41 (
42  const bool writeSorted,
43  Ostream& os
44 ) const
45 {
47  surfacePatchList myPatches(calcPatches(faceMap));
48 
49  // Print patch names as comment
50  os << "# Patches:" << endl;
51  forAll(myPatches, patchI)
52  {
53  os << "# " << patchI << " "
54  << myPatches[patchI].name() << endl;
55  }
56  os << endl << endl;
57 
58  // Write vertex coordinates
59 
60  os << "# The irregular positions" << endl
61  << "object 1 class array type float rank 1 shape 3 items "
62  << nPoints() << " data follows" << endl;
63  forAll(localPoints(), pointI)
64  {
65  const point& pt = localPoints()[pointI];
66  os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
67  }
68  os << endl;
69 
70  os << "# The irregular connections (triangles)" << endl
71  << "object 2 class array type int rank 1 shape 3 items "
72  << size() << " data follows" << endl;
73 
74  if (writeSorted)
75  {
76  label faceIndex = 0;
77 
78  forAll(myPatches, patchI)
79  {
80  // Print all faces belonging to this patch
81 
82  for
83  (
84  label patchFaceI = 0;
85  patchFaceI < myPatches[patchI].size();
86  patchFaceI++
87  )
88  {
89  const label faceI = faceMap[faceIndex++];
90 
91  const labelledTri& f = localFaces()[faceI];
92 
93  os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
94  }
95  }
96  }
97  else
98  {
99  forAll(*this, faceI)
100  {
101  const labelledTri& f = localFaces()[faceI];
102 
103  os << f[0] << ' ' << f[1] << ' ' << f[2] << endl;
104  }
105  }
106  os << "attribute \"element type\" string \"triangles\"" << endl
107  << "attribute \"ref\" string \"positions\"" << endl << endl;
108 }
109 
110 
111 // Standard trailer
113 {
114  os << "# the field, with three components: \"positions\", \"connections\""
115  << ", and \"data\"" << endl
116  << "object \"irregular positions irregular connections\" class field"
117  << endl
118  << "component \"positions\" value 1" << endl
119  << "component \"connections\" value 2" << endl
120  << "component \"data\" value 3" << endl;
121 }
122 
123 
124 // Geometry only (data field is either faceIndex or patchIndex)
125 void triSurface::writeDX(const bool writeSorted, Ostream& os) const
126 {
127  writeDXGeometry(writeSorted, os);
128 
129  os << "object 3 class array type float rank 0 items " << size()
130  << " data follows" << endl;
131  if (writeSorted)
132  {
133  // Write patch number as data
134 
137 
138  forAll(myPatches, patchI)
139  {
140  forAll(myPatches[patchI], patchFaceI)
141  {
142  os << patchI << endl;
143  }
144  }
145  }
146  else
147  {
148  // Write face number as data
149 
150  forAll(*this, faceI)
151  {
152  os << faceI << endl;
153  }
154  }
155 
156  os << endl << "attribute \"dep\" string \"connections\"" << endl << endl;
157 
158  writeDXTrailer(os);
159 
160  os << "end" << endl;
161 }
162 
163 
164 // Geometry + scalar data
165 void triSurface::writeDX(const scalarField& field, Ostream& os) const
166 {
167  writeDXGeometry(false, os);
168 
169  if (field.size() == size())
170  {
171  // Connections dependent data
172  os << "object 3 class array type float rank 0 items " << field.size()
173  << " data follows" << endl;
174  forAll(field, faceI)
175  {
176  os << field[faceI] << endl;
177  }
178  os << endl
179  << "attribute \"dep\" string \"connections\"" << endl << endl;
180  }
181  else if (field.size() == nPoints())
182  {
183  // Positions dependent data
184  os << "object 3 class array type float rank 0 items " << field.size()
185  << " data follows" << endl;
186  forAll(field, pointI)
187  {
188  os << field[pointI] << endl;
189  }
190  os << endl
191  << "attribute \"dep\" string \"positions\"" << endl << endl;
192  }
193  else
194  {
196  (
197  "writeDX(const scalarField&, Ostream&)"
198  ) << "Illegal field size " << field.size() << " is not equal "
199  << " to number of faces " << size() << " or to number "
200  << " of points " << nPoints() << exit(FatalError);
201  }
202 
203  writeDXTrailer(os);
204 
205  os << "end" << endl;
206 }
207 
208 
209 // Geometry + vector data
210 void triSurface::writeDX(const vectorField& field, Ostream& os) const
211 {
212  writeDXGeometry(false, os);
213 
214  if (field.size() == size())
215  {
216  // Connections dependent data
217  os << "object 3 class array type float rank 1 shape 3 items "
218  << field.size() << " data follows" << endl;
219  forAll(field, faceI)
220  {
221  os << field[faceI].x() << ' '
222  << field[faceI].y() << ' '
223  << field[faceI].z() << endl;
224  }
225  os << endl
226  << "attribute \"dep\" string \"connections\"" << endl << endl;
227  }
228  else if (field.size() == nPoints())
229  {
230  // Positions dependent data
231  os << "object 3 class array type float rank 1 shape 3 items "
232  << field.size() << " data follows" << endl;
233  forAll(field, pointI)
234  {
235  os << field[pointI].x() << ' '
236  << field[pointI].y() << ' '
237  << field[pointI].z() << endl;
238  }
239  os << endl
240  << "attribute \"dep\" string \"positions\"" << endl << endl;
241  }
242  else
243  {
245  (
246  "writeDX(const vectorField&, Ostream&)"
247  ) << "Illegal field size " << field.size() << " is not equal "
248  << " to number of faces " << size() << " or to number "
249  << " of points " << nPoints() << exit(FatalError);
250  }
251 
252  writeDXTrailer(os);
253 
254  os << "end" << endl;
255 }
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 } // End namespace Foam
261 
262 // ************************************************************************* //
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::triSurface::writeDX
void writeDX(const bool, Ostream &) const
For DX writing.
Definition: writeDX.C:125
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::triSurface::writeDXGeometry
void writeDXGeometry(const bool, Ostream &) const
Definition: writeDX.C:41
Foam::PrimitivePatch< labelledTri, List, pointField, point >::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatchTemplate.H:293
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::FatalError
error FatalError
Foam::triSurface::writeDXTrailer
void writeDXTrailer(Ostream &) const
Definition: writeDX.C:112
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::List< labelledTri >::size
label size() const
Return the number of elements in the UList.
Foam::triSurface::calcPatches
surfacePatchList calcPatches(labelList &faceMap) const
Sort faces according to region. Returns patch list.
Definition: triSurface.C:501
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53