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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
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 "linearSpring.H"
30 #include "sixDoFRigidBodyMotion.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace sixDoFRigidBodyMotionRestraints
37 {
38  defineTypeNameAndDebug(linearSpring, 0);
39 
41  (
42  sixDoFRigidBodyMotionRestraint,
43  linearSpring,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  const word& name,
55  const dictionary& sDoFRBMRDict
56 )
57 :
58  sixDoFRigidBodyMotionRestraint(name, sDoFRBMRDict),
59  anchor_(),
60  refAttachmentPt_(),
61  stiffness_(),
62  damping_(),
63  restLength_()
64 {
65  read(sDoFRBMRDict);
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 
72 {}
73 
74 
75 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
76 
78 (
79  const sixDoFRigidBodyMotion& motion,
80  vector& restraintPosition,
81  vector& restraintForce,
82  vector& restraintMoment
83 ) const
84 {
85  restraintPosition = motion.transform(refAttachmentPt_);
86 
87  vector r = restraintPosition - anchor_;
88 
89  scalar magR = mag(r);
90  r /= (magR + VSMALL);
91 
92  vector v = motion.velocity(restraintPosition);
93 
94  restraintForce = -stiffness_*(magR - restLength_)*r - damping_*(r & v)*r;
95 
96  restraintMoment = Zero;
97 
98  if (motion.report())
99  {
100  Info<< " attachmentPt - anchor " << r*magR
101  << " spring length " << magR
102  << " force " << restraintForce
103  << endl;
104  }
105 }
106 
107 
109 (
110  const dictionary& sDoFRBMRDict
111 )
112 {
114 
115  sDoFRBMRCoeffs_.readEntry("anchor", anchor_);
116  sDoFRBMRCoeffs_.readEntry("refAttachmentPt", refAttachmentPt_);
117  sDoFRBMRCoeffs_.readEntry("stiffness", stiffness_);
118  sDoFRBMRCoeffs_.readEntry("damping", damping_);
119  sDoFRBMRCoeffs_.readEntry("restLength", restLength_);
120 
121  return true;
122 }
123 
124 
126 (
127  Ostream& os
128 ) const
129 {
130  os.writeEntry("anchor", anchor_);
131  os.writeEntry("refAttachmentPt", refAttachmentPt_);
132  os.writeEntry("stiffness", stiffness_);
133  os.writeEntry("damping", damping_);
134  os.writeEntry("restLength", restLength_);
135 }
136 
137 // ************************************************************************* //
Foam::sixDoFRigidBodyMotionRestraint::read
virtual bool read(const dictionary &sDoFRBMRDict)
Update properties from given dictionary.
Definition: sixDoFRigidBodyMotionRestraint.C:61
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::sixDoFRigidBodyMotionRestraints::linearSpring::write
virtual void write(Ostream &) const
Write.
Definition: linearSpring.C:126
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::sixDoFRigidBodyMotion::velocity
point velocity(const point &pt) const
Return the velocity of a position.
Definition: sixDoFRigidBodyMotionI.H:292
Foam::sixDoFRigidBodyMotionRestraints::linearSpring::linearSpring
linearSpring(const word &name, const dictionary &sDoFRBMRDict)
Construct from components.
Definition: linearSpring.C:53
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
sixDoFRigidBodyMotion.H
Foam::sixDoFRigidBodyMotionRestraints::addToRunTimeSelectionTable
addToRunTimeSelectionTable(sixDoFRigidBodyMotionRestraint, linearAxialAngularSpring, dictionary)
linearSpring.H
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::sixDoFRigidBodyMotionRestraint
Base class for defining restraints for sixDoF motions.
Definition: sixDoFRigidBodyMotionRestraint.H:66
Foam::sixDoFRigidBodyMotionRestraints::defineTypeNameAndDebug
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
Foam::sixDoFRigidBodyMotionRestraints::linearSpring::read
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Definition: linearSpring.C:109
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
Foam::sixDoFRigidBodyMotionRestraints::linearSpring::restrain
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
Definition: linearSpring.C:78
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::sixDoFRigidBodyMotionRestraints::linearSpring::~linearSpring
virtual ~linearSpring()
Destructor.
Definition: linearSpring.C:71
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