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-------------------------------------------------------------------------------
10License
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"
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 (
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
244 writer.piece(pp.localPoints(), pp.localFaces());
245
247
249
250 writer.writeUniform("patchId", patchi);
251 writer.write("lumpedId", faceToPoint);
252
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 (
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// ************************************************************************* //
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Output to file stream, using an OSstream.
Definition: OFstream.H:57
virtual std::ostream & stdStream()
Access to underlying std::ostream.
Definition: OFstream.C:102
A list of faces which address into the list of points.
const Field< point_type > & localPoints() const
Return pointField of points in patch.
const List< face_type > & localFaces() const
Return patch faces addressing into local point list.
A List obtained as a section of another List.
Definition: SubList.H:70
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
T & first()
Return the first element of the list.
Definition: UListI.H:202
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A topoSetPointSource to select all points based on usage in given faceSet(s).
Definition: faceToPoint.H:177
A class for handling file names.
Definition: fileName.H:76
void writeForcesAndMomentsVTP(const fileName &file, const UList< vector > &forces, const UList< vector > &moments) const
Write forces on points as VTK PolyData format.
void writeStateVTP(const lumpedPointState &state, const fileName &file) const
Write state as VTK PolyData format.
const lumpedPointState & state() const
The current state (positions/rotations)
void writeZonesVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write pressure-zones geometry, write as VTK PolyData format.
void writeVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write displaced geometry according to the current state,.
The state of lumped points corresponds to positions and rotations.
label size() const
The number of points.
void writeVTP(const fileName &outputFile, const labelListList &lines=labelListList(), const labelList &pointIds=labelList::null()) const
Output points/rotations as VTK file for debugging/visualization.
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:55
const pointBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: pointMesh.H:114
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:64
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
labelRange range() const noexcept
The face range for all boundary faces.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1108
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
splitCell * master() const
Definition: splitCell.H:113
A class for managing temporary objects.
Definition: tmp.H:65
bool endCellData()
Explicitly end CellData output and switch to PIECE state.
bool endPointData()
Explicitly end PointData output and switch to PIECE state.
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell or Point values.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
virtual bool writeGeometry()
Write mesh topology.
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
A class for handling words, derived from Foam::string.
Definition: word.H:68
labelList patchIds
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
label nPoints
@ NUMBER_OF_VERTS
"NumberOfVerts"
@ NUMBER_OF_POINTS
"NumberOfPoints"
void writeIdentity(vtk::formatter &fmt, const label len, label start=0)
Write an identity list of labels.
Definition: foamVtkOutput.C:96
@ CONNECTIVITY
"connectivity"
@ POLY_DATA
"PolyData"
@ INLINE_ASCII
XML inline ASCII, asciiFormatter.
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
Definition: foamVtkOutput.C:48
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
word format(conversionProperties.get< word >("format"))
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, false)))