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 | 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 
29 #include "sphericalAngularSpring.H"
31 #include "sixDoFRigidBodyMotion.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace sixDoFRigidBodyMotionRestraints
38 {
39  defineTypeNameAndDebug(sphericalAngularSpring, 0);
40 
42  (
43  sixDoFRigidBodyMotionRestraint,
44  sphericalAngularSpring,
45  dictionary
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
55 (
56  const word& name,
57  const dictionary& sDoFRBMRDict
58 )
59 :
60  sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict),
61  refQ_(),
62  stiffness_(),
63  damping_()
64 {
65  read(sDoFRBMRDict);
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 
73 {}
74 
75 
76 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
77 
79 (
80  const sixDoFRigidBodyMotion& motion,
81  vector& restraintPosition,
82  vector& restraintForce,
83  vector& restraintMoment
84 ) const
85 {
86  restraintMoment = Zero;
87 
88  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
89  {
90  vector axis = Zero;
91  axis[cmpt] = 1;
92 
93  vector refDir = Zero;
94  refDir[(cmpt + 1) % 3] = 1;
95 
96  vector newDir = motion.orientation() & refDir;
97 
98  axis = (refQ_ & axis);
99  refDir = (refQ_ & refDir);
100  newDir -= (axis & newDir)*axis;
101 
102  restraintMoment += -stiffness_*(refDir ^ newDir);
103  }
104 
105  restraintMoment += -damping_*motion.omega();
106 
107  restraintForce = Zero;
108 
109  // Not needed to be altered as restraintForce is zero, but set to
110  // centreOfRotation to be sure of no spurious moment
111  restraintPosition = motion.centreOfRotation();
112 
113  if (motion.report())
114  {
115  Info<< " moment " << restraintMoment
116  << endl;
117  }
118 }
119 
120 
122 (
123  const dictionary& sDoFRBMRDict
124 )
125 {
127 
128  refQ_ = sDoFRBMRCoeffs_.getOrDefault<tensor>("referenceOrientation", I);
129 
130  if (mag(mag(refQ_) - sqrt(3.0)) > ROOTSMALL)
131  {
133  << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
134  << "mag(referenceOrientation) - sqrt(3) = "
135  << mag(refQ_) - sqrt(3.0) << nl
136  << exit(FatalError);
137  }
138 
139  sDoFRBMRCoeffs_.readEntry("stiffness", stiffness_);
140  sDoFRBMRCoeffs_.readEntry("damping", damping_);
141 
142  return true;
143 }
144 
145 
147 (
148  Ostream& os
149 ) const
150 {
151  os.writeEntry("referenceOrientation", refQ_);
152  os.writeEntry("stiffness", stiffness_);
153  os.writeEntry("damping", damping_);
154 }
155 
156 
157 // ************************************************************************* //
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
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:79
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::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::read
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Definition: sphericalAngularSpring.C:122
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.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
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::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
sphericalAngularSpring.H
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::~sphericalAngularSpring
virtual ~sphericalAngularSpring()
Destructor.
Definition: sphericalAngularSpring.C:72
Foam::sixDoFRigidBodyMotion::report
bool report() const
Return the report Switch.
Definition: sixDoFRigidBodyMotionI.H:273
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
Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::write
virtual void write(Ostream &) const
Write.
Definition: sphericalAngularSpring.C:147
Foam::sixDoFRigidBodyMotion::omega
vector omega() const
Return the angular velocity in the global frame.
Definition: sixDoFRigidBodyMotionI.H:263
Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::sphericalAngularSpring
sphericalAngularSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
Definition: sphericalAngularSpring.C:55
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
static constexpr direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:101
Foam::I
static const Identity< scalar > I
Definition: Identity.H:95