linearSpring.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 | Copyright (C) 2011-2016 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  os.writeKeyword("anchor")
129  << anchor_ << token::END_STATEMENT << nl;
130 
131  os.writeKeyword("refAttachmentPt")
132  << refAttachmentPt_ << token::END_STATEMENT << nl;
133 
134  os.writeKeyword("stiffness")
135  << stiffness_ << token::END_STATEMENT << nl;
136 
137  os.writeKeyword("damping")
138  << damping_ << token::END_STATEMENT << nl;
139 
140  os.writeKeyword("restLength")
141  << restLength_ << token::END_STATEMENT << nl;
142 }
143 
144 // ************************************************************************* //
Six degree of freedom motion for a rigid body.
bool report() const
Return the report Switch.
point velocity(const point &pt) const
Return the velocity of a position.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void write(Ostream &) const
Write.
Definition: linearSpring.C:124
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
Definition: linearSpring.C:76
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:253
linearSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
Definition: linearSpring.C:51
Macros for easy insertion into run-time selection tables.
point transform(const point &initialPoints) const
Transform the given initial state point by the current motion.
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.
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
static const zero Zero
Definition: zero.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, linearAxialAngularSpring, dictionary)
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
Namespace for OpenFOAM.