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-2020 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 "pointMesh.H"
31 #include "OFstream.H"
32 #include "foamVtkOutput.H"
33 #include "foamVtkSurfaceWriter.H"
34 
35 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
36 
38 (
39  const lumpedPointState& state,
40  const fileName& file
41 ) const
42 {
43  if (!Pstream::master())
44  {
45  // No extra information available from slaves, write on master only.
46  return;
47  }
48 
49  labelListList lines;
50 
51  label nLines = controllers_.size();
52 
53  if (nLines)
54  {
55  lines.resize(nLines);
56  nLines = 0;
57 
58  for (const word& ctrlName : controllers_.sortedToc())
59  {
60  lines[nLines] = controllers_[ctrlName]->pointLabels();
61  ++nLines;
62  }
63  }
64  else
65  {
66  // Default - global with all points as a single line
67  lines.resize(1);
68  lines.first() = identity(state.size());
69  }
70 
71  state.writeVTP(file, lines, originalIds_);
72 }
73 
74 
76 {
77  writeStateVTP(state(), file);
78 }
79 
80 
82 (
83  const fileName& file,
84  const UList<vector>& forces,
85  const UList<vector>& moments
86 ) const
87 {
88  if (!Pstream::master())
89  {
90  // Force, moments already reduced
91  return;
92  }
93 
94  OFstream fos(file);
95  std::ostream& os = fos.stdStream();
96 
98  (
99  os,
101  );
102 
103  format().xmlHeader()
104  .beginVTKFile<vtk::fileTag::POLY_DATA>();
105 
106  //
107  // The 'backbone' of lumped mass points
108  //
109  const label nPoints = state().points().size();
110 
111  {
112  format()
113  .tag
114  (
118  );
119 
120  // 'points'
121  {
122  const uint64_t payLoad = vtk::sizeofData<float, 3>(nPoints);
123 
124  format()
126  .beginDataArray<float, 3>(vtk::dataArrayAttr::POINTS);
127 
128  format().writeSize(payLoad);
129  vtk::writeList(format(), state().points());
130  format().flush();
131 
132  format()
133  .endDataArray()
134  .endTag(vtk::fileTag::POINTS);
135  }
136 
137  // <Verts>
139 
140  //
141  // 'connectivity'
142  //
143  {
144  const uint64_t payLoad = vtk::sizeofData<label>(nPoints);
145 
146  format().beginDataArray<label>(vtk::dataArrayAttr::CONNECTIVITY);
147  format().writeSize(payLoad);
148 
150 
151  format().flush();
152 
153  format().endDataArray();
154  }
155 
156  //
157  // 'offsets' (connectivity offsets)
158  // = linear mapping onto points (with 1 offset)
159  //
160  {
161  const uint64_t payLoad = vtk::sizeofData<label>(nPoints);
162 
163  format().beginDataArray<label>(vtk::dataArrayAttr::OFFSETS);
164  format().writeSize(payLoad);
165 
167 
168  format().flush();
169 
170  format().endDataArray();
171  }
172 
173  format().endTag(vtk::fileTag::VERTS);
174  // </Verts>
175  }
176 
177  format().beginPointData();
178 
179  // forces
180  if (forces.size() == nPoints)
181  {
182  const uint64_t payLoad = vtk::sizeofData<float, 3>(nPoints);
183 
184  format().beginDataArray<float, 3>("forces");
185  format().writeSize(payLoad);
186 
187  vtk::writeList(format(), forces);
188  format().flush();
189 
190  format().endDataArray();
191  }
192 
193  // moments
194  if (moments.size() == nPoints)
195  {
196  const uint64_t payLoad = vtk::sizeofData<float, 3>(nPoints);
197 
198  format().beginDataArray<float, 3>("moments");
199  format().writeSize(payLoad);
200 
201  vtk::writeList(format(), moments);
202  format().flush();
203 
204  format().endDataArray();
205  }
206 
207  format().endPointData();
208 
209  format().endPiece();
210 
212  .endVTKFile();
213 }
214 
215 
217 (
218  const fileName& file,
219  const polyMesh& mesh,
220  const pointField& points0
221 ) const
222 {
224  const labelList patchIds(patchControls_.sortedToc());
225 
227  (
229  faceList::null(),
231  file
232  );
233 
234  for (const label patchi : patchIds)
235  {
236  const labelList& faceToPoint = patchControls_[patchi].faceToPoint_;
237 
238  primitivePatch pp
239  (
240  SubList<face>(mesh.faces(), patches[patchi].range()),
241  points0
242  );
243 
244  writer.piece(pp.localPoints(), pp.localFaces());
245 
246  writer.writeGeometry();
247 
248  writer.beginCellData(2);
249 
250  writer.writeUniform("patchId", patchi);
251  writer.write("lumpedId", faceToPoint);
252 
253  writer.endCellData();
254  }
255 }
256 
257 
259 (
260  const fileName& file,
261  const polyMesh& mesh,
262  const pointField& points0
263 ) const
264 {
265  writeVTP(file, state(), mesh, points0);
266 }
267 
268 
270 (
271  const fileName& file,
272  const lumpedPointState& state,
273  const polyMesh& mesh,
274  const pointField& points0
275 ) const
276 {
278  const labelList patchIds(patchControls_.sortedToc());
279 
280  pointMesh ptMesh(mesh);
281 
283  (
285  faceList::null(),
287  file
288  );
289 
290  for (const label patchi : patchIds)
291  {
292  const polyPatch& pp = patches[patchi];
293 
294  const pointPatch& ptPatch = ptMesh.boundary()[patchi];
295 
296  // Current position (not displacement)
297  tmp<pointField> tpts = pointsPosition(state, ptPatch, points0);
298 
299  writer.piece(tpts(), pp.localFaces());
300 
301  writer.writeGeometry();
302 
303  // Face mapping
304  const labelList& faceToPoint = patchControls_[patchi].faceToPoint_;
305 
306  writer.beginCellData(2);
307 
308  writer.writeUniform("patchId", patchi);
309  writer.write("lumpedId", faceToPoint);
310 
311  writer.endCellData();
312 
313  // The interpolator
314  const List<lumpedPointInterpolator>& interpList
315  = patchControls_[patchi].interp_;
316 
317  writer.beginPointData(3);
318 
319  // Nearest, Next
320  {
321  labelList intData(interpList.size());
322 
323  forAll(interpList, i)
324  {
325  intData[i] = interpList[i].nearest();
326  }
327  writer.write("nearest", intData);
328 
329  forAll(interpList, i)
330  {
331  intData[i] = interpList[i].next1();
332  }
333  writer.write("next1", intData);
334 
335 
336  forAll(interpList, i)
337  {
338  intData[i] = interpList[i].next2();
339  }
340  writer.write("next2", intData);
341  }
342 
343  // Weights
344  {
345  scalarList floatData(interpList.size());
346 
347  forAll(interpList, i)
348  {
349  floatData[i] = interpList[i].weight0();
350  }
351  writer.write("weight", floatData);
352 
353  forAll(interpList, i)
354  {
355  floatData[i] = interpList[i].weight1();
356  }
357  writer.write("weight1", floatData);
358 
359  forAll(interpList, i)
360  {
361  floatData[i] = interpList[i].weight2();
362  }
363  writer.write("weight2", floatData);
364  }
365 
366  writer.endPointData();
367  }
368 }
369 
370 
371 // ************************************************************************* //
foamVtkOutput.H
Foam::List::null
static const List< T > & null()
Return a null List.
Definition: ListI.H:109
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::vtk::dataArrayAttr::OFFSETS
"offsets"
Foam::vtk::formatType::INLINE_ASCII
XML inline ASCII, asciiFormatter.
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:54
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::writer::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const =0
General entry point for writing.
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:457
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::lumpedPointState::points
const pointField & points() const
The points corresponding to mass centres.
Definition: lumpedPointStateI.H:46
Foam::lumpedPointMovement::writeStateVTP
void writeStateVTP(const lumpedPointState &state, const fileName &file) const
Write state as VTK PolyData format.
Definition: lumpedPointMovementWriter.C:38
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:58
foamVtkSurfaceWriter.H
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::polyBoundaryMesh::range
labelRange range() const
The face range for all boundary faces.
Definition: polyBoundaryMesh.C:623
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
OFstream.H
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::lumpedPointState
The state of lumped points corresponds to positions and rotations.
Definition: lumpedPointState.H:112
format
word format(conversionProperties.get< word >("format"))
patchIds
labelList patchIds
Definition: convertProcessorPatches.H:67
Foam::Field< vector >
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
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:217
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:82
Foam::lumpedPointMovement::writeVTP
void writeVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write displaced geometry according to the current state,.
Definition: lumpedPointMovementWriter.C:259
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::lumpedPointState::writeVTP
void writeVTP(const fileName &outputFile, const labelListList &lines=labelListList(), const labelList &pointIds=labelList::null()) const
Output points/rotations as VTK file for debugging/visualization.
Definition: lumpedPointStateWriter.C:36
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
Foam::PrimitivePatch::localFaces
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
Definition: PrimitivePatch.C:317
Foam::vtk::fileTag::POINTS
"Points"
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:51
Foam::lumpedPointMovement::state
const lumpedPointState & state() const
The current state (positions/rotations)
Definition: lumpedPointMovementI.H:87
Foam::PrimitivePatch::localPoints
const Field< point_type > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatch.C:359
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
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:1094
Foam::OFstream::stdStream
virtual std::ostream & stdStream()
Access to underlying std::ostream.
Definition: OFstream.C:102
Foam::vtk::surfaceWriter
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
Definition: foamVtkSurfaceWriter.H:65
Foam::List< labelList >
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::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::vtk::dataArrayAttr::CONNECTIVITY
"connectivity"
Foam::vtk::fileAttr::NUMBER_OF_VERTS
"NumberOfVerts"
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::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::vtk::dataArrayAttr::POINTS
"Points"
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Foam::faceToPoint
A topoSetPointSource to select all points based on usage in given faceSet(s).
Definition: faceToPoint.H:174
Foam::lumpedPointState::size
label size() const
The number of points.
Definition: lumpedPointStateI.H:40
lumpedPointMovement.H
pointMesh.H
Foam::Field::null
static const Field< Type > & null()
Return nullObject reference Field.
Definition: FieldI.H:31
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79