1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "linearSpring.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "sixDoFRigidBodyMotion.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace sixDoFRigidBodyMotionRestraints
36 defineTypeNameAndDebug(linearSpring, 0);
38 addToRunTimeSelectionTable
40 sixDoFRigidBodyMotionRestraint,
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionRestraints::linearSpring::linearSpring
52 const dictionary& sDoFRBMRDict
55 sixDoFRigidBodyMotionRestraint(sDoFRBMRDict),
66 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
68 Foam::sixDoFRigidBodyMotionRestraints::linearSpring::~linearSpring()
72 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
74 void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::restrain
76 const sixDoFRigidBodyMotion& motion,
77 vector& restraintPosition,
78 vector& restraintForce,
79 vector& restraintMoment
82 restraintPosition = motion.currentPosition(refAttachmentPt_);
84 vector r = restraintPosition - anchor_;
88 // r is now the r unit vector
91 vector v = motion.currentVelocity(restraintPosition);
93 restraintForce = -stiffness_*(magR - restLength_)*r - damping_*(r & v)*r;
95 restraintMoment = vector::zero;
99 Info<< " attachmentPt - anchor " << r*magR
100 << " spring length " << magR
101 << " force " << restraintForce
102 << " moment " << restraintMoment
108 bool Foam::sixDoFRigidBodyMotionRestraints::linearSpring::read
110 const dictionary& sDoFRBMRDict
113 sixDoFRigidBodyMotionRestraint::read(sDoFRBMRDict);
115 sDoFRBMRCoeffs_.lookup("anchor") >> anchor_;
117 sDoFRBMRCoeffs_.lookup("refAttachmentPt") >> refAttachmentPt_;
119 sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
121 sDoFRBMRCoeffs_.lookup("damping") >> damping_;
123 sDoFRBMRCoeffs_.lookup("restLength") >> restLength_;
129 void Foam::sixDoFRigidBodyMotionRestraints::linearSpring::write
134 os.writeKeyword("anchor")
135 << anchor_ << token::END_STATEMENT << nl;
137 os.writeKeyword("refAttachmentPt")
138 << refAttachmentPt_ << token::END_STATEMENT << nl;
140 os.writeKeyword("stiffness")
141 << stiffness_ << token::END_STATEMENT << nl;
143 os.writeKeyword("damping")
144 << damping_ << token::END_STATEMENT << nl;
146 os.writeKeyword("restLength")
147 << restLength_ << token::END_STATEMENT << nl;
150 // ************************************************************************* //