sphericalAngularSpring.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-2019 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 "sphericalAngularSpring.H"
28 #include "sixDoFRigidBodyMotion.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sixDoFRigidBodyMotionRestraints
35 {
36  defineTypeNameAndDebug(sphericalAngularSpring, 0);
37 
39  (
40  sixDoFRigidBodyMotionRestraint,
41  sphericalAngularSpring,
42  dictionary
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
52 (
53  const word& name,
54  const dictionary& sDoFRBMRDict
55 )
56 :
57  sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict),
58  refQ_(),
59  stiffness_(),
60  damping_()
61 {
62  read(sDoFRBMRDict);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
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  restraintMoment = Zero;
84 
85  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
86  {
87  vector axis = Zero;
88  axis[cmpt] = 1;
89 
90  vector refDir = Zero;
91  refDir[(cmpt + 1) % 3] = 1;
92 
93  vector newDir = motion.orientation() & refDir;
94 
95  axis = (refQ_ & axis);
96  refDir = (refQ_ & refDir);
97  newDir -= (axis & newDir)*axis;
98 
99  restraintMoment += -stiffness_*(refDir ^ newDir);
100  }
101 
102  restraintMoment += -damping_*motion.omega();
103 
104  restraintForce = Zero;
105 
106  // Not needed to be altered as restraintForce is zero, but set to
107  // centreOfRotation to be sure of no spurious moment
108  restraintPosition = motion.centreOfRotation();
109 
110  if (motion.report())
111  {
112  Info<< " moment " << restraintMoment
113  << endl;
114  }
115 }
116 
117 
119 (
120  const dictionary& sDoFRBMRDict
121 )
122 {
124 
125  refQ_ = sDoFRBMRCoeffs_.lookupOrDefault<tensor>("referenceOrientation", I);
126 
127  if (mag(mag(refQ_) - sqrt(3.0)) > 1e-9)
128  {
130  << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
131  << "mag(referenceOrientation) - sqrt(3) = "
132  << mag(refQ_) - sqrt(3.0) << nl
133  << exit(FatalError);
134  }
135 
136  sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
137  sDoFRBMRCoeffs_.lookup("damping") >> damping_;
138 
139  return true;
140 }
141 
142 
144 (
145  Ostream& os
146 ) const
147 {
148  writeEntry(os, "referenceOrientation", refQ_);
149 
150  writeEntry(os, "stiffness", stiffness_);
151 
152  writeEntry(os, "damping", damping_);
153 }
154 
155 
156 // ************************************************************************* //
Six degree of freedom motion for a rigid body.
bool report() const
Return the report Switch.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
const point & centreOfRotation() const
Return the current centre of rotation.
uint8_t direction
Definition: direction.H:45
Base class for defining restraints for sixDoF motions.
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Macros for easy insertion into run-time selection tables.
defineTypeNameAndDebug(axialAngularSpring, 0)
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, axialAngularSpring, dictionary)
bool read(const char *, int32_t &)
Definition: int32IO.C:85
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:99
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
static const Identity< scalar > I
Definition: Identity.H:93
vector omega() const
Return the angular velocity in the global frame.
A class for handling words, derived from string.
Definition: word.H:59
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
const tensor & orientation() const
Return the orientation tensor, Q.
static const zero Zero
Definition: zero.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
sphericalAngularSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105
Namespace for OpenFOAM.