diff --git a/applications/test/rigidBodyDynamics/pendulum/pendulum b/applications/test/rigidBodyDynamics/pendulum/pendulum new file mode 100644 index 0000000000..4a8378b9f2 --- /dev/null +++ b/applications/test/rigidBodyDynamics/pendulum/pendulum @@ -0,0 +1,38 @@ +bodies0 +{ + pendulum + { + type rigidBody; + parent root; + mass 1; + centreOfMass (0 -1 0); + inertia (0.001 0 0 0.001 0 0.001); + transform (1 0 0 0 1 0 0 0 1) (0 0 0); + joint + { + type Rz; + } + } +} + +bodies +{ + hinge + { + type masslessBody; + parent root; + transform (1 0 0 0 1 0 0 0 1) (0 0 0); + joint + { + type Rz; + } + } + weight + { + type sphere; + mergeWith hinge; + mass 1; + radius 0.05; + transform (1 0 0 0 1 0 0 0 1) (0 -1 0); + } +} diff --git a/applications/test/rigidBodyDynamics/pendulum/pendulum.C b/applications/test/rigidBodyDynamics/pendulum/pendulum.C index 8a15aec82d..2401ec256c 100644 --- a/applications/test/rigidBodyDynamics/pendulum/pendulum.C +++ b/applications/test/rigidBodyDynamics/pendulum/pendulum.C @@ -34,6 +34,7 @@ Description #include "masslessBody.H" #include "sphere.H" #include "joints.H" +#include "IFstream.H" using namespace Foam; using namespace RBD; @@ -42,7 +43,8 @@ using namespace RBD; int main(int argc, char *argv[]) { - bool testMerge = false; + /* + bool testMerge = true; // Create a model for the pendulum rigidBodyModel pendulum; @@ -55,7 +57,7 @@ int main(int argc, char *argv[]) ( pendulum.bodyID("root"), Xt(Zero), - joint::New(new joints::Rz(pendulum)), + joint::New(new joints::Rz()), autoPtr(new masslessBody("hinge")) ); @@ -72,10 +74,16 @@ int main(int argc, char *argv[]) ( pendulum.bodyID("root"), Xt(Zero), - joint::New(new joints::Rz(pendulum)), + joint::New(new joints::Rz()), rigidBody::New("pendulum", 1, vector(0, -1, 0), 1e-3*I) ); } + */ + + // Create the pendulum model from dictionary + rigidBodyModel pendulum(dictionary(IFstream("pendulum")())); + + pendulum.write(Info); // Create the joint-space state fields scalarField q(pendulum.nDoF(), Zero); @@ -110,7 +118,7 @@ int main(int argc, char *argv[]) qdot += 0.5*deltaT*qddot; - Info<< "Time << " << t << "s, angle = " << q[0] << "rad" << endl; + Info<< "Time " << t << "s, angle = " << q[0] << "rad" << endl; } Info<< "\nEnd\n" << endl; diff --git a/src/OpenFOAM/primitives/spatialVectorAlgebra/spatialTransform/spatialTransformI.H b/src/OpenFOAM/primitives/spatialVectorAlgebra/spatialTransform/spatialTransformI.H index 8c2724aa33..c245fde390 100644 --- a/src/OpenFOAM/primitives/spatialVectorAlgebra/spatialTransform/spatialTransformI.H +++ b/src/OpenFOAM/primitives/spatialVectorAlgebra/spatialTransform/spatialTransformI.H @@ -217,7 +217,7 @@ inline Foam::Ostream& Foam::operator<< const spatialTransform& X ) { - os << X.E() << token::SPACE << X.r() << endl; + os << X.E() << token::SPACE << X.r(); return os; } diff --git a/src/rigidBodyDynamics/Make/files b/src/rigidBodyDynamics/Make/files index c2c03b7172..7fc99c209a 100644 --- a/src/rigidBodyDynamics/Make/files +++ b/src/rigidBodyDynamics/Make/files @@ -1,5 +1,6 @@ bodies/rigidBody/rigidBody.C bodies/masslessBody/masslessBody.C +bodies/compositeBody/compositeBody.C bodies/subBody/subBody.C bodies/sphere/sphere.C diff --git a/src/rigidBodyDynamics/bodies/compositeBody/compositeBody.C b/src/rigidBodyDynamics/bodies/compositeBody/compositeBody.C new file mode 100644 index 0000000000..f898386c1a --- /dev/null +++ b/src/rigidBodyDynamics/bodies/compositeBody/compositeBody.C @@ -0,0 +1,48 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "compositeBody.H" + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::RBD::compositeBody::~compositeBody() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +const Foam::word& Foam::RBD::compositeBody::type() const +{ + return body_->type(); +} + + +void Foam::RBD::compositeBody::write(Ostream& os) const +{ + body_->write(os); +} + + +// ************************************************************************* // diff --git a/src/rigidBodyDynamics/bodies/compositeBody/compositeBody.H b/src/rigidBodyDynamics/bodies/compositeBody/compositeBody.H new file mode 100644 index 0000000000..c92d9bda31 --- /dev/null +++ b/src/rigidBodyDynamics/bodies/compositeBody/compositeBody.H @@ -0,0 +1,103 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +Class + Foam::compositeBody + +Description + This specialized rigidBody holds the original body after it has been merged + into a parent. + +SourceFiles + compositeBodyI.H + compositeBody.C + +\*---------------------------------------------------------------------------*/ + +#ifndef RBD_compositeBody_H +#define RBD_compositeBody_H + +#include "rigidBody.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ + +/*---------------------------------------------------------------------------*\ + Class compositeBody Declaration +\*---------------------------------------------------------------------------*/ + +class compositeBody +: + public rigidBody +{ + // Private data + + //- Original body from which this composite-body was constructed + autoPtr body_; + +public: + + // Constructors + + //- Construct a merged version of the given rigidBody + // providing the ID of the parent body to which this will be merged + // and the transform relative to the parent + inline compositeBody(const autoPtr& bodyPtr); + + + //- Destructor + virtual ~compositeBody(); + + + // Member Functions + + //- Return the type name of the original body + virtual const word& type() const; + + //- Return the original body from which this composite-body + // was constructed + inline const rigidBody& body() const; + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace RBD +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "compositeBodyI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/rigidBodyDynamics/bodies/compositeBody/compositeBodyI.H b/src/rigidBodyDynamics/bodies/compositeBody/compositeBodyI.H new file mode 100644 index 0000000000..dee27aec8c --- /dev/null +++ b/src/rigidBodyDynamics/bodies/compositeBody/compositeBodyI.H @@ -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 . + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +inline Foam::RBD::compositeBody::compositeBody +( + const autoPtr& bodyPtr +) +: + rigidBody(bodyPtr()), + body_(bodyPtr) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +inline const Foam::RBD::rigidBody& Foam::RBD::compositeBody::body() const +{ + return body_(); +} + + +// ************************************************************************* // diff --git a/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.C b/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.C index 7e97bd8462..da0f731876 100644 --- a/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.C +++ b/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.C @@ -24,6 +24,25 @@ License \*---------------------------------------------------------------------------*/ #include "masslessBody.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ + defineTypeNameAndDebug(masslessBody, 0); + + addToRunTimeSelectionTable + ( + rigidBody, + masslessBody, + dictionary + ); +} +} + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.H b/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.H index 4c58f97616..d20c160d07 100644 --- a/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.H +++ b/src/rigidBodyDynamics/bodies/masslessBody/masslessBody.H @@ -55,6 +55,10 @@ class masslessBody public: + //- Runtime type information + TypeName("masslessBody"); + + // Constructors //- Construct a massless body @@ -63,6 +67,13 @@ public: //- Construct a named massless body inline masslessBody(const word& name); + //- Construct from dictionary + inline masslessBody + ( + const word& name, + const dictionary& dict + ); + //- Destructor virtual ~masslessBody(); diff --git a/src/rigidBodyDynamics/bodies/masslessBody/masslessBodyI.H b/src/rigidBodyDynamics/bodies/masslessBody/masslessBodyI.H index 06acc415b6..e8319b4a39 100644 --- a/src/rigidBodyDynamics/bodies/masslessBody/masslessBodyI.H +++ b/src/rigidBodyDynamics/bodies/masslessBody/masslessBodyI.H @@ -37,4 +37,15 @@ inline Foam::RBD::masslessBody::masslessBody(const word& name) {} +inline Foam::RBD::masslessBody::masslessBody +( + const word& name, + const dictionary& dict +) +: + rigidBody(name, rigidBodyInertia()) +{} + + + // ************************************************************************* // diff --git a/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.C b/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.C index d71a082b51..7d797f0142 100644 --- a/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.C +++ b/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.C @@ -25,6 +25,26 @@ License #include "rigidBody.H" #include "subBody.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ + defineTypeNameAndDebug(rigidBody, 0); + defineRunTimeSelectionTable(rigidBody, dictionary); + + addToRunTimeSelectionTable + ( + rigidBody, + rigidBody, + dictionary + ); +} +} + // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // @@ -40,6 +60,31 @@ Foam::autoPtr Foam::RBD::rigidBody::New } +Foam::autoPtr Foam::RBD::rigidBody::New +( + const word& name, + const dictionary& dict +) +{ + const word bodyType(dict.lookup("type")); + + dictionaryConstructorTable::iterator cstrIter = + dictionaryConstructorTablePtr_->find(bodyType); + + if (cstrIter == dictionaryConstructorTablePtr_->end()) + { + FatalErrorInFunction + << "Unknown rigidBody type " + << bodyType << nl << nl + << "Valid rigidBody types are : " << endl + << dictionaryConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr(cstrIter()(name, dict)); +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::RBD::rigidBody::~rigidBody() @@ -72,7 +117,7 @@ void Foam::RBD::rigidBody::write(Ostream& os) const os.writeKeyword("centreOfMass") << c() << token::END_STATEMENT << nl; - os.writeKeyword("Inertia") + 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 9a7aad09e1..9d2b3f279d 100644 --- a/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.H +++ b/src/rigidBodyDynamics/bodies/rigidBody/rigidBody.H @@ -35,6 +35,8 @@ SourceFiles #define RBD_rigidBody_H #include "rigidBodyInertia.H" +#include "dictionary.H" +#include "runTimeSelectionTables.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -62,6 +64,22 @@ class rigidBody public: + //- Runtime type information + TypeName("rigidBody"); + + + // Declare run-time constructor selection table + + declareRunTimeSelectionTable + ( + autoPtr, + rigidBody, + dictionary, + (const word& name, const dictionary& dict), + (name, dict) + ); + + // Constructors //- Construct from mass, centre of mass and moment of inertia tensor @@ -81,6 +99,13 @@ public: const rigidBodyInertia& rbi ); + //- Construct from dictionary + inline rigidBody + ( + const word& name, + const dictionary& dict + ); + //- Return clone of this rigidBody inline autoPtr clone() const; @@ -96,6 +121,13 @@ public: const symmTensor& Ic ); + //- Select constructed from name and dictionary + static autoPtr New + ( + const word& name, + const dictionary& dict + ); + //- Destructor virtual ~rigidBody(); diff --git a/src/rigidBodyDynamics/bodies/rigidBody/rigidBodyI.H b/src/rigidBodyDynamics/bodies/rigidBody/rigidBodyI.H index 2e68928a45..5b6a66e874 100644 --- a/src/rigidBodyDynamics/bodies/rigidBody/rigidBodyI.H +++ b/src/rigidBodyDynamics/bodies/rigidBody/rigidBodyI.H @@ -43,12 +43,23 @@ inline Foam::RBD::rigidBody::rigidBody const word& name, const rigidBodyInertia& rbi ) - : +: rigidBodyInertia(rbi), name_(name) {} +inline Foam::RBD::rigidBody::rigidBody +( + const word& name, + const dictionary& dict +) +: + rigidBodyInertia(dict), + name_(name) +{} + + inline Foam::autoPtr Foam::RBD::rigidBody::clone() const { return autoPtr(new rigidBody(*this)); diff --git a/src/rigidBodyDynamics/bodies/sphere/sphere.C b/src/rigidBodyDynamics/bodies/sphere/sphere.C index 275565ea9d..e581ce8648 100644 --- a/src/rigidBodyDynamics/bodies/sphere/sphere.C +++ b/src/rigidBodyDynamics/bodies/sphere/sphere.C @@ -24,6 +24,25 @@ License \*---------------------------------------------------------------------------*/ #include "sphere.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ + defineTypeNameAndDebug(sphere, 0); + + addToRunTimeSelectionTable + ( + rigidBody, + sphere, + dictionary + ); +} +} + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/rigidBodyDynamics/bodies/sphere/sphere.H b/src/rigidBodyDynamics/bodies/sphere/sphere.H index 72eb9c5788..ad5ca48bab 100644 --- a/src/rigidBodyDynamics/bodies/sphere/sphere.H +++ b/src/rigidBodyDynamics/bodies/sphere/sphere.H @@ -61,11 +61,22 @@ class sphere public: + //- Runtime type information + TypeName("sphere"); + + // Constructors //- Construct from name, mass and radius inline sphere(const word& name, const scalar m, const scalar r); + //- Construct from dictionary + inline sphere + ( + const word& name, + const dictionary& dict + ); + //- Destructor virtual ~sphere(); diff --git a/src/rigidBodyDynamics/bodies/sphere/sphereI.H b/src/rigidBodyDynamics/bodies/sphere/sphereI.H index 9543e16a9d..42f429f1d4 100644 --- a/src/rigidBodyDynamics/bodies/sphere/sphereI.H +++ b/src/rigidBodyDynamics/bodies/sphere/sphereI.H @@ -37,6 +37,27 @@ inline Foam::RBD::sphere::sphere {} +inline Foam::RBD::sphere::sphere +( + const word& name, + const dictionary& dict +) +: + 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) + ); +} + + // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // inline Foam::scalar Foam::RBD::sphere::r() const diff --git a/src/rigidBodyDynamics/bodies/subBody/subBody.C b/src/rigidBodyDynamics/bodies/subBody/subBody.C index e8756177c9..1508b8f431 100644 --- a/src/rigidBodyDynamics/bodies/subBody/subBody.C +++ b/src/rigidBodyDynamics/bodies/subBody/subBody.C @@ -35,7 +35,7 @@ Foam::RBD::subBody::~subBody() void Foam::RBD::subBody::write(Ostream& os) const { - os.writeKeyword("parentBody") + os.writeKeyword("parent") << parentName_ << token::END_STATEMENT << nl; os.writeKeyword("transform") diff --git a/src/rigidBodyDynamics/bodies/subBody/subBody.H b/src/rigidBodyDynamics/bodies/subBody/subBody.H index f47fa2c299..a9163e8e3f 100644 --- a/src/rigidBodyDynamics/bodies/subBody/subBody.H +++ b/src/rigidBodyDynamics/bodies/subBody/subBody.H @@ -78,7 +78,7 @@ public: // and the transform relative to the parent inline subBody ( - autoPtr bodyPtr, + const autoPtr& bodyPtr, const word& parentName, const label parentID, const spatialTransform& parentXT diff --git a/src/rigidBodyDynamics/bodies/subBody/subBodyI.H b/src/rigidBodyDynamics/bodies/subBody/subBodyI.H index 84f705ef4b..b8c2813d42 100644 --- a/src/rigidBodyDynamics/bodies/subBody/subBodyI.H +++ b/src/rigidBodyDynamics/bodies/subBody/subBodyI.H @@ -27,7 +27,7 @@ License inline Foam::RBD::subBody::subBody ( - autoPtr bodyPtr, + const autoPtr& bodyPtr, const word& parentName, const label parentID, const spatialTransform& parentXT diff --git a/src/rigidBodyDynamics/joints/Pa/Pa.C b/src/rigidBodyDynamics/joints/Pa/Pa.C index 8472269504..2263ce3283 100644 --- a/src/rigidBodyDynamics/joints/Pa/Pa.C +++ b/src/rigidBodyDynamics/joints/Pa/Pa.C @@ -50,17 +50,17 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Pa::Pa(const rigidBodyModel& model, const vector& axis) +Foam::RBD::joints::Pa::Pa(const vector& axis) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(Zero, axis); } -Foam::RBD::joints::Pa::Pa(const rigidBodyModel& model, const dictionary& dict) +Foam::RBD::joints::Pa::Pa(const dictionary& dict) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(Zero, dict.lookup("axis")); } diff --git a/src/rigidBodyDynamics/joints/Pa/Pa.H b/src/rigidBodyDynamics/joints/Pa/Pa.H index 99208d1e72..09f7eee753 100644 --- a/src/rigidBodyDynamics/joints/Pa/Pa.H +++ b/src/rigidBodyDynamics/joints/Pa/Pa.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model and axis - Pa(const rigidBodyModel& model, const vector& axis); + Pa(const vector& axis); //- Construct for given model from dictionary - Pa(const rigidBodyModel&, const dictionary& dict); + Pa(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Px/Px.C b/src/rigidBodyDynamics/joints/Px/Px.C index 3edbb7a2a3..412a3df472 100644 --- a/src/rigidBodyDynamics/joints/Px/Px.C +++ b/src/rigidBodyDynamics/joints/Px/Px.C @@ -50,17 +50,17 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Px::Px(const rigidBodyModel& model) +Foam::RBD::joints::Px::Px() : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 0, 0, 1, 0, 0); } -Foam::RBD::joints::Px::Px(const rigidBodyModel& model, const dictionary& dict) +Foam::RBD::joints::Px::Px(const dictionary& dict) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 0, 0, 1, 0, 0); } diff --git a/src/rigidBodyDynamics/joints/Px/Px.H b/src/rigidBodyDynamics/joints/Px/Px.H index 0bbd6028b8..b7d77f344a 100644 --- a/src/rigidBodyDynamics/joints/Px/Px.H +++ b/src/rigidBodyDynamics/joints/Px/Px.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model - Px(const rigidBodyModel& model); + Px(); //- Construct for given model from dictionary - Px(const rigidBodyModel&, const dictionary& dict); + Px(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Pxyz/Pxyz.C b/src/rigidBodyDynamics/joints/Pxyz/Pxyz.C index 131bcad8c9..fcb5dac7e8 100644 --- a/src/rigidBodyDynamics/joints/Pxyz/Pxyz.C +++ b/src/rigidBodyDynamics/joints/Pxyz/Pxyz.C @@ -50,9 +50,9 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Pxyz::Pxyz(const rigidBodyModel& model) +Foam::RBD::joints::Pxyz::Pxyz() : - joint(model, 3) + joint(3) { S_[0] = spatialVector(0, 0, 0, 1, 0, 0); S_[1] = spatialVector(0, 0, 0, 0, 1, 0); @@ -60,13 +60,9 @@ Foam::RBD::joints::Pxyz::Pxyz(const rigidBodyModel& model) } -Foam::RBD::joints::Pxyz::Pxyz -( - const rigidBodyModel& model, - const dictionary& dict -) +Foam::RBD::joints::Pxyz::Pxyz(const dictionary& dict) : - joint(model, 3) + joint(3) { S_[0] = spatialVector(0, 0, 0, 1, 0, 0); S_[1] = spatialVector(0, 0, 0, 0, 1, 0); diff --git a/src/rigidBodyDynamics/joints/Pxyz/Pxyz.H b/src/rigidBodyDynamics/joints/Pxyz/Pxyz.H index b5e87f6f1f..5fbdeb7833 100644 --- a/src/rigidBodyDynamics/joints/Pxyz/Pxyz.H +++ b/src/rigidBodyDynamics/joints/Pxyz/Pxyz.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model - Pxyz(const rigidBodyModel& model); + Pxyz(); //- Construct for given model from dictionary - Pxyz(const rigidBodyModel&, const dictionary& dict); + Pxyz(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Py/Py.C b/src/rigidBodyDynamics/joints/Py/Py.C index e7e5b147ff..4b297bbcab 100644 --- a/src/rigidBodyDynamics/joints/Py/Py.C +++ b/src/rigidBodyDynamics/joints/Py/Py.C @@ -50,17 +50,17 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Py::Py(const rigidBodyModel& model) +Foam::RBD::joints::Py::Py() : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 0, 0, 0, 1, 0); } -Foam::RBD::joints::Py::Py(const rigidBodyModel& model, const dictionary& dict) +Foam::RBD::joints::Py::Py(const dictionary& dict) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 0, 0, 0, 1, 0); } diff --git a/src/rigidBodyDynamics/joints/Py/Py.H b/src/rigidBodyDynamics/joints/Py/Py.H index fb2a87601a..981e7154af 100644 --- a/src/rigidBodyDynamics/joints/Py/Py.H +++ b/src/rigidBodyDynamics/joints/Py/Py.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model - Py(const rigidBodyModel& model); + Py(); //- Construct for given model from dictionary - Py(const rigidBodyModel&, const dictionary& dict); + Py(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Pz/Pz.C b/src/rigidBodyDynamics/joints/Pz/Pz.C index cbccb6dddd..83850020dd 100644 --- a/src/rigidBodyDynamics/joints/Pz/Pz.C +++ b/src/rigidBodyDynamics/joints/Pz/Pz.C @@ -50,17 +50,17 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Pz::Pz(const rigidBodyModel& model) +Foam::RBD::joints::Pz::Pz() : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 0, 0, 0, 0, 1); } -Foam::RBD::joints::Pz::Pz(const rigidBodyModel& model, const dictionary& dict) +Foam::RBD::joints::Pz::Pz(const dictionary& dict) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 0, 0, 0, 0, 1); } diff --git a/src/rigidBodyDynamics/joints/Pz/Pz.H b/src/rigidBodyDynamics/joints/Pz/Pz.H index d1a7a4e61f..18783f0d49 100644 --- a/src/rigidBodyDynamics/joints/Pz/Pz.H +++ b/src/rigidBodyDynamics/joints/Pz/Pz.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model - Pz(const rigidBodyModel& model); + Pz(); //- Construct for given model from dictionary - Pz(const rigidBodyModel&, const dictionary& dict); + Pz(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Ra/Ra.C b/src/rigidBodyDynamics/joints/Ra/Ra.C index 2230863898..6d9e6aa5fe 100644 --- a/src/rigidBodyDynamics/joints/Ra/Ra.C +++ b/src/rigidBodyDynamics/joints/Ra/Ra.C @@ -50,17 +50,17 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Ra::Ra(const rigidBodyModel& model, const vector& axis) +Foam::RBD::joints::Ra::Ra(const vector& axis) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(axis, Zero); } -Foam::RBD::joints::Ra::Ra(const rigidBodyModel& model, const dictionary& dict) +Foam::RBD::joints::Ra::Ra(const dictionary& dict) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(dict.lookup("axis"), Zero); } diff --git a/src/rigidBodyDynamics/joints/Ra/Ra.H b/src/rigidBodyDynamics/joints/Ra/Ra.H index b429678318..d098b2c82e 100644 --- a/src/rigidBodyDynamics/joints/Ra/Ra.H +++ b/src/rigidBodyDynamics/joints/Ra/Ra.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model and axis - Ra(const rigidBodyModel& model, const vector& axis); + Ra(const vector& axis); //- Construct for given model from dictionary - Ra(const rigidBodyModel&, const dictionary& dict); + Ra(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Rs/Rs.C b/src/rigidBodyDynamics/joints/Rs/Rs.C index c5da501f0e..9658b7595e 100644 --- a/src/rigidBodyDynamics/joints/Rs/Rs.C +++ b/src/rigidBodyDynamics/joints/Rs/Rs.C @@ -50,9 +50,9 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Rs::Rs(const rigidBodyModel& model) +Foam::RBD::joints::Rs::Rs() : - joint(model, 3) + joint(3) { S_[0] = spatialVector(1, 0, 0, 0, 0, 0); S_[1] = spatialVector (0, 1, 0, 0, 0, 0); @@ -60,9 +60,9 @@ Foam::RBD::joints::Rs::Rs(const rigidBodyModel& model) } -Foam::RBD::joints::Rs::Rs(const rigidBodyModel& model, const dictionary& dict) +Foam::RBD::joints::Rs::Rs(const dictionary& dict) : - joint(model, 3) + joint(3) { S_[0] = spatialVector(1, 0, 0, 0, 0, 0); S_[1] = spatialVector (0, 1, 0, 0, 0, 0); diff --git a/src/rigidBodyDynamics/joints/Rs/Rs.H b/src/rigidBodyDynamics/joints/Rs/Rs.H index 3e1b0655f3..386a869bf6 100644 --- a/src/rigidBodyDynamics/joints/Rs/Rs.H +++ b/src/rigidBodyDynamics/joints/Rs/Rs.H @@ -73,10 +73,10 @@ public: // Constructors //- Construct for given model - Rs(const rigidBodyModel& model); + Rs(); //- Construct for given model from dictionary - Rs(const rigidBodyModel&, const dictionary& dict); + Rs(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Rx/Rx.C b/src/rigidBodyDynamics/joints/Rx/Rx.C index c90f6fd976..87343fe55f 100644 --- a/src/rigidBodyDynamics/joints/Rx/Rx.C +++ b/src/rigidBodyDynamics/joints/Rx/Rx.C @@ -50,17 +50,17 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Rx::Rx(const rigidBodyModel& model) +Foam::RBD::joints::Rx::Rx() : - joint(model, 1) + joint(1) { S_[0] = spatialVector(1, 0, 0, 0, 0, 0); } -Foam::RBD::joints::Rx::Rx(const rigidBodyModel& model, const dictionary& dict) +Foam::RBD::joints::Rx::Rx(const dictionary& dict) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(1, 0, 0, 0, 0, 0); } diff --git a/src/rigidBodyDynamics/joints/Rx/Rx.H b/src/rigidBodyDynamics/joints/Rx/Rx.H index 79ca52d9f2..3da54830a9 100644 --- a/src/rigidBodyDynamics/joints/Rx/Rx.H +++ b/src/rigidBodyDynamics/joints/Rx/Rx.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model - Rx(const rigidBodyModel& model); + Rx(); //- Construct for given model from dictionary - Rx(const rigidBodyModel&, const dictionary& dict); + Rx(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Rxyz/Rxyz.C b/src/rigidBodyDynamics/joints/Rxyz/Rxyz.C index 8dda6d3e6a..39b3d5f7de 100644 --- a/src/rigidBodyDynamics/joints/Rxyz/Rxyz.C +++ b/src/rigidBodyDynamics/joints/Rxyz/Rxyz.C @@ -50,9 +50,9 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Rxyz::Rxyz(const rigidBodyModel& model) +Foam::RBD::joints::Rxyz::Rxyz() : - joint(model, 3) + joint(3) { S_[0] = spatialVector(1, 0, 0, 0, 0, 0); S_[1] = spatialVector(0, 1, 0, 0, 0, 0); @@ -60,13 +60,9 @@ Foam::RBD::joints::Rxyz::Rxyz(const rigidBodyModel& model) } -Foam::RBD::joints::Rxyz::Rxyz -( - const rigidBodyModel& model, - const dictionary& dict -) +Foam::RBD::joints::Rxyz::Rxyz(const dictionary& dict) : - joint(model, 3) + joint(3) { S_[0] = spatialVector(1, 0, 0, 0, 0, 0); S_[1] = spatialVector(0, 1, 0, 0, 0, 0); diff --git a/src/rigidBodyDynamics/joints/Rxyz/Rxyz.H b/src/rigidBodyDynamics/joints/Rxyz/Rxyz.H index 7ada2cc4a5..3a63a4ffbe 100644 --- a/src/rigidBodyDynamics/joints/Rxyz/Rxyz.H +++ b/src/rigidBodyDynamics/joints/Rxyz/Rxyz.H @@ -73,10 +73,10 @@ public: // Constructors //- Construct for given model - Rxyz(const rigidBodyModel& model); + Rxyz(); //- Construct for given model from dictionary - Rxyz(const rigidBodyModel&, const dictionary& dict); + Rxyz(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Ry/Ry.C b/src/rigidBodyDynamics/joints/Ry/Ry.C index 4814264f1b..d771a7130f 100644 --- a/src/rigidBodyDynamics/joints/Ry/Ry.C +++ b/src/rigidBodyDynamics/joints/Ry/Ry.C @@ -50,17 +50,17 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Ry::Ry(const rigidBodyModel& model) +Foam::RBD::joints::Ry::Ry() : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 1, 0, 0, 0, 0); } -Foam::RBD::joints::Ry::Ry(const rigidBodyModel& model, const dictionary& dict) +Foam::RBD::joints::Ry::Ry(const dictionary& dict) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 1, 0, 0, 0, 0); } diff --git a/src/rigidBodyDynamics/joints/Ry/Ry.H b/src/rigidBodyDynamics/joints/Ry/Ry.H index 4a88a659a4..4bfa32401f 100644 --- a/src/rigidBodyDynamics/joints/Ry/Ry.H +++ b/src/rigidBodyDynamics/joints/Ry/Ry.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model - Ry(const rigidBodyModel& model); + Ry(); //- Construct for given model from dictionary - Ry(const rigidBodyModel&, const dictionary& dict); + Ry(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Ryxz/Ryxz.C b/src/rigidBodyDynamics/joints/Ryxz/Ryxz.C index a52896299a..2de4088517 100644 --- a/src/rigidBodyDynamics/joints/Ryxz/Ryxz.C +++ b/src/rigidBodyDynamics/joints/Ryxz/Ryxz.C @@ -50,9 +50,9 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Ryxz::Ryxz(const rigidBodyModel& model) +Foam::RBD::joints::Ryxz::Ryxz() : - joint(model, 3) + joint(3) { S_[0] = spatialVector(0, 1, 0, 0, 0, 0); S_[1] = spatialVector(1, 0, 0, 0, 0, 0); @@ -60,13 +60,9 @@ Foam::RBD::joints::Ryxz::Ryxz(const rigidBodyModel& model) } -Foam::RBD::joints::Ryxz::Ryxz -( - const rigidBodyModel& model, - const dictionary& dict -) +Foam::RBD::joints::Ryxz::Ryxz(const dictionary& dict) : - joint(model, 3) + joint(3) { S_[0] = spatialVector(0, 1, 0, 0, 0, 0); S_[1] = spatialVector(1, 0, 0, 0, 0, 0); diff --git a/src/rigidBodyDynamics/joints/Ryxz/Ryxz.H b/src/rigidBodyDynamics/joints/Ryxz/Ryxz.H index 604e849b3a..02a7fe4200 100644 --- a/src/rigidBodyDynamics/joints/Ryxz/Ryxz.H +++ b/src/rigidBodyDynamics/joints/Ryxz/Ryxz.H @@ -73,10 +73,10 @@ public: // Constructors //- Construct for given model - Ryxz(const rigidBodyModel& model); + Ryxz(); //- Construct for given model from dictionary - Ryxz(const rigidBodyModel&, const dictionary& dict); + Ryxz(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Rz/Rz.C b/src/rigidBodyDynamics/joints/Rz/Rz.C index 1465dfc460..9027e2d8c7 100644 --- a/src/rigidBodyDynamics/joints/Rz/Rz.C +++ b/src/rigidBodyDynamics/joints/Rz/Rz.C @@ -50,17 +50,17 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Rz::Rz(const rigidBodyModel& model) +Foam::RBD::joints::Rz::Rz() : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 0, 1, 0, 0, 0); } -Foam::RBD::joints::Rz::Rz(const rigidBodyModel& model, const dictionary& dict) +Foam::RBD::joints::Rz::Rz(const dictionary& dict) : - joint(model, 1) + joint(1) { S_[0] = spatialVector(0, 0, 1, 0, 0, 0); } diff --git a/src/rigidBodyDynamics/joints/Rz/Rz.H b/src/rigidBodyDynamics/joints/Rz/Rz.H index b14b6408fb..19a7697503 100644 --- a/src/rigidBodyDynamics/joints/Rz/Rz.H +++ b/src/rigidBodyDynamics/joints/Rz/Rz.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model - Rz(const rigidBodyModel& model); + Rz(); //- Construct for given model from dictionary - Rz(const rigidBodyModel&, const dictionary& dict); + Rz(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/Rzyx/Rzyx.C b/src/rigidBodyDynamics/joints/Rzyx/Rzyx.C index f55775330f..7b1a8bc1fc 100644 --- a/src/rigidBodyDynamics/joints/Rzyx/Rzyx.C +++ b/src/rigidBodyDynamics/joints/Rzyx/Rzyx.C @@ -50,9 +50,9 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::Rzyx::Rzyx(const rigidBodyModel& model) +Foam::RBD::joints::Rzyx::Rzyx() : - joint(model, 3) + joint(3) { S_[0] = spatialVector(0, 0, 1, 0, 0, 0); S_[1] = spatialVector(0, 1, 0, 0, 0, 0); @@ -60,13 +60,9 @@ Foam::RBD::joints::Rzyx::Rzyx(const rigidBodyModel& model) } -Foam::RBD::joints::Rzyx::Rzyx -( - const rigidBodyModel& model, - const dictionary& dict -) +Foam::RBD::joints::Rzyx::Rzyx(const dictionary& dict) : - joint(model, 3) + joint(3) { S_[0] = spatialVector(0, 0, 1, 0, 0, 0); S_[1] = spatialVector(0, 1, 0, 0, 0, 0); diff --git a/src/rigidBodyDynamics/joints/Rzyx/Rzyx.H b/src/rigidBodyDynamics/joints/Rzyx/Rzyx.H index 52c53939f1..344ad4fbc1 100644 --- a/src/rigidBodyDynamics/joints/Rzyx/Rzyx.H +++ b/src/rigidBodyDynamics/joints/Rzyx/Rzyx.H @@ -73,10 +73,10 @@ public: // Constructors //- Construct for given model - Rzyx(const rigidBodyModel& model); + Rzyx(); //- Construct for given model from dictionary - Rzyx(const rigidBodyModel&, const dictionary& dict); + Rzyx(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/joints/joint/joint.C b/src/rigidBodyDynamics/joints/joint/joint.C index 04f41d65a4..4374990eb5 100644 --- a/src/rigidBodyDynamics/joints/joint/joint.C +++ b/src/rigidBodyDynamics/joints/joint/joint.C @@ -49,6 +49,30 @@ Foam::autoPtr Foam::RBD::joint::New(joint* jointPtr) } +Foam::autoPtr Foam::RBD::joint::New +( + const dictionary& dict +) +{ + const word bodyType(dict.lookup("type")); + + dictionaryConstructorTable::iterator cstrIter = + dictionaryConstructorTablePtr_->find(bodyType); + + if (cstrIter == dictionaryConstructorTablePtr_->end()) + { + FatalErrorInFunction + << "Unknown joint type " + << bodyType << nl << nl + << "Valid joint types are : " << endl + << dictionaryConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr(cstrIter()(dict)); +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::RBD::joint::~joint() @@ -57,15 +81,12 @@ Foam::RBD::joint::~joint() // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -Foam::PtrList Foam::RBD::joint::floating -( - const rigidBodyModel& model -) +Foam::PtrList Foam::RBD::joint::floating() { PtrList cj(2); - cj.set(0, new joints::Pxyz(model)); - //cj.set(1, new joints::Rs(model)); - cj.set(1, new joints::Rzyx(model)); + cj.set(0, new joints::Pxyz()); + //cj.set(1, new joints::Rs()); + cj.set(1, new joints::Rzyx()); return cj; } diff --git a/src/rigidBodyDynamics/joints/joint/joint.H b/src/rigidBodyDynamics/joints/joint/joint.H index 4acfb7da95..58d68190de 100644 --- a/src/rigidBodyDynamics/joints/joint/joint.H +++ b/src/rigidBodyDynamics/joints/joint/joint.H @@ -157,20 +157,16 @@ public: autoPtr, joint, dictionary, - ( - const rigidBodyModel& model, - const dictionary& dict - ), - (model, dict) + (const dictionary& dict), + (dict) ); // Constructors - //- Construct joint for given rigidBodyModel - // setting the size of the motion sub-space + //- Construct joint setting the size of the motion sub-space // to the given degrees of freedom of the joint - inline joint(const rigidBodyModel&, const label nDoF); + inline joint(const label nDoF); //- Clone this joint (needed by PtrList) virtual autoPtr clone() const = 0; @@ -185,12 +181,8 @@ public: //- Simple selector to return an autoPtr of the given joint* static autoPtr New(joint* jointPtr); - //- Select constructed from dictionary - static autoPtr New - ( - const rigidBodyModel& model, - const dictionary& dict - ); + //- Select from dictionary + static autoPtr New(const dictionary& dict); // Member Functions @@ -216,7 +208,7 @@ public: inline const List& S() const; //- Return a list of joints needed to emulate a floating body - static PtrList floating(const rigidBodyModel& model); + static PtrList floating(); //- Update the rigidBodyModel state for the joint given // the joint state q, w and velocity qDot diff --git a/src/rigidBodyDynamics/joints/joint/jointI.H b/src/rigidBodyDynamics/joints/joint/jointI.H index f2020c047c..47db466a7d 100644 --- a/src/rigidBodyDynamics/joints/joint/jointI.H +++ b/src/rigidBodyDynamics/joints/joint/jointI.H @@ -25,7 +25,7 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -inline Foam::RBD::joint::joint(const rigidBodyModel&, const label nDoF) +inline Foam::RBD::joint::joint(const label nDoF) : S_(nDoF), index_(0), diff --git a/src/rigidBodyDynamics/joints/nullJoint/nullJoint.C b/src/rigidBodyDynamics/joints/nullJoint/nullJoint.C index 04cccfb6c2..30b72b1907 100644 --- a/src/rigidBodyDynamics/joints/nullJoint/nullJoint.C +++ b/src/rigidBodyDynamics/joints/nullJoint/nullJoint.C @@ -50,19 +50,15 @@ namespace joints // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::RBD::joints::null::null(const rigidBodyModel& model) +Foam::RBD::joints::null::null() : - joint(model, 0) + joint(0) {} -Foam::RBD::joints::null::null -( - const rigidBodyModel& model, - const dictionary& dict -) +Foam::RBD::joints::null::null(const dictionary& dict) : - joint(model, 0) + joint(0) {} diff --git a/src/rigidBodyDynamics/joints/nullJoint/nullJoint.H b/src/rigidBodyDynamics/joints/nullJoint/nullJoint.H index d7fc158d1a..68844d2e5f 100644 --- a/src/rigidBodyDynamics/joints/nullJoint/nullJoint.H +++ b/src/rigidBodyDynamics/joints/nullJoint/nullJoint.H @@ -72,10 +72,10 @@ public: // Constructors //- Construct for given model - null(const rigidBodyModel& model); + null(); //- Construct for given model from dictionary - null(const rigidBodyModel&, const dictionary& dict); + null(const dictionary& dict); //- Clone this joint virtual autoPtr clone() const; diff --git a/src/rigidBodyDynamics/rigidBodyInertia/rigidBodyInertia.H b/src/rigidBodyDynamics/rigidBodyInertia/rigidBodyInertia.H index b5f1233837..44cc221c14 100644 --- a/src/rigidBodyDynamics/rigidBodyInertia/rigidBodyInertia.H +++ b/src/rigidBodyDynamics/rigidBodyInertia/rigidBodyInertia.H @@ -111,6 +111,9 @@ public: const symmTensor& Ic ); + //- Construct from dictionary + inline rigidBodyInertia(const dictionary& dict); + //- Construct from the components of a spatial tensor inline explicit rigidBodyInertia(const spatialTensor& st); diff --git a/src/rigidBodyDynamics/rigidBodyInertia/rigidBodyInertiaI.H b/src/rigidBodyDynamics/rigidBodyInertia/rigidBodyInertiaI.H index 96d0264126..78d74db215 100644 --- a/src/rigidBodyDynamics/rigidBodyInertia/rigidBodyInertiaI.H +++ b/src/rigidBodyDynamics/rigidBodyInertia/rigidBodyInertiaI.H @@ -25,6 +25,7 @@ License #include "spatialTransform.H" #include "transform.H" +#include "dictionary.H" // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -61,6 +62,14 @@ inline Foam::RBD::rigidBodyInertia::rigidBodyInertia {} +inline Foam::RBD::rigidBodyInertia::rigidBodyInertia(const dictionary& dict) +: + m_(readScalar(dict.lookup("mass"))), + c_(dict.lookup("centreOfMass")), + Ic_(dict.lookup("inertia")) +{} + + inline Foam::RBD::rigidBodyInertia::rigidBodyInertia(const spatialTensor& st) : m_(st(3, 3)), diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C index 7c8679dcf8..af3d70b19a 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C @@ -25,6 +25,7 @@ License #include "rigidBodyModel.H" #include "masslessBody.H" +#include "compositeBody.H" #include "nullJoint.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -42,10 +43,10 @@ namespace RBD void Foam::RBD::rigidBodyModel::initializeRootBody() { - bodies_.append(new masslessBody); + bodies_.append(new masslessBody("root")); lambda_.append(0); bodyIDs_.insert("root", 0); - joints_.append(new joints::null(*this)); + joints_.append(new joints::null()); XT_.append(spatialTransform()); nDoF_ = 0; @@ -86,6 +87,41 @@ Foam::RBD::rigidBodyModel::rigidBodyModel() } +Foam::RBD::rigidBodyModel::rigidBodyModel(const dictionary& dict) +: + g_(Zero) +{ + initializeRootBody(); + + const dictionary& bodiesDict = dict.subDict("bodies"); + + forAllConstIter(IDLList, bodiesDict, iter) + { + const dictionary& bodyDict = iter().dict(); + + if (bodyDict.found("mergeWith")) + { + merge + ( + bodyID(bodyDict.lookup("mergeWith")), + bodyDict.lookup("transform"), + rigidBody::New(iter().keyword(), bodyDict) + ); + } + else + { + join + ( + bodyID(bodyDict.lookup("parent")), + bodyDict.lookup("transform"), + joint::New(bodyDict.subDict("joint")), + rigidBody::New(iter().keyword(), bodyDict) + ); + } + } +} + + // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // Foam::label Foam::RBD::rigidBodyModel::join @@ -168,6 +204,23 @@ Foam::label Foam::RBD::rigidBodyModel::join } +void Foam::RBD::rigidBodyModel::makeComposite(const label bodyID) +{ + if (!isA(bodies_[bodyID])) + { + // Retrieve the un-merged body + autoPtr bodyPtr = bodies_.set(bodyID, NULL); + + // Insert the compositeBody containing the original body + bodies_.set + ( + bodyID, + new compositeBody(bodyPtr) + ); + } +} + + Foam::label Foam::RBD::rigidBodyModel::merge ( const label parentID, @@ -183,6 +236,9 @@ Foam::label Foam::RBD::rigidBodyModel::merge if (merged(parentID)) { const subBody& sBody = mergedBody(parentID); + + makeComposite(sBody.parentID()); + sBodyPtr.set ( new subBody @@ -196,6 +252,8 @@ Foam::label Foam::RBD::rigidBodyModel::merge } else { + makeComposite(parentID); + sBodyPtr.set ( new subBody @@ -238,4 +296,62 @@ Foam::spatialTransform Foam::RBD::rigidBodyModel::X0 } +void Foam::RBD::rigidBodyModel::write(Ostream& os) const +{ + os << indent << "bodies" << nl + << indent << token::BEGIN_BLOCK << incrIndent << nl; + + for (label i=1; i