joint.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 | Copyright (C) 2016 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 
70 // Forward declaration of friend functions and operators
71 class joint;
72 
73 inline Ostream& operator<<(Ostream&, const joint&);
74 
75 
76 /*---------------------------------------------------------------------------*\
77  Class joint Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 class joint
81 {
82 
83 protected:
84 
85  // Protected data
86 
87  //- Joint motion sub-space
89 
90  //- Index of this joint in the rigidBodyModel
91  label index_;
92 
93  //- Index of this joints data in the rigidBodyModel state
94  label qIndex_;
95 
96 
97 private:
98 
99  // Private member functions to be used by rigidBodyModel
100 
101  //- Allow the rigidBodyModel to set the index for this joint
102  label& index()
103  {
104  return index_;
105  }
106 
107  //- Allow the rigidBodyModel to set the qIndex for this joint
108  label& qIndex()
109  {
110  return qIndex_;
111  }
112 
113 
114 public:
115 
116  //- Allow the rigidBodyModel class to set the joint indices
117  friend class rigidBodyModel;
118 
119  //- Joint state returned by jcalc
120  class XSvc
121  {
122  public:
123 
124  //- The joint transformation
126 
127  //- The joint motion sub-space (3-DoF)
129 
130  //- The joint motion sub-space (1-DoF)
132 
133  //- The constrained joint velocity
135 
136  //- The constrained joint acceleration correction
137  // due to changes in the motion sub-space S
139 
140  //- Null constructor
141  XSvc()
142  :
143  X(),
144  v(Zero),
145  c(Zero)
146  {}
147  };
148 
149 
150 public:
151 
152  //- Runtime type information
153  TypeName("joint");
154 
155 
156  // Declare run-time constructor selection table
157 
159  (
160  autoPtr,
161  joint,
162  dictionary,
163  (const dictionary& dict),
164  (dict)
165  );
166 
167 
168  // Constructors
169 
170  //- Construct joint setting the size of the motion sub-space
171  // to the given degrees of freedom of the joint
172  inline joint(const label nDoF);
173 
174  //- Clone this joint (needed by PtrList)
175  virtual autoPtr<joint> clone() const = 0;
177  class iNew
178  {
179 
180  public:
182  iNew()
183  {}
184 
185  inline autoPtr<joint> operator()(Istream& is) const;
186  };
187 
188 
189  //- Destructor
190  virtual ~joint();
191 
192 
193  // Selectors
194 
195  //- Simple selector to return an autoPtr<joint> of the given joint*
196  static autoPtr<joint> New(joint* jointPtr);
197 
198  //- Select from dictionary
199  static autoPtr<joint> New(const dictionary& dict);
200 
201 
202  // Member Functions
203 
204  //- Return the number of degrees of freedom in this joint
205  inline label nDoF() const;
206 
207  //- Return true if this joint describes rotation using a quaternion
208  inline virtual bool unitQuaternion() const;
209 
210  //- Return the index of this joint in the model
211  inline label index() const;
212 
213  //- Return start index for the state variables for this joint
214  // in the rigidBodyModel state fields
215  inline label qIndex() const;
216 
217  //- Return the joint motion sub-space
218  inline const List<spatialVector>& S() const;
219 
220  //- Update the rigidBodyModel state for the joint given
221  // the joint state q, w and velocity qDot
222  virtual void jcalc
223  (
224  XSvc& J,
225  const scalarField& q,
226  const scalarField& qDot
227  ) const = 0;
228 
229  //- Write
230  virtual void write(Ostream&) const;
231 
232 
233  // Member Operators
234 
235  //- Return the unit quaternion for this joint
236  // if it uses a quaternion representation for rotation
238  (
239  const scalarField& q
240  ) const;
241 
242  //- Set the unit quaternion for this joint
243  // if it uses a quaternion representation for rotation
244  inline void unitQuaternion
245  (
246  const quaternion& quat,
247  scalarField& q
248  ) const;
249 
250 
251  // Ostream Operator
252 
253  friend Ostream& operator<<(Ostream&, const joint&);
254 };
255 
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259 } // End namespace RBD
260 } // End namespace Foam
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #include "jointI.H"
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #endif
269 
270 // ************************************************************************* //
Abstract base-class for all rigid-body joints.
Definition: joint.H:79
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:133
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:130
label qIndex_
Index of this joints data in the rigidBodyModel state.
Definition: joint.H:93
compactSpatialTensor S
The joint motion sub-space (3-DoF)
Definition: joint.H:127
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
declareRunTimeSelectionTable(autoPtr, joint, dictionary,(const dictionary &dict),(dict))
virtual autoPtr< joint > clone() const =0
Clone this joint (needed by PtrList)
label index_
Index of this joint in the rigidBodyModel.
Definition: joint.H:90
spatialVector c
The constrained joint acceleration correction.
Definition: joint.H:137
XSvc()
Null constructor.
Definition: joint.H:140
friend Ostream & operator<<(Ostream &, const joint &)
virtual bool unitQuaternion() const
Return true if this joint describes rotation using a quaternion.
Definition: jointI.H:43
Joint state returned by jcalc.
Definition: joint.H:119
virtual ~joint()
Destructor.
Definition: joint.C:75
label nDoF() const
Return the number of degrees of freedom in this joint.
Definition: jointI.H:38
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
static const zero Zero
Definition: zero.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
List< spatialVector > S_
Joint motion sub-space.
Definition: joint.H:87
virtual void jcalc(XSvc &J, const scalarField &q, const scalarField &qDot) const =0
Update the rigidBodyModel state for the joint given.
virtual void write(Ostream &) const
Write.
Definition: joint.C:81
spatialTransform X
The joint transformation.
Definition: joint.H:124
joint(const label nDoF)
Construct joint setting the size of the motion sub-space.
Definition: jointI.H:28
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:53
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.
Namespace for OpenFOAM.