rigidBodyModelI.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 inline const Foam::Time& Foam::RBD::rigidBodyModel::time() const
32 {
33  return time_;
34 }
35 
36 
37 inline Foam::label Foam::RBD::rigidBodyModel::nBodies() const
38 {
39  return bodies_.size();
40 }
41 
42 
45 {
46  return bodies_;
47 }
48 
49 
52 {
53  return lambda_;
54 }
55 
56 
59 {
60  return joints_;
61 }
62 
63 
64 inline Foam::label Foam::RBD::rigidBodyModel::nDoF() const
65 {
66  return nDoF_;
67 }
68 
69 
71 {
72  return unitQuaternions_;
73 }
74 
75 
76 inline const Foam::vector& Foam::RBD::rigidBodyModel::g() const
77 {
78  return g_;
79 }
80 
81 
83 {
84  return g_;
85 }
86 
87 
89 (
90  const label bodyID
91 ) const
92 {
93  if (merged(bodyID))
94  {
95  return mergedBody(bodyID).name();
96  }
97  else
98  {
99  return bodies_[bodyID].name();
100  }
101 }
102 
103 
104 inline const Foam::RBD::rigidBodyInertia&
105 Foam::RBD::rigidBodyModel::I(const label i) const
106 {
107  return bodies_[i];
108 }
109 
110 
111 inline const Foam::spatialVector&
112 Foam::RBD::rigidBodyModel::v(const label i) const
113 {
114  return v_[i];
115 }
117 inline const Foam::spatialVector&
118 Foam::RBD::rigidBodyModel::a(const label i) const
119 {
120  return a_[i];
121 }
123 inline bool Foam::RBD::rigidBodyModel::merged(label bodyID) const
124 {
125  return bodyID < 0;
126 }
127 
128 
129 inline Foam::label Foam::RBD::rigidBodyModel::master(label bodyID) const
130 {
131  if (bodyID < 0)
132  {
133  return mergedBody(bodyID).masterID();
134  }
135  else
136  {
137  return bodyID;
138  }
139 }
140 
141 
142 inline Foam::label
143 Foam::RBD::rigidBodyModel::mergedBodyID(const label mergedBodyIndex) const
144 {
145  return -1 - mergedBodyIndex;
146 }
147 
148 
149 inline Foam::label
150 Foam::RBD::rigidBodyModel::mergedBodyIndex(const label mergedBodyID) const
151 {
152  return -1 - mergedBodyID;
153 }
154 
155 
156 inline const Foam::RBD::subBody&
157 Foam::RBD::rigidBodyModel::mergedBody(label mergedBodyID) const
158 {
159  if (!merged(mergedBodyID))
160  {
162  << "Body " << mergedBodyID << " has not been merged"
164  }
165 
166  return mergedBodies_[mergedBodyIndex(mergedBodyID)];
167 }
168 
169 
170 inline Foam::label Foam::RBD::rigidBodyModel::bodyID(const word& name) const
171 {
172  return bodyIDs_[name];
173 }
174 
175 
177 (
178  const label bodyID,
179  const vector& p
180 ) const
181 {
182  if (merged(bodyID))
183  {
184  return
185  (
186  mergedBody(bodyID).masterXT().inv()
187  && spatialVector(Zero, p)
188  ).l();
189  }
190  else
191  {
192  return p;
193  }
194 }
195 
196 
198 (
199  const label bodyID,
200  const vector& p
201 ) const
202 {
203  return
204  (
206  (
207  X0_[master(bodyID)].E().T(),
208  masterPoint(bodyID, p)
209  )
210  & v_[master(bodyID)]
211  );
212 }
213 
214 
215 // ************************************************************************* //
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.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
const spatialVector & v(const label i) const
Return the spatial velocity of the bodies.
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
const spatialVector & a(const label i) const
Return the spatial acceleration 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.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
label master(label bodyID) const
Return the ID of the master body for a sub-body otherwise.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
A class for handling words, derived from Foam::string.
Definition: word.H:63
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:46
label mergedBodyIndex(const label mergedBodyID) const
Return the index of the merged body in the mergedBody list.
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.
bool unitQuaternions() const
Return true if any of the joints using quaternions.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
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.
const Time & time() const
Return the time.
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
const Time & time_
Reference to time database.
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.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127