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-2026 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 "foamVtkSurfaceWriter.H"
32 #include "foamVtkVertexWriter.H"
33 
34 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
35 
37 (
38  const lumpedPointState& state,
39  const fileName& file
40 ) const
41 {
42  if (!UPstream::master())
43  {
44  // No extra information available from slaves, write on master only.
45  return;
46  }
47 
48  labelListList lines;
49 
50  if (label nLines = controllers_.size(); nLines > 0)
51  {
52  lines.resize(nLines);
53  nLines = 0;
54 
55  for (const word& ctrlName : controllers_.sortedToc())
56  {
57  lines[nLines] = controllers_[ctrlName]->pointLabels();
58  ++nLines;
59  }
60  }
61  else
62  {
63  // Default - global with all points as a single line
64  lines.resize(1);
65  lines.first() = identity(state.size());
66  }
67 
68  state.writeVTP(file, lines, originalIds_);
69 }
70 
71 
73 {
74  writeStateVTP(state(), file);
75 }
76 
77 
79 (
80  const fileName& file,
81  const UList<vector>& forces,
82  const UList<vector>& moments
83 ) const
84 {
85  if (!UPstream::master())
86  {
87  // Force, moments already reduced
88  return;
89  }
90 
91  vtk::vertexWriter writer
92  (
93  state().points(),
95  file,
96  false // non-parallel
97  );
98 
100 
101  const auto nPoints = state().points().size();
102 
103  int nFields(0);
104  if (forces.size() == nPoints) ++nFields;
105  if (moments.size() == nPoints) ++nFields;
106 
107  if (!nFields)
108  {
109  return;
110  }
111 
112  // CellData
113  writer.beginCellData(nFields);
114  if (forces.size() == nPoints)
115  {
116  writer.writeCellData("forces", forces);
117  }
118  if (moments.size() == nPoints)
119  {
120  writer.writeCellData("moments", moments);
121  }
122 
123  // PointData
124  writer.beginPointData(nFields);
125  if (forces.size() == nPoints)
126  {
127  writer.writePointData("forces", forces);
128  }
129  if (moments.size() == nPoints)
130  {
131  writer.writePointData("moments", moments);
132  }
133 }
134 
135 
137 (
138  const fileName& file,
139  const polyMesh& mesh,
140  const pointField& points0
141 ) const
142 {
143  const polyBoundaryMesh& patches = mesh.boundaryMesh();
144  const labelList patchIds(patchControls_.sortedToc());
145 
146  vtk::surfaceWriter writer
147  (
149  faceList::null(),
151  file
152  );
153 
154  for (const label patchi : patchIds)
155  {
156  const labelList& faceToPoint = patchControls_[patchi].faceToPoint_;
157 
158  primitivePatch pp(patches[patchi].faces(), points0);
159 
161 
163 
165 
166  writer.writeUniform("patchId", patchi);
167  writer.write("lumpedId", faceToPoint);
170  }
171 }
172 
173 
175 (
176  const fileName& file,
177  const polyMesh& mesh,
178  const pointField& points0
179 ) const
180 {
181  writeVTP(file, state(), mesh, points0);
182 }
183 
184 
186 (
187  const fileName& file,
188  const lumpedPointState& state,
189  const polyMesh& mesh,
190  const pointField& points0
191 ) const
192 {
194  const labelList patchIds(patchControls_.sortedToc());
195 
196  pointMesh ptMesh(mesh);
197 
199  (
201  faceList::null(),
203  file
204  );
205 
206  for (const label patchi : patchIds)
207  {
208  const polyPatch& pp = patches[patchi];
209 
210  const pointPatch& ptPatch = ptMesh.boundary()[patchi];
211 
212  // Current position (not displacement)
213  tmp<pointField> tpts = pointsPosition(state, ptPatch, points0);
214 
215  writer.piece(tpts(), pp.localFaces());
216 
218 
219  // Face mapping
220  const labelList& faceToPoint = patchControls_[patchi].faceToPoint_;
221 
223 
224  writer.writeUniform("patchId", patchi);
225  writer.write("lumpedId", faceToPoint);
226 
228 
229  // The interpolator
230  const List<lumpedPointInterpolator>& interpList
231  = patchControls_[patchi].interp_;
232 
234 
235  // Nearest, Next
236  {
237  labelList intData(interpList.size());
238 
239  forAll(interpList, i)
240  {
241  intData[i] = interpList[i].nearest();
242  }
243  writer.write("nearest", intData);
244 
245  forAll(interpList, i)
246  {
247  intData[i] = interpList[i].next1();
248  }
249  writer.write("next1", intData);
250 
251 
252  forAll(interpList, i)
253  {
254  intData[i] = interpList[i].next2();
255  }
256  writer.write("next2", intData);
257  }
258 
259  // Weights
260  {
261  scalarList floatData(interpList.size());
262 
263  forAll(interpList, i)
264  {
265  floatData[i] = interpList[i].weight0();
266  }
267  writer.write("weight", floatData);
268 
269  forAll(interpList, i)
270  {
271  floatData[i] = interpList[i].weight1();
272  }
273  writer.write("weight1", floatData);
274 
275  forAll(interpList, i)
276  {
277  floatData[i] = interpList[i].weight2();
278  }
279  writer.write("weight2", floatData);
280  }
281 
283  }
284 }
285 
286 
287 // ************************************************************************* //
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:119
const pointField & points() const noexcept
The points corresponding to mass centres.
A class for handling file names.
Definition: fileName.H:72
virtual bool writeGeometry()
Write vertex topology.
const Field< point_type > & localPoints() const
Return pointField of points in patch.
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:153
void writeStateVTP(const lumpedPointState &state, const fileName &file) const
Write state as VTK PolyData format.
void writePointData(const word &fieldName, const UList< Type > &field)
Write primitive field of PointData.
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:192
T & first()
Access first element of the list, position [0].
Definition: UList.H:958
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 or PointData values (size depending on the current context)...
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:400
void writeCellData(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
const pointField & points
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:611
A class for handling words, derived from Foam::string.
Definition: word.H:63
label nPoints
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
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...
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of CellData or PointData (depending on the current context).
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
A PrimitivePatch with a SubList addressing for the faces, const reference for the point field...
void writeForcesAndMomentsVTP(const fileName &file, const UList< vector > &forces, const UList< vector > &moments) const
Write forces on points as VTK PolyData format.
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, IOobject::NO_REGISTER)))
void piece(const pointField &points)
Reset point references to begin a new piece.
const lumpedPointState & state() const
The current state (positions/rotations)
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:64
const polyBoundaryMesh & patches
static bool master(label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1807
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
vtk::vertexWriter writer(edgeCentres, outputOpts,(aMesh.time().globalPath()/outputName), UPstream::parRun())
List< label > labelList
A List of labels.
Definition: List.H:61
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
label size() const noexcept
The number of points.
static const List< face > & null() noexcept
Return a null List (reference to a nullObject). Behaves like an empty List.
Definition: List.H:137
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
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())
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...
A topoSetPointSource to select all points based on usage in given faceSet(s).
Definition: faceToPoint.H:168