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 // ************************************************************************* //
Foam::sixDoFRigidBodyMotionRestraint::read
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
Definition: sixDoFRigidBodyMotionRestraint.C:61
Foam::TimeState::timeOutputValue
scalar timeOutputValue() const
Return current time value.
Definition: TimeStateI.H:31
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::sixDoFRigidBodyMotion::mass
scalar mass() const
Return the mass.
Definition: sixDoFRigidBodyMotionI.H:211
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::sixDoFRigidBodyMotionRestraints::linearSpringDamper::restrain
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
Definition: linearSpringDamper.C:75
Foam::sixDoFRigidBodyMotion::velocity
point velocity(const point &pt) const
Return the velocity of a position.
Definition: sixDoFRigidBodyMotionI.H:292
Foam::sixDoFRigidBodyMotionRestraints::linearSpringDamper::read
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Definition: linearSpringDamper.C:159
linearSpringDamper.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::sixDoFRigidBodyMotion::time
const Time & time() const
Return time.
Definition: sixDoFRigidBodyMotionI.H:268
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
sixDoFRigidBodyMotion.H
Foam::sixDoFRigidBodyMotionRestraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, linearAxialAngularSpring, dictionary)
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::sixDoFRigidBodyMotionRestraints::linearSpringDamper::~linearSpringDamper
virtual ~linearSpringDamper()
Destructor.
Definition: linearSpringDamper.C:68
Foam::sixDoFRigidBodyMotionRestraints::linearSpringDamper::linearSpringDamper
linearSpringDamper(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
Definition: linearSpringDamper.C:54
Foam::sixDoFRigidBodyMotionRestraint
Base class for defining restraints for sixDoF motions.
Definition: sixDoFRigidBodyMotionRestraint.H:66
Foam::sixDoFRigidBodyMotionRestraints::linearSpringDamper::write
virtual void write(Ostream &) const
Write.
Definition: linearSpringDamper.C:177
Foam::sixDoFRigidBodyMotionRestraints::defineTypeNameAndDebug
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
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
Time.H
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::sixDoFRigidBodyMotion
Six degree of freedom motion for a rigid body.
Definition: sixDoFRigidBodyMotion.H:69
Foam::sixDoFRigidBodyMotion::transform
point transform(const point &initialPoints) const
Transform the given initial state point by the current motion.
Definition: sixDoFRigidBodyMotionI.H:301
Foam::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::sixDoFRigidBodyMotion::report
bool report() const
Return the report Switch.
Definition: sixDoFRigidBodyMotionI.H:273
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56