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-2018 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  //- Clone this joint (needed by PtrList)
179  virtual autoPtr<joint> clone() const = 0;
181  class iNew
182  {
183 
184  const rigidBodyModel& model_;
185 
186  public:
188  iNew(const rigidBodyModel& model)
189  :
190  model_(model)
191  {}
192 
193  inline autoPtr<joint> operator()(Istream& is) const;
194  };
195 
196 
197  //- Destructor
198  virtual ~joint();
199 
200 
201  // Selectors
202 
203  //- Simple selector to return an autoPtr<joint> of the given joint*
204  static autoPtr<joint> New(joint* jointPtr);
205 
206  //- Select from dictionary
207  static autoPtr<joint> New
208  (
209  const rigidBodyModel& model,
210  const dictionary& dict
211  );
212 
213 
214  // Member Functions
215 
216  //- Return the number of degrees of freedom in this joint
217  inline label nDoF() const;
218 
219  //- Return true if this joint describes rotation using a quaternion
220  inline virtual bool unitQuaternion() const;
221 
222  //- Return the index of this joint in the model
223  inline label index() const;
224 
225  //- Return start index for the state variables for this joint
226  // in the rigidBodyModel state fields
227  inline label qIndex() const;
228 
229  //- Return the joint motion sub-space
230  inline const List<spatialVector>& S() const;
231 
232  //- Update the rigidBodyModel state for the joint given
233  // the joint state q, w and velocity qDot
234  virtual void jcalc
235  (
236  XSvc& J,
237  const rigidBodyModelState& state
238  ) const = 0;
239 
240  //- Write
241  virtual void write(Ostream&) const;
242 
243 
244  // Member Operators
245 
246  //- Assignment
247  inline void operator=(const joint& j);
248 
249  //- Return the unit quaternion for this joint
250  // if it uses a quaternion representation for rotation
252  (
253  const scalarField& q
254  ) const;
255 
256  //- Set the unit quaternion for this joint
257  // if it uses a quaternion representation for rotation
258  inline void unitQuaternion
259  (
260  const quaternion& quat,
261  scalarField& q
262  ) const;
263 
264 
265  // Ostream Operator
266 
267  friend Ostream& operator<<(Ostream&, const joint&);
268 };
269 
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 } // End namespace RBD
274 } // End namespace Foam
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #include "jointI.H"
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 #endif
283 
284 // ************************************************************************* //
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:137
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:60
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:53
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.