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-------------------------------------------------------------------------------
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
26Class
27 Foam::lumpedPointMovement
28
29Description
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
90SourceFiles
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"
108#include "lumpedPointState.H"
109#include "Enum.H"
110
111// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112
113namespace Foam
114{
115
116// Forward Declarations
117class polyMesh;
118class polyPatch;
119class pointPatch;
120
121/*---------------------------------------------------------------------------*\
122 Class lumpedPointMovement Declaration
123\*---------------------------------------------------------------------------*/
124
125class lumpedPointMovement
126{
127public:
128
129 // Data Types
130
131 //- Output format types
132 enum class outputFormatType
133 {
134 PLAIN,
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
156private:
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
228
229 //- No copy assignment
230 void operator=(const lumpedPointMovement&) = delete;
231
232
233public:
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;
265
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);
274
275 //- Communication control
276 inline const externalFileCoupler& coupler() const;
277
278 //- Communication control
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;
301
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
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.
386 const polyMesh& pmesh,
387 List<vector>& forces,
388 List<vector>& moments
389 ) const;
390
392 //- Displace points according to the current state
395 const pointPatch& fpatch,
396 const pointField& points0
397 ) const;
399 //- Displace points according to specified state
401 (
402 const lumpedPointState& state,
403 const pointPatch& fpatch,
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// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:68
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: Tuple2.H:58
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Encapsulates the logic for coordinating between OpenFOAM and an external application.
A class for handling file names.
Definition: fileName.H:76
The movement driver that describes initial point locations, the current state of the points/rotations...
void writeForcesAndMomentsVTP(const fileName &file, const UList< vector > &forces, const UList< vector > &moments) const
Write forces on points as VTK PolyData format.
const word & outputName() const
The output (forces) file name.
void writeStateVTP(const lumpedPointState &state, const fileName &file) const
Write state as VTK PolyData format.
bool hasPatchControl(const label patchIndex) const
Check if patch control exists for specified patch.
void scalePoints(lumpedPointState &state) const
Scale the lumped points (on input).
static const word canonicalName
The canonical name ("lumpedPointMovement") for the dictionary.
scalar relax() const
The relaxation factor when changing states.
tmp< pointField > pointsDisplacement(const pointPatch &fpatch, const pointField &points0) const
Displace points according to the current state.
bool degrees() const
Rotation angles in degrees.
static const Enum< outputFormatType > formatNames
Names for the output format types.
tmp< pointField > pointsDisplacement(const lumpedPointState &state, const pointPatch &fpatch, const pointField &points0) const
Displace points according to specified state.
const word & logName() const
The log file name.
label size() const
The number of lumped points (number of locations)
lumpedPointMovement::outputFormatType outputFormat() const
The output (forces) file format.
const lumpedPointState & state() const
The current state (positions/rotations)
bool empty() const
If no number of lumped points (locations) were specified.
tmp< pointField > pointsPosition(const lumpedPointState &state, const pointPatch &fpatch, const pointField &points0) const
The points absolute position according to specified state.
void readDict(const dictionary &dict)
Update settings from dictionary.
void setInterpolator(const pointPatch &fpatch, const pointField &points0)
Check if patch control exists for specified patch.
void setPatchControl(const polyPatch &pp, const wordList &ctrlNames, const pointField &points0)
Define pressure-zones mapping for faces in the specified patches.
bool readState()
Read state from file, applying relaxation as requested.
quaternion::eulerOrder rotationOrder() const
The Euler-angle rotation order.
void couplingCompleted(const label timeIndex) const
Register that coupling is completed at this calcFrequency.
bool couplingPending(const label timeIndex) const
Check if coupling is pending (according to the calcFrequency)
bool writeData(const UList< vector > &forces, const UList< vector > &moments=List< vector >(), const Tuple2< scalar, scalar > *timesWritten=nullptr) const
Write points, forces, moments.
label ownerId() const
An owner Id, if needed for bookkeeping purposes.
static const Enum< scalingType > scalingNames
Names for the scaling types.
const word & inputName() const
The input (state) file name.
bool hasMapping() const
True if the pressure-zones mapping has already been performed.
void checkPatchControl(const polyPatch &pp) const
Check if patch control exists for specified patch.
outputFormatType
Output format types.
@ DICTIONARY
"dictionary" is the OpenFOAM dictionary format
@ PLAIN
"plain" is a simple ASCII format
lumpedPointState::inputFormatType inputFormat() const
The input (state) file format.
const externalFileCoupler & coupler() const
Communication control.
void setMapping(const polyMesh &mesh, const labelUList &patchIds, const pointField &points0)
Define pressure-zones mapping for faces in the specified patches.
const lumpedPointState & state0() const
The initial state (positions/rotations)
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 writeDict(Ostream &os) const
Write axis, locations, division as a dictionary.
static int debug
Debug switch.
virtual ~lumpedPointMovement()=default
Destructor.
void writeZonesVTP(const fileName &file, const polyMesh &mesh, const pointField &points0) const
Write pressure-zones geometry, write as VTK PolyData format.
bool hasInterpolator(const pointPatch &fpatch) const
Check if patch control exists for specified patch.
lumpedPointMovement()
Default construct.
const point & origin() const
The offset for lumped points, used on input.
lumpedPointMovement(const dictionary &dict, label ownerId=-1)
Construct from dictionary, optionally with some owner information.
bool forcesAndMoments(const polyMesh &pmesh, List< vector > &forces, List< vector > &moments) const
The forces and moments acting on each pressure-zone.
scalingType
Output format types.
@ FORCE
The "force" scaling.
@ LENGTH
The "length" scaling.
@ MOMENT
The "moment" scaling.
bool hasPatchControl(const polyPatch &pp) const
Check if patch control exists for specified patch.
List< scalar > areas(const polyMesh &pmesh) const
The areas for each pressure-zone.
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.
inputFormatType
Input format types.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:64
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
eulerOrder
Euler-angle rotation order.
Definition: quaternion.H:104
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
labelList patchIds
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:63
List< label > labelList
A List of labels.
Definition: List.H:66
vector point
Point is a vector.
Definition: point.H:43
label timeIndex
Definition: getTimeIndex.H:30
Specialisations of Field<T> for scalar, vector and tensor.
dictionary dict
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, false)))