FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sixDoFRigidBodyMotionRestraints
35 {
36  defineTypeNameAndDebug(linearSpring, 0);
38  (
39  sixDoFRigidBodyMotionRestraint,
40  linearSpring,
41  dictionary
42  );
43 };
44 };
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const dictionary& sDoFRBMRDict
52 )
53 :
54  sixDoFRigidBodyMotionRestraint(sDoFRBMRDict),
55  anchor_(),
56  refAttachmentPt_(),
57  stiffness_(),
58  damping_(),
59  restLength_()
60 {
61  read(sDoFRBMRDict);
62 }
63 
64 
65 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
66 
68 {}
69 
70 
71 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
72 
74 (
75  const sixDoFRigidBodyMotion& motion,
76  vector& restraintPosition,
77  vector& restraintForce,
78  vector& restraintMoment
79 ) const
80 {
81  restraintPosition = motion.currentPosition(refAttachmentPt_);
82 
83  vector r = restraintPosition - anchor_;
84 
85  scalar magR = mag(r);
86 
87  // r is now the r unit vector
88  r /= (magR + VSMALL);
89 
90  vector v = motion.currentVelocity(restraintPosition);
91 
92  restraintForce = -stiffness_*(magR - restLength_)*r - damping_*(r & v)*r;
93 
94  restraintMoment = vector::zero;
95 
96  if (motion.report())
97  {
98  Info<< " attachmentPt - anchor " << r*magR
99  << " spring length " << magR
100  << " force " << restraintForce
101  << " moment " << restraintMoment
102  << endl;
103  }
104 }
105 
106 
108 (
109  const dictionary& sDoFRBMRDict
110 )
111 {
113 
114  sDoFRBMRCoeffs_.lookup("anchor") >> anchor_;
115 
116  sDoFRBMRCoeffs_.lookup("refAttachmentPt") >> refAttachmentPt_;
117 
118  sDoFRBMRCoeffs_.lookup("stiffness") >> stiffness_;
119 
120  sDoFRBMRCoeffs_.lookup("damping") >> damping_;
121 
122  sDoFRBMRCoeffs_.lookup("restLength") >> restLength_;
123 
124  return true;
125 }
126 
127 
129 (
130  Ostream& os
131 ) const
132 {
133  os.writeKeyword("anchor")
134  << anchor_ << token::END_STATEMENT << nl;
135 
136  os.writeKeyword("refAttachmentPt")
137  << refAttachmentPt_ << token::END_STATEMENT << nl;
138 
139  os.writeKeyword("stiffness")
140  << stiffness_ << token::END_STATEMENT << nl;
141 
142  os.writeKeyword("damping")
143  << damping_ << token::END_STATEMENT << nl;
144 
145  os.writeKeyword("restLength")
146  << restLength_ << token::END_STATEMENT << nl;
147 }
148 
149 // ************************ vim: set sw=4 sts=4 et: ************************ //