From 8ffd700ca6b12d203343871fbf8fceb0055e27d2 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Thu, 7 Apr 2016 21:47:08 +0100 Subject: [PATCH] rigidBodyDynamics: Added dictionary-based IO of the rigidBodyModel --- .../test/rigidBodyDynamics/pendulum/pendulum | 38 ++++++ .../rigidBodyDynamics/pendulum/pendulum.C | 16 ++- .../spatialTransform/spatialTransformI.H | 2 +- src/rigidBodyDynamics/Make/files | 1 + .../bodies/compositeBody/compositeBody.C | 48 +++++++ .../bodies/compositeBody/compositeBody.H | 103 +++++++++++++++ .../bodies/compositeBody/compositeBodyI.H | 46 +++++++ .../bodies/masslessBody/masslessBody.C | 19 +++ .../bodies/masslessBody/masslessBody.H | 11 ++ .../bodies/masslessBody/masslessBodyI.H | 11 ++ .../bodies/rigidBody/rigidBody.C | 47 ++++++- .../bodies/rigidBody/rigidBody.H | 32 +++++ .../bodies/rigidBody/rigidBodyI.H | 13 +- src/rigidBodyDynamics/bodies/sphere/sphere.C | 19 +++ src/rigidBodyDynamics/bodies/sphere/sphere.H | 11 ++ src/rigidBodyDynamics/bodies/sphere/sphereI.H | 21 +++ .../bodies/subBody/subBody.C | 2 +- .../bodies/subBody/subBody.H | 2 +- .../bodies/subBody/subBodyI.H | 2 +- src/rigidBodyDynamics/joints/Pa/Pa.C | 8 +- src/rigidBodyDynamics/joints/Pa/Pa.H | 4 +- src/rigidBodyDynamics/joints/Px/Px.C | 8 +- src/rigidBodyDynamics/joints/Px/Px.H | 4 +- src/rigidBodyDynamics/joints/Pxyz/Pxyz.C | 12 +- src/rigidBodyDynamics/joints/Pxyz/Pxyz.H | 4 +- src/rigidBodyDynamics/joints/Py/Py.C | 8 +- src/rigidBodyDynamics/joints/Py/Py.H | 4 +- src/rigidBodyDynamics/joints/Pz/Pz.C | 8 +- src/rigidBodyDynamics/joints/Pz/Pz.H | 4 +- src/rigidBodyDynamics/joints/Ra/Ra.C | 8 +- src/rigidBodyDynamics/joints/Ra/Ra.H | 4 +- src/rigidBodyDynamics/joints/Rs/Rs.C | 8 +- src/rigidBodyDynamics/joints/Rs/Rs.H | 4 +- src/rigidBodyDynamics/joints/Rx/Rx.C | 8 +- src/rigidBodyDynamics/joints/Rx/Rx.H | 4 +- src/rigidBodyDynamics/joints/Rxyz/Rxyz.C | 12 +- src/rigidBodyDynamics/joints/Rxyz/Rxyz.H | 4 +- src/rigidBodyDynamics/joints/Ry/Ry.C | 8 +- src/rigidBodyDynamics/joints/Ry/Ry.H | 4 +- src/rigidBodyDynamics/joints/Ryxz/Ryxz.C | 12 +- src/rigidBodyDynamics/joints/Ryxz/Ryxz.H | 4 +- src/rigidBodyDynamics/joints/Rz/Rz.C | 8 +- src/rigidBodyDynamics/joints/Rz/Rz.H | 4 +- src/rigidBodyDynamics/joints/Rzyx/Rzyx.C | 12 +- src/rigidBodyDynamics/joints/Rzyx/Rzyx.H | 4 +- src/rigidBodyDynamics/joints/joint/joint.C | 35 ++++- src/rigidBodyDynamics/joints/joint/joint.H | 22 +--- src/rigidBodyDynamics/joints/joint/jointI.H | 2 +- .../joints/nullJoint/nullJoint.C | 12 +- .../joints/nullJoint/nullJoint.H | 4 +- .../rigidBodyInertia/rigidBodyInertia.H | 3 + .../rigidBodyInertia/rigidBodyInertiaI.H | 9 ++ .../rigidBodyModel/rigidBodyModel.C | 120 +++++++++++++++++- .../rigidBodyModel/rigidBodyModel.H | 21 ++- 54 files changed, 700 insertions(+), 144 deletions(-) create mode 100644 applications/test/rigidBodyDynamics/pendulum/pendulum create mode 100644 src/rigidBodyDynamics/bodies/compositeBody/compositeBody.C create mode 100644 src/rigidBodyDynamics/bodies/compositeBody/compositeBody.H create mode 100644 src/rigidBodyDynamics/bodies/compositeBody/compositeBodyI.H diff --git a/applications/test/rigidBodyDynamics/pendulum/pendulum b/applications/test/rigidBodyDynamics/pendulum/pendulum new file mode 100644 index 000000000..4a8378b9f --- /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 8a15aec82..2401ec256 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 8c2724aa3..c245fde39 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 c2c03b717..7fc99c209 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 000000000..f898386c1 --- /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 000000000..c92d9bda3 --- /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 000000000..dee27aec8 --- /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 7e97bd846..da0f73187 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 4c58f9761..d20c160d0 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 06acc415b..e8319b4a3 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 d71a082b5..7d797f014 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 9a7aad09e..9d2b3f279 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 2e68928a4..5b6a66e87 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 275565ea9..e581ce864 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 72eb9c578..ad5ca48ba 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 9543e16a9..42f429f1d 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 e8756177c..1508b8f43 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 f47fa2c29..a9163e8e3 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 84f705ef4..b8c2813d4 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 847226950..2263ce328 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 99208d1e7..09f7eee75 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 3edbb7a2a..412a3df47 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 0bbd6028b..b7d77f344 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 131bcad8c..fcb5dac7e 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 b5e87f6f1..5fbdeb783 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 e7e5b147f..4b297bbca 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 fb2a87601..981e7154a 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 cbccb6ddd..83850020d 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 d1a7a4e61..18783f0d4 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 223086389..6d9e6aa5f 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 b42967831..d098b2c82 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 c5da501f0..9658b7595 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 3e1b0655f..386a869bf 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 c90f6fd97..87343fe55 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 79ca52d9f..3da54830a 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 8dda6d3e6..39b3d5f7d 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 7ada2cc4a..3a63a4ffb 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 4814264f1..d771a7130 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 4a88a659a..4bfa32401 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 a52896299..2de408851 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 604e849b3..02a7fe420 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 1465dfc46..9027e2d8c 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 b14b6408f..19a769750 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 f55775330..7b1a8bc1f 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 52c53939f..344ad4fbc 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 04f41d65a..4374990eb 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 4acfb7da9..58d68190d 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 f2020c047..47db466a7 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 04cccfb6c..30b72b190 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 d7fc158d1..68844d2e5 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 b5f123383..44cc221c1 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 96d026412..78d74db21 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 7c8679dcf..af3d70b19 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