linearAxialAngularSpring.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 #include "sixDoFRigidBodyMotion.H"
29 #include "transform.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace sixDoFRigidBodyMotionRestraints
36 {
38 
40  (
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
53 (
54  const word& name,
55  const dictionary& sDoFRBMRDict
56 )
57 :
58  sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict),
59  refQ_(),
60  axis_(),
61  stiffness_(),
62  damping_()
63 {
64  read(sDoFRBMRDict);
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69 
72 {}
73 
74 
75 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
76 
77 void
79 (
80  const sixDoFRigidBodyMotion& motion,
81  vector& restraintPosition,
82  vector& restraintForce,
83  vector& restraintMoment
84 ) const
85 {
86  vector refDir = rotationTensor(vector(1, 0 ,0), axis_) & vector(0, 1, 0);
87 
88  vector oldDir = refQ_ & refDir;
89  vector newDir = motion.orientation() & refDir;
90 
91  if (mag(oldDir & axis_) > 0.95 || mag(newDir & axis_) > 0.95)
92  {
93  // Directions getting close to the axis, change reference
94 
95  refDir = rotationTensor(vector(1, 0 ,0), axis_) & vector(0, 0, 1);
96  oldDir = refQ_ & refDir;
97  newDir = motion.orientation() & refDir;
98  }
99 
100  // Removing any axis component from oldDir and newDir and normalising
101  oldDir -= (axis_ & oldDir)*axis_;
102  oldDir /= (mag(oldDir) + VSMALL);
103 
104  newDir -= (axis_ & newDir)*axis_;
105  newDir /= (mag(newDir) + VSMALL);
106 
107  scalar theta = mag(acos(min(oldDir & newDir, 1.0)));
108 
109  // Temporary axis with sign information.
110  vector a = (oldDir ^ newDir);
111 
112  // Remove any component that is not along axis that may creep in
113  a = (a & axis_)*axis_;
114 
115  scalar magA = mag(a);
116 
117  if (magA > VSMALL)
118  {
119  a /= magA;
120  }
121  else
122  {
123  a = vector::zero;
124  }
125 
126  // Damping of along axis angular velocity only
127  restraintMoment = -stiffness_*theta*a - damping_*(motion.omega() & a)*a;
128 
129  restraintForce = vector::zero;
130 
131  // Not needed to be altered as restraintForce is zero, but set to
132  // centreOfRotation to be sure of no spurious moment
133  restraintPosition = motion.centreOfRotation();
134 
135  if (motion.report())
136  {
137  Info<< " angle " << theta*sign(a & axis_)
138  << " moment " << restraintMoment
139  << endl;
140  }
141 }
142 
143 
145 (
146  const dictionary& sDoFRBMRDict
147 )
148 {
150 
151  refQ_ = sDoFRBMRCoeffs_.lookupOrDefault<tensor>("referenceOrientation", I);
152 
153  if (mag(mag(refQ_) - sqrt(3.0)) > 1e-9)
154  {
156  (
157  "Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::"
158  "read"
159  "("
160  "const dictionary& sDoFRBMRDict"
161  ")"
162  )
163  << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
164  << "mag(referenceOrientation) - sqrt(3) = "
165  << mag(refQ_) - sqrt(3.0) << nl
166  << exit(FatalError);
167  }
168 
169  axis_ = sDoFRBMRCoeffs_.lookup("axis");
170 
171  scalar magAxis(mag(axis_));
172 
173  if (magAxis > VSMALL)
174  {
175  axis_ /= magAxis;
176  }
177  else
178  {
180  (
181  "Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::"
182  "read"
183  "("
184  "const dictionary& sDoFRBMCDict"
185  ")"
186  )
187  << "axis has zero length"
188  << abort(FatalError);
189  }
190 
191  sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
192  sDoFRBMRCoeffs_.lookup("damping") >> damping_;
193 
194  return true;
195 }
196 
197 
199 (
200  Ostream& os
201 ) const
202 {
203  os.writeKeyword("referenceOrientation")
204  << refQ_ << token::END_STATEMENT << nl;
205 
206  os.writeKeyword("axis")
207  << axis_ << token::END_STATEMENT << nl;
208 
209  os.writeKeyword("stiffness")
210  << stiffness_ << token::END_STATEMENT << nl;
211 
212  os.writeKeyword("damping")
213  << damping_ << token::END_STATEMENT << nl;
214 }
215 
216 // ************************************************************************* //
dimensionedScalar sqrt(const dimensionedScalar &ds)
linearAxialAngularSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
dimensioned< scalar > mag(const dimensioned< Type > &)
const tensor & orientation() const
Return the orientation tensor, Q.
static const sphericalTensor I(1)
A class for handling words, derived from string.
Definition: word.H:59
Base class for defining restraints for sixDoF motions.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dimensionedScalar sign(const dimensionedScalar &ds)
messageStream Info
bool report() const
Return the report Switch.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, linearAxialAngularSpring, dictionary)
static const char nl
Definition: Ostream.H:260
const double e
Elementary charge.
Definition: doubleFloat.H:78
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
Macros for easy insertion into run-time selection tables.
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
dimensionedScalar acos(const dimensionedScalar &ds)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
vector omega() const
Return the angular velocity in the global frame.
static const Vector zero
Definition: Vector.H:80
3D tensor transformation operations.
sixDoFRigidBodyMotionRestraints model. Linear axial angular spring.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Six degree of freedom motion for a rigid body.
tensor rotationTensor(const vector &n1, const vector &n2)
Definition: transform.H:46
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
const point & centreOfRotation() const
Return the current centre of rotation.