Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
32#include "transform.H"
33#include "unitConversion.H"
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37namespace Foam
38{
40{
42
44 (
48 );
49}
50}
51
52
53// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54
57(
58 const word& name,
59 const dictionary& sDoFRBMRDict
60)
61:
63 refQ_(),
64 axis_(),
65 moment_(),
66 convertToDegrees_(),
67 damping_()
69 read(sDoFRBMRDict);
70}
71
72
73// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74
77{}
78
79
80// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
81
82void
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 }
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
An interpolation/look-up table of scalar vs <Type> values. The reference scalar values must be monoto...
Base class for defining restraints for sixDoF motions.
sixDoFRigidBodyMotionRestraint(const word &name, const dictionary &sDoFRBMRDict)
Construct from the sDoFRBMRDict dictionary and Time.
const word & name() const
Return the name.
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
dictionary sDoFRBMRCoeffs_
Restraint model specific coefficient dictionary.
sixDoFRigidBodyMotionRestraints model. Axial angular spring with moment values drawn from an interpol...
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
tabulatedAxialAngularSpring(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 Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
Namespace for six DoF motion restraints.
Namespace for OpenFOAM.
dimensionedScalar sign(const dimensionedScalar &ds)
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Definition transform.H:47
messageStream Info
Information stream (stdout output on master, null elsewhere).
static const Identity< scalar > I
Definition Identity.H:100
Tensor< scalar > tensor
Definition symmTensor.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
constexpr scalar radToDeg() noexcept
Multiplication factor for radians to degrees conversion.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
errorManip< error > abort(error &err)
Definition errorManip.H:139
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Vector< scalar > vector
Definition vector.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dimensionedScalar acos(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
3D tensor transformation operations.
Unit conversion functions.