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-------------------------------------------------------------------------------
11License
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
94inline 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
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
141inline Foam::Istream& Foam::RBD::operator>>
142(
143 Istream& is,
145)
146{
147 is >> rbi.m_ >> rbi.c_ >> rbi.Ic_;
148 return is;
149}
150
151
152inline 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
165namespace Foam
166{
167namespace RBD
168{
169
170// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171
172//- Return the rigid-body inertia of the combined body
173inline 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)
192inline 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
247(
248 const rigidBodyInertia& rbi
249)
250{
251 *this = *this + rbi;
252}
253
254
255// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
symmTensor Icc(const vector &c) const
Return the difference between the inertia tensor of the rigid-body.
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.
rigidBodyInertia()
Null constructor, initializes to zero.
symmTensor Io() const
Return the inertia tensor of the rigid-body about the origin.
symmTensor Ioc() const
Return the difference between the inertia tensor of the rigid-body.
scalar m() const
Return the mass of the rigid-body.
const symmTensor & Ic() const
Return the inertia tensor of the rigid-body about the centre of mass.
Templated 3D spatial tensor derived from MatrixSpace used to represent transformations of spatial vec...
Definition: SpatialTensor.H:70
Tensor< Cmpt > T() const
Return non-Hermitian transpose.
Definition: TensorI.H:526
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:61
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
Compact representation of the Plücker spatial transformation tensor in terms of the rotation tensor E...
const vector & r() const
Return the translation vector.
const tensor & E() const
Return the rotation tensor.
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
dimensionedSymmTensor symm(const dimensionedSymmTensor &dt)
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:536
dimensionedSymmTensor sqr(const dimensionedVector &dv)
SpatialTensor< scalar > spatialTensor
SpatialTensor of scalars.
Definition: spatialTensor.H:50
static const Identity< scalar > I
Definition: Identity.H:94
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
3D tensor transformation operations.