linearSpringDamper.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) 2019-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "linearSpringDamper.H"
30 #include "sixDoFRigidBodyMotion.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace sixDoFRigidBodyMotionRestraints
38 {
39  defineTypeNameAndDebug(linearSpringDamper, 0);
40 
42  (
43  sixDoFRigidBodyMotionRestraint,
44  linearSpringDamper,
45  dictionary
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const word& name,
56  const dictionary& sDoFRBMRDict
57 )
58 :
60 {
61  oldRestraintForce_ = Zero;
62  read(sDoFRBMRDict);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
69 {}
70 
71 
72 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
73 
75 (
76  const sixDoFRigidBodyMotion& motion,
77  vector& restraintPosition,
78  vector& restraintForce,
79  vector& restraintMoment
80 ) const
81 {
82  if (!anchor_)
83  {
84  anchor_.reset
85  (
87  (
88  "anchor",
89  coeffDict(),
90  &motion.time()
91  )
92  );
93  }
94 
95  scalar t = motion.time().timeOutputValue();
96 
97  restraintPosition = motion.transform(refAttachmentPt_);
98 
99  // Current axis of the spring
100  vector r = restraintPosition - anchor_->value(t);
101  vector rDir = r/(mag(r) + VSMALL);
102 
103  vector v = motion.velocity(restraintPosition);
104 
105  scalar m = motion.mass();
106 
107  restraintMoment = Zero;
108 
109 // scalar dt = motion.time().deltaTValue();
110 //
111 // oldError_ = error_;
112 // oldErrorIntegral_ = errorIntegral_;
113 // error_ = (mag(r) - restLength_)/restLength_;
114 // errorIntegral_ =
115 // oldErrorIntegral_ + 0.5*(error_ + oldError_);
116 //
117 // scalar errorDifferential = (error_ - oldError_)/dt;
118 
119  if (mag(r) > restLength_)
120  {
121 
122 // factor_ =
123 // P_*error_ + I_*errorIntegral_ + D_*errorDifferential;
124 //
125 // factor_ = max(factor_, -1);
126 
127  scalar damping = psi_*2*m*wn_/numberOfChains_;
128  scalar stiffness = sqr(wn_)*m/numberOfChains_;
129 
130  restraintForce =
131  frelax_
132  *(
133  - damping*(rDir & v)*rDir
134  - stiffness*(mag(r) - restLength_)*rDir
135  )
136  + (1-frelax_)*oldRestraintForce_;
137 
138  oldRestraintForce_ = restraintForce;
139  }
140  else
141  {
142  restraintForce = Zero;
143  oldRestraintForce_ = Zero;
144  }
145 
146 
147  if (motion.report())
148  {
149  Info<< t << " " << restraintForce.x() //2
150  << " " << restraintForce.y() //3
151  << " " << restraintForce.z() //4
152  << " " << mag(r) - restLength_ //5
153  << endl;
154  }
155 }
156 
157 
159 (
160  const dictionary& sDoFRBMRDict
161 )
162 {
164 
165  sDoFRBMRCoeffs_.readEntry("refAttachmentPt", refAttachmentPt_);
166  psi_ = sDoFRBMRCoeffs_.getOrDefault<scalar>("psi", 1);
167  sDoFRBMRCoeffs_.readEntry("wn", wn_);
168  sDoFRBMRCoeffs_.readEntry("restLength", restLength_);
169  sDoFRBMRCoeffs_.readEntry("numberOfChains", numberOfChains_);
170  frelax_ = sDoFRBMRCoeffs_.getOrDefault<scalar>("frelax", 0.8);
171 
172  return true;
173 }
174 
175 
177 (
178  Ostream& os
179 ) const
180 {
181  os.writeEntry("refAttachmentPt", refAttachmentPt_);
182  os.writeEntry("psi", psi_);
183  os.writeEntry("wn", wn_);
184  os.writeEntry("restLength", restLength_);
185  os.writeEntry("numberOfChains", numberOfChains_);
186  os.writeEntryIfDifferent<scalar>("psi", 1, psi_);
187  os.writeEntryIfDifferent<scalar>("frelax", 0.8, frelax_);
188 }
189 
190 
191 // ************************************************************************* //
Six degree of freedom motion for a rigid body.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
bool report() const
Return the report Switch.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
linearSpringDamper(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Base class for defining restraints for sixDoF motions.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
point transform(const point &initialPoints) const
Transform the given initial state point by the current motion.
Macros for easy insertion into run-time selection tables.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, linearAxialAngularSpring, dictionary)
point velocity(const point &pt) const
Return the velocity of a position.
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
const Time & time() const
Return time.
scalar timeOutputValue() const
Return the current user-time value. (ie, after applying any timeToUserTime() conversion) ...
Definition: TimeStateI.H:24
scalar mass() const
Return the mass.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127