From 0289f383eb6e98344ea18eb8d1561e0b9675288f Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Tue, 5 Apr 2022 11:26:07 +0100 Subject: [PATCH] rigidBodyDynamics: Added rotating joint This joint allows two bodies to rotate relative to each other at a specified speed. The relative motion is completely specified, so this joint has zero degrees of freedom. It could be used, for example, to attach a rotating propeller to a moving ship: bodies { hull { ... } propeller { type rigidBody; // Dynamic properties mass ...; centreOfMass ...; inertia ...; // The propeller is connected to the hull parent hull; // The position relative to the hull transform (1 0 0 0 1 0 0 0 1) (20 0 0); // Rotation settings joint { type rotating; omega (6 0 0); } } } --- .../rigidBodyDynamics/doublePendulumAndRotor | 59 +++++++++ src/rigidBodyDynamics/Make/files | 1 + .../joints/rotating/rotating.C | 106 ++++++++++++++++ .../joints/rotating/rotating.H | 114 ++++++++++++++++++ 4 files changed, 280 insertions(+) create mode 100644 applications/test/rigidBodyDynamics/doublePendulumAndRotor create mode 100644 src/rigidBodyDynamics/joints/rotating/rotating.C create mode 100644 src/rigidBodyDynamics/joints/rotating/rotating.H diff --git a/applications/test/rigidBodyDynamics/doublePendulumAndRotor b/applications/test/rigidBodyDynamics/doublePendulumAndRotor new file mode 100644 index 0000000000..3e3183f586 --- /dev/null +++ b/applications/test/rigidBodyDynamics/doublePendulumAndRotor @@ -0,0 +1,59 @@ +solver +{ + type symplectic; +} + +bodies +{ + bar1 + { + type rigidBody; + mass 3; + centreOfMass (0 -0.5 0); + inertia (0.2575 0 0 0.015 0 0.2575); + parent root; + transform (1 0 0 0 1 0 0 0 1) (0 0 0); + joint + { + type Rz; + } + outline ((0 0 0) (0 -1 0)); + } + bar2 + { + type rigidBody; + mass 3; + centreOfMass (0 -0.5 0); + inertia (0.2575 0 0 0.015 0 0.2575); + parent bar1; + transform (1 0 0 0 1 0 0 0 1) (0 -1 0); + joint + { + type Rz; + } + outline ((0 0 0) (0 -1 0)); + } + rotor + { + type rigidBody; + mass 3; + centreOfMass (0 -0.5 0); + inertia (0.2575 0 0 0.015 0 0.2575); + parent bar2; + transform (1 0 0 0 1 0 0 0 1) (0 -1 0); + joint + { + type rotating; + omega (0 0 1); + } + outline ((0 0 0) (0 -1 0)); + } +} + +g (0 -9.81 0); + +q (1.5707963267948966 0 0); + +deltaT 0.01; + +endTime 20; diff --git a/src/rigidBodyDynamics/Make/files b/src/rigidBodyDynamics/Make/files index 6546a28cff..2689e777ee 100644 --- a/src/rigidBodyDynamics/Make/files +++ b/src/rigidBodyDynamics/Make/files @@ -27,6 +27,7 @@ joints/Pa/Pa.C joints/Pxyz/Pxyz.C joints/rigid/rigid.C +joints/rotating/rotating.C joints/function/function.C joints/functionDot/functionDot.C diff --git a/src/rigidBodyDynamics/joints/rotating/rotating.C b/src/rigidBodyDynamics/joints/rotating/rotating.C new file mode 100644 index 0000000000..e67e866d29 --- /dev/null +++ b/src/rigidBodyDynamics/joints/rotating/rotating.C @@ -0,0 +1,106 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2018-2022 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 "rotating.H" +#include "rigidBodyModelState.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ +namespace joints +{ + defineTypeNameAndDebug(rotating, 0); + + addToRunTimeSelectionTable + ( + joint, + rotating, + dictionary + ); +} +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::RBD::joints::rotating::rotating +( + const rigidBodyModel& model, + const dictionary& dict +) +: + joint(model, 0), + omega_(Function1::New("omega", dict)) +{} + + +Foam::autoPtr Foam::RBD::joints::rotating::clone() const +{ + return autoPtr(new rotating(*this)); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::RBD::joints::rotating::~rotating() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::RBD::joints::rotating::jcalc +( + joint::XSvc& J, + const rigidBodyModelState& state +) const +{ + const scalar t = state.t(), deltaT = state.deltaT(); + + if (t < vSmall || deltaT < vSmall) + { + return; + } + + const vector omega = omega_->value(t); + const vector omegaDot = (omega - omega_->value(t - deltaT))/deltaT; + const vector theta = omega_->integral(0, t); + const scalar magTheta = mag(theta); + const tensor R = + magTheta > vSmall ? quaternion(theta, magTheta).R() : tensor::I; + + J.X = spatialTransform(R, Zero); + J.S = Zero; + J.S1 = Zero; + J.v = spatialVector(omega, Zero); + J.c = - spatialVector(omegaDot, Zero); +} + + +// ************************************************************************* // diff --git a/src/rigidBodyDynamics/joints/rotating/rotating.H b/src/rigidBodyDynamics/joints/rotating/rotating.H new file mode 100644 index 0000000000..6d64bcdd4f --- /dev/null +++ b/src/rigidBodyDynamics/joints/rotating/rotating.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2018-2022 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::joints::rotating + +Description + Joint with a specified rotational speed + + Reference: + \verbatim + Featherstone, R. (2008). + Rigid body dynamics algorithms. + Springer. + Chapter 4. + \endverbatim + +SourceFiles + rotating.C + +\*---------------------------------------------------------------------------*/ + +#ifndef RBD_joints_rotating_H +#define RBD_joints_rotating_H + +#include "joint.H" +#include "Function1.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace RBD +{ +namespace joints +{ + +/*---------------------------------------------------------------------------*\ + Class rotating Declaration +\*---------------------------------------------------------------------------*/ + +class rotating +: + public joint +{ +private: + + // Private data + + //- Rotation vector function + autoPtr> omega_; + + +public: + + //- Runtime type information + TypeName("rotating"); + + + // Constructors + + //- Construct for given model from dictionary + rotating(const rigidBodyModel& model, const dictionary& dict); + + //- Clone this joint + virtual autoPtr clone() const; + + + //- Destructor + virtual ~rotating(); + + + // Member Functions + + //- Update the model state for this joint + virtual void jcalc + ( + joint::XSvc& J, + const rigidBodyModelState& state + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace joints +} // End namespace RBD +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //