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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "sixDoFRigidBodyMotion.H"
32 #include "transform.H"
33 #include "unitConversion.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace sixDoFRigidBodyMotionRestraints
40 {
41  defineTypeNameAndDebug(tabulatedAxialAngularSpring, 0);
42 
44  (
45  sixDoFRigidBodyMotionRestraint,
46  tabulatedAxialAngularSpring,
47  dictionary
48  );
49 }
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
57 (
58  const word& name,
59  const dictionary& sDoFRBMRDict
60 )
61 :
62  sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict),
63  refQ_(),
64  axis_(),
65  moment_(),
66  convertToDegrees_(),
67  damping_()
68 {
69  read(sDoFRBMRDict);
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74 
77 {}
78 
79 
80 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
81 
82 void
84 (
85  const sixDoFRigidBodyMotion& motion,
86  vector& restraintPosition,
87  vector& restraintForce,
88  vector& restraintMoment
89 ) const
90 {
91  vector refDir = rotationTensor(vector(1, 0 ,0), axis_) & vector(0, 1, 0);
92 
93  vector oldDir = refQ_ & refDir;
94 
95  vector newDir = motion.orientation() & refDir;
96 
97  if (mag(oldDir & axis_) > 0.95 || mag(newDir & axis_) > 0.95)
98  {
99  // Directions getting close to the axis, change reference
100 
101  refDir = rotationTensor(vector(1, 0 ,0), axis_) & vector(0, 0, 1);
102  oldDir = refQ_ & refDir;
103  newDir = motion.orientation() & refDir;
104  }
105 
106  // Removing any axis component from oldDir and newDir and normalising
107  oldDir -= (axis_ & oldDir)*axis_;
108  oldDir /= (mag(oldDir) + VSMALL);
109 
110  newDir -= (axis_ & newDir)*axis_;
111  newDir /= (mag(newDir) + VSMALL);
112 
113  scalar theta = mag(acos(min(oldDir & newDir, 1.0)));
114 
115  // Determining the sign of theta by comparing the cross product of
116  // the direction vectors with the axis
117  theta *= sign((oldDir ^ newDir) & axis_);
118 
119  scalar moment;
120 
121  if (convertToDegrees_)
122  {
123  moment = moment_(radToDeg(theta));
124  }
125  else
126  {
127  moment = moment_(theta);
128  }
129 
130  // Damping of along axis angular velocity only
131  restraintMoment = moment*axis_ - damping_*(motion.omega() & axis_)*axis_;
132 
133  restraintForce = Zero;
134 
135  // Not needed to be altered as restraintForce is zero, but set to
136  // centreOfRotation to be sure of no spurious moment
137  restraintPosition = motion.centreOfRotation();
138 
139  if (motion.report())
140  {
141  Info<< " angle " << theta
142  << " moment " << restraintMoment
143  << endl;
144  }
145 }
146 
147 
149 (
150  const dictionary& sDoFRBMRDict
151 )
152 {
154 
155  refQ_ = sDoFRBMRCoeffs_.getOrDefault<tensor>("referenceOrientation", I);
156 
157  if (mag(mag(refQ_) - sqrt(3.0)) > ROOTSMALL)
158  {
160  << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
161  << "mag(referenceOrientation) - sqrt(3) = "
162  << mag(refQ_) - sqrt(3.0) << nl
163  << exit(FatalError);
164  }
165 
166  sDoFRBMRCoeffs_.readEntry("axis", axis_);
167 
168  scalar magAxis(mag(axis_));
169 
170  if (magAxis > VSMALL)
171  {
172  axis_ /= magAxis;
173  }
174  else
175  {
177  << "axis has zero length"
178  << abort(FatalError);
179  }
180 
181  moment_ = interpolationTable<scalar>(sDoFRBMRCoeffs_);
182 
183  const word angleFormat(sDoFRBMRCoeffs_.get<word>("angleFormat"));
184 
185  if (angleFormat == "degrees" || angleFormat == "degree")
186  {
187  convertToDegrees_ = true;
188  }
189  else if (angleFormat == "radians" || angleFormat == "radian")
190  {
191  convertToDegrees_ = false;
192  }
193  else
194  {
196  << "angleFormat must be degree, degrees, radian or radians"
197  << abort(FatalError);
198  }
199 
200  sDoFRBMRCoeffs_.readEntry("damping", damping_);
201 
202  return true;
203 }
204 
205 
207 (
208  Ostream& os
209 ) const
210 {
211  os.writeEntry("referenceOrientation", refQ_);
212  os.writeEntry("axis", axis_);
213 
214  moment_.write(os);
215 
216  if (convertToDegrees_)
217  {
218  os.writeEntry("angleFormat", "degrees");
219  }
220  else
221  {
222  os.writeEntry("angleFormat", "radians");
223  }
224 
225  os.writeEntry("damping", damping_);
226 }
227 
228 
229 // ************************************************************************* //
Foam::sixDoFRigidBodyMotionRestraint::read
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
Definition: sixDoFRigidBodyMotionRestraint.C:61
tabulatedAxialAngularSpring.H
Foam::sixDoFRigidBodyMotionRestraints::tabulatedAxialAngularSpring::write
virtual void write(Ostream &) const
Write.
Definition: tabulatedAxialAngularSpring.C:207
Foam::Tensor< scalar >
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::sixDoFRigidBodyMotion::orientation
const tensor & orientation() const
Return the orientation tensor, Q.
Definition: sixDoFRigidBodyMotionI.H:257
Foam::sixDoFRigidBodyMotionRestraints::tabulatedAxialAngularSpring::~tabulatedAxialAngularSpring
virtual ~tabulatedAxialAngularSpring()
Destructor.
Definition: tabulatedAxialAngularSpring.C:76
unitConversion.H
Unit conversion functions.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
sixDoFRigidBodyMotion.H
Foam::sixDoFRigidBodyMotionRestraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, linearAxialAngularSpring, dictionary)
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::sixDoFRigidBodyMotion::centreOfRotation
const point & centreOfRotation() const
Return the current centre of rotation.
Definition: sixDoFRigidBodyMotionI.H:231
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::sixDoFRigidBodyMotionRestraint
Base class for defining restraints for sixDoF motions.
Definition: sixDoFRigidBodyMotionRestraint.H:66
Foam::sixDoFRigidBodyMotionRestraints::defineTypeNameAndDebug
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
Foam::radToDeg
constexpr scalar radToDeg(const scalar rad) noexcept
Conversion from radians to degrees.
Definition: unitConversion.H:54
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::sixDoFRigidBodyMotion
Six degree of freedom motion for a rigid body.
Definition: sixDoFRigidBodyMotion.H:69
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< scalar >
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::acos
dimensionedScalar acos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:268
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::sixDoFRigidBodyMotion::report
bool report() const
Return the report Switch.
Definition: sixDoFRigidBodyMotionI.H:273
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::interpolationTable< scalar >
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
transform.H
3D tensor transformation operations.
Foam::rotationTensor
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Definition: transform.H:51
Foam::sixDoFRigidBodyMotionRestraints::tabulatedAxialAngularSpring::read
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Definition: tabulatedAxialAngularSpring.C:149
Foam::sixDoFRigidBodyMotion::omega
vector omega() const
Return the angular velocity in the global frame.
Definition: sixDoFRigidBodyMotionI.H:263
Foam::sixDoFRigidBodyMotionRestraints::tabulatedAxialAngularSpring::restrain
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
Definition: tabulatedAxialAngularSpring.C:84
Foam::I
static const Identity< scalar > I
Definition: Identity.H:95
Foam::sixDoFRigidBodyMotionRestraints::tabulatedAxialAngularSpring::tabulatedAxialAngularSpring
tabulatedAxialAngularSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
Definition: tabulatedAxialAngularSpring.C:57