sixDoFMotion: Adding restraints and constraints to the motion of objects.
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / forces / pointPatchFields / derived / sixDoFRigidBodyMotion / sixDoFRigidBodyMotionRestraint / sphericalAngularSpring / sphericalAngularSpring.C
blob43a5e795b62728a14318d34d4a65097018f0b60a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 * * * * * * * * * * * * * //
33 namespace Foam
35 namespace sixDoFRigidBodyMotionRestraints
37     defineTypeNameAndDebug(sphericalAngularSpring, 0);
38     addToRunTimeSelectionTable
39     (
40         sixDoFRigidBodyMotionRestraint,
41         sphericalAngularSpring,
42         dictionary
43     );
48 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
50 Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::
51 sphericalAngularSpring
53     const dictionary& sDoFRBMRDict
56     sixDoFRigidBodyMotionRestraint(sDoFRBMRDict),
57     refQ_(),
58     stiffness_(),
59     damping_()
61     read(sDoFRBMRDict);
65 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
67 Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::
68 ~sphericalAngularSpring()
72 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
74 void
75 Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::restrain
77     const sixDoFRigidBodyMotion& motion,
78     vector& restraintPosition,
79     vector& restraintForce,
80     vector& restraintMoment
81 ) const
83     restraintMoment = vector::zero;
85     for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
86     {
87         vector axis = vector::zero;
89         axis[cmpt] = 1;
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);
104     }
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();
114     if (motion.report())
115     {
116         Info<< " force " << restraintForce
117             << " moment " << restraintMoment
118             << endl;
119     }
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)
133     {
134         FatalErrorIn
135         (
136             "Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::"
137             "read"
138             "("
139                 "const dictionary& sDoFRBMRDict"
140             ")"
141         )
142             << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
143             << "mag(referenceOrientation) - sqrt(3) = "
144             << mag(refQ_) - sqrt(3.0) << nl
145             << exit(FatalError);
146     }
148     sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
150     sDoFRBMRCoeffs_.lookup("damping") >> damping_;
152     return true;
156 void Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::write
158     Ostream& os
159 ) const
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 // ************************************************************************* //