lumpedPointState.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::lumpedPointState
28 
29 Description
30  The \a state of lumped points corresponds to positions and rotations.
31 
32  This class encapsulates the response from the external application and
33  serves as the entry point for applying relaxation, sub-stepping etc.
34 
35  \heading Dictionary input format
36  \table
37  Property | Description | Required | Default
38  points | List of points | yes |
39  angles | List of Euler rotation angles | yes |
40  rotationOrder | The Euler-angle rotation order | no | zxz
41  degrees | Rotation angles in degrees | no | false
42  \endtable
43 
44  \heading Plain input format.
45  Blank and comment lines starting with a '#' character are ignored.
46  The angles are always in radians.
47  \verbatim
48  NumPoints
49  x0 y0 z0 eulerz0 eulerx'0 eulerz''0
50  x1 y1 z1 eulerz1 eulerx'1 eulerz''1
51  ...
52  \endverbatim
53 
54 SeeAlso
55  Foam::coordinateRotations::euler, Foam::quaternion
56 
57 SourceFiles
58  lumpedPointState.C
59  lumpedPointStateI.H
60 
61 \*---------------------------------------------------------------------------*/
62 
63 #ifndef lumpedPointState_H
64 #define lumpedPointState_H
65 
66 #include "dictionary.H"
67 #include "scalarList.H"
68 #include "pointField.H"
69 #include "scalarField.H"
70 #include "vectorField.H"
71 #include "tensorField.H"
72 #include "quaternion.H"
73 #include "Enum.H"
74 
75 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76 
77 namespace Foam
78 {
79 
80 /*---------------------------------------------------------------------------*\
81  Class lumpedPointState Declaration
82 \*---------------------------------------------------------------------------*/
83 
84 class lumpedPointState
85 {
86 public:
87 
88  // Data Types
89 
90  //- Input format types
91  enum class inputFormatType
92  {
93  PLAIN,
94  DICTIONARY
95  };
96 
97 
98  // Static Data
99 
100  //- Names for the input format types
101  static const Enum<inputFormatType> formatNames;
102 
103 
104 private:
105 
106  // Private Data
107 
108  //- Positions of lumped points
109  pointField points_;
110 
111  //- Orientation of lumped points (as Euler angles)
112  vectorField angles_;
114  //- The Euler-angle rotation order (default: zxz)
115  quaternion::eulerOrder order_;
116 
117  //- Euler angles measured in degrees
118  bool degrees_;
119 
120  //- Tensor rotation of lumped points
121  mutable std::unique_ptr<tensorField> rotationPtr_;
122 
123 
124  // Private Member Functions
126  void calcRotations() const;
127 
128  void readDict
129  (
130  const dictionary& dict,
131  const quaternion::eulerOrder rotOrder = quaternion::eulerOrder::ZXZ,
132  const bool degrees = false
133  );
134 
135 public:
136 
137  // Public Data
138 
139  //- Enable/disable visualization of unused points
140  static bool visUnused;
141 
142  //- The length for visualization triangles
143  static scalar visLength;
144 
145 
146  // Constructors
147 
148  //- Default construct
150 
151  //- Copy construct
153 
154  //- Copy construct from points and angles
156  (
157  const pointField& pts,
158  const vectorField& ang,
159  const quaternion::eulerOrder rotOrder = quaternion::eulerOrder::ZXZ,
160  const bool degrees = false
161  );
162 
163  //- Copy construct from points with zero-rotation
164  explicit lumpedPointState
165  (
166  const pointField& pts,
167  const quaternion::eulerOrder rotOrder = quaternion::eulerOrder::ZXZ,
168  const bool degrees = false
169  );
170 
171  //- Construct from points with zero-rotation
172  explicit lumpedPointState
173  (
175  const quaternion::eulerOrder rotOrder = quaternion::eulerOrder::ZXZ,
176  const bool degrees = false
177  );
178 
179  //- Construct from dictionary
180  explicit lumpedPointState
181  (
182  const dictionary& dict,
183  const quaternion::eulerOrder rotOrder = quaternion::eulerOrder::ZXZ,
184  const bool degrees = false
185  );
186 
187 
188  //- Destructor
189  virtual ~lumpedPointState() = default;
190 
191 
192  // Member Functions
193 
194  //- Has positions and consistent number of rotations?
195  inline bool valid() const;
196 
197  //- If no points were specified
198  inline bool empty() const;
199 
200  //- The number of points
201  inline label size() const;
202 
203  //- The points corresponding to mass centres
204  inline const pointField& points() const;
205 
206  //- The orientation of the points (mass centres)
207  inline const vectorField& angles() const;
208 
209  //- The local-to-global transformation for each point
210  inline const tensorField& rotations() const;
211 
212  //- Scale points by given factor.
213  // Zero and negative values are ignored.
214  void scalePoints(const scalar scaleFactor);
215 
216  //- The Euler-angle rotation order
217  inline quaternion::eulerOrder rotationOrder() const;
218 
219  //- Rotation angles in degrees
220  inline bool degrees() const;
221 
222  //- Relax the state
223  // alpha = 1 : no relaxation
224  // alpha < 1 : relaxation
225  // alpha = 0 : do nothing
226  void relax(const scalar alpha, const lumpedPointState& prev);
227 
228  //- Read input as dictionary content
229  bool readData
230  (
231  Istream& is,
232  const quaternion::eulerOrder rotOrder = quaternion::eulerOrder::ZXZ,
233  const bool degrees = false
234  );
235 
236  //- Output as dictionary content
237  bool writeData(Ostream& os) const;
238 
239  //- Output as dictionary content
240  void writeDict(Ostream& os) const;
241 
242  //- Read input as plain content
243  bool readPlain
244  (
245  Istream& is,
246  const quaternion::eulerOrder rotOrder = quaternion::eulerOrder::ZXZ,
247  const bool degrees = false
248  );
249 
250  //- Output as plain content
251  void writePlain(Ostream& os) const;
252 
253  //- Read input from file (master process only) using specified format
254  bool readData
255  (
256  const inputFormatType fmt,
257  const fileName& file,
258  const quaternion::eulerOrder rotOrder = quaternion::eulerOrder::ZXZ,
259  const bool degrees = false
260  );
261 
262  //- Output points/rotations as VTK file for debugging/visualization
263  // The points are written as vertices, rotation as a triangle
264  void writeVTP
265  (
266  const fileName& outputFile,
267  const labelListList& lines = labelListList(),
268  const labelList& pointIds = labelList::null()
269  ) const;
270 
271 
272  // Member Operators
273 
274  //- Assignment operator
275  void operator=(const lumpedPointState& rhs);
276 
277  //- Shift points by specified origin
278  void operator+=(const point& origin);
279 };
280 
281 
282 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 
284 } // End namespace Foam
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 #include "lumpedPointStateI.H"
289 
290 #endif
291 
292 // ************************************************************************* //
dictionary dict
"dictionary" is the OpenFOAM dictionary format
A class for handling file names.
Definition: fileName.H:71
static scalar visLength
The length for visualization triangles.
inputFormatType
Input format types.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
quaternion::eulerOrder rotationOrder() const
The Euler-angle rotation order.
void writeDict(Ostream &os) const
Output as dictionary content.
void writePlain(Ostream &os) const
Output as plain content.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void operator=(const lumpedPointState &rhs)
Assignment operator.
"plain" is a simple ASCII format
static const List< label > & null()
Return a null List.
Definition: ListI.H:102
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
bool valid() const
Has positions and consistent number of rotations?
bool writeData(Ostream &os) const
Output as dictionary content.
static bool visUnused
Enable/disable visualization of unused points.
bool readPlain(Istream &is, const quaternion::eulerOrder rotOrder=quaternion::eulerOrder::ZXZ, const bool degrees=false)
Read input as plain content.
static const Enum< inputFormatType > formatNames
Names for the input format types.
void operator+=(const point &origin)
Shift points by specified origin.
const vectorField & angles() const
The orientation of the points (mass centres)
eulerOrder
Euler-angle rotation order.
Definition: quaternion.H:115
lumpedPointState()
Default construct.
bool degrees() const
Rotation angles in degrees.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
void scalePoints(const scalar scaleFactor)
Scale points by given factor.
void relax(const scalar alpha, const lumpedPointState &prev)
Relax the state.
const tensorField & rotations() const
The local-to-global transformation for each point.
const pointField & points() const
The points corresponding to mass centres.
label size() const
The number of points.
bool empty() const
If no points were specified.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
bool readData(Istream &is, const quaternion::eulerOrder rotOrder=quaternion::eulerOrder::ZXZ, const bool degrees=false)
Read input as dictionary content.
virtual ~lumpedPointState()=default
Destructor.
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.
Namespace for OpenFOAM.
const pointField & pts