diff --git a/src/rigidBodyDynamics/Make/files b/src/rigidBodyDynamics/Make/files index ad592dc7ef..bdd244ae8a 100644 --- a/src/rigidBodyDynamics/Make/files +++ b/src/rigidBodyDynamics/Make/files @@ -28,6 +28,7 @@ joints/Pxyz/Pxyz.C restraints/restraint/rigidBodyRestraint.C restraints/restraint/rigidBodyRestraintNew.C restraints/linearSpring/linearSpring.C +restraints/linearDamper/linearDamper.C rigidBodyModel/rigidBodyModel.C rigidBodyModel/forwardDynamics.C diff --git a/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.C b/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.C new file mode 100644 index 0000000000..8b2939a56a --- /dev/null +++ b/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.C @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013-2015 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 "linearDamper.H" +#include "rigidBodyModel.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ +namespace restraints +{ + defineTypeNameAndDebug(linearDamper, 0); + + addToRunTimeSelectionTable + ( + restraint, + linearDamper, + dictionary + ); +} +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::RBD::restraints::linearDamper::linearDamper +( + const word& name, + const dictionary& dict, + const rigidBodyModel& model +) +: + restraint(name, dict, model) +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::RBD::restraints::linearDamper::~linearDamper() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +Foam::spatialVector Foam::RBD::restraints::linearDamper::restrain() const +{ + vector force = -coeff_*model_.v(model_.master(bodyID_)).l(); + + if (model_.debug) + { + Info<< " force " << force << endl; + } + + return spatialVector(Zero, force); +} + + +bool Foam::RBD::restraints::linearDamper::read +( + const dictionary& dict +) +{ + restraint::read(dict); + + coeffs_.lookup("coeff") >> coeff_; + + return true; +} + + +void Foam::RBD::restraints::linearDamper::write +( + Ostream& os +) const +{ + restraint::write(os); + + os.writeKeyword("coeff") + << coeff_ << token::END_STATEMENT << nl; +} + + +// ************************************************************************* // diff --git a/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.H b/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.H new file mode 100644 index 0000000000..e9ede58277 --- /dev/null +++ b/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.H @@ -0,0 +1,116 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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::RBD::restraints::linearDamper + +Description + Linear damper restraint. Operates in the local frame of the body. + +SourceFiles + linearDamper.C + +\*---------------------------------------------------------------------------*/ + +#ifndef RBD_restraints_linearDamper_H +#define RBD_restraints_linearDamper_H + +#include "rigidBodyRestraint.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ +namespace restraints +{ + +/*---------------------------------------------------------------------------*\ + Class linearDamper Declaration +\*---------------------------------------------------------------------------*/ + +class linearDamper +: + public restraint +{ + // Private data + + //- Damping coefficient [Ns/m] + scalar coeff_; + + +public: + + //- Runtime type information + TypeName("linearDamper"); + + + // Constructors + + //- Construct from components + linearDamper + ( + const word& name, + const dictionary& dict, + const rigidBodyModel& model + ); + + //- Construct and return a clone + virtual autoPtr clone() const + { + return autoPtr + ( + new linearDamper(*this) + ); + } + + + //- Destructor + virtual ~linearDamper(); + + + // Member Functions + + //- Return the external force applied to the body by this restraint + virtual spatialVector restrain() const; + + //- Update properties from given dictionary + virtual bool read(const dictionary& dict); + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace restraints +} // End namespace RBD +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.C b/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.C index 42dc95b3ef..63e3763443 100644 --- a/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.C +++ b/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.C @@ -57,12 +57,7 @@ Foam::RBD::restraints::linearSpring::linearSpring const rigidBodyModel& model ) : - restraint(name, dict, model), - anchor_(), - refAttachmentPt_(), - stiffness_(), - damping_(), - restLength_() + restraint(name, dict, model) { read(dict); } @@ -88,9 +83,16 @@ Foam::spatialVector Foam::RBD::restraints::linearSpring::restrain() const // 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 - model_.X0(bodyIndex_).r()) ^ force; + // Force and moment on the master body including optional damping + vector force + ( + (-stiffness_*(magR - restLength_) - damping_*(r & v))*r + ); + + vector moment + ( + (attachmentPt - model_.X0(model_.master(bodyID_)).r()) ^ force + ); if (model_.debug) { diff --git a/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.H b/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.H index 26bff8b8c0..5d87ca8896 100644 --- a/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.H +++ b/src/rigidBodyDynamics/restraints/linearSpring/linearSpring.H @@ -63,10 +63,10 @@ class linearSpring //- Reference point of attachment to the solid body point refAttachmentPt_; - //- Spring stiffness coefficient (N/m) + //- Spring stiffness coefficient [N/m] scalar stiffness_; - //- Damping coefficient (Ns/m) + //- Damping coefficient [Ns/m] scalar damping_; //- Rest length - length of spring when no forces are applied to it diff --git a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.C b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.C index f17b3b133a..fb44f9fea1 100644 --- a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.C +++ b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.C @@ -48,7 +48,7 @@ Foam::RBD::restraint::restraint ) : name_(name), - bodyIndex_(model.bodyID(dict.lookup("body"))), + bodyID_(model.bodyID(dict.lookup("body"))), coeffs_(dict), model_(model) {} @@ -80,7 +80,7 @@ void Foam::RBD::restraint::write(Ostream& os) const os.writeKeyword("type") << type() << token::END_STATEMENT << nl; os.writeKeyword("body") - << model_.name(bodyIndex_) << token::END_STATEMENT << nl; + << model_.name(bodyID_) << token::END_STATEMENT << nl; } diff --git a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.H b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.H index c8320cbe7e..ea281a5350 100644 --- a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.H +++ b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraint.H @@ -72,8 +72,8 @@ protected: //- Name of the restraint word name_; - //- Index of the body the restraint is applied to - label bodyIndex_; + //- ID of the body the restraint is applied to + label bodyID_; //- Restraint model specific coefficient dictionary dictionary coeffs_; @@ -148,9 +148,9 @@ public: return name_; } - label bodyIndex() const + label bodyID() const { - return bodyIndex_; + return bodyID_; } //- Return the external force applied to the body by this restraint diff --git a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H index c825702455..11679170c4 100644 --- a/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H +++ b/src/rigidBodyDynamics/restraints/restraint/rigidBodyRestraintI.H @@ -32,7 +32,7 @@ inline Foam::point Foam::RBD::restraint::bodyPoint const point& p ) const { - return (model_.X0(bodyIndex_).inv() && spatialVector(Zero, p)).l(); + return (model_.X0(bodyID_).inv() && spatialVector(Zero, p)).l(); } @@ -41,7 +41,7 @@ inline Foam::spatialVector Foam::RBD::restraint::bodyPointVelocity const point& p ) const { - return model_.v(bodyIndex_, p); + return model_.v(bodyID_, p); } diff --git a/src/rigidBodyDynamics/rigidBodyModel/forwardDynamics.C b/src/rigidBodyDynamics/rigidBodyModel/forwardDynamics.C index fbd0b02573..37800dcadd 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/forwardDynamics.C +++ b/src/rigidBodyDynamics/rigidBodyModel/forwardDynamics.C @@ -40,7 +40,7 @@ void Foam::RBD::rigidBodyModel::applyRestraints(Field& fx) const DebugInfo << "Restraint " << restraints_[ri].name(); // Accumulate the restraint forces - fx[restraints_[ri].bodyIndex()] += restraints_[ri].restrain(); + fx[master(restraints_[ri].bodyID())] += restraints_[ri].restrain(); } } diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C index 7993b3c77e..9b2a32de71 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.C @@ -162,6 +162,12 @@ Foam::RBD::rigidBodyModel::rigidBodyModel(const dictionary& dict) } +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::RBD::rigidBodyModel::~rigidBodyModel() +{} + + // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // Foam::label Foam::RBD::rigidBodyModel::join_ diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H index c7a995a4be..d02baa1704 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModel.H @@ -89,7 +89,6 @@ class rigidBodyModel //- Add restraints to the motion void addRestraints(const dictionary& dict); - protected: // Protected data representing the model structure @@ -220,8 +219,7 @@ public: //- Destructor - virtual ~rigidBodyModel() - {} + virtual ~rigidBodyModel(); // Member Functions @@ -261,6 +259,9 @@ public: //- Return the inertia of body i inline const rigidBodyInertia& I(const label i) const; + //- Return the spatial velocity of the bodies + inline const spatialVector& v(const label i) const; + //- Join the given body to the parent with ID parentID via the given // joint with transform from the parent frame to the joint frame XT. virtual label join diff --git a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H index ece6c9766d..9cfab5e8cd 100644 --- a/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H +++ b/src/rigidBodyDynamics/rigidBodyModel/rigidBodyModelI.H @@ -99,6 +99,13 @@ Foam::RBD::rigidBodyModel::I(const label i) const } +inline const Foam::spatialVector& +Foam::RBD::rigidBodyModel::v(const label i) const +{ + return v_[i]; +} + + inline bool Foam::RBD::rigidBodyModel::merged(label bodyID) const { return bodyID < 0;