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-2026 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 const Foam::spatialVector&
111 {
112  return a_[i];
113 }
114 
115 
116 inline bool Foam::RBD::rigidBodyModel::merged(label bodyID) const
117 {
118  return bodyID < 0;
119 }
120 
121 
123 {
124  if (bodyID < 0)
125  {
126  return mergedBody(bodyID).masterIndex();
127  }
128  else
129  {
130  return bodyID;
131  }
132 }
133 
134 
135 inline Foam::label
136 Foam::RBD::rigidBodyModel::mergedBodyID(const label mergedBodyIndex) const
137 {
138  return -1 - mergedBodyIndex;
139 }
140 
141 
142 inline Foam::label
144 {
145  return -1 - mergedBodyID;
146 }
147 
148 
149 inline const Foam::RBD::subBody&
151 {
152  if (!merged(mergedBodyID))
153  {
155  << "Body " << mergedBodyID << " has not been merged"
156  << abort(FatalError);
157  }
158 
159  return mergedBodies_[mergedBodyIndex(mergedBodyID)];
160 }
161 
162 
164 {
165  return bodyIndices_[name];
166 }
167 
168 
170 (
171  const label bodyID,
172  const vector& p
173 ) const
174 {
175  if (merged(bodyID))
176  {
177  return
178  (
179  mergedBody(bodyID).masterXT().inv()
180  && spatialVector(Zero, p)
181  ).l();
182  }
183  else
184  {
185  return p;
186  }
187 }
188 
189 
191 (
192  const label bodyID,
193  const vector& p
194 ) const
195 {
196  return (X0(bodyID).inv() && spatialVector(Zero, p)).l();
197 }
198 
199 
201 (
202  const label bodyID,
203  const vector& d
204 ) const
205 {
206  return X0_[master(bodyID)].E().T() & d;
207 }
208 
209 
211 (
212  const label bodyID,
213  const vector& p
214 ) const
215 {
216  return
217  (
219  (
220  X0_[master(bodyID)].E().T(),
221  masterPoint(bodyID, p)
222  )
223  & v_[master(bodyID)]
224  );
225 }
226 
227 
229 (
230  const label bodyID,
231  const vector& p
232 ) const
233 {
234  return
235  (
236  (
238  (
239  X0_[master(bodyID)].E().T(),
240  masterPoint(bodyID, p)
241  )
242  & a_[master(bodyID)]
243  )
244  + spatialVector(Zero, g_)
245  );
246 }
247 
248 
249 // ************************************************************************* //
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 body i.
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.
const spatialVector & a(const label i) const
Return the spatial acceleration of body i.
vector masterPoint(const label bodyID, const vector &p) const
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.
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< rigidBody > & bodies() const
Return the list of the bodies in the model.
const PtrList< joint > & joints() const
Return the list of joints in the model.
vector d(const label bodyID, const vector &d) const
Return the current direction of the given direction.
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:63
#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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void inv(pointPatchField< tensor > &, const pointPatchField< tensor > &)
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:47
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
scalarList X0(nSpecie, 0.0)
volScalarField & p