Loading...
Searching...
No Matches
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(
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
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();
210
212 .endVTKFile();
213}
214
215
217(
218 const fileName& file,
219 const polyMesh& mesh,
220 const pointField& points0
221) const
222{
223 const polyBoundaryMesh& patches = mesh.boundaryMesh();
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
238 primitivePatch pp(patches[patchi].faces(), points0);
239
240 writer.piece(pp.localPoints(), pp.localFaces());
241
242 writer.writeGeometry();
243
244 writer.beginCellData(2);
245
246 writer.writeUniform("patchId", patchi);
247 writer.write("lumpedId", faceToPoint);
248
249 writer.endCellData();
250 }
251}
252
253
255(
256 const fileName& file,
257 const polyMesh& mesh,
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{
273 const polyBoundaryMesh& patches = mesh.boundaryMesh();
274 const labelList patchIds(patchControls_.sortedToc());
275
276 pointMesh ptMesh(mesh);
277
279 (
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
297 writer.writeGeometry();
298
299 // Face mapping
300 const labelList& faceToPoint = patchControls_[patchi].faceToPoint_;
301
302 writer.beginCellData(2);
303
304 writer.writeUniform("patchId", patchi);
305 writer.write("lumpedId", faceToPoint);
306
307 writer.endCellData();
308
309 // The interpolator
310 const List<lumpedPointInterpolator>& interpList
311 = patchControls_[patchi].interp_;
312
313 writer.beginPointData(3);
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// ************************************************************************* //
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edgesCentres")))
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
static const Field< vector > & null() noexcept
Definition Field.H:192
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
static const List< face > & null() noexcept
Definition List.H:138
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Definition OFstream.H:75
virtual const std::ostream & stdStream() const override
Const access to underlying std::ostream.
Definition OFstream.C:125
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:89
T & first()
Access first element of the list, position [0].
Definition UList.H:957
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition UPstream.H:1714
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A topoSetPointSource to select all points based on usage in given faceSet(s).
A class for handling file names.
Definition fileName.H:75
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).
tmp< pointField > pointsPosition(const lumpedPointState &state, const pointPatch &fpatch, const pointField &points0) const
The points absolute position according to specified state.
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.
void writeVTP(const fileName &outputFile, const labelListList &lines=labelListList(), const labelList &pointIds=labelList::null()) const
Output points/rotations as VTK file for debugging/visualization.
const pointField & points() const
The points corresponding to mass centres.
Mesh representing a set of points created from polyMesh.
Definition pointMesh.H:49
const pointBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition pointMesh.H:177
Basic pointPatch represents a set of points from the mesh.
Definition pointPatch.H:67
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
A class for managing temporary objects.
Definition tmp.H:75
bool endPointData()
Explicitly end PointData output and switch to PIECE state.
void write(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData (Poly or Line) or PointData values.
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:66
labelList patchIds
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
label nPoints
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
uint64_t sizeofData(label count)
Commonly used calculation for header and payload sizes.
@ 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.
@ CONNECTIVITY
"connectivity"
@ POLY_DATA
"PolyData"
@ INLINE_ASCII
XML inline ASCII, asciiFormatter.
Definition foamVtkCore.H:90
void writeList(vtk::formatter &fmt, const UList< uint8_t > &values)
Write a list of uint8_t values.
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
A PrimitivePatch with a SubList addressing for the faces, const reference for the point field.
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...
vectorField pointField
pointField is a vectorField.
List< scalar > scalarList
List of scalar.
Definition scalarList.H:32
word format(conversionProperties.get< word >("format"))
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, IOobject::NO_REGISTER)))