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-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 \*---------------------------------------------------------------------------*/
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).masterID();
120  }
121  else
122  {
123  return bodyID;
124  }
125 }
126 
127 
128 inline Foam::label
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 bodyIDs_[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
190  (
192  (
193  X0_[master(bodyID)].E().T(),
194  masterPoint(bodyID, p)
195  )
196  & v_[master(bodyID)]
197  );
198 }
199 
200 
201 // ************************************************************************* //
const subBody & mergedBody(label mergedBodyID) const
Return the merged body for the given body ID.
const rigidBodyInertia & I(const label i) const
Return the inertia of body i.
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
DynamicList< spatialTransform > X0_
Transform for external forces to the bodies reference frame.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
const spatialVector & v(const label i) const
Return the spatial velocity of the bodies.
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
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.
const word & name() const
Return the body name.
Definition: subBodyI.H:57
label master(label bodyID) const
Return the ID of the master body for a sub-body otherwise.
HashTable< label, word > bodyIDs_
Lookup-table of the IDs of the bodies.
DynamicList< spatialVector > v_
The spatial velocity of the bodies.
PtrList< joint > joints_
Each body it attached with a joint which are held on this list.
PtrList< rigidBody > bodies_
List of the bodies.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
This specialised rigidBody holds the original body after it has been merged into a master...
Definition: subBody.H:52
A class for handling words, derived from string.
Definition: word.H:59
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:47
label mergedBodyIndex(const label mergedBodyID) const
Return the index of the merged body in the mergedBody list.
label nDoF_
The number of degrees of freedom of the model.
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.
static const zero Zero
Definition: zero.H:97
bool unitQuaternions() const
Return true if any of the joints using quaternions.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
DynamicList< label > lambda_
List of indices of the parent of each body.
label masterID() const
Return the master body Id.
Definition: subBodyI.H:69
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
label nDoF() const
Return the number of degrees of freedom of the model.
const vector & g() const
Return the acceleration due to gravity.
PtrList< rigidBody > bodies() const
Return the list of the bodies in the model.
bool unitQuaternions_
True if any of the joints using quaternions.
PtrList< subBody > mergedBodies_
Bodies may be merged into existing bodies, the inertia of which is.
const DynamicList< label > & lambda() const
List of indices of the parent of each body.
Compact representation of the Plücker spatial transformation tensor in terms of the rotation tensor E...
label bodyID(const word &name) const
Return the ID of the body with the given name.
volScalarField & p
vector masterPoint(const label bodyID, const vector &p) const
bool merged(label bodyID) const
Return true if the body with given ID has been merged with a parent.
vector g_
Acceleration due to gravity.
This class represents the linear and angular inertia of a rigid body by the mass, centre of mass and ...