joint.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Namespace
25  Foam::RBD::joints
26 
27 Description
28  Namespace for rigid-body joints
29 
30 Class
31  Foam::RBD::joint
32 
33 Description
34  Abstract base-class for all rigid-body joints.
35 
36  Reference:
37  \verbatim
38  Featherstone, R. (2008).
39  Rigid body dynamics algorithms.
40  Springer.
41  Chapter 4.
42  \endverbatim
43 
44 SourceFiles
45  jointI.H
46  joint.C
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef RBD_joint_H
51 #define RBD_joint_H
52 
53 #include "List.H"
54 #include "spatialVector.H"
55 #include "compactSpatialTensor.H"
56 #include "CompactSpatialTensorT.H"
57 #include "spatialTransform.H"
58 #include "quaternion.H"
59 #include "scalarField.H"
60 #include "runTimeSelectionTables.H"
61 
62 namespace Foam
63 {
64 namespace RBD
65 {
66 
67 // Forward declaration of classes
68 class rigidBodyModel;
69 class rigidBodyModelState;
70 
71 // Forward declaration of friend functions and operators
72 class joint;
73 
74 inline Ostream& operator<<(Ostream&, const joint&);
75 
76 
77 /*---------------------------------------------------------------------------*\
78  Class joint Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 class joint
82 {
83 
84 protected:
85 
86  // Protected data
87 
88  //- Reference to the model
89  const rigidBodyModel& model_;
90 
91  //- Joint motion sub-space
93 
94  //- Index of this joint in the rigidBodyModel
95  label index_;
96 
97  //- Index of this joints data in the rigidBodyModel state
98  label qIndex_;
99 
100 
101 private:
102 
103  // Private Member Functions to be used by rigidBodyModel
104 
105  //- Allow the rigidBodyModel to set the index for this joint
106  label& index()
107  {
108  return index_;
109  }
110 
111  //- Allow the rigidBodyModel to set the qIndex for this joint
112  label& qIndex()
113  {
114  return qIndex_;
115  }
116 
117 
118 public:
119 
120  //- Allow the rigidBodyModel class to set the joint indices
121  friend class rigidBodyModel;
122 
123  //- Joint state returned by jcalc
124  class XSvc
125  {
126  public:
127 
128  //- The joint transformation
130 
131  //- The joint motion sub-space (3-DoF)
133 
134  //- The joint motion sub-space (1-DoF)
136 
137  //- The constrained joint velocity
139 
140  //- The constrained joint acceleration correction
141  // due to changes in the motion sub-space S
143 
144  //- Null constructor
145  XSvc()
146  :
147  X(),
148  v(Zero),
149  c(Zero)
150  {}
151  };
152 
153 
154 public:
155 
156  //- Runtime type information
157  TypeName("joint");
158 
159 
160  // Declare run-time constructor selection table
161 
163  (
164  autoPtr,
165  joint,
166  dictionary,
167  (const rigidBodyModel& model, const dictionary& dict),
168  (model, dict)
169  );
170 
171 
172  // Constructors
173 
174  //- Construct joint setting the size of the motion sub-space
175  // to the given degrees of freedom of the joint
176  inline joint(const rigidBodyModel& model, const label nDoF);
177 
178  //- Copy constructor
179  joint(const joint&) = default;
180 
181  //- Clone this joint (needed by PtrList)
182  virtual autoPtr<joint> clone() const = 0;
184  class iNew
185  {
186 
187  const rigidBodyModel& model_;
188 
189  public:
191  iNew(const rigidBodyModel& model)
192  :
193  model_(model)
194  {}
195 
196  inline autoPtr<joint> operator()(Istream& is) const;
197  };
198 
199 
200  //- Destructor
201  virtual ~joint();
202 
203 
204  // Selectors
205 
206  //- Simple selector to return an autoPtr<joint> of the given joint*
207  static autoPtr<joint> New(joint* jointPtr);
208 
209  //- Select from dictionary
210  static autoPtr<joint> New
211  (
212  const rigidBodyModel& model,
213  const dictionary& dict
214  );
215 
216 
217  // Member Functions
218 
219  //- Return the number of degrees of freedom in this joint
220  inline label nDoF() const;
221 
222  //- Return true if this joint describes rotation using a quaternion
223  inline virtual bool unitQuaternion() const;
224 
225  //- Return the index of this joint in the model
226  inline label index() const;
227 
228  //- Return start index for the state variables for this joint
229  // in the rigidBodyModel state fields
230  inline label qIndex() const;
231 
232  //- Return the joint motion sub-space
233  inline const List<spatialVector>& S() const;
234 
235  //- Update the rigidBodyModel state for the joint given
236  // the joint state q, w and velocity qDot
237  virtual void jcalc
238  (
239  XSvc& J,
240  const rigidBodyModelState& state
241  ) const = 0;
242 
243  //- Write
244  virtual void write(Ostream&) const;
245 
246 
247  // Member Operators
248 
249  //- Assignment
250  inline void operator=(const joint& j);
251 
252  //- Return the unit quaternion for this joint
253  // if it uses a quaternion representation for rotation
255  (
256  const scalarField& q
257  ) const;
258 
259  //- Set the unit quaternion for this joint
260  // if it uses a quaternion representation for rotation
261  inline void unitQuaternion
262  (
263  const quaternion& quat,
264  scalarField& q
265  ) const;
266 
267 
268  // Ostream Operator
269 
270  friend Ostream& operator<<(Ostream&, const joint&);
271 };
272 
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 } // End namespace RBD
277 } // End namespace Foam
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 #include "jointI.H"
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
285 #endif
286 
287 // ************************************************************************* //
Abstract base-class for all rigid-body joints.
Definition: joint.H:80
Ostream & operator<<(Ostream &, const rigidBody &)
Definition: rigidBodyI.H:73
dictionary dict
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
spatialVector v
The constrained joint velocity.
Definition: joint.H:137
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
spatialVector S1
The joint motion sub-space (1-DoF)
Definition: joint.H:134
label qIndex_
Index of this joints data in the rigidBodyModel state.
Definition: joint.H:97
compactSpatialTensor S
The joint motion sub-space (3-DoF)
Definition: joint.H:131
virtual void jcalc(XSvc &J, const rigidBodyModelState &state) const =0
Update the rigidBodyModel state for the joint given.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual autoPtr< joint > clone() const =0
Clone this joint (needed by PtrList)
void operator=(const joint &j)
Assignment.
Definition: jointI.H:67
label index_
Index of this joint in the rigidBodyModel.
Definition: joint.H:94
spatialVector c
The constrained joint acceleration correction.
Definition: joint.H:141
XSvc()
Null constructor.
Definition: joint.H:144
declareRunTimeSelectionTable(autoPtr, joint, dictionary,(const rigidBodyModel &model, const dictionary &dict),(model, dict))
Holds the motion state of rigid-body model.
friend Ostream & operator<<(Ostream &, const joint &)
Joint state returned by jcalc.
Definition: joint.H:123
virtual void write(Ostream &) const
Write.
Definition: joint.C:82
virtual ~joint()
Destructor.
Definition: joint.C:76
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
static const zero Zero
Definition: zero.H:97
joint(const rigidBodyModel &model, const label nDoF)
Construct joint setting the size of the motion sub-space.
Definition: jointI.H:28
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
label nDoF() const
Return the number of degrees of freedom in this joint.
Definition: jointI.H:39
List< spatialVector > S_
Joint motion sub-space.
Definition: joint.H:91
spatialTransform X
The joint transformation.
Definition: joint.H:128
TypeName("joint")
Runtime type information.
static autoPtr< joint > New(joint *jointPtr)
Simple selector to return an autoPtr<joint> of the given joint*.
Definition: joint.C:43
Compact representation of the Plücker spatial transformation tensor in terms of the rotation tensor E...
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
const rigidBodyModel & model_
Reference to the model.
Definition: joint.H:88
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints...
Macros to ease declaration of run-time selection tables.
virtual bool unitQuaternion() const
Return true if this joint describes rotation using a quaternion.
Definition: jointI.H:44
Namespace for OpenFOAM.