lumpedPointMovementWriter.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "lumpedPointMovement.H"
29 #include "polyMesh.H"
30 #include "OFstream.H"
32 
33 #include "foamVtkOutput.H"
34 
35 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
36 
38 {
39  state().writeVTP(file, axis());
40 }
41 
42 
44 (
45  const fileName& file,
46  const UList<vector>& forces,
47  const UList<vector>& moments
48 ) const
49 {
50  OFstream fos(file);
51  std::ostream& os = fos.stdStream();
52 
54  (
55  os,
57  );
58 
59  format().xmlHeader()
60  .beginVTKFile<vtk::fileTag::POLY_DATA>();
61 
62  //
63  // The 'spine' of lumped mass points
64  //
65  const label nPoints = state().points().size();
66 
67  {
68  format()
69  .tag
70  (
74  );
75 
76  // 'points'
77  {
78  const uint64_t payLoad = vtk::sizeofData<float, 3>(nPoints);
79 
80  format()
82  .beginDataArray<float, 3>(vtk::dataArrayAttr::POINTS);
83 
84  format().writeSize(payLoad);
85  vtk::writeList(format(), state().points());
86  format().flush();
87 
88  format()
89  .endDataArray()
90  .endTag(vtk::fileTag::POINTS);
91  }
92 
93  // <Verts>
95 
96  //
97  // 'connectivity'
98  //
99  {
100  const uint64_t payLoad = vtk::sizeofData<label>(nPoints);
101 
102  format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY);
103  format().writeSize(payLoad);
104 
106 
107  format().flush();
108 
109  format().endDataArray();
110  }
111 
112  //
113  // 'offsets' (connectivity offsets)
114  // = linear mapping onto points (with 1 offset)
115  //
116  {
117  const uint64_t payLoad = vtk::sizeofData<label>(nPoints);
118 
119  format().beginDataArray<label>(vtk::dataArrayAttr::OFFSETS);
120  format().writeSize(payLoad);
121 
123 
124  format().flush();
125 
126  format().endDataArray();
127  }
128 
129  format().endTag(vtk::fileTag::VERTS);
130  // </Verts>
131  }
132 
133  format().beginPointData();
134 
135  // forces
136  if (forces.size() == nPoints)
137  {
138  const uint64_t payLoad = vtk::sizeofData<float, 3>(nPoints);
139 
140  format().beginDataArray<float, 3>("forces");
141  format().writeSize(payLoad);
142 
143  vtk::writeList(format(), forces);
144  format().flush();
145 
146  format().endDataArray();
147  }
148 
149  // moments
150  if (moments.size() == nPoints)
151  {
152  const uint64_t payLoad = vtk::sizeofData<float, 3>(nPoints);
153 
154  format().beginDataArray<float, 3>("moments");
155  format().writeSize(payLoad);
156 
157  vtk::writeList(format(), moments);
158  format().flush();
159 
160  format().endDataArray();
161  }
162 
163  format().endPointData();
164 
165  format().endPiece();
166 
168  .endVTKFile();
169 }
170 
171 
173 (
174  const fileName& file,
175  const polyMesh& mesh,
176  const pointField& points0
177 ) const
178 {
179  OFstream fos(file);
180  std::ostream& os = fos.stdStream();
181 
183  (
184  os,
186  );
187 
188  format().xmlHeader()
189  .beginVTKFile<vtk::fileTag::POLY_DATA>();
190 
191  forAll(faceZones_, zoneI)
192  {
194  (
195  UIndirectList<face>(mesh.faces(), faceZones_[zoneI]),
196  points0
197  );
198 
199  format()
200  .tag
201  (
205  );
206 
207  // 'points'
208  {
209  const uint64_t payLoad = vtk::sizeofData<float, 3>(pp.nPoints());
210 
211  format()
213  .beginDataArray<float, 3>(vtk::dataArrayAttr::POINTS);
214 
215  format().writeSize(payLoad);
217  format().flush();
218 
219  format()
220  .endDataArray()
221  .endTag(vtk::fileTag::POINTS);
222  }
223 
224  // <Polys>
226 
227  //
228  // 'connectivity'
229  //
230  {
231  label nVerts = 0;
232  for (const face& f : pp)
233  {
234  nVerts += f.size();
235  }
236 
237  const uint64_t payLoad = vtk::sizeofData<label>(nVerts);
238 
239  format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY);
240  format().writeSize(payLoad);
241 
242  for (const face& f : pp.localFaces())
243  {
244  vtk::writeList(format(), f);
245  }
246  format().flush();
247 
248  format().endDataArray();
249  }
250 
251  //
252  // 'offsets' (connectivity offsets)
253  //
254  {
255  const uint64_t payLoad = vtk::sizeofData<label>(pp.size());
256 
257  format().beginDataArray<label>(vtk::dataArrayAttr::OFFSETS);
258  format().writeSize(payLoad);
259 
260  label off = 0;
261  forAll(pp, facei)
262  {
263  const face& f = pp[facei];
264  off += f.size();
265 
266  format().write(off);
267  }
268  format().flush();
269 
270  format().endDataArray();
271  }
272 
273  format().endTag(vtk::fileTag::POLYS);
274 
275 
276  format().beginCellData();
277 
278  // zone Id
279  {
280  const uint64_t payLoad = vtk::sizeofData<label>(pp.size());
281 
282  format().beginDataArray<label>("zoneId");
283  format().writeSize(payLoad);
284 
285  vtk::write(format(), zoneI, pp.size());
286 
287  format().flush();
288 
289  format().endDataArray();
290  }
291 
292  format().endCellData();
293 
294  format().endPiece();
295  }
296 
298  .endVTKFile();
299 }
300 
301 
303 (
304  const fileName& file,
305  const polyMesh& mesh,
306  const labelUList& patchIds,
307  const pointField& points0
308 ) const
309 {
310  writeVTP(file, state(), mesh, patchIds, points0);
311 }
312 
313 
315 (
316  const fileName& file,
317  const lumpedPointState& state,
318  const polyMesh& mesh,
319  const labelUList& patchIds,
320  const pointField& points0
321 ) const
322 {
324 
325  OFstream fos(file);
326  std::ostream& os = fos.stdStream();
327 
329  (
330  os,
332  );
333 
334  format().xmlHeader()
335  .beginVTKFile<vtk::fileTag::POLY_DATA>();
336 
337  for (const label patchId : patchIds)
338  {
339  const polyPatch& pp = boundaryMesh[patchId];
340 
341  format()
342  .tag
343  (
347  );
348 
349  // 'points'
350  {
351  const uint64_t payLoad = vtk::sizeofData<float, 3>(pp.nPoints());
352 
353  format()
355  .beginDataArray<float, 3>(vtk::dataArrayAttr::POINTS);
356 
357  // Could be more efficient, but not often needed
358  tmp<pointField> tpts = displacePoints
359  (
360  state,
361  points0,
362  pp.meshPoints()
363  ) + pointField(points0, pp.meshPoints());
364 
365  const pointField& pts = tpts();
366 
367  format().writeSize(payLoad);
368  vtk::writeList(format(), pts);
369  format().flush();
370 
371  format()
372  .endDataArray()
373  .endTag(vtk::fileTag::POINTS);
374  }
375 
376  // <Polys>
378 
379 
380  //
381  // 'connectivity'
382  //
383  {
384  label nVerts = 0;
385  for (const face& f : pp)
386  {
387  nVerts += f.size();
388  }
389 
390  const uint64_t payLoad = vtk::sizeofData<label>(nVerts);
391 
392  format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY);
393  format().writeSize(payLoad);
394 
395  for (const face& f : pp.localFaces())
396  {
397  vtk::writeList(format(), f);
398  }
399  format().flush();
400 
401  format().endDataArray();
402  }
403 
404  //
405  // 'offsets' (connectivity offsets)
406  //
407  {
408  const uint64_t payLoad = vtk::sizeofData<label>(pp.size());
409 
410  format().beginDataArray<label>(vtk::dataArrayAttr::OFFSETS);
411  format().writeSize(payLoad);
412 
413  label off = 0;
414  for (const face& f : pp)
415  {
416  off += f.size();
417 
418  format().write(off);
419  }
420  format().flush();
421 
422  format().endDataArray();
423  }
424 
425  format().endTag(vtk::fileTag::POLYS);
426 
427  format().endPiece();
428  }
429 
431  .endVTKFile();
432 }
433 
434 
435 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
foamVtkOutput.H
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
uindirectPrimitivePatch.H
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::vtk::dataArrayAttr::OFFSETS
"offsets"
Foam::vtk::formatType::INLINE_ASCII
XML inline ASCII, asciiFormatter.
Foam::PrimitivePatch::localPoints
const Field< PointType > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatch.C:458
Foam::vtk::fileTag::POLY_DATA
"PolyData"
Foam::vtk::writeIdentity
void writeIdentity(vtk::formatter &fmt, const label len, label start=0)
Write an identity list of labels.
Definition: foamVtkOutput.C:96
Foam::lumpedPointMovement::writeVTP
void writeVTP(const fileName &file, const polyMesh &mesh, const labelUList &patchIds, const pointField &points0) const
Write displaced geometry according to the current state,.
Definition: lumpedPointMovementWriter.C:303
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::lumpedPointState::points
const pointField & points() const
The points corresponding to mass centres.
Definition: lumpedPointStateI.H:46
polyMesh.H
Foam::vtk::fileTag::POLYS
"Polys"
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
OFstream.H
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::lumpedPointState
The state of lumped points corresponds to positions and rotations.
Definition: lumpedPointState.H:111
format
word format(conversionProperties.get< word >("format"))
patchIds
labelList patchIds
Definition: convertProcessorPatches.H:67
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:62
Foam::lumpedPointMovement::axis
const vector & axis() const
The normalized reference axis.
Definition: lumpedPointMovementI.H:40
Foam::Field< vector >
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::vtk::fileAttr::NUMBER_OF_POINTS
"NumberOfPoints"
Foam::lumpedPointMovement::writeZonesVTP
void writeZonesVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write pressure-zones geometry, write as VTK PolyData format.
Definition: lumpedPointMovementWriter.C:173
Foam::lumpedPointMovement::writeForcesAndMomentsVTP
void writeForcesAndMomentsVTP(const fileName &file, const UList< vector > &forces, const UList< vector > &moments) const
Write forces on points as VTK PolyData format.
Definition: lumpedPointMovementWriter.C:44
Foam::vtk::fileTag::VERTS
"Verts"
Foam::vtk::writeList
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
Definition: foamVtkOutput.C:112
Foam::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatch.H:311
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::vtk::fileTag::POINTS
"Points"
Foam::lumpedPointMovement::state
const lumpedPointState & state() const
The current state (positions/rotations)
Definition: lumpedPointMovementI.H:108
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:99
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
points0
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, false)))
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1063
Foam::OFstream::stdStream
virtual std::ostream & stdStream()
Access to underlying std::ostream.
Definition: OFstream.C:167
f
labelList f(nPoints)
Foam::lumpedPointMovement::writeStateVTP
void writeStateVTP(const fileName &file) const
Write state as VTK PolyData format.
Definition: lumpedPointMovementWriter.C:37
Foam::lumpedPointState::writeVTP
void writeVTP(const fileName &outputFile, const vector &axis) const
Output as VTK file for debugging/visualization.
Definition: lumpedPointStateWriter.C:50
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
Foam::vtk::dataArrayAttr::CONNECTIVITY
"connectivity"
Foam::vtk::fileAttr::NUMBER_OF_VERTS
"NumberOfVerts"
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:109
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:61
Foam::vtk::fileTag::PIECE
"Piece"
Foam::vtk::newFormatter
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
Definition: foamVtkOutput.C:48
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
patchId
label patchId(-1)
Foam::PrimitivePatch::meshPoints
const labelList & meshPoints() const
Return labelList of mesh points in patch.
Definition: PrimitivePatch.C:418
lumpedPointMovement.H
Foam::vtk::fileAttr::NUMBER_OF_POLYS
"NumberOfPolys"
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:90