lumpedPointMovement.H
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 Class
27  Foam::lumpedPointMovement
28 
29 Description
30  The movement \a driver that describes initial point locations,
31  the current state of the points/rotations,
32  and forwarding to the externalFileCoupler
33  communication coordinator.
34 
35  The lumpedPointIOMovement class is simply a registered version of
36  the same.
37 
38  See externalFileCoupler for more information about some of
39  the communication parameters and setup.
40 
41  \heading Dictionary parameters
42  \table
43  Property | Description | Required | Default
44  points | Initial locations of lumped points | yes |
45  pointLabels | The FEA ids for the points | no |
46  origin | Shift offset when reading points | no | (0 0 0)
47  rotationOrder | The Euler rotation order | no | zxz
48  degrees | Input rotations in degrees | no | false
49  relax | Relaxation/scaling for updating positions | no | 1
50  controllers | Motion controllers (dictionary) | yes |
51  forces | Force settings (dictionary) | no |
52  communication | Communication settings (dictionary) | yes |
53  \endtable
54 
55  \heading Parameters for communication dictionary
56  \table
57  Property | Description | Required | Default
58  inputName | Name of positions input file | yes |
59  outputName | Name of forces output file | yes |
60  logName | Name of log file | no | movement.log
61  inputFormat | Input format: dictionary/plain | yes |
62  outputFormat | Output format: dictionary/plain | yes |
63  scaleInput | Input scaling parameter dictionary | no |
64  scaleOutput | Output scaling parameter dictionary | no |
65  calcFrequency | Calculation/coupling frequency | no | 1
66  \endtable
67 
68  \heading Parameters for optional communication/scaleInput dictionary
69  \table
70  Property | Description | Required | Default
71  length | Scaling for input positions | no | 1
72  \endtable
73 
74  \heading Parameters for optional communication/scaleOutput dictionary
75  \table
76  Property | Description | Required | Default
77  length | Scaling for output positions | no | 1
78  force | Scaling for force | no | 1
79  moment | Scaling for moment | no | 1
80  \endtable
81 
82  \heading Parameters for optional forces dictionary
83  \table
84  Property | Description | Required | Default
85  p | Name of the pressure field | no | p
86  pRef | Reference pressure in Pa | no | 0
87  rhoRef | Reference density for incompressible | no | 1
88  \endtable
89 
90 SourceFiles
91  lumpedPointMovement.C
92 
93 \*---------------------------------------------------------------------------*/
94 
95 #ifndef lumpedPointMovement_H
96 #define lumpedPointMovement_H
97 
98 #include "dictionary.H"
99 #include "scalarList.H"
100 #include "primitiveFields.H"
101 #include "IOobject.H"
102 #include "tmp.H"
103 #include "Tuple2.H"
104 #include "HashPtrTable.H"
105 #include "externalFileCoupler.H"
106 #include "lumpedPointController.H"
107 #include "lumpedPointInterpolator.H"
108 #include "lumpedPointState.H"
109 #include "Enum.H"
110 
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 
113 namespace Foam
114 {
115 
116 // Forward Declarations
117 class polyMesh;
118 class polyPatch;
119 class pointPatch;
120 
121 /*---------------------------------------------------------------------------*\
122  Class lumpedPointMovement Declaration
123 \*---------------------------------------------------------------------------*/
124 
125 class lumpedPointMovement
126 {
127 public:
128 
129  // Data Types
130 
131  //- Output format types
132  enum class outputFormatType
133  {
134  PLAIN,
135  DICTIONARY
136  };
137 
138  //- Output format types
139  enum scalingType
140  {
141  LENGTH = 0,
142  FORCE,
143  MOMENT
144  };
145 
146 
147  // Static Data
148 
149  //- Names for the output format types
150  static const Enum<outputFormatType> formatNames;
151 
152  //- Names for the scaling types
153  static const Enum<scalingType> scalingNames;
154 
155 
156 private:
157 
158  // Private Class
159 
160  //- The controller names and faceCentre mapping for a patch
161  struct patchControl
162  {
163  wordList names_;
164  labelList faceToPoint_;
165  List<lumpedPointInterpolator> interp_;
166  };
167 
168 
169  // Private Data
170 
171  //- The offset for lumped points, used on input.
172  point origin_;
173 
174  //- The initial state of positions with zero rotations.
175  lumpedPointState state0_;
176 
177  //- The current state (positions, rotations)
178  // Eg, as response from external application
179  lumpedPointState state_;
180 
181  //- The original point ids (optional information)
182  labelList originalIds_;
183 
184  //- Connectivity for the controllers
185  HashPtrTable<lumpedPointController> controllers_;
186 
187  //- The controller names and faceCentre mapping for patches
188  Map<patchControl> patchControls_;
189 
190  //- The relaxation factor when moving points (default: 1)
191  scalar relax_;
192 
193  //- Optional owner information (patch owner)
194  label ownerId_;
195 
196  //- Dictionary of controls for force calculation
197  dictionary forcesDict_;
198 
199  //- Communication control
200  externalFileCoupler coupler_;
201 
202  //- File IO names
203  word inputName_;
204  word outputName_;
205  word logName_;
206 
207  //- The input format for points, rotations
209 
210  //- The output format for forces, moments
211  outputFormatType outputFormat_;
212 
213  //- Scale factors for input/output files (optional)
214  FixedList<scalar, 1> scaleInput_;
215  FixedList<scalar, 3> scaleOutput_;
216 
217  //- Calculation frequency
218  label calcFrequency_;
219 
220  //- The last timeIndex when coupling was triggered
221  mutable label lastTrigger_;
222 
223 
224  // Private Member Functions
225 
226  //- No copy construct
227  lumpedPointMovement(const lumpedPointMovement&) = delete;
228 
229  //- No copy assignment
230  void operator=(const lumpedPointMovement&) = delete;
231 
232 
233 public:
234 
235  // Static Data Members
236 
237  //- Debug switch
238  static int debug;
239 
240  //- The canonical name ("lumpedPointMovement") for the dictionary
241  static const word canonicalName;
242 
243 
244  // Constructors
245 
246  //- Default construct
248 
249  //- Construct from dictionary, optionally with some owner information
250  explicit lumpedPointMovement(const dictionary& dict, label ownerId=-1);
251 
252 
253  //- Destructor
254  virtual ~lumpedPointMovement() = default;
255 
256 
257  // Member Functions
258 
259  //- Update settings from dictionary
260  void readDict(const dictionary& dict);
261 
262 
263  //- If no number of lumped points (locations) were specified
264  inline bool empty() const;
266  //- The number of lumped points (number of locations)
267  inline label size() const;
268 
269  //- An owner Id, if needed for bookkeeping purposes
270  inline label ownerId() const;
271 
272  //- Change the owner id, if needed for bookkeeping purposes
273  inline void ownerId(label id);
275  //- Communication control
276  inline const externalFileCoupler& coupler() const;
277 
278  //- Communication control
279  inline externalFileCoupler& coupler();
280 
281  //- Check if coupling is pending (according to the calcFrequency)
282  bool couplingPending(const label timeIndex) const;
284  //- Register that coupling is completed at this calcFrequency
285  void couplingCompleted(const label timeIndex) const;
287  //- The initial state (positions/rotations)
288  inline const lumpedPointState& state0() const;
289 
290  //- The current state (positions/rotations)
291  inline const lumpedPointState& state() const;
292 
293  //- The offset for lumped points, used on input.
294  inline const point& origin() const;
295 
296  //- Scale the lumped points (on input).
297  inline void scalePoints(lumpedPointState& state) const;
298 
299  //- The relaxation factor when changing states
300  inline scalar relax() const;
302  //- The relaxation factor when changing states
303  inline scalar& relax();
304 
305  //- The input (state) file name
306  inline const word& inputName() const;
307 
308  //- The output (forces) file name
309  inline const word& outputName() const;
310 
311  //- The log file name
312  inline const word& logName() const;
313 
314  //- The input (state) file format
316 
317  //- The output (forces) file format
319 
320  //- The Euler-angle rotation order
321  inline quaternion::eulerOrder rotationOrder() const;
322 
323  //- Rotation angles in degrees
324  inline bool degrees() const;
325 
326  //- Check if patch control exists for specified patch
327  inline bool hasPatchControl(const label patchIndex) const;
328 
329  //- Check if patch control exists for specified patch
330  bool hasPatchControl(const polyPatch& pp) const;
331 
332  //- Check if patch control exists for specified patch
333  bool hasInterpolator(const pointPatch& fpatch) const;
334 
335  //- Check if patch control exists for specified patch
336  void checkPatchControl(const polyPatch& pp) const;
337 
338  //- Define pressure-zones mapping for faces in the specified patches.
339  // The face centres are compared to the controller points,
340  //
341  // \param pp The patch with a control
342  // \param ctrlNames The patch ids to be included in the mapping
343  // \param points0 The initial mesh points, prior to movement
344  void setPatchControl
345  (
346  const polyPatch& pp,
347  const wordList& ctrlNames,
348  const pointField& points0
349  );
350 
351 
352  //- Define pressure-zones mapping for faces in the specified patches.
353  // The face centres are compared to the controller points,
354  //
355  // \param mesh The volume mesh reference
356  // \param patchIds The patch ids to be included in the mapping
357  // \param points0 The initial mesh points, prior to movement
358  void setMapping
359  (
360  const polyMesh& mesh,
361  const labelUList& patchIds,
362  const pointField& points0
363  );
364 
365 
366  //- Check if patch control exists for specified patch
367  void setInterpolator
368  (
369  const pointPatch& fpatch,
370  const pointField& points0
371  );
372 
373  //- True if the pressure-zones mapping has already been performed
374  inline bool hasMapping() const;
375 
376  //- Check if patch interpolator exists for specified patch
377  inline bool hasInterpolator(const label patchIndex) const;
378 
379  //- The areas for each pressure-zone.
380  List<scalar> areas(const polyMesh& pmesh) const;
381 
382  //- The forces and moments acting on each pressure-zone.
383  // The zones must be previously defined via setMapping.
384  bool forcesAndMoments
385  (
386  const polyMesh& pmesh,
387  List<vector>& forces,
388  List<vector>& moments
389  ) const;
390 
391 
392  //- Displace points according to the current state
394  (
395  const pointPatch& fpatch,
396  const pointField& points0
397  ) const;
398 
399  //- Displace points according to specified state
401  (
402  const lumpedPointState& state,
403  const pointPatch& fpatch,
404  const pointField& points0
405  ) const;
406 
407  //- The points absolute position according to specified state
409  (
410  const lumpedPointState& state,
411  const pointPatch& fpatch,
412  const pointField& points0
413  ) const;
414 
415 
416  //- Write axis, locations, division as a dictionary
417  void writeDict(Ostream& os) const;
418 
419  //- Write points, forces, moments. Only call from the master process
420  bool writeData
421  (
422  Ostream& os,
423  const UList<vector>& forces,
424  const UList<vector>& moments,
426  const Tuple2<scalar, scalar>* timesWritten = nullptr
427  ) const;
428 
429  //- Write points, forces, moments
430  bool writeData
431  (
432  const UList<vector>& forces,
433  const UList<vector>& moments = List<vector>(),
434  const Tuple2<scalar, scalar>* timesWritten = nullptr
435  ) const;
436 
437  //- Read state from file, applying relaxation as requested
438  bool readState();
439 
440  //- Write state as VTK PolyData format.
441  void writeStateVTP
442  (
443  const lumpedPointState& state,
444  const fileName& file
445  ) const;
446 
447  //- Write state as VTK PolyData format.
448  void writeStateVTP(const fileName& file) const;
449 
450  //- Write forces on points as VTK PolyData format.
452  (
453  const fileName& file,
454  const UList<vector>& forces,
455  const UList<vector>& moments
456  ) const;
457 
458 
459  //- Write pressure-zones geometry, write as VTK PolyData format.
460  void writeZonesVTP
461  (
462  const fileName& file,
463  const polyMesh& mesh,
464  const pointField& points0
465  ) const;
466 
467  //- Write displaced geometry according to the current state,
468  // write as VTK PolyData format.
469  void writeVTP
470  (
471  const fileName& file,
472  const polyMesh& mesh,
473  const pointField& points0
474  ) const;
475 
476  //- Write displaced geometry according to the specified state,
477  // write as VTK PolyData format.
478  void writeVTP
479  (
480  const fileName& file,
481  const lumpedPointState& state,
482  const polyMesh& mesh,
483  const pointField& points0
484  ) const;
485 };
486 
487 
488 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
489 
490 } // End namespace Foam
491 
492 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
493 
494 #include "lumpedPointMovementI.H"
495 
496 #endif
497 
498 // ************************************************************************* //
labelList patchIds
dictionary dict
const word & inputName() const
The input (state) file name.
Encapsulates the logic for coordinating between OpenFOAM and an external application.
const word & outputName() const
The output (forces) file name.
List< scalar > areas(const polyMesh &pmesh) const
The areas for each pressure-zone.
A class for handling file names.
Definition: fileName.H:72
tmp< pointField > pointsPosition(const lumpedPointState &state, const pointPatch &fpatch, const pointField &points0) const
The points absolute position according to specified state.
inputFormatType
Input format types.
void writeStateVTP(const lumpedPointState &state, const fileName &file) const
Write state as VTK PolyData format.
void setInterpolator(const pointPatch &fpatch, const pointField &points0)
Check if patch control exists for specified patch.
static const Enum< outputFormatType > formatNames
Names for the output format types.
bool hasMapping() const
True if the pressure-zones mapping has already been performed.
quaternion::eulerOrder rotationOrder() const
The Euler-angle rotation order.
void couplingCompleted(const label timeIndex) const
Register that coupling is completed at this calcFrequency.
void readDict(const dictionary &dict)
Update settings from dictionary.
void writeZonesVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write pressure-zones geometry, write as VTK PolyData format.
bool writeData(Ostream &os, const UList< vector > &forces, const UList< vector > &moments, const outputFormatType fmt=outputFormatType::PLAIN, const Tuple2< scalar, scalar > *timesWritten=nullptr) const
Write points, forces, moments. Only call from the master process.
void scalePoints(lumpedPointState &state) const
Scale the lumped points (on input).
lumpedPointMovement::outputFormatType outputFormat() const
The output (forces) file format.
void setPatchControl(const polyPatch &pp, const wordList &ctrlNames, const pointField &points0)
Define pressure-zones mapping for faces in the specified patches.
static const Enum< scalingType > scalingNames
Names for the scaling types.
scalingType
Output format types.
virtual ~lumpedPointMovement()=default
Destructor.
static const word canonicalName
The canonical name ("lumpedPointMovement") for the dictionary.
label ownerId() const
An owner Id, if needed for bookkeeping purposes.
lumpedPointState::inputFormatType inputFormat() const
The input (state) file format.
dynamicFvMesh & mesh
bool degrees() const
Rotation angles in degrees.
const word & logName() const
The log file name.
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool forcesAndMoments(const polyMesh &pmesh, List< vector > &forces, List< vector > &moments) const
The forces and moments acting on each pressure-zone.
const externalFileCoupler & coupler() const
Communication control.
bool hasInterpolator(const pointPatch &fpatch) const
Check if patch control exists for specified patch.
outputFormatType
Output format types.
scalar relax() const
The relaxation factor when changing states.
void writeVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write displaced geometry according to the current state,.
eulerOrder
Euler-angle rotation order.
Definition: quaternion.H:115
bool empty() const
If no number of lumped points (locations) were specified.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
"dictionary" is the OpenFOAM dictionary format
tmp< pointField > pointsDisplacement(const pointPatch &fpatch, const pointField &points0) const
Displace points according to the current state.
OBJstream os(runTime.globalPath()/outputName)
bool readState()
Read state from file, applying relaxation as requested.
void writeDict(Ostream &os) const
Write axis, locations, division as a dictionary.
void writeForcesAndMomentsVTP(const fileName &file, const UList< vector > &forces, const UList< vector > &moments) const
Write forces on points as VTK PolyData format.
Specialisations of Field<T> for scalar, vector and tensor.
void checkPatchControl(const polyPatch &pp) const
Check if patch control exists for specified patch.
List< word > wordList
List of word.
Definition: fileName.H:59
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, IOobject::NO_REGISTER)))
bool couplingPending(const label timeIndex) const
Check if coupling is pending (according to the calcFrequency)
vector point
Point is a vector.
Definition: point.H:37
const lumpedPointState & state() const
The current state (positions/rotations)
const point & origin() const
The offset for lumped points, used on input.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
static int debug
Debug switch.
const lumpedPointState & state0() const
The initial state (positions/rotations)
void setMapping(const polyMesh &mesh, const labelUList &patchIds, const pointField &points0)
Define pressure-zones mapping for faces in the specified patches.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
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
bool hasPatchControl(const label patchIndex) const
Check if patch control exists for specified patch.
label size() const
The number of lumped points (number of locations)
lumpedPointMovement()
Default construct.
The state of lumped points corresponds to positions and rotations.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
label timeIndex
Definition: getTimeIndex.H:24