diff --git a/src/rigidBodyDynamics/Make/files b/src/rigidBodyDynamics/Make/files index 4d8c27d482..c2c03b7172 100644 --- a/src/rigidBodyDynamics/Make/files +++ b/src/rigidBodyDynamics/Make/files @@ -1,5 +1,6 @@ bodies/rigidBody/rigidBody.C bodies/masslessBody/masslessBody.C +bodies/subBody/subBody.C bodies/sphere/sphere.C joints/joint/joint.C diff --git a/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.C b/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.C index b5e3cfecd8..7e97bd8462 100644 --- a/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.C +++ b/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.C @@ -39,4 +39,8 @@ bool Foam::RBD::masslessBody::massless() const } +void Foam::RBD::masslessBody::write(Ostream& os) const +{} + + // ************************************************************************* // diff --git a/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.H b/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.H index 46e0104093..4c58f97616 100644 --- a/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.H +++ b/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.H @@ -41,19 +41,9 @@ SourceFiles namespace Foam { - -// Forward declaration of Foam classes -class Istream; -class Ostream; - namespace RBD { -// Forward declaration of friend functions and operators -class masslessBody; -Ostream& operator<<(Ostream&, const masslessBody&); - - /*---------------------------------------------------------------------------*\ Class masslessBody Declaration \*---------------------------------------------------------------------------*/ @@ -83,10 +73,8 @@ public: //- Return true if this body is a massless component of a composite body virtual bool massless() const; - - // IOstream Operators - - //friend Ostream& operator<<(Ostream&, const masslessBody&); + //- Write + virtual void write(Ostream&) const; }; diff --git a/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.C b/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.C index 57848850d6..d71a082b51 100644 --- a/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.C +++ b/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.C @@ -64,4 +64,17 @@ void Foam::RBD::rigidBody::merge(const subBody& subBody) } +void Foam::RBD::rigidBody::write(Ostream& os) const +{ + os.writeKeyword("mass") + << m() << token::END_STATEMENT << nl; + + os.writeKeyword("centreOfMass") + << c() << token::END_STATEMENT << nl; + + os.writeKeyword("Inertia") + << Ic() << token::END_STATEMENT << nl; +} + + // ************************************************************************* // diff --git a/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.H b/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.H index 8658659e3a..9a7aad09e1 100644 --- a/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.H +++ b/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.H @@ -40,22 +40,12 @@ SourceFiles namespace Foam { - -// Forward declaration of Foam classes -class Istream; -class Ostream; - namespace RBD { // Forward declaration of classes class subBody; -// Forward declaration of friend functions and operators -class rigidBody; -Ostream& operator<<(Ostream&, const rigidBody&); - - /*---------------------------------------------------------------------------*\ Class rigidBody Declaration \*---------------------------------------------------------------------------*/ @@ -122,10 +112,8 @@ public: //- Merge a body into this parent body void merge(const subBody&); - - // IOstream Operators - - //friend Ostream& operator<<(Ostream&, const rigidBody&); + //- Write + virtual void write(Ostream&) const; }; diff --git a/src/rigidBodyDynamics/bodies/sphere/sphere.C b/src/rigidBodyDynamics/bodies/sphere/sphere.C index 95d7b020b4..275565ea9d 100644 --- a/src/rigidBodyDynamics/bodies/sphere/sphere.C +++ b/src/rigidBodyDynamics/bodies/sphere/sphere.C @@ -33,4 +33,14 @@ Foam::RBD::sphere::~sphere() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // +void Foam::RBD::sphere::write(Ostream& os) const +{ + os.writeKeyword("mass") + << m() << token::END_STATEMENT << nl; + + os.writeKeyword("radius") + << r() << token::END_STATEMENT << nl; +} + + // ************************************************************************* // diff --git a/src/rigidBodyDynamics/bodies/sphere/sphere.H b/src/rigidBodyDynamics/bodies/sphere/sphere.H index e1c24e0d30..72eb9c5788 100644 --- a/src/rigidBodyDynamics/bodies/sphere/sphere.H +++ b/src/rigidBodyDynamics/bodies/sphere/sphere.H @@ -25,6 +25,7 @@ Class Foam::sphere Description + Specialization of rigidBody to construct a sphere given the mass and radius. SourceFiles sphereI.H @@ -41,19 +42,9 @@ SourceFiles namespace Foam { - -// Forward declaration of Foam classes -class Istream; -class Ostream; - namespace RBD { -// Forward declaration of friend functions and operators -class sphere; -Ostream& operator<<(Ostream&, const sphere&); - - /*---------------------------------------------------------------------------*\ Class sphere Declaration \*---------------------------------------------------------------------------*/ @@ -62,6 +53,11 @@ class sphere : public rigidBody { + // Private member data + + //- Radius + scalar r_; + public: @@ -77,9 +73,11 @@ public: // Member Functions - // IOstream Operators + //- Return the radius of the sphere + inline scalar r() const; - //friend Ostream& operator<<(Ostream&, const sphere&); + //- Write + virtual void write(Ostream&) const; }; diff --git a/src/rigidBodyDynamics/bodies/sphere/sphereI.H b/src/rigidBodyDynamics/bodies/sphere/sphereI.H index 557d35348f..9543e16a9d 100644 --- a/src/rigidBodyDynamics/bodies/sphere/sphereI.H +++ b/src/rigidBodyDynamics/bodies/sphere/sphereI.H @@ -32,8 +32,17 @@ inline Foam::RBD::sphere::sphere const scalar r ) : - rigidBody(name, m, Zero, (2.0/5.0)*m*sqr(r)*I) + rigidBody(name, m, Zero, (2.0/5.0)*m*sqr(r)*I), + r_(r) {} +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +inline Foam::scalar Foam::RBD::sphere::r() const +{ + return r_; +} + + // ************************************************************************* // diff --git a/src/rigidBodyDynamics/bodies/subBody/subBody.C b/src/rigidBodyDynamics/bodies/subBody/subBody.C new file mode 100644 index 0000000000..e8756177c9 --- /dev/null +++ b/src/rigidBodyDynamics/bodies/subBody/subBody.C @@ -0,0 +1,46 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "subBody.H" + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::RBD::subBody::~subBody() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::RBD::subBody::write(Ostream& os) const +{ + os.writeKeyword("parentBody") + << parentName_ << token::END_STATEMENT << nl; + + os.writeKeyword("transform") + << parentXT_ << token::END_STATEMENT << nl; +} + + +// ************************************************************************* // diff --git a/src/rigidBodyDynamics/bodies/subBody/subBody.H b/src/rigidBodyDynamics/bodies/subBody/subBody.H index 684cb4b7e3..f47fa2c299 100644 --- a/src/rigidBodyDynamics/bodies/subBody/subBody.H +++ b/src/rigidBodyDynamics/bodies/subBody/subBody.H @@ -43,19 +43,9 @@ SourceFiles namespace Foam { - -// Forward declaration of Foam classes -class Istream; -class Ostream; - namespace RBD { -// Forward declaration of friend functions and operators -class subBody; -Ostream& operator<<(Ostream&, const subBody&); - - /*---------------------------------------------------------------------------*\ Class subBody Declaration \*---------------------------------------------------------------------------*/ @@ -69,6 +59,9 @@ class subBody //- Original body from which this sub-body was constructed autoPtr body_; + //- Parent body name + word parentName_; + //- Parent body ID label parentID_; @@ -86,26 +79,32 @@ public: inline subBody ( autoPtr bodyPtr, + const word& parentName, const label parentID, const spatialTransform& parentXT ); + //- Destructor + virtual ~subBody(); + + // Member Functions //- Return the original body from which this sub-body was constructed inline const rigidBody& body() const; + //- Return the parent body name + inline const word& parentName() const; + //- Return the parent body Id inline label parentID() const; //- Return the transform with respect to the parent body inline const spatialTransform& parentXT() const; - - // IOstream Operators - - //friend Ostream& operator<<(Ostream&, const subBody&); + //- Write + virtual void write(Ostream&) const; }; diff --git a/src/rigidBodyDynamics/bodies/subBody/subBodyI.H b/src/rigidBodyDynamics/bodies/subBody/subBodyI.H index 2cfd606cc4..84f705ef4b 100644 --- a/src/rigidBodyDynamics/bodies/subBody/subBodyI.H +++ b/src/rigidBodyDynamics/bodies/subBody/subBodyI.H @@ -28,12 +28,14 @@ License inline Foam::RBD::subBody::subBody ( autoPtr bodyPtr, + const word& parentName, const label parentID, const spatialTransform& parentXT ) : rigidBody(bodyPtr()), body_(bodyPtr), + parentName_(parentName), parentID_(parentID), parentXT_(parentXT) {} @@ -47,6 +49,12 @@ inline const Foam::RBD::rigidBody& Foam::RBD::subBody::body() const } +inline const Foam::word& Foam::RBD::subBody::parentName() const +{ + return parentName_; +} + + inline Foam::label Foam::RBD::subBody::parentID() const { return parentID_; diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C index 4d859be759..7c8679dcf8 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C @@ -188,6 +188,7 @@ Foam::label Foam::RBD::rigidBodyModel::merge new subBody ( bodyPtr, + bodies_[sBody.parentID()].name(), sBody.parentID(), XT & sBody.parentXT() ) @@ -195,7 +196,16 @@ Foam::label Foam::RBD::rigidBodyModel::merge } else { - sBodyPtr.set(new subBody(bodyPtr, parentID, XT)); + sBodyPtr.set + ( + new subBody + ( + bodyPtr, + bodies_[parentID].name(), + parentID, + XT + ) + ); } const subBody& sBody = sBodyPtr();