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