diff --git a/src/rigidBodyDynamics/bodies/sphere/sphere.H b/src/rigidBodyDynamics/bodies/sphere/sphere.H index f2642c8a7..e3310f735 100644 --- a/src/rigidBodyDynamics/bodies/sphere/sphere.H +++ b/src/rigidBodyDynamics/bodies/sphere/sphere.H @@ -59,6 +59,12 @@ class sphere scalar r_; + // Private member functions + + // Calculate and return the inertia tensor + inline symmTensor I(const scalar m, const scalar r) const; + + public: //- Runtime type information @@ -67,8 +73,14 @@ public: // Constructors - //- Construct from name, mass and radius - inline sphere(const word& name, const scalar m, const scalar r); + //- Construct from name, mass, centre of mass and radius + inline sphere + ( + const word& name, + const scalar m, + const vector& c, + const scalar r + ); //- Construct from dictionary inline sphere diff --git a/src/rigidBodyDynamics/bodies/sphere/sphereI.H b/src/rigidBodyDynamics/bodies/sphere/sphereI.H index 42f429f1d..49d9fc0e0 100644 --- a/src/rigidBodyDynamics/bodies/sphere/sphereI.H +++ b/src/rigidBodyDynamics/bodies/sphere/sphereI.H @@ -23,16 +23,29 @@ License \*---------------------------------------------------------------------------*/ +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +inline Foam::symmTensor Foam::RBD::sphere::I +( + const scalar m, + const scalar r +) const +{ + return ((2.0/5.0)*m*sqr(r))*Foam::I; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::RBD::sphere::sphere ( const word& name, const scalar m, + const vector& c, const scalar r ) : - rigidBody(name, m, Zero, (2.0/5.0)*m*sqr(r)*I), + rigidBody(name, m, c, I(m, r)), r_(r) {} @@ -43,18 +56,12 @@ inline Foam::RBD::sphere::sphere const dictionary& dict ) : - rigidBody - ( - name, - rigidBodyInertia() - ), + rigidBody(name, rigidBodyInertia()), r_(readScalar(dict.lookup("radius"))) { const scalar m(readScalar(dict.lookup("mass"))); - rigidBodyInertia::operator= - ( - rigidBodyInertia(m, Zero, (2.0/5.0)*m*sqr(r_)*I) - ); + const vector c(dict.lookup("centreOfMass")); + rigidBodyInertia::operator=(rigidBodyInertia(m, c, I(m, r_))); }