linearAxialAngularSpring.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
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38namespace sixDoFRigidBodyMotionRestraints
39{
41
43 (
47 );
48}
49}
50
51
52// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53
54Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::
55linearAxialAngularSpring
56(
57 const word& name,
58 const dictionary& sDoFRBMRDict
59)
60:
62 refQ_(),
63 axis_(),
64 stiffness_(),
65 damping_()
66{
67 read(sDoFRBMRDict);
68}
69
70
71// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
72
75{}
76
77
78// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
79
80void
82(
83 const sixDoFRigidBodyMotion& motion,
84 vector& restraintPosition,
85 vector& restraintForce,
86 vector& restraintMoment
87) const
88{
89 vector refDir = rotationTensor(vector(1, 0 ,0), axis_) & vector(0, 1, 0);
90
91 vector oldDir = refQ_ & refDir;
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 // Temporary axis with sign information.
113 vector a = (oldDir ^ newDir);
114
115 // Remove any component that is not along axis that may creep in
116 a = (a & axis_)*axis_;
117
118 scalar magA = mag(a);
119
120 if (magA > VSMALL)
121 {
122 a /= magA;
123 }
124 else
125 {
126 a = Zero;
127 }
128
129 // Damping of along axis angular velocity only
130 restraintMoment = -stiffness_*theta*a - damping_*(motion.omega() & a)*a;
131
132 restraintForce = Zero;
133
134 // Not needed to be altered as restraintForce is zero, but set to
135 // centreOfRotation to be sure of no spurious moment
136 restraintPosition = motion.centreOfRotation();
137
138 if (motion.report())
139 {
140 Info<< " angle " << theta*sign(a & axis_)
141 << " moment " << restraintMoment
142 << endl;
143 }
144}
145
146
148(
149 const dictionary& sDoFRBMRDict
150)
151{
153
154 refQ_ = sDoFRBMRCoeffs_.getOrDefault<tensor>("referenceOrientation", I);
155
156 if (mag(mag(refQ_) - sqrt(3.0)) > ROOTSMALL)
157 {
159 << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
160 << "mag(referenceOrientation) - sqrt(3) = "
161 << mag(refQ_) - sqrt(3.0) << nl
162 << exit(FatalError);
163 }
164
165 sDoFRBMRCoeffs_.readEntry("axis", axis_);
166
167 const scalar magAxis(mag(axis_));
168
169 if (magAxis > VSMALL)
170 {
171 axis_ /= magAxis;
172 }
173 else
174 {
176 << "axis has zero length"
177 << abort(FatalError);
178 }
179
180 sDoFRBMRCoeffs_.readEntry("stiffness", stiffness_);
181 sDoFRBMRCoeffs_.readEntry("damping", damping_);
182
183 return true;
184}
185
186
188(
189 Ostream& os
190) const
191{
192 os.writeEntry("referenceOrientation", refQ_);
193 os.writeEntry("axis", axis_);
194 os.writeEntry("stiffness", stiffness_);
195 os.writeEntry("damping", damping_);
196}
197
198// ************************************************************************* //
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:62
virtual bool read()
Re-read model coefficients if they have changed.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
virtual bool write()
Write the output fields.
Base class for defining restraints for sixDoF motions.
sixDoFRigidBodyMotionRestraints model. Linear axial angular spring.
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
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:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
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:51
messageStream Info
Information stream (stdout output on master, null elsewhere)
static const Identity< scalar > I
Definition: Identity.H:94
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
errorManip< error > abort(error &err)
Definition: errorManip.H:144
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Vector< scalar > vector
Definition: vector.H:61
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dimensionedScalar acos(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
3D tensor transformation operations.