linearAxialAngularSpring.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) 2016-2017 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
30#include "rigidBodyModel.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
37namespace RBD
38{
39namespace restraints
40{
42
44 (
48 );
49}
50}
51}
52
53
54// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55
57(
58 const word& name,
59 const dictionary& dict,
60 const rigidBodyModel& model
61)
62:
63 restraint(name, dict, model)
64{
65 read(dict);
66}
67
68
69// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70
72{}
73
74
75// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
76
78(
79 scalarField& tau,
81 const rigidBodyModelState& state
82) const
83{
84 vector refDir = rotationTensor(vector(1, 0, 0), axis_) & vector(0, 1, 0);
85
86 vector oldDir = refQ_ & refDir;
87 vector newDir = model_.X0(bodyID_).E() & refDir;
88
89 if (mag(oldDir & axis_) > 0.95 || mag(newDir & axis_) > 0.95)
90 {
91 // Directions close to the axis, changing reference
92 refDir = rotationTensor(vector(1, 0, 0), axis_) & vector(0, 0, 1);
93 oldDir = refQ_ & refDir;
94 newDir = model_.X0(bodyID_).E() & refDir;
95 }
96
97 // Removing axis component from oldDir and newDir and normalising
98 oldDir -= (axis_ & oldDir)*axis_;
99 oldDir /= (mag(oldDir) + VSMALL);
100
101 newDir -= (axis_ & newDir)*axis_;
102 newDir /= (mag(newDir) + VSMALL);
103
104 scalar theta = mag(acos(min(oldDir & newDir, 1.0)));
105
106 // Temporary axis with sign information
107 vector a = (oldDir ^ newDir);
108
109 // Ensure a is in direction of axis
110 a = (a & axis_)*axis_;
111
112 scalar magA = mag(a);
113
114 if (magA > VSMALL)
115 {
116 a /= magA;
117 }
118 else
119 {
120 a = Zero;
121 }
122
123 // Damping of along axis angular velocity only
124 vector moment
125 (
126 -(
127 stiffness_*theta
128 + damping_*(model_.v(model_.master(bodyID_)).w() & a)
129 )*a
130 );
131
132 if (model_.debug)
133 {
134 Info<< " angle " << theta*sign(a & axis_)
135 << " moment " << moment
136 << endl;
137 }
138
139 // Accumulate the force for the restrained body
140 fx[bodyIndex_] += model_.X0(bodyID_).T() & spatialVector(moment, Zero);
141}
142
143
145(
146 const dictionary& dict
147)
148{
150
151 refQ_ = coeffs_.getOrDefault<tensor>("referenceOrientation", I);
152
153 if (mag(mag(refQ_) - sqrt(3.0)) > ROOTSMALL)
154 {
156 << "referenceOrientation " << refQ_ << " is not a rotation tensor. "
157 << "mag(referenceOrientation) - sqrt(3) = "
158 << mag(refQ_) - sqrt(3.0) << nl
159 << exit(FatalError);
160 }
161
162 coeffs_.readEntry("axis", axis_);
163
164 const scalar magAxis(mag(axis_));
165
166 if (magAxis > VSMALL)
167 {
168 axis_ /= magAxis;
169 }
170 else
171 {
173 << "axis has zero length"
174 << abort(FatalError);
175 }
176
177 coeffs_.readEntry("stiffness", stiffness_);
178 coeffs_.readEntry("damping", damping_);
179
180 return true;
181}
182
183
185(
186 Ostream& os
187) const
188{
190
191 os.writeEntry("referenceOrientation", refQ_);
192 os.writeEntry("axis", axis_);
193 os.writeEntry("stiffness", stiffness_);
194 os.writeEntry("damping", damping_);
195}
196
197
198// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:605
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.
Base class for defining restraints for rigid-body dynamics.
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
virtual void restrain(scalarField &tau, Field< spatialVector > &fx, const rigidBodyModelState &state) const
Accumulate the restraint internal joint forces into the tau field and.
Holds the motion state of rigid-body model.
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints.
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.
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.
dimensionedScalar sign(const dimensionedScalar &ds)
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Definition: transform.H:51
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)
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:50
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
errorManip< error > abort(error &err)
Definition: errorManip.H:144
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
Vector< scalar > vector
Definition: vector.H:61
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dimensionedScalar acos(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict