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  << "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  os.writeKeyword("referenceOrientation")
149  << refQ_ << token::END_STATEMENT << nl;
150 
151  os.writeKeyword("stiffness") << stiffness_ << token::END_STATEMENT << nl;
152 
153  os.writeKeyword("damping") << damping_ << token::END_STATEMENT << nl;
154 }
155 
156 
157 // ************************************************************************* //
Foam::sixDoFRigidBodyMotionRestraint::read
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
Definition: sixDoFRigidBodyMotionRestraint.C:59
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::sixDoFRigidBodyMotion::orientation
const tensor & orientation() const
Return the orientation tensor, Q.
Definition: sixDoFRigidBodyMotionI.H:254
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
@ nComponents
Number of components in this vector space.
Definition: VectorSpace.H:88
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
sixDoFRigidBodyMotion.H
Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::restrain
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
Definition: sphericalAngularSpring.C:76
Foam::sixDoFRigidBodyMotionRestraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, linearAxialAngularSpring, dictionary)
Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::read
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Definition: sphericalAngularSpring.C:119
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::sixDoFRigidBodyMotionRestraint
Base class for defining restraints for sixDoF motions.
Definition: sixDoFRigidBodyMotionRestraint.H:64
Foam::sixDoFRigidBodyMotionRestraints::defineTypeNameAndDebug
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
Foam::I
static const sphericalTensor I(1)
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sixDoFRigidBodyMotion
Six degree of freedom motion for a rigid body.
Definition: sixDoFRigidBodyMotion.H:66
Foam::Vector< scalar >
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:142
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
sphericalAngularSpring.H
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::~sphericalAngularSpring
virtual ~sphericalAngularSpring()
Destructor.
Definition: sphericalAngularSpring.C:69
Foam::sixDoFRigidBodyMotion::report
bool report() const
Return the report Switch.
Definition: sixDoFRigidBodyMotionI.H:266
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::write
virtual void write(Ostream &) const
Write.
Definition: sphericalAngularSpring.C:144
Foam::sixDoFRigidBodyMotion::omega
vector omega() const
Return the angular velocity in the global frame.
Definition: sixDoFRigidBodyMotionI.H:260
Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::sphericalAngularSpring
sphericalAngularSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
Definition: sphericalAngularSpring.C:52
Foam::sixDoFRigidBodyMotion::centreOfRotation
const point & centreOfRotation() const
Return the current centre of rotation.
Definition: sixDoFRigidBodyMotionI.H:228
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47