rigidBodyInertiaI.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) 2020 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 #include "spatialTransform.H"
30 #include "transform.H"
31 #include "dictionary.H"
32 
33 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
34 
36 (
37  const scalar m,
38  const vector& c
39 )
40 {
41  return m*(Foam::I*magSqr(c) - sqr(c));
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 :
49  m_(Zero),
50  c_(Zero),
51  Ic_(Zero)
52 {}
53 
54 
56 (
57  const scalar m,
58  const vector& c,
59  const symmTensor& Ic
60 )
61 :
62  m_(m),
63  c_(c),
64  Ic_(Ic)
65 {}
66 
67 
69 :
70  m_(dict.get<scalar>("mass")),
71  c_(dict.get<vector>("centreOfMass")),
72  Ic_(dict.get<symmTensor>("inertia"))
73 {}
74 
75 
77 :
78  m_(st(3, 3)),
79  c_(vector(-st(1, 5), st(0, 5), -st(0, 4))/m_),
80  Ic_(symm(st.block<tensor, 0, 0>()()) - Ioc())
81 {}
82 
83 
85 :
86  m_(readScalar(is)),
87  c_(is),
88  Ic_(is)
89 {}
90 
91 
92 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
93 
94 inline Foam::scalar Foam::RBD::rigidBodyInertia::m() const
95 {
96  return m_;
97 }
98 
100 {
101  return c_;
102 }
103 
105 {
106  return Ic_;
107 }
108 
110 {
111  return Ioc(m_, c_);
112 }
113 
115 {
116  return Ioc(m_, c - c_);
117 }
118 
120 {
121  return Ic_ + Ioc();
122 }
123 
124 
125 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
126 
127 inline Foam::RBD::rigidBodyInertia::operator spatialTensor() const
128 {
129  tensor mcStar(m_*(*c_));
130 
131  return spatialTensor
132  (
133  Io(), mcStar,
134  -mcStar, m_*I
135  );
136 }
137 
138 
139 // * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
140 
141 inline Foam::Istream& Foam::RBD::operator>>
142 (
143  Istream& is,
144  rigidBodyInertia& rbi
145 )
146 {
147  is >> rbi.m_ >> rbi.c_ >> rbi.Ic_;
148  return is;
149 }
150 
151 
152 inline Foam::Ostream& Foam::RBD::operator<<
153 (
154  Ostream& os,
155  const rigidBodyInertia& rbi
156 )
157 {
158  os << rbi.m_ << nl << rbi.c_ << nl << rbi.Ic_ << endl;
159  return os;
160 }
161 
162 
163 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
164 
165 namespace Foam
166 {
167 namespace RBD
168 {
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 //- Return the rigid-body inertia of the combined body
173 inline rigidBodyInertia operator+
174 (
175  const rigidBodyInertia& rbi1,
176  const rigidBodyInertia& rbi2
177 )
178 {
179  const scalar m12 = rbi1.m() + rbi2.m();
180  const vector c12 = (rbi1.m()*rbi1.c() + rbi2.m()*rbi2.c())/m12;
181 
182  return rigidBodyInertia
183  (
184  m12,
185  c12,
186  rbi1.Ic() + rbi1.Icc(c12) + rbi2.Ic() + rbi2.Icc(c12)
187  );
188 }
189 
190 
191 //- Inner-product with a spatialVector (e.g. velocity returning the momentum)
192 inline spatialVector operator&
193 (
194  const rigidBodyInertia& rbi,
195  const spatialVector& sv
196 )
197 {
198  const vector av(sv.w());
199  const vector lv(sv.l());
200 
201  return spatialVector
202  (
203  (rbi.Io() & av) + rbi.m()*(rbi.c() ^ lv),
204  rbi.m()*lv - rbi.m()*(rbi.c() ^ av)
205  );
206 }
207 
208 
209 //- Return (^BX_A)^* I ^AX_B
211 (
212  const spatialTransform& X,
213  const rigidBodyInertia& I
214 )
215 {
216  const vector Xc((X.E().T() & I.c()) + X.r());
217 
218  return rigidBodyInertia
219  (
220  I.m(),
221  Xc,
222  transform(X.E().T(), I.Ic())
223  );
224 }
225 
226 
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228 
229 } // End namespace RBD
230 } // End namespace Foam
231 
232 
233 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
234 
236 (
237  const spatialVector& v
238 )
239 {
240  return 0.5*(v && (*this & v));
241 }
242 
243 
244 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
245 
246 inline void Foam::RBD::rigidBodyInertia::operator+=
247 (
248  const rigidBodyInertia& rbi
249 )
250 {
251  *this = *this + rbi;
252 }
253 
254 
255 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::symm
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:84
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:58
Foam::SymmTensor
A templated (3 x 3) symmetric tensor of objects of <T>, effectively containing 6 elements,...
Definition: SymmTensor.H:58
Foam::spatialTransform
Compact representation of the Plücker spatial transformation tensor in terms of the rotation tensor E...
Definition: spatialTransform.H:70
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
rigidBodyInertia
This class represents the linear and angular inertia of a rigid body by the mass, centre of mass and ...
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::RBD::rigidBodyInertia::Ioc
symmTensor Ioc() const
Return the difference between the inertia tensor of the rigid-body.
Definition: rigidBodyInertiaI.H:109
Foam::SpatialTensor
Templated 3D spatial tensor derived from MatrixSpace used to represent transformations of spatial vec...
Definition: SpatialTensor.H:67
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::spatialTransform::r
const vector & r() const
Return the translation vector.
Definition: spatialTransformI.H:89
Foam::RBD::rigidBodyInertia::rigidBodyInertia
rigidBodyInertia()
Null constructor, initializes to zero.
Definition: rigidBodyInertiaI.H:47
Foam::SpatialVector< scalar >
Foam::RBD::rigidBodyInertia::m
scalar m() const
Return the mass of the rigid-body.
Definition: rigidBodyInertiaI.H:94
Foam::spatialTransform::E
const tensor & E() const
Return the rotation tensor.
Definition: spatialTransformI.H:79
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::RBD::rigidBodyInertia::Icc
symmTensor Icc(const vector &c) const
Return the difference between the inertia tensor of the rigid-body.
Definition: rigidBodyInertiaI.H:114
Foam::spatialTensor
SpatialTensor< scalar > spatialTensor
SpatialTensor of scalars.
Definition: spatialTensor.H:50
Foam::Vector< scalar >
Foam::RBD::rigidBodyInertia::Ic
const symmTensor & Ic() const
Return the inertia tensor of the rigid-body about the centre of mass.
Definition: rigidBodyInertiaI.H:104
Foam::RBD::transform
rigidBodyInertia transform(const spatialTransform &X, const rigidBodyInertia &I)
Return (^BX_A)^* I ^AX_B.
Definition: rigidBodyInertiaI.H:211
dictionary.H
Foam::Tensor::T
Tensor< Cmpt > T() const
Return non-Hermitian transpose.
Definition: TensorI.H:504
spatialTransform.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::PtrListOps::get
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
Foam::spatialVector
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:50
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
transform.H
3D tensor transformation operations.
Foam::RBD::rigidBodyInertia::kineticEnergy
scalar kineticEnergy(const spatialVector &v)
Return the kinetic energy of the body with the given velocity.
Definition: rigidBodyInertiaI.H:236
Foam::RBD::rigidBodyInertia::Io
symmTensor Io() const
Return the inertia tensor of the rigid-body about the origin.
Definition: rigidBodyInertiaI.H:119
Foam::I
static const Identity< scalar > I
Definition: Identity.H:95
Foam::RBD::rigidBodyInertia
Definition: rigidBodyInertia.H:77
Foam::RBD::rigidBodyInertia::c
const vector & c() const
Return the centre of mass of the rigid-body.
Definition: rigidBodyInertiaI.H:99