From c409ae7d90966250bb3be9cfbc2a0538bc8e288d Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Mon, 8 Jan 2018 10:58:00 +0000 Subject: [PATCH] RBD: restraints: Corrected restraint force transformations From commit d4c479cb6447dbfd920bbe3e0204b70a1d5fbb03 in OpenFOAM-dev The restraints generate either joint-local (tau) or global (fx) forces. At the moment they all generate the latter. This change corrects three of the four restraints so that the forces are in the gobal coordinate system and not the local coordinate system of the body. The problem with this is that the forward dynamics code then transforms most of the forces back to the body local coordinate system. A better solution would be to associate restraints which are more sensibly defined in a local frame with the joints instead of the bodies, and return the forces as part of the tau variable. --- .../joints/composite/compositeJoint.H | 6 +++--- .../joints/floating/floatingJoint.H | 6 +++--- src/rigidBodyDynamics/joints/null/nullJoint.H | 6 +++--- .../linearAxialAngularSpring.C | 4 ++-- .../restraints/linearDamper/linearDamper.C | 4 ++-- .../sphericalAngularDamper.C | 4 ++-- .../rigidBodyModelState/rigidBodyModelState.C | 4 +++- .../rigidBodyModelState/rigidBodyModelState.H | 15 ++++++++++----- .../rigidBodyModelState/rigidBodyModelStateI.H | 14 +++++++++++++- .../rigidBodyModelState/rigidBodyModelStateIO.C | 6 +++++- .../rigidBodyMotion/rigidBodyMotion.C | 7 +++++-- .../rigidBodyMotion/rigidBodyMotion.H | 7 ++++--- .../rigidBodyMeshMotion/rigidBodyMeshMotion.C | 2 ++ .../rigidBodyMeshMotionSolver.C | 2 ++ 14 files changed, 59 insertions(+), 28 deletions(-) diff --git a/src/rigidBodyDynamics/joints/composite/compositeJoint.H b/src/rigidBodyDynamics/joints/composite/compositeJoint.H index 5d12bf502..f55b6f3d8 100644 --- a/src/rigidBodyDynamics/joints/composite/compositeJoint.H +++ b/src/rigidBodyDynamics/joints/composite/compositeJoint.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -40,8 +40,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef RBD_joints_composite_H -#define RBD_joints_composite_H +#ifndef compositeJoint_H +#define compositeJoint_H #include "joint.H" diff --git a/src/rigidBodyDynamics/joints/floating/floatingJoint.H b/src/rigidBodyDynamics/joints/floating/floatingJoint.H index 58c314d78..eb6f1e09e 100644 --- a/src/rigidBodyDynamics/joints/floating/floatingJoint.H +++ b/src/rigidBodyDynamics/joints/floating/floatingJoint.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -40,8 +40,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef RBD_joints_floating_H -#define RBD_joints_floating_H +#ifndef floatingJoint_H +#define floatingJoint_H #include "compositeJoint.H" diff --git a/src/rigidBodyDynamics/joints/null/nullJoint.H b/src/rigidBodyDynamics/joints/null/nullJoint.H index cc97aed72..f242050ac 100644 --- a/src/rigidBodyDynamics/joints/null/nullJoint.H +++ b/src/rigidBodyDynamics/joints/null/nullJoint.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -40,8 +40,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef RBD_joints_null_H -#define RBD_joints_null_H +#ifndef nullJoint_H +#define nullJoint_H #include "joint.H" diff --git a/src/rigidBodyDynamics/restraints/linearAxialAngularSpring/linearAxialAngularSpring.C b/src/rigidBodyDynamics/restraints/linearAxialAngularSpring/linearAxialAngularSpring.C index 8f0b6143e..f9525e423 100644 --- a/src/rigidBodyDynamics/restraints/linearAxialAngularSpring/linearAxialAngularSpring.C +++ b/src/rigidBodyDynamics/restraints/linearAxialAngularSpring/linearAxialAngularSpring.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -133,7 +133,7 @@ void Foam::RBD::restraints::linearAxialAngularSpring::restrain } // Accumulate the force for the restrained body - fx[bodyIndex_] += spatialVector(moment, Zero); + fx[bodyIndex_] += model_.X0(bodyID_).T() & spatialVector(moment, Zero); } diff --git a/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.C b/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.C index d3e4e063d..da58d2fcc 100644 --- a/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.C +++ b/src/rigidBodyDynamics/restraints/linearDamper/linearDamper.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -85,7 +85,7 @@ void Foam::RBD::restraints::linearDamper::restrain } // Accumulate the force for the restrained body - fx[bodyIndex_] += spatialVector(Zero, force); + fx[bodyIndex_] += model_.X0(bodyID_).T() & spatialVector(Zero, force); } diff --git a/src/rigidBodyDynamics/restraints/sphericalAngularDamper/sphericalAngularDamper.C b/src/rigidBodyDynamics/restraints/sphericalAngularDamper/sphericalAngularDamper.C index 8ef17486b..5cec794d0 100644 --- a/src/rigidBodyDynamics/restraints/sphericalAngularDamper/sphericalAngularDamper.C +++ b/src/rigidBodyDynamics/restraints/sphericalAngularDamper/sphericalAngularDamper.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -85,7 +85,7 @@ void Foam::RBD::restraints::sphericalAngularDamper::restrain } // Accumulate the force for the restrained body - fx[bodyIndex_] += spatialVector(moment, Zero); + fx[bodyIndex_] += model_.X0(bodyID_).T() & spatialVector(moment, Zero); } diff --git a/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelState.C b/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelState.C index c1a086ec1..b3ee98eef 100644 --- a/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelState.C +++ b/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelState.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,6 +35,7 @@ Foam::RBD::rigidBodyModelState::rigidBodyModelState q_(model.nDoF(), Zero), qDot_(model.nDoF(), Zero), qDdot_(model.nDoF(), Zero), + t_(-1), deltaT_(0) {} @@ -48,6 +49,7 @@ Foam::RBD::rigidBodyModelState::rigidBodyModelState q_(dict.lookupOrDefault("q", scalarField(model.nDoF(), Zero))), qDot_(dict.lookupOrDefault("qDot", scalarField(model.nDoF(), Zero))), qDdot_(dict.lookupOrDefault("qDdot", scalarField(model.nDoF(), Zero))), + t_(dict.lookupOrDefault("t", -1)), deltaT_(dict.lookupOrDefault("deltaT", 0)) {} diff --git a/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelState.H b/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelState.H index 6b10ac355..5bbc71624 100644 --- a/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelState.H +++ b/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelState.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -76,6 +76,9 @@ class rigidBodyModelState //- Joint acceleration scalarField qDdot_; + //- The time + scalar t_; + //- The time-step used to integrate to this state scalar deltaT_; @@ -102,14 +105,15 @@ public: //- Return access to the joint position and orientation inline const scalarField& q() const; - //- Return access to the joint quaternion - //- Return access to the joint velocity inline const scalarField& qDot() const; //- Return access to the joint acceleration inline const scalarField& qDdot() const; + //- Return access to the time + inline scalar t() const; + //- Return access to the time-step inline scalar deltaT() const; @@ -119,14 +123,15 @@ public: //- Return access to the joint position and orientation inline scalarField& q(); - //- Return access to the joint quaternion - //- Return access to the joint velocity inline scalarField& qDot(); //- Return access to the joint acceleration inline scalarField& qDdot(); + //- Return access to the time + inline scalar& t(); + //- Return access to the time-step inline scalar& deltaT(); diff --git a/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelStateI.H b/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelStateI.H index e3fb2678f..b14946dae 100644 --- a/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelStateI.H +++ b/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelStateI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,6 +43,12 @@ inline const Foam::scalarField& Foam::RBD::rigidBodyModelState::qDdot() const } +inline Foam::scalar Foam::RBD::rigidBodyModelState::t() const +{ + return t_; +} + + inline Foam::scalar Foam::RBD::rigidBodyModelState::deltaT() const { return deltaT_; @@ -73,4 +79,10 @@ inline Foam::scalar& Foam::RBD::rigidBodyModelState::deltaT() } +inline Foam::scalar& Foam::RBD::rigidBodyModelState::t() +{ + return t_; +} + + // ************************************************************************* // diff --git a/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelStateIO.C b/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelStateIO.C index c17819b41..fb9ab3197 100644 --- a/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelStateIO.C +++ b/src/rigidBodyDynamics/rigidBodyModelState/rigidBodyModelStateIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,6 +33,7 @@ void Foam::RBD::rigidBodyModelState::write(dictionary& dict) const dict.add("q", q_); dict.add("qDot", qDot_); dict.add("qDdot", qDdot_); + dict.add("t", t_); dict.add("deltaT", deltaT_); } @@ -42,6 +43,7 @@ void Foam::RBD::rigidBodyModelState::write(Ostream& os) const os.writeKeyword("q") << q_ << token::END_STATEMENT << nl; os.writeKeyword("qDot") << qDot_ << token::END_STATEMENT << nl; os.writeKeyword("qDdot") << qDdot_ << token::END_STATEMENT << nl; + os.writeKeyword("t") << t_ << token::END_STATEMENT << nl; os.writeKeyword("deltaT") << deltaT_ << token::END_STATEMENT << nl; } @@ -57,6 +59,7 @@ Foam::Istream& Foam::RBD::operator>> is >> state.q_ >> state.qDot_ >> state.qDdot_ + >> state.t_ >> state.deltaT_; // Check state of Istream @@ -79,6 +82,7 @@ Foam::Ostream& Foam::RBD::operator<< os << state.q_ << token::SPACE << state.qDot_ << token::SPACE << state.qDdot_ + << token::SPACE << state.t_ << token::SPACE << state.deltaT_; // Check state of Ostream diff --git a/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.C b/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.C index 6cf2514c0..841286729 100644 --- a/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.C +++ b/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -140,15 +140,18 @@ void Foam::RBD::rigidBodyMotion::forwardDynamics void Foam::RBD::rigidBodyMotion::solve ( - scalar deltaT, + const scalar t, + const scalar deltaT, const scalarField& tau, const Field& fx ) { + motionState_.t() = t; motionState_.deltaT() = deltaT; if (motionState0_.deltaT() < SMALL) { + motionState0_.t() = t; motionState0_.deltaT() = deltaT; } diff --git a/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.H b/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.H index d065d9797..d3fc11647 100644 --- a/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.H +++ b/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -169,10 +169,11 @@ public: ) const; //- Integrate velocities, orientation and position - // for the given time-step + // for the given time and time-step void solve ( - scalar deltaT, + const scalar t, + const scalar deltaT, const scalarField& tau, const Field& fx ); diff --git a/src/rigidBodyMeshMotion/rigidBodyMeshMotion/rigidBodyMeshMotion.C b/src/rigidBodyMeshMotion/rigidBodyMeshMotion/rigidBodyMeshMotion.C index 3676f8dea..7ccaa928c 100644 --- a/src/rigidBodyMeshMotion/rigidBodyMeshMotion/rigidBodyMeshMotion.C +++ b/src/rigidBodyMeshMotion/rigidBodyMeshMotion/rigidBodyMeshMotion.C @@ -259,6 +259,7 @@ void Foam::rigidBodyMeshMotion::solve() { model_.solve ( + t.value(), t.deltaTValue(), scalarField(model_.nDoF(), Zero), Field(model_.nBodies(), Zero) @@ -288,6 +289,7 @@ void Foam::rigidBodyMeshMotion::solve() model_.solve ( + t.value(), t.deltaTValue(), scalarField(model_.nDoF(), Zero), fx diff --git a/src/rigidBodyMeshMotion/rigidBodyMeshMotionSolver/rigidBodyMeshMotionSolver.C b/src/rigidBodyMeshMotion/rigidBodyMeshMotionSolver/rigidBodyMeshMotionSolver.C index 6434e69fb..70b4acbdc 100644 --- a/src/rigidBodyMeshMotion/rigidBodyMeshMotionSolver/rigidBodyMeshMotionSolver.C +++ b/src/rigidBodyMeshMotion/rigidBodyMeshMotionSolver/rigidBodyMeshMotionSolver.C @@ -207,6 +207,7 @@ void Foam::rigidBodyMeshMotionSolver::solve() { model_.solve ( + t.value(), t.deltaTValue(), scalarField(model_.nDoF(), Zero), Field(model_.nBodies(), Zero) @@ -236,6 +237,7 @@ void Foam::rigidBodyMeshMotionSolver::solve() model_.solve ( + t.value(), t.deltaTValue(), scalarField(model_.nDoF(), Zero), fx