dxSurfaceWriter.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) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 "dxSurfaceWriter.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  makeSurfaceWriterType(dxSurfaceWriter);
34 }
35 
36 
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 
40 (
41  Ostream& os,
42  const pointField& points,
43  const faceList& faces
44 )
45 {
46  // Write vertex coordinates
47 
48  os << "# The irregular positions" << nl
49  << "object 1 class array type float rank 1 shape 3 items "
50  << points.size() << " data follows" << nl;
51 
52  forAll(points, pointI)
53  {
54  const point& pt = points[pointI];
55 
56  os << float(pt.x()) << ' ' << float(pt.y()) << ' ' << float(pt.z())
57  << nl;
58  }
59  os << nl;
60 
61  // Write triangles
62  os << "# The irregular connections (triangles)" << nl
63  << "object 2 class array type int rank 1 shape 3 items "
64  << faces.size() << " data follows" << nl;
65 
66  forAll(faces, faceI)
67  {
68  const face& f = faces[faceI];
69 
70  if (f.size() != 3)
71  {
73  << "Face " << faceI << " vertices " << f
74  << " is not a triangle."
75  << exit(FatalError);
76  }
77 
78  os << f[0] << ' ' << f[1] << ' ' << f[2] << nl;
79  }
80  os << "attribute \"element type\" string \"triangles\"" << nl
81  << "attribute \"ref\" string \"positions\"" << nl << nl;
82 }
83 
84 
85 void Foam::dxSurfaceWriter::writeTrailer(Ostream& os, const bool isNodeValues)
86 {
87  if (isNodeValues)
88  {
89  os << nl << "attribute \"dep\" string \"positions\""
90  << nl << nl;
91  }
92  else
93  {
94  os << nl << "attribute \"dep\" string \"connections\""
95  << nl << nl;
96  }
97 
98  os << "# the field, with three components: \"positions\","
99  << " \"connections\", and \"data\"" << nl
100  << "object \"irregular positions irregular "
101  << "connections\" class field"
102  << nl
103  << "component \"positions\" value 1" << nl
104  << "component \"connections\" value 2" << nl
105  << "component \"data\" value 3" << nl;
106 
107  os << "end" << endl;
108 }
109 
110 
111 namespace Foam
112 {
113  template<>
115  (
116  Ostream& os,
117  const Field<scalar>& values
118  )
119  {
120  os << "object 3 class array type float rank 0 items "
121  << values.size() << " data follows" << nl;
122 
123  forAll(values, elemI)
124  {
125  os << float(values[elemI]) << nl;
126  }
127  }
128 
129 
130  template<>
132  (
133  Ostream& os,
134  const Field<vector>& values
135  )
136  {
137  os << "object 3 class array type float rank 1 shape 3 items "
138  << values.size() << " data follows" << nl;
139 
140  forAll(values, elemI)
141  {
142  os << float(values[elemI].x()) << ' '
143  << float(values[elemI].y()) << ' '
144  << float(values[elemI].z()) << nl;
145  }
146  }
147 
148 
149  template<>
151  (
152  Ostream& os,
153  const Field<sphericalTensor>& values
154  )
155  {
156  os << "object 3 class array type float rank 0 items "
157  << values.size() << " data follows" << nl;
158 
159  forAll(values, elemI)
160  {
161  os << float(values[elemI][0]) << nl;
162  }
163  }
164 
165 
166  template<>
168  (
169  Ostream& os,
170  const Field<symmTensor>& values
171  )
172  {
173  os << "object 3 class array type float rank 2 shape 3 items "
174  << values.size() << " data follows" << nl;
175 
176  forAll(values, elemI)
177  {
178  const symmTensor& t = values[elemI];
179 
180  os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
181  << float(t.xy()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
182  << float(t.xz()) << ' ' << float(t.yz()) << ' ' << float(t.zz())
183  << nl;
184  }
185  }
186 
187 
188  // Write Field<tensor> in DX format
189  template<>
191  (
192  Ostream& os,
193  const Field<tensor>& values
194  )
195  {
196  os << "object 3 class array type float rank 2 shape 3 items "
197  << values.size() << " data follows" << nl;
198 
199  forAll(values, elemI)
200  {
201  const tensor& t = values[elemI];
202 
203  os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
204  << float(t.yx()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
205  << float(t.zx()) << ' ' << float(t.zy()) << ' ' << float(t.zz())
206  << nl;
207  }
208  }
209 }
210 
211 
212 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
213 
215 :
216  surfaceWriter()
217 {}
218 
219 
220 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
221 
223 {}
224 
225 
226 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
227 
228 // create write methods
230 
231 
232 // ************************************************************************* //
Foam::dxSurfaceWriter::writeData
static void writeData(Ostream &, const Field< Type > &)
Definition: dxSurfaceWriterTemplates.C:33
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::SymmTensor< scalar >
Foam::Tensor::zx
const Cmpt & zx() const
Definition: TensorI.H:202
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:54
Foam::dxSurfaceWriter::writeGeometry
static void writeGeometry(Ostream &, const pointField &, const faceList &)
Definition: dxSurfaceWriter.C:40
dxSurfaceWriter.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::SymmTensor::zz
const Cmpt & zz() const
Definition: SymmTensorI.H:115
Foam::SymmTensor::xy
const Cmpt & xy() const
Definition: SymmTensorI.H:91
Foam::Tensor::yx
const Cmpt & yx() const
Definition: TensorI.H:181
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::Tensor::xz
const Cmpt & xz() const
Definition: TensorI.H:174
Foam::dxSurfaceWriter::~dxSurfaceWriter
virtual ~dxSurfaceWriter()
Destructor.
Definition: dxSurfaceWriter.C:222
Foam::Tensor::yz
const Cmpt & yz() const
Definition: TensorI.H:195
Foam::SymmTensor::yz
const Cmpt & yz() const
Definition: SymmTensorI.H:109
makeSurfaceWriterMethods.H
Convenience macros for instantiating writer methods for surfaceWriter classes.
Foam::Tensor::zy
const Cmpt & zy() const
Definition: TensorI.H:209
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Tensor::yy
const Cmpt & yy() const
Definition: TensorI.H:188
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::SymmTensor::xx
const Cmpt & xx() const
Definition: SymmTensorI.H:85
Foam::Tensor::zz
const Cmpt & zz() const
Definition: TensorI.H:216
Foam::defineSurfaceWriterWriteFields
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam::FatalError
error FatalError
Foam::Tensor::xy
const Cmpt & xy() const
Definition: TensorI.H:167
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::dxSurfaceWriter::writeTrailer
static void writeTrailer(Ostream &, const bool isNodeValues)
Definition: dxSurfaceWriter.C:85
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::Tensor::xx
const Cmpt & xx() const
Definition: TensorI.H:160
Foam::dxSurfaceWriter::dxSurfaceWriter
dxSurfaceWriter()
Construct null.
Definition: dxSurfaceWriter.C:214
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
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::SymmTensor::yy
const Cmpt & yy() const
Definition: SymmTensorI.H:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::dxSurfaceWriter
A surfaceWriter for OpenDX format.
Definition: dxSurfaceWriter.H:48
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
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
Foam::SymmTensor::xz
const Cmpt & xz() const
Definition: SymmTensorI.H:97
Foam::makeSurfaceWriterType
makeSurfaceWriterType(boundaryDataSurfaceWriter)
y
scalar y
Definition: LISASMDCalcMethod1.H:14