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 -------------------------------------------------------------------------------
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 
30 #include "rigidBodyModel.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace RBD
38 {
39 namespace restraints
40 {
41  defineTypeNameAndDebug(linearAxialAngularSpring, 0);
42 
44  (
45  restraint,
46  linearAxialAngularSpring,
47  dictionary
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 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::RBD::restraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(restraint, externalForce, dictionary)
Foam::RBD::restraints::defineTypeNameAndDebug
defineTypeNameAndDebug(externalForce, 0)
Foam::RBD::rigidBodyModelState
Holds the motion state of rigid-body model.
Definition: rigidBodyModelState.H:67
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::RBD::restraints::linearAxialAngularSpring::linearAxialAngularSpring
linearAxialAngularSpring(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from components.
Definition: linearAxialAngularSpring.C:57
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
rigidBodyModel.H
Foam::RBD::restraints::linearAxialAngularSpring::~linearAxialAngularSpring
virtual ~linearAxialAngularSpring()
Destructor.
Definition: linearAxialAngularSpring.C:71
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::RBD::restraints::linearAxialAngularSpring::read
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
Definition: linearAxialAngularSpring.C:145
linearAxialAngularSpring.H
Foam::Field::T
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors)
Definition: Field.C:599
Foam::RBD::restraint::read
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
Definition: rigidBodyRestraint.C:74
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::RBD::rigidBodyModel
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints.
Definition: rigidBodyModel.H:83
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::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::RBD::restraints::linearAxialAngularSpring::write
virtual void write(Ostream &) const
Write.
Definition: linearAxialAngularSpring.C:185
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< scalar >
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::acos
dimensionedScalar acos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:268
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::RBD::restraint::write
virtual void write(Ostream &) const =0
Write.
Definition: rigidBodyRestraint.C:81
Foam::RBD::restraint
Base class for defining restraints for rigid-body dynamics.
Definition: rigidBodyRestraint.H:68
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::spatialVector
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:50
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::rotationTensor
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Definition: transform.H:51
Foam::RBD::restraints::linearAxialAngularSpring::restrain
virtual void restrain(scalarField &tau, Field< spatialVector > &fx, const rigidBodyModelState &state) const
Accumulate the restraint internal joint forces into the tau field and.
Definition: linearAxialAngularSpring.C:78
Foam::I
static const Identity< scalar > I
Definition: Identity.H:95