From 11775540293a2ab7d94f125c7af192faccf71316 Mon Sep 17 00:00:00 2001 From: Henry Weller <http://cfd.direct> Date: Mon, 11 Apr 2016 11:45:51 +0100 Subject: [PATCH] rigidBodyDynamics/restraints: Complete dictionary IO --- .../test/rigidBodyDynamics/spring/spring.C | 1 + .../restraints/linearSpring/linearSpring.C | 13 ++--- .../restraints/linearSpring/linearSpring.H | 5 +- .../restraints/restraint/rigidBodyRestraint.C | 5 +- .../restraints/restraint/rigidBodyRestraint.H | 16 ++++++- .../restraint/rigidBodyRestraintI.H | 48 +++++++++++++++++++ .../rigidBodyModel/forwardDynamics.C | 1 + .../rigidBodyModel/rigidBodyModel.C | 1 + .../rigidBodyModel/rigidBodyModel.H | 5 +- .../rigidBodyModel/rigidBodyModelI.H | 22 +++++++-- 10 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H diff --git a/applications/test/rigidBodyDynamics/spring/spring.C b/applications/test/rigidBodyDynamics/spring/spring.C index 65c6e88a5a..a62bcb696d 100644 --- a/applications/test/rigidBodyDynamics/spring/spring.C +++ b/applications/test/rigidBodyDynamics/spring/spring.C @@ -33,6 +33,7 @@ Description #include "masslessBody.H" #include "sphere.H" #include "joints.H" +#include "rigidBodyRestraint.H" #include "IFstream.H" #include "OFstream.H" diff --git a/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.C b/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.C index ed1efb7f42..42dc95b3ef 100644 --- a/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.C +++ b/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.C @@ -78,22 +78,19 @@ Foam::RBD::restraints::linearSpring::~linearSpring() Foam::spatialVector Foam::RBD::restraints::linearSpring::restrain() const { - spatialVector attachmentPt - ( - model_.X0(bodyIndex_).inv() && spatialVector(Zero, refAttachmentPt_) - ); + point attachmentPt = bodyPoint(refAttachmentPt_); // Current axis of the spring - vector r = attachmentPt.l() - anchor_; + vector r = attachmentPt - anchor_; scalar magR = mag(r); r /= (magR + VSMALL); - // Velocity of the end of the spring - vector v = model_.v(bodyIndex_, refAttachmentPt_).l(); + // Velocity of the attached end of the spring + vector v = bodyPointVelocity(refAttachmentPt_).l(); // Force and moment including optional damping vector force = (-stiffness_*(magR - restLength_) - damping_*(r & v))*r; - vector moment = (attachmentPt.l() - model_.X0(bodyIndex_).r()) ^ force; + vector moment = (attachmentPt - model_.X0(bodyIndex_).r()) ^ force; if (model_.debug) { diff --git a/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.H b/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.H index 83d26b512e..26bff8b8c0 100644 --- a/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.H +++ b/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.H @@ -32,11 +32,10 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef linearSpring_H -#define linearSpring_H +#ifndef RBD_restraints_linearSpring_H +#define RBD_restraints_linearSpring_H #include "rigidBodyRestraint.H" -#include "point.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.C b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.C index 3a75c4efbb..f17b3b133a 100644 --- a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.C +++ b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.C @@ -77,7 +77,10 @@ bool Foam::RBD::restraint::read(const dictionary& dict) void Foam::RBD::restraint::write(Ostream& os) const { - os.writeKeyword("type") << type() << token::END_STATEMENT << nl; + os.writeKeyword("type") + << type() << token::END_STATEMENT << nl; + os.writeKeyword("body") + << model_.name(bodyIndex_) << token::END_STATEMENT << nl; } diff --git a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.H b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.H index 917e2e6e19..c8320cbe7e 100644 --- a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.H +++ b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.H @@ -39,12 +39,13 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef RBD_restraint_H -#define RBD_restraint_H +#ifndef RBD_rigidBodyRestraint_H +#define RBD_rigidBodyRestraint_H #include "dictionary.H" #include "autoPtr.H" #include "spatialVector.H" +#include "point.H" #include "runTimeSelectionTables.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -80,6 +81,13 @@ protected: //- Reference to the model const rigidBodyModel& model_; + //- Transform the given point on the restrained body to the global frame + inline point bodyPoint(const point& p) const; + + //- Transform the velocity of the given point on the restrained body + // to the global frame + inline spatialVector bodyPointVelocity(const point& p) const; + public: @@ -166,6 +174,10 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#include "rigidBodyRestraintI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H new file mode 100644 index 0000000000..c825702455 --- /dev/null +++ b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H @@ -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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "rigidBodyModel.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +inline Foam::point Foam::RBD::restraint::bodyPoint +( + const point& p +) const +{ + return (model_.X0(bodyIndex_).inv() && spatialVector(Zero, p)).l(); +} + + +inline Foam::spatialVector Foam::RBD::restraint::bodyPointVelocity +( + const point& p +) const +{ + return model_.v(bodyIndex_, p); +} + + +// ************************************************************************* // diff --git a/src/rigidBodyDynamics/rigidBodyModel/forwardDynamics.C b/src/rigidBodyDynamics/rigidBodyModel/forwardDynamics.C index 411404dd85..fbd0b02573 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/forwardDynamics.C +++ b/src/rigidBodyDynamics/rigidBodyModel/forwardDynamics.C @@ -24,6 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "rigidBodyModel.H" +#include "rigidBodyRestraint.H" // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C index fe6471ac30..7993b3c77e 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C @@ -28,6 +28,7 @@ License #include "compositeBody.H" #include "jointBody.H" #include "nullJoint.H" +#include "rigidBodyRestraint.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H index 5f4d18fb0d..c7a995a4be 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H @@ -53,7 +53,6 @@ SourceFiles #include "subBody.H" #include "joint.H" #include "compositeJoint.H" -#include "rigidBodyRestraint.H" #include "PtrList.H" #include "HashTable.H" @@ -64,6 +63,7 @@ namespace RBD // Forward declaration of friend functions and operators class rigidBodyModel; +class restraint; Ostream& operator<<(Ostream&, const rigidBodyModel&); @@ -255,6 +255,9 @@ public: // after model construction inline vector& g(); + //- Return the name of body with the given ID + inline const word& name(const label bodyID) const; + //- Return the inertia of body i inline const rigidBodyInertia& I(const label i) const; diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H index 478547892e..ece6c9766d 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H @@ -38,6 +38,13 @@ Foam::RBD::rigidBodyModel::bodies() const } +inline const Foam::DynamicList<Foam::label>& +Foam::RBD::rigidBodyModel::lambda() const +{ + return lambda_; +} + + inline const Foam::PtrList<Foam::RBD::joint>& Foam::RBD::rigidBodyModel::joints() const { @@ -69,10 +76,19 @@ inline Foam::vector& Foam::RBD::rigidBodyModel::g() } -inline const Foam::DynamicList<Foam::label>& -Foam::RBD::rigidBodyModel::lambda() const +inline const Foam::word& Foam::RBD::rigidBodyModel::name +( + const label bodyID +) const { - return lambda_; + if (merged(bodyID)) + { + return mergedBody(bodyID).name(); + } + else + { + return bodies_[bodyID].name(); + } } -- GitLab