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-------------------------------------------------------------------------------
10License
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"
31#include "Time.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
37namespace sixDoFRigidBodyMotionRestraints
38{
40
42 (
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:96
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
scalar timeOutputValue() const
Return current time value.
Definition: TimeStateI.H:31
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
virtual bool write()
Write the output fields.
Base class for defining restraints for sixDoF motions.
sixDoFRigidBodyMotionRestraints model. Linear Spring-Damper system.
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Six degree of freedom motion for a rigid body.
bool report() const
Return the report Switch.
const Time & time() const
Return time.
point transform(const point &initialPoints) const
Transform the given initial state point by the current motion.
scalar mass() const
Return the mass.
point velocity(const point &pt) const
Return the velocity of a position.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59