tabulatedAxialAngularSpring.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 = 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  << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
158  << "mag(referenceOrientation) - sqrt(3) = "
159  << mag(refQ_) - sqrt(3.0) << nl
160  << exit(FatalError);
161  }
162 
163  axis_ = sDoFRBMRCoeffs_.lookup("axis");
164 
165  scalar magAxis(mag(axis_));
166 
167  if (magAxis > vSmall)
168  {
169  axis_ /= magAxis;
170  }
171  else
172  {
174  << "axis has zero length"
175  << abort(FatalError);
176  }
177 
178  moment_ = interpolationTable<scalar>(sDoFRBMRCoeffs_);
179 
180  const word angleFormat = sDoFRBMRCoeffs_.lookup("angleFormat");
181 
182  if (angleFormat == "degrees" || angleFormat == "degree")
183  {
184  convertToDegrees_ = true;
185  }
186  else if (angleFormat == "radians" || angleFormat == "radian")
187  {
188  convertToDegrees_ = false;
189  }
190  else
191  {
193  << "angleFormat must be degree, degrees, radian or radians"
194  << abort(FatalError);
195  }
196 
197  sDoFRBMRCoeffs_.lookup("damping") >> damping_;
198 
199  return true;
200 }
201 
202 
204 (
205  Ostream& os
206 ) const
207 {
208  os.writeKeyword("referenceOrientation")
209  << refQ_ << token::END_STATEMENT << nl;
210 
211  os.writeKeyword("axis")
212  << axis_ << token::END_STATEMENT << nl;
213 
214  moment_.write(os);
215 
216  os.writeKeyword("angleFormat");
217 
218  if (convertToDegrees_)
219  {
220  os << "degrees" << token::END_STATEMENT << nl;
221  }
222  else
223  {
224  os << "radians" << token::END_STATEMENT << nl;
225  }
226 
227  os.writeKeyword("damping")
228  << damping_ << token::END_STATEMENT << nl;
229 }
230 
231 
232 // ************************************************************************* //
tabulatedAxialAngularSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
Six degree of freedom motion for a rigid body.
dimensionedScalar sign(const dimensionedScalar &ds)
dimensionedScalar acos(const dimensionedScalar &ds)
bool report() const
Return the report Switch.
scalar radToDeg(const scalar rad)
Conversion from radians to degrees.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const point & centreOfRotation() const
Return the current centre of rotation.
Unit conversion functions.
Base class for defining restraints for sixDoF motions.
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Definition: transform.H:47
Macros for easy insertion into run-time selection tables.
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
static const Identity< scalar > I
Definition: Identity.H:93
vector omega() const
Return the angular velocity in the global frame.
A class for handling words, derived from string.
Definition: word.H:59
3D tensor transformation operations.
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
const tensor & orientation() const
Return the orientation tensor, Q.
static const zero Zero
Definition: zero.H:97
errorManip< error > abort(error &err)
Definition: errorManip.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:265
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, linearAxialAngularSpring, dictionary)
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:98
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Namespace for OpenFOAM.