1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "sphericalAngularSpring.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "sixDoFRigidBodyMotion.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace sixDoFRigidBodyMotionRestraints
37 defineTypeNameAndDebug(sphericalAngularSpring, 0);
38 addToRunTimeSelectionTable
40 sixDoFRigidBodyMotionRestraint,
41 sphericalAngularSpring,
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::
51 sphericalAngularSpring
53 const dictionary& sDoFRBMRDict
56 sixDoFRigidBodyMotionRestraint(sDoFRBMRDict),
65 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
67 Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::
68 ~sphericalAngularSpring()
72 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
75 Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::restrain
77 const sixDoFRigidBodyMotion& motion,
78 vector& restraintPosition,
79 vector& restraintForce,
80 vector& restraintMoment
83 restraintMoment = vector::zero;
85 for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
87 vector axis = vector::zero;
91 vector refDir = vector::zero;
93 refDir[(cmpt + 1) % 3] = 1;
95 vector newDir = motion.orientation() & refDir;
97 axis = (refQ_ & axis);
99 refDir = (refQ_ & refDir);
101 newDir -= (axis & newDir)*axis;
103 restraintMoment += -stiffness_*(refDir ^ newDir);
106 restraintMoment += -damping_*motion.omega();
108 restraintForce = vector::zero;
110 // Not needed to be altered as restraintForce is zero, but set to
111 // centreOfMass to be sure of no spurious moment
112 restraintPosition = motion.centreOfMass();
116 Info<< " force " << restraintForce
117 << " moment " << restraintMoment
123 bool Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::read
125 const dictionary& sDoFRBMRDict
128 sixDoFRigidBodyMotionRestraint::read(sDoFRBMRDict);
130 refQ_ = sDoFRBMRCoeffs_.lookupOrDefault<tensor>("referenceOrientation", I);
132 if (mag(mag(refQ_) - sqrt(3.0)) > 1e-9)
136 "Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::"
139 "const dictionary& sDoFRBMRDict"
142 << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
143 << "mag(referenceOrientation) - sqrt(3) = "
144 << mag(refQ_) - sqrt(3.0) << nl
148 sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
150 sDoFRBMRCoeffs_.lookup("damping") >> damping_;
156 void Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::write
161 os.writeKeyword("referenceOrientation")
162 << refQ_ << token::END_STATEMENT << nl;
164 os.writeKeyword("stiffness") << stiffness_ << token::END_STATEMENT << nl;
166 os.writeKeyword("damping") << damping_ << token::END_STATEMENT << nl;
170 // ************************************************************************* //