From 704829a15e3033d5a42058db23c1c2b43d0bd035 Mon Sep 17 00:00:00 2001 From: Vuko Vukcevic Date: Fri, 10 Mar 2017 11:20:42 +0100 Subject: [PATCH] Finalised the use of translationa/rotational restraints in sixDOFODE classes --- src/ODE/Make/files | 1 + .../sixDOF/geometricSixDOF/geometricSixDOF.C | 28 +++-- .../quaternionSixDOF/quaternionSixDOF.C | 28 +++-- .../rotationalRestraint/rotationalRestraint.H | 2 +- .../linearSpringDamper/linearSpringDamper.C | 98 +++++++++++++++ .../linearSpringDamper/linearSpringDamper.H | 119 ++++++++++++++++++ src/ODE/sixDOF/sixDOFODE/sixDOFODE.C | 60 ++++++--- src/ODE/sixDOF/sixDOFODE/sixDOFODE.H | 27 ++-- src/ODE/sixDOF/sixDOFODE/sixDOFODEI.H | 12 -- 9 files changed, 318 insertions(+), 57 deletions(-) create mode 100644 src/ODE/sixDOF/sixDOFODE/restraints/translationalRestraints/linearSpringDamper/linearSpringDamper.C create mode 100644 src/ODE/sixDOF/sixDOFODE/restraints/translationalRestraints/linearSpringDamper/linearSpringDamper.H diff --git a/src/ODE/Make/files b/src/ODE/Make/files index b532c0dd3..f32948cb7 100644 --- a/src/ODE/Make/files +++ b/src/ODE/Make/files @@ -23,6 +23,7 @@ $(sixDOF)/sixDOFODE/constraints/translationalConstraints/constantTranslationalAc $(sixDOF)/sixDOFODE/constraints/translationalConstraints/periodicOscillation/periodicOscillation.C $(sixDOF)/sixDOFODE/restraints/translationalRestraints/translationalRestraint/translationalRestraint.C +$(sixDOF)/sixDOFODE/restraints/translationalRestraints/linearSpringDamper/linearSpringDamper.C $(sixDOF)/sixDOFODE/restraints/rotationalRestraints/rotationalRestraint/rotationalRestraint.C $(sixDOF)/sixDOFODE/sixDOFODE.C diff --git a/src/ODE/sixDOF/geometricSixDOF/geometricSixDOF.C b/src/ODE/sixDOF/geometricSixDOF/geometricSixDOF.C index fa738aa8d..fb97882cb 100644 --- a/src/ODE/sixDOF/geometricSixDOF/geometricSixDOF.C +++ b/src/ODE/sixDOF/geometricSixDOF/geometricSixDOF.C @@ -73,13 +73,17 @@ Foam::dimensionedVector Foam::geometricSixDOF::A scalarSquareMatrix M(rhs.size(), 0.0); // Insert mass and explicit forcing into the system. Note: translations are - // solved in the global coordinate system - const dimensionedVector explicitForcing - ( - force(t) // External force - - (linSpringCoeffs() & xR) // Spring force - - (linDampingCoeffs() & uR) // Damping force - ); + // solved in the global coordinate system and the explicit forcing contains + // restraining forces + const dimensionedVector explicitForcing = + force + ( + t, + R.T(), + xR.value(), + uR.value() + ); + const vector& efVal = explicitForcing.value(); const scalar& m = mass().value(); @@ -155,7 +159,15 @@ Foam::dimensionedVector Foam::geometricSixDOF::OmegaDot const dimensionedVector explicitForcing ( E(omega) // Euler part - + (RT & moment(t)) // External torque + + ( + RT + & moment + ( + t, + RT.value(), + omega.value() + ) + ) // External torque with restraints ); const vector& efVal = explicitForcing.value(); const diagTensor& I = momentOfInertia().value(); diff --git a/src/ODE/sixDOF/quaternionSixDOF/quaternionSixDOF.C b/src/ODE/sixDOF/quaternionSixDOF/quaternionSixDOF.C index eadead02a..e8f2232c4 100644 --- a/src/ODE/sixDOF/quaternionSixDOF/quaternionSixDOF.C +++ b/src/ODE/sixDOF/quaternionSixDOF/quaternionSixDOF.C @@ -57,13 +57,17 @@ Foam::dimensionedVector Foam::quaternionSixDOF::A scalarSquareMatrix M(rhs.size(), 0.0); // Insert mass and explicit forcing into the system. Note: translations are - // solved in the global coordinate system - const dimensionedVector explicitForcing - ( - force(t) // External force - - (linSpringCoeffs() & xR) // Spring force - - (linDampingCoeffs() & uR) // Damping force - ); + // solved in the global coordinate system and the explicit forcing contains + // restraining forces + const dimensionedVector explicitForcing = + force + ( + t, + rotation.R(), + xR.value(), + uR.value() + ); + const vector& efVal = explicitForcing.value(); const scalar& m = mass().value(); @@ -147,7 +151,15 @@ Foam::dimensionedVector Foam::quaternionSixDOF::OmegaDot const dimensionedVector explicitForcing ( E(omega) // Euler part - + (R & moment(t)) // External torque + + ( + R.value() + & moment + ( + t, + R.value(), + omega.value() + ) + ) // External torque with restraints ); const vector& efVal = explicitForcing.value(); const diagTensor& I = momentOfInertia().value(); diff --git a/src/ODE/sixDOF/sixDOFODE/restraints/rotationalRestraints/rotationalRestraint/rotationalRestraint.H b/src/ODE/sixDOF/sixDOFODE/restraints/rotationalRestraints/rotationalRestraint/rotationalRestraint.H index b5420e019..6050836f7 100644 --- a/src/ODE/sixDOF/sixDOFODE/restraints/rotationalRestraints/rotationalRestraint/rotationalRestraint.H +++ b/src/ODE/sixDOF/sixDOFODE/restraints/rotationalRestraints/rotationalRestraint/rotationalRestraint.H @@ -137,7 +137,7 @@ public: // Restraint specific functions - //- Return restraining force (in the local coordinate system) + //- Return restraining moment (in the local coordinate system) virtual vector restrainingMoment ( const scalar t, diff --git a/src/ODE/sixDOF/sixDOFODE/restraints/translationalRestraints/linearSpringDamper/linearSpringDamper.C b/src/ODE/sixDOF/sixDOFODE/restraints/translationalRestraints/linearSpringDamper/linearSpringDamper.C new file mode 100644 index 000000000..08c0214c3 --- /dev/null +++ b/src/ODE/sixDOF/sixDOFODE/restraints/translationalRestraints/linearSpringDamper/linearSpringDamper.C @@ -0,0 +1,98 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "linearSpringDamper.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(linearSpringDamper, 0); + addToRunTimeSelectionTable + ( + translationalRestraint, + linearSpringDamper, + word + ); +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::linearSpringDamper::linearSpringDamper +( + const word& name, + const dictionary& dict +) +: + translationalRestraint(name, dict), + linSpringCoeffs_(dict.lookup("linearSpring")), + linDampingCoeffs_(dict.lookup("linearDamping")) +{} + + +Foam::autoPtr +Foam::linearSpringDamper::clone() const +{ + return autoPtr + ( + new linearSpringDamper(*this) + ); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::linearSpringDamper::~linearSpringDamper() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::vector Foam::linearSpringDamper::restrainingForce +( + const scalar, + const tensor&, + const vector& x, + const vector& u +) const +{ + return - (linSpringCoeffs_ & x) - (linDampingCoeffs_ & u); +} + + +void Foam::linearSpringDamper::write(Ostream& os) const +{ + os.writeKeyword("type") << tab << type() + << token::END_STATEMENT << nl << nl; + + os.writeKeyword("linearSpring") << tab << linSpringCoeffs_ + << token::END_STATEMENT << nl; + os.writeKeyword("linearDamping") << tab << linDampingCoeffs_ + << token::END_STATEMENT << endl; +} + + +// ************************************************************************* // diff --git a/src/ODE/sixDOF/sixDOFODE/restraints/translationalRestraints/linearSpringDamper/linearSpringDamper.H b/src/ODE/sixDOF/sixDOFODE/restraints/translationalRestraints/linearSpringDamper/linearSpringDamper.H new file mode 100644 index 000000000..31a7df49b --- /dev/null +++ b/src/ODE/sixDOF/sixDOFODE/restraints/translationalRestraints/linearSpringDamper/linearSpringDamper.H @@ -0,0 +1,119 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Class + Foam::linearSpringDamper + +Description + Translational restraint corresponding to linear spring and linear damper + defined by linear spring coefficients and linear damping coefficients. + +Author + Vuko Vukcevic, FSB Zagreb. All rights reserved. + +SourceFiles + linearSpringDamper.C + +\*---------------------------------------------------------------------------*/ + +#ifndef linearSpringDamper_H +#define linearSpringDamper_H + +#include "translationalRestraint.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class linearSpringDamper Declaration +\*---------------------------------------------------------------------------*/ + +class linearSpringDamper +: + public translationalRestraint +{ + // Private Data + + //- Linear spring coefficients + diagTensor linSpringCoeffs_; + + //- Linear damping coefficients + diagTensor linDampingCoeffs_; + + +public: + + //- Runtime type information + TypeName("linearSpringDamper"); + + + // Constructors + + //- Construct from dictionary + linearSpringDamper + ( + const word& name, + const dictionary& dict + ); + + //- Construct and return a clone + virtual autoPtr clone() const; + + + // Destructor + + virtual ~linearSpringDamper(); + + + // Member Functions + + // Restraint specific functions + + //- Return restraining force (in the global coordinate system) + virtual vector restrainingForce + ( + const scalar t, + const tensor& toRelative, + const vector& x, + const vector& u + ) const; + + + // I-O Functions and Operators + + //- Virtual write function + virtual void write(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/ODE/sixDOF/sixDOFODE/sixDOFODE.C b/src/ODE/sixDOF/sixDOFODE/sixDOFODE.C index c605543e5..f144ad3ba 100644 --- a/src/ODE/sixDOF/sixDOFODE/sixDOFODE.C +++ b/src/ODE/sixDOF/sixDOFODE/sixDOFODE.C @@ -191,8 +191,6 @@ void Foam::sixDOFODE::setState(const sixDOFODE& sd) momentOfInertia_ = sd.momentOfInertia_; Xequilibrium_ = sd.Xequilibrium_; - linSpringCoeffs_ = sd.linSpringCoeffs_; - linDampingCoeffs_ = sd.linDampingCoeffs_; force_ = sd.force_; moment_ = sd.moment_; @@ -207,23 +205,61 @@ void Foam::sixDOFODE::setState(const sixDOFODE& sd) } -Foam::dimensionedVector Foam::sixDOFODE::force(const scalar t) const +Foam::dimensionedVector Foam::sixDOFODE::force +( + const scalar t, + const tensor& toRelative, + const vector& x, + const vector& u +) const { // Get ODE step fraction const scalar alpha = odeStepFraction(t); - // Return linearly interpolated external force - return (alpha*oldStatePtr_->force() + (1 - alpha)*force()); + // Calculate restraining force + dimensionedVector rForce("zero", dimForce, vector::zero); + + forAll(translationalRestraints_, trI) + { + rForce.value() += translationalRestraints_[trI].restrainingForce + ( + t, // Time + toRelative, // Transformation tensor + x, // Position in the global c.s. + u // Velocity in the global c.s. + ); + } + + // Return linearly interpolated external force with restraining force + return (alpha*oldStatePtr_->force() + (1 - alpha)*force()) + rForce; } -Foam::dimensionedVector Foam::sixDOFODE::moment(const scalar t) const +Foam::dimensionedVector Foam::sixDOFODE::moment +( + const scalar t, + const tensor& toRelative, + const vector& omega +) const { // Get ODE step fraction const scalar alpha = odeStepFraction(t); - // Return linearly interpolated external moment - return (alpha*oldStatePtr_->moment() + (1 - alpha)*moment()); + // Calculate restraining moment + dimensionedVector rMoment("zero", dimForce*dimLength, vector::zero); + + forAll(rotationalRestraints_, rrI) + { + rMoment.value() += rotationalRestraints_[rrI].restrainingMoment + ( + t, // Time + toRelative, // Transformation tensor + omega // Angular velocity in local c.s. + ); + } + + // Return linearly interpolated external moment with restraining moment + return (alpha*oldStatePtr_->moment() + (1 - alpha)*moment() + rMoment); } @@ -238,8 +274,6 @@ Foam::sixDOFODE::sixDOFODE(const IOobject& io) momentOfInertia_(dict_.lookup("momentOfInertia")), Xequilibrium_(dict_.lookup("equilibriumPosition")), - linSpringCoeffs_(dict_.lookup("linearSpring")), - linDampingCoeffs_(dict_.lookup("linearDamping")), aitkensRelaxation_ ( @@ -345,8 +379,6 @@ Foam::sixDOFODE::sixDOFODE(const word& name, const sixDOFODE& sd) momentOfInertia_(sd.momentOfInertia_), Xequilibrium_(sd.Xequilibrium_), - linSpringCoeffs_(sd.linSpringCoeffs_), - linDampingCoeffs_(sd.linDampingCoeffs_), aitkensRelaxation_(sd.aitkensRelaxation_), minRelaxFactor_(sd.minRelaxFactor_), @@ -399,10 +431,6 @@ bool Foam::sixDOFODE::writeData(Ostream& os) const os.writeKeyword("equilibriumPosition") << tab << Xequilibrium_ << token::END_STATEMENT << nl; - os.writeKeyword("linearSpring") << tab << linSpringCoeffs_ - << token::END_STATEMENT << nl; - os.writeKeyword("linearDamping") << tab << linDampingCoeffs_ - << token::END_STATEMENT << nl << nl; os.writeKeyword("useAitkensRelaxation") << tab << aitkensRelaxation_ << token::END_STATEMENT << nl; diff --git a/src/ODE/sixDOF/sixDOFODE/sixDOFODE.H b/src/ODE/sixDOF/sixDOFODE/sixDOFODE.H index 2c0b42306..adb7e93e8 100644 --- a/src/ODE/sixDOF/sixDOFODE/sixDOFODE.H +++ b/src/ODE/sixDOF/sixDOFODE/sixDOFODE.H @@ -92,12 +92,6 @@ class sixDOFODE //- Spring equilibrium position for translation dimensionedVector Xequilibrium_; - //- Linear spring coeffs - dimensionedDiagTensor linSpringCoeffs_; - - //- Linear damping coeffs - dimensionedDiagTensor linDampingCoeffs_; - // Aitkens relaxation data members @@ -216,13 +210,22 @@ protected: // Get external force and moment (used during the solution process) - //- Return external force given time (linearly interpolated from - // old state and current state) - dimensionedVector force(const scalar t) const; + //- Return external force with restraints for given ODE state + dimensionedVector force + ( + const scalar t, + const tensor& toRelative, + const vector& x, + const vector& u + ) const; - //- Return external moment given time (linearly interpolated from - // old state and current state) - dimensionedVector moment(const scalar t) const; + //- Return external moment with restraints given ODE state + dimensionedVector moment + ( + const scalar t, + const tensor& toRelative, + const vector& omega + ) const; public: diff --git a/src/ODE/sixDOF/sixDOFODE/sixDOFODEI.H b/src/ODE/sixDOF/sixDOFODE/sixDOFODEI.H index 383d1b0f9..aa5e68ee0 100644 --- a/src/ODE/sixDOF/sixDOFODE/sixDOFODEI.H +++ b/src/ODE/sixDOF/sixDOFODE/sixDOFODEI.H @@ -81,18 +81,6 @@ Foam::dimensionedVector& Foam::sixDOFODE::Xequilibrium() } -const Foam::dimensionedDiagTensor& Foam::sixDOFODE::linSpringCoeffs() const -{ - return linSpringCoeffs_; -} - - -const Foam::dimensionedDiagTensor& Foam::sixDOFODE::linDampingCoeffs() const -{ - return linDampingCoeffs_; -} - - const Foam::dimensionedVector& Foam::sixDOFODE::force() const { return force_;