sphericalAngularSpring.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 | Copyright (C) 2011-2015 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 = vector::zero;
84 
85  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
86  {
87  vector axis = vector::zero;
88  axis[cmpt] = 1;
89 
90  vector refDir = vector::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 = vector::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  (
131  "Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::"
132  "read"
133  "("
134  "const dictionary& sDoFRBMRDict"
135  ")"
136  )
137  << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
138  << "mag(referenceOrientation) - sqrt(3) = "
139  << mag(refQ_) - sqrt(3.0) << nl
140  << exit(FatalError);
141  }
142 
143  sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
144  sDoFRBMRCoeffs_.lookup("damping") >> damping_;
145 
146  return true;
147 }
148 
149 
151 (
152  Ostream& os
153 ) const
154 {
155  os.writeKeyword("referenceOrientation")
156  << refQ_ << token::END_STATEMENT << nl;
157 
158  os.writeKeyword("stiffness") << stiffness_ << token::END_STATEMENT << nl;
159 
160  os.writeKeyword("damping") << damping_ << token::END_STATEMENT << nl;
161 }
162 
163 
164 // ************************************************************************* //
dimensionedScalar sqrt(const dimensionedScalar &ds)
unsigned char direction
Definition: direction.H:43
dimensioned< scalar > mag(const dimensioned< Type > &)
const tensor & orientation() const
Return the orientation tensor, Q.
static const sphericalTensor I(1)
A class for handling words, derived from string.
Definition: word.H:59
Base class for defining restraints for sixDoF motions.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
messageStream Info
bool report() const
Return the report Switch.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
Number of components in this vector space.
Definition: VectorSpace.H:88
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, linearAxialAngularSpring, dictionary)
static const char nl
Definition: Ostream.H:260
const double e
Elementary charge.
Definition: doubleFloat.H:78
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
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.
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Macros for easy insertion into run-time selection tables.
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
vector omega() const
Return the angular velocity in the global frame.
static const Vector zero
Definition: Vector.H:80
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Six degree of freedom motion for a rigid body.
const point & centreOfRotation() const
Return the current centre of rotation.