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-------------------------------------------------------------------------------
11License
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
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
37namespace sixDoFRigidBodyMotionRestraints
38{
40
42 (
46 );
47}
48}
49
50
51// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52
53Foam::sixDoFRigidBodyMotionRestraints::sphericalAngularSpring::
54sphericalAngularSpring
55(
56 const word& name,
57 const dictionary& sDoFRBMRDict
58)
59:
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
virtual bool write()
Write the output fields.
static constexpr direction nComponents
Number of components in bool is 1.
Definition: bool.H:98
Base class for defining restraints for sixDoF motions.
sixDoFRigidBodyMotionRestraints model. Spherical angular spring.
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.
Six degree of freedom motion for a rigid body.
bool report() const
Return the report Switch.
const tensor & orientation() const
Return the orientation tensor, Q.
vector omega() const
Return the angular velocity in the global frame.
const point & centreOfRotation() const
Return the current centre of rotation.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
static const Identity< scalar > I
Definition: Identity.H:94
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
uint8_t direction
Definition: direction.H:56
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53