tabulatedAxialAngularSpring.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 #include "unitConversion.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace sixDoFRigidBodyMotionRestraints
37 {
38  defineTypeNameAndDebug(tabulatedAxialAngularSpring, 0);
39 
41  (
42  sixDoFRigidBodyMotionRestraint,
43  tabulatedAxialAngularSpring,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
54 (
55  const word& name,
56  const dictionary& sDoFRBMRDict
57 )
58 :
59  sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict),
60  refQ_(),
61  axis_(),
62  moment_(),
63  convertToDegrees_(),
64  damping_()
65 {
66  read(sDoFRBMRDict);
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
71 
74 {}
75 
76 
77 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
78 
79 void
81 (
82  const sixDoFRigidBodyMotion& motion,
83  vector& restraintPosition,
84  vector& restraintForce,
85  vector& restraintMoment
86 ) const
87 {
88  vector refDir = rotationTensor(vector(1, 0 ,0), axis_) & vector(0, 1, 0);
89 
90  vector oldDir = refQ_ & refDir;
91 
92  vector newDir = motion.orientation() & refDir;
93 
94  if (mag(oldDir & axis_) > 0.95 || mag(newDir & axis_) > 0.95)
95  {
96  // Directions getting close to the axis, change reference
97 
98  refDir = rotationTensor(vector(1, 0 ,0), axis_) & vector(0, 0, 1);
99  oldDir = refQ_ & refDir;
100  newDir = motion.orientation() & refDir;
101  }
102 
103  // Removing any axis component from oldDir and newDir and normalising
104  oldDir -= (axis_ & oldDir)*axis_;
105  oldDir /= (mag(oldDir) + VSMALL);
106 
107  newDir -= (axis_ & newDir)*axis_;
108  newDir /= (mag(newDir) + VSMALL);
109 
110  scalar theta = mag(acos(min(oldDir & newDir, 1.0)));
111 
112  // Determining the sign of theta by comparing the cross product of
113  // the direction vectors with the axis
114  theta *= sign((oldDir ^ newDir) & axis_);
115 
116  scalar moment;
117 
118  if (convertToDegrees_)
119  {
120  moment = moment_(radToDeg(theta));
121  }
122  else
123  {
124  moment = moment_(theta);
125  }
126 
127  // Damping of along axis angular velocity only
128  restraintMoment = moment*axis_ - damping_*(motion.omega() & axis_)*axis_;
129 
130  restraintForce = vector::zero;
131 
132  // Not needed to be altered as restraintForce is zero, but set to
133  // centreOfRotation to be sure of no spurious moment
134  restraintPosition = motion.centreOfRotation();
135 
136  if (motion.report())
137  {
138  Info<< " angle " << theta
139  << " moment " << restraintMoment
140  << endl;
141  }
142 }
143 
144 
146 (
147  const dictionary& sDoFRBMRDict
148 )
149 {
151 
152  refQ_ = sDoFRBMRCoeffs_.lookupOrDefault<tensor>("referenceOrientation", I);
153 
154  if (mag(mag(refQ_) - sqrt(3.0)) > 1e-9)
155  {
157  (
158  "Foam::sixDoFRigidBodyMotionRestraints::"
159  "tabulatedAxialAngularSpring::read"
160  "("
161  "const dictionary& sDoFRBMRDict"
162  ")"
163  )
164  << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
165  << "mag(referenceOrientation) - sqrt(3) = "
166  << mag(refQ_) - sqrt(3.0) << nl
167  << exit(FatalError);
168  }
169 
170  axis_ = sDoFRBMRCoeffs_.lookup("axis");
171 
172  scalar magAxis(mag(axis_));
173 
174  if (magAxis > VSMALL)
175  {
176  axis_ /= magAxis;
177  }
178  else
179  {
181  (
182  "Foam::sixDoFRigidBodyMotionRestraints::"
183  "tabulatedAxialAngularSpring::read"
184  "("
185  "const dictionary& sDoFRBMCDict"
186  ")"
187  )
188  << "axis has zero length"
189  << abort(FatalError);
190  }
191 
192  moment_ = interpolationTable<scalar>(sDoFRBMRCoeffs_);
193 
194  const word angleFormat = sDoFRBMRCoeffs_.lookup("angleFormat");
195 
196  if (angleFormat == "degrees" || angleFormat == "degree")
197  {
198  convertToDegrees_ = true;
199  }
200  else if (angleFormat == "radians" || angleFormat == "radian")
201  {
202  convertToDegrees_ = false;
203  }
204  else
205  {
207  (
208  "Foam::sixDoFRigidBodyMotionRestraints::"
209  "tabulatedAxialAngularSpring::read"
210  "("
211  "const dictionary&"
212  ")"
213  )
214  << "angleFormat must be degree, degrees, radian or radians"
215  << abort(FatalError);
216  }
217 
218  sDoFRBMRCoeffs_.lookup("damping") >> damping_;
219 
220  return true;
221 }
222 
223 
225 (
226  Ostream& os
227 ) const
228 {
229  os.writeKeyword("referenceOrientation")
230  << refQ_ << token::END_STATEMENT << nl;
231 
232  os.writeKeyword("axis")
233  << axis_ << token::END_STATEMENT << nl;
234 
235  moment_.write(os);
236 
237  os.writeKeyword("angleFormat");
238 
239  if (convertToDegrees_)
240  {
241  os << "degrees" << token::END_STATEMENT << nl;
242  }
243  else
244  {
245  os << "radians" << token::END_STATEMENT << nl;
246  }
247 
248  os.writeKeyword("damping")
249  << damping_ << token::END_STATEMENT << nl;
250 }
251 
252 
253 // ************************************************************************* //
dimensionedScalar sqrt(const dimensionedScalar &ds)
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.
tabulatedAxialAngularSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
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)
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
Macros for easy insertion into run-time selection tables.
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
Unit conversion functions.
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
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
vector omega() const
Return the angular velocity in the global frame.
static const Vector zero
Definition: Vector.H:80
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
3D tensor transformation operations.
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 > &)
const point & centreOfRotation() const
Return the current centre of rotation.