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 -------------------------------------------------------------------------------
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 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace sixDoFRigidBodyMotionRestraints
39 {
41 
43  (
47  );
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
56 (
57  const word& name,
58  const dictionary& sDoFRBMRDict
59 )
60 :
61  sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict),
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 
80 void
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 // ************************************************************************* //
Foam::sixDoFRigidBodyMotionRestraint::read
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
Definition: sixDoFRigidBodyMotionRestraint.C:61
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::linearAxialAngularSpring::linearAxialAngularSpring
linearAxialAngularSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
Definition: linearAxialAngularSpring.C:56
Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::restrain
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
Definition: linearAxialAngularSpring.C:82
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::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.
linearAxialAngularSpring.H
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::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::read
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Definition: linearAxialAngularSpring.C:148
Foam::sixDoFRigidBodyMotion::report
bool report() const
Return the report Switch.
Definition: sixDoFRigidBodyMotionI.H:273
Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring
sixDoFRigidBodyMotionRestraints model. Linear axial angular spring.
Definition: linearAxialAngularSpring.H:55
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
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::sixDoFRigidBodyMotion::omega
vector omega() const
Return the angular velocity in the global frame.
Definition: sixDoFRigidBodyMotionI.H:263
Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::~linearAxialAngularSpring
virtual ~linearAxialAngularSpring()
Destructor.
Definition: linearAxialAngularSpring.C:74
Foam::I
static const Identity< scalar > I
Definition: Identity.H:95
Foam::sixDoFRigidBodyMotionRestraints::linearAxialAngularSpring::write
virtual void write(Ostream &) const
Write.
Definition: linearAxialAngularSpring.C:188