rigidBodyModelI.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-2024 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 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
27 
29 {
30  return bodies_.size();
31 }
32 
33 
36 {
37  return bodies_;
38 }
39 
40 
43 {
44  return lambda_;
45 }
46 
47 
50 {
51  return joints_;
52 }
53 
54 
56 {
57  return nDoF_;
58 }
59 
60 
62 {
63  return unitQuaternions_;
64 }
65 
66 
68 {
69  return g_;
70 }
71 
72 
74 {
75  return g_;
76 }
77 
78 
80 (
81  const label bodyID
82 ) const
83 {
84  if (merged(bodyID))
85  {
86  return mergedBody(bodyID).name();
87  }
88  else
89  {
90  return bodies_[bodyID].name();
91  }
92 }
93 
94 
95 inline const Foam::RBD::rigidBodyInertia&
97 {
98  return bodies_[i];
99 }
100 
101 
102 inline const Foam::spatialVector&
104 {
105  return v_[i];
106 }
107 
108 
109 inline bool Foam::RBD::rigidBodyModel::merged(label bodyID) const
110 {
111  return bodyID < 0;
112 }
113 
114 
116 {
117  if (bodyID < 0)
118  {
119  return mergedBody(bodyID).masterIndex();
120  }
121  else
122  {
123  return bodyID;
124  }
125 }
126 
127 
128 inline Foam::label
129 Foam::RBD::rigidBodyModel::mergedBodyID(const label mergedBodyIndex) const
130 {
131  return -1 - mergedBodyIndex;
132 }
133 
134 
135 inline Foam::label
137 {
138  return -1 - mergedBodyID;
139 }
140 
141 
142 inline const Foam::RBD::subBody&
144 {
145  if (!merged(mergedBodyID))
146  {
148  << "Body " << mergedBodyID << " has not been merged"
149  << abort(FatalError);
150  }
151 
152  return mergedBodies_[mergedBodyIndex(mergedBodyID)];
153 }
154 
155 
157 {
158  return bodyIndices_[name];
159 }
160 
161 
163 (
164  const label bodyID,
165  const vector& p
166 ) const
167 {
168  if (merged(bodyID))
169  {
170  return
171  (
172  mergedBody(bodyID).masterXT().inv()
173  && spatialVector(Zero, p)
174  ).l();
175  }
176  else
177  {
178  return p;
179  }
180 }
181 
182 
184 (
185  const label bodyID,
186  const vector& p
187 ) const
188 {
189  return (X0(bodyID).inv() && spatialVector(Zero, p)).l();
190 }
191 
192 
194 (
195  const label bodyID,
196  const vector& p
197 ) const
198 {
199  return
200  (
202  (
203  X0_[master(bodyID)].E().T(),
204  masterPoint(bodyID, p)
205  )
206  & v_[master(bodyID)]
207  );
208 }
209 
210 
212 (
213  const label bodyID,
214  const vector& p
215 ) const
216 {
217  return
218  (
219  (
221  (
222  X0_[master(bodyID)].E().T(),
223  masterPoint(bodyID, p)
224  )
225  & a_[master(bodyID)]
226  )
227  + spatialVector(Zero, g_)
228  );
229 }
230 
231 
232 // ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
This class represents the linear and angular inertia of a rigid body by the mass, centre of mass and ...
const spatialVector & v(const label i) const
Return the spatial velocity of the bodies.
label nBodies() const
Return the number of bodies in the model (bodies().size())
label mergedBodyID(const label mergedBodyIndex) const
Return the merged body ID for the given merged body index.
bool unitQuaternions() const
Return true if any of the joints using quaternions.
label master(label bodyID) const
Return the ID of the master body for a sub-body otherwise.
vector masterPoint(const label bodyID, const vector &p) const
spatialVector a(const label bodyID, const vector &p) const
Return the acceleration of the given point on the given body.
const subBody & mergedBody(label mergedBodyID) const
Return the merged body for the given body ID.
vector p(const label bodyID, const vector &p) const
Return the current position of the given point on the given body.
PtrList< rigidBody > bodies_
List of the bodies.
const vector & g() const
Return the acceleration due to gravity.
label nDoF() const
Return the number of degrees of freedom of the model.
PtrList< rigidBody > bodies() const
Return the list of the bodies in the model.
label mergedBodyIndex(const label mergedBodyID) const
Return the index of the merged body in the mergedBody list.
label bodyIndex(const word &name) const
Return the ID of the body with the given name.
const DynamicList< label > & lambda() const
List of indices of the parent of each body.
const word & name(const label bodyID) const
Return the name of body with the given ID.
const PtrList< joint > & joints() const
Return the list of joints in the model.
const rigidBodyInertia & I(const label i) const
Return the inertia of body i.
bool merged(label bodyID) const
Return true if the body with given ID has been merged with a parent.
This specialised rigidBody holds the original body after it has been merged into a master.
Definition: subBody.H:53
Compact representation of the Plücker spatial transformation tensor in terms of the rotation tensor E...
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
static const zero Zero
Definition: zero.H:97
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
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
errorManip< error > abort(error &err)
Definition: errorManip.H:131
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:47
error FatalError
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
scalarList X0(nSpecie, 0.0)
volScalarField & p