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 
238  primitivePatch pp(patches[patchi].faces(), points0);
239 
241 
243 
245 
246  writer.writeUniform("patchId", patchi);
247  writer.write("lumpedId", faceToPoint);
250  }
251 }
252 
253 
255 (
256  const fileName& file,
257  const polyMesh& mesh,
258  const pointField& points0
259 ) const
260 {
261  writeVTP(file, state(), mesh, points0);
262 }
263 
264 
266 (
267  const fileName& file,
268  const lumpedPointState& state,
269  const polyMesh& mesh,
270  const pointField& points0
271 ) const
272 {
274  const labelList patchIds(patchControls_.sortedToc());
275 
276  pointMesh ptMesh(mesh);
277 
279  (
281  faceList::null(),
283  file
284  );
285 
286  for (const label patchi : patchIds)
287  {
288  const polyPatch& pp = patches[patchi];
289 
290  const pointPatch& ptPatch = ptMesh.boundary()[patchi];
291 
292  // Current position (not displacement)
293  tmp<pointField> tpts = pointsPosition(state, ptPatch, points0);
294 
295  writer.piece(tpts(), pp.localFaces());
296 
298 
299  // Face mapping
300  const labelList& faceToPoint = patchControls_[patchi].faceToPoint_;
301 
303 
304  writer.writeUniform("patchId", patchi);
305  writer.write("lumpedId", faceToPoint);
306 
308 
309  // The interpolator
310  const List<lumpedPointInterpolator>& interpList
311  = patchControls_[patchi].interp_;
312 
314 
315  // Nearest, Next
316  {
317  labelList intData(interpList.size());
318 
319  forAll(interpList, i)
320  {
321  intData[i] = interpList[i].nearest();
322  }
323  writer.write("nearest", intData);
324 
325  forAll(interpList, i)
326  {
327  intData[i] = interpList[i].next1();
328  }
329  writer.write("next1", intData);
330 
331 
332  forAll(interpList, i)
333  {
334  intData[i] = interpList[i].next2();
335  }
336  writer.write("next2", intData);
337  }
338 
339  // Weights
340  {
341  scalarList floatData(interpList.size());
342 
343  forAll(interpList, i)
344  {
345  floatData[i] = interpList[i].weight0();
346  }
347  writer.write("weight", floatData);
348 
349  forAll(interpList, i)
350  {
351  floatData[i] = interpList[i].weight1();
352  }
353  writer.write("weight1", floatData);
354 
355  forAll(interpList, i)
356  {
357  floatData[i] = interpList[i].weight2();
358  }
359  writer.write("weight2", floatData);
360  }
361 
363  }
364 }
365 
366 
367 // ************************************************************************* //
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:114
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:150
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.
static const Field< vector > & null() noexcept
Return a null Field (reference to a nullObject). Behaves like an empty Field.
Definition: Field.H:186
T & first()
Access first element of the list, position [0].
Definition: UList.H:886
void writeZonesVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write pressure-zones geometry, write as VTK PolyData format.
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:286
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.
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:609
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,.
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 registered IO, a reference to the associated polyMesh...
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:64
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1619
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:75
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
static const List< face > & null() noexcept
Return a null List (reference to a nullObject). Behaves like an empty List.
Definition: List.H:158
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:168