axialAngularSpring.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-2024 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 
26 #include "axialAngularSpring.H"
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 
52 (
53  const word& name,
54  const dictionary& sDoFRBMRDict
55 )
56 :
57  sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict),
58  refQ_(),
59  axis_(),
60  moment_(),
61  damping_()
62 {
63  read(sDoFRBMRDict);
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
68 
70 {}
71 
72 
73 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
74 
76 (
77  const sixDoFRigidBodyMotion& motion,
78  vector& restraintPosition,
79  vector& restraintForce,
80  vector& restraintMoment
81 ) const
82 {
83  vector refDir = rotationTensor(vector(1, 0 ,0), axis_) & vector(0, 1, 0);
84 
85  vector oldDir = refQ_ & refDir;
86 
87  vector newDir = motion.orientation() & refDir;
88 
89  if (mag(oldDir & axis_) > 0.95 || mag(newDir & axis_) > 0.95)
90  {
91  // Directions getting close to the axis, change reference
92 
93  refDir = rotationTensor(vector(1, 0 ,0), axis_) & vector(0, 0, 1);
94  oldDir = refQ_ & refDir;
95  newDir = motion.orientation() & refDir;
96  }
97 
98  // Removing any axis component from oldDir and newDir and normalising
99  oldDir -= (axis_ & oldDir)*axis_;
100  oldDir /= (mag(oldDir) + vSmall);
101 
102  newDir -= (axis_ & newDir)*axis_;
103  newDir /= (mag(newDir) + vSmall);
104 
105  scalar theta = mag(acos(min(oldDir & newDir, 1.0)));
106 
107  // Determining the sign of theta by comparing the cross product of
108  // the direction vectors with the axis
109  theta *= sign((oldDir ^ newDir) & axis_);
110 
111  const scalar moment = moment_->value(theta);
112 
113  // Damping of along axis angular velocity only
114  restraintMoment = moment*axis_ - damping_*(motion.omega() & axis_)*axis_;
115 
116  restraintForce = Zero;
117 
118  // Not needed to be altered as restraintForce is zero, but set to
119  // centreOfRotation to be sure of no spurious moment
120  restraintPosition = motion.centreOfRotation();
121 
122  if (motion.report())
123  {
124  Info<< " angle " << theta
125  << " moment " << restraintMoment
126  << endl;
127  }
128 }
129 
130 
132 (
133  const dictionary& sDoFRBMRDict
134 )
135 {
137 
138  refQ_ = sDoFRBMRCoeffs_.lookupOrDefault<tensor>("referenceOrientation", I);
139 
140  if (mag(mag(refQ_) - sqrt(3.0)) > 1e-9)
141  {
143  << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
144  << "mag(referenceOrientation) - sqrt(3) = "
145  << mag(refQ_) - sqrt(3.0) << nl
146  << exit(FatalError);
147  }
148 
149  axis_ = sDoFRBMRCoeffs_.lookup("axis");
150 
151  scalar magAxis(mag(axis_));
152 
153  if (magAxis > vSmall)
154  {
155  axis_ /= magAxis;
156  }
157  else
158  {
160  << "axis has zero length"
161  << abort(FatalError);
162  }
163 
164  moment_ =
166  (
167  "moment",
168  unitRadians,
170  sDoFRBMRCoeffs_
171  );
172 
173  if
174  (
175  sDoFRBMRCoeffs_.found("angleUnits")
176  || sDoFRBMRCoeffs_.found("angleFormat")
177  )
178  {
179  FatalIOErrorInFunction(sDoFRBMRCoeffs_)
180  << "Angle units are no longer specified with 'angleUnits' or "
181  << "'angleFormat' entries. Instead, parameters of the 'moment' "
182  << "function can have their units specified directly."
183  << exit(FatalIOError);
184  }
185 
186  sDoFRBMRCoeffs_.lookup("damping") >> damping_;
187 
188  return true;
189 }
190 
191 
193 (
194  Ostream& os
195 ) const
196 {
197  writeEntry(os, "referenceOrientation", refQ_);
198 
199  writeEntry(os, "axis", axis_);
200 
201  writeEntry(os, moment_());
202 
203  writeEntry(os, "damping", damping_);
204 }
205 
206 
207 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
static autoPtr< Function1< Type > > New(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
Select from dictionary.
Definition: Function1New.C:32
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Base class for defining restraints for sixDoF motions.
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
Axial angular spring with moment values obtained from a Function1 and linear damping.
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
axialAngularSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Six degree of freedom motion for a rigid body.
bool report() const
Return the report Switch.
const tensor & orientation() const
Return the orientation tensor, Q.
vector omega() const
Return the angular velocity in the global frame.
const point & centreOfRotation() const
Return the current centre of rotation.
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
defineTypeNameAndDebug(axialAngularSpring, 0)
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, axialAngularSpring, dictionary)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
static const zero Zero
Definition: zero.H:97
const doubleScalar e
Definition: doubleScalar.H:106
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from unit vector n1 to n2.
Definition: transform.H:47
dimensionedScalar sign(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
errorManip< error > abort(error &err)
Definition: errorManip.H:131
messageStream Info
const dimensionSet dimLength
static const Identity< scalar > I
Definition: Identity.H:93
const dimensionSet dimForce
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< scalar > mag(const dimensioned< Type > &)
IOerror FatalIOError
const unitConversion unitRadians
error FatalError
static const char nl
Definition: Ostream.H:266
dimensionedScalar acos(const dimensionedScalar &ds)
3D tensor transformation operations.