linearSpring.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 "linearSpring.H"
28 #include "sixDoFRigidBodyMotion.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sixDoFRigidBodyMotionRestraints
35 {
36  defineTypeNameAndDebug(linearSpring, 0);
37 
39  (
40  sixDoFRigidBodyMotionRestraint,
41  linearSpring,
42  dictionary
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  const word& name,
53  const dictionary& sDoFRBMRDict
54 )
55 :
56  sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict),
57  anchor_(),
58  refAttachmentPt_(),
59  stiffness_(),
60  damping_(),
61  restLength_()
62 {
63  read(sDoFRBMRDict);
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
68 
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  restraintPosition = motion.transform(refAttachmentPt_);
84 
85  vector r = restraintPosition - anchor_;
86 
87  scalar magR = mag(r);
88  r /= (magR + vSmall);
89 
90  vector v = motion.velocity(restraintPosition);
91 
92  restraintForce = -stiffness_*(magR - restLength_)*r - damping_*(r & v)*r;
93 
94  restraintMoment = Zero;
95 
96  if (motion.report())
97  {
98  Info<< " attachmentPt - anchor " << r*magR
99  << " spring length " << magR
100  << " force " << restraintForce
101  << endl;
102  }
103 }
104 
105 
107 (
108  const dictionary& sDoFRBMRDict
109 )
110 {
112 
113  sDoFRBMRCoeffs_.lookup("anchor") >> anchor_;
114  sDoFRBMRCoeffs_.lookup("refAttachmentPt") >> refAttachmentPt_;
115  sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
116  sDoFRBMRCoeffs_.lookup("damping") >> damping_;
117  sDoFRBMRCoeffs_.lookup("restLength") >> restLength_;
118 
119  return true;
120 }
121 
122 
124 (
125  Ostream& os
126 ) const
127 {
128  writeEntry(os, "anchor", anchor_);
129 
130  writeEntry(os, "refAttachmentPt", refAttachmentPt_);
131 
132  writeEntry(os, "stiffness", stiffness_);
133 
134  writeEntry(os, "damping", damping_);
135 
136  writeEntry(os, "restLength", restLength_);
137 }
138 
139 // ************************************************************************* //
Six degree of freedom motion for a rigid body.
bool report() const
Return the report Switch.
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
Definition: linearSpring.C:76
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
Base class for defining restraints for sixDoF motions.
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Definition: linearSpring.C:107
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
point transform(const point &initialPoints) const
Transform the given initial state point by the current motion.
linearSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
Definition: linearSpring.C:51
Macros for easy insertion into run-time selection tables.
virtual void write(Ostream &) const
Write.
Definition: linearSpring.C:124
defineTypeNameAndDebug(axialAngularSpring, 0)
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, axialAngularSpring, dictionary)
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
static const zero Zero
Definition: zero.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
point velocity(const point &pt) const
Return the velocity of a position.
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
Namespace for OpenFOAM.