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 
97  autoPtr<vtk::formatter> format = vtk::newFormatter
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();
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 
239  (
240  SubList<face>(mesh.faces(), patches[patchi].range()),
241  points0
242  );
243 
245 
247 
249 
250  writer.writeUniform("patchId", patchi);
251  writer.write("lumpedId", faceToPoint);
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 
302 
303  // Face mapping
304  const labelList& faceToPoint = patchControls_[patchi].faceToPoint_;
305 
307 
308  writer.writeUniform("patchId", patchi);
309  writer.write("lumpedId", faceToPoint);
310 
312 
313  // The interpolator
314  const List<lumpedPointInterpolator>& interpList
315  = patchControls_[patchi].interp_;
316 
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 
367  }
368 }
369 
370 
371 // ************************************************************************* //
List< scalar > scalarList
List of scalar.
Definition: scalarList.H:32
labelList patchIds
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
A class for handling file names.
Definition: fileName.H:72
const Field< point_type > & localPoints() const
Return pointField of points in patch.
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
void writeStateVTP(const lumpedPointState &state, const fileName &file) const
Write state as VTK PolyData format.
void piece(const pointField &points, const edgeList &edges)
Reset point/edge references to begin a new piece.
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
Definition: foamVtkOutput.C:41
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
T & first()
Access first element of the list, position [0].
Definition: UList.H:853
void writeZonesVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write pressure-zones geometry, write as VTK PolyData format.
labelRange range() const noexcept
The face range for all boundary faces.
static const List< face > & null()
Return a null List.
Definition: ListI.H:130
void write(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData (Poly or Line) or PointData values.
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Line) or Point values.
XML inline ASCII, asciiFormatter.
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
virtual const std::ostream & stdStream() const override
Const access to underlying std::ostream.
Definition: OFstream.C:125
A list of faces which address into the list of points.
A List obtained as a section of another List.
Definition: SubList.H:50
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
const pointField & points
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Definition: labelLists.C:44
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
A class for handling words, derived from Foam::string.
Definition: word.H:63
label nPoints
void writeIdentity(vtk::formatter &fmt, const label len, label start=0)
Write an identity list of labels.
Definition: foamVtkOutput.C:89
bool endCellData()
Explicitly end CellData output and switch to PIECE state.
bool endPointData()
Explicitly end PointData output and switch to PIECE state.
void writeVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write displaced geometry according to the current state,.
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1103
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:105
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
OBJstream os(runTime.globalPath()/outputName)
void writeForcesAndMomentsVTP(const fileName &file, const UList< vector > &forces, const UList< vector > &moments) const
Write forces on points as VTK PolyData format.
word format(conversionProperties.get< word >("format"))
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, IOobject::NO_REGISTER)))
const lumpedPointState & state() const
The current state (positions/rotations)
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
static const Field< vector > & null()
Return nullObject reference Field.
Definition: FieldI.H:24
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1082
const polyBoundaryMesh & patches
const pointField & points() const
The points corresponding to mass centres.
virtual bool writeGeometry()
Write patch topology.
label size() const
The number of points.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
void writeVTP(const fileName &outputFile, const labelListList &lines=labelListList(), const labelList &pointIds=labelList::null()) const
Output points/rotations as VTK file for debugging/visualization.
The state of lumped points corresponds to positions and rotations.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
A topoSetPointSource to select all points based on usage in given faceSet(s).
Definition: faceToPoint.H:170