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-------------------------------------------------------------------------------
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 "linearSpring.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace sixDoFRigidBodyMotionRestraints
37{
39
41 (
45 );
46}
47}
48
49
50// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51
53(
54 const word& name,
55 const dictionary& sDoFRBMRDict
56)
57:
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
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.
Linear spring restraint.
Definition: linearSpring.H:60
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.
Definition: linearSpring.H:57
virtual void restrain(const sixDoFRigidBodyMotion &motion, vector &restraintPosition, vector &restraintForce, vector &restraintMoment) const
Calculate the restraint position, force and moment.
Definition: linearSpring.C:78
virtual bool read(const dictionary &sDoFRBMRCoeff)
Update properties from given dictionary.
Definition: linearSpring.C:109
Six degree of freedom motion for a rigid body.
bool report() const
Return the report Switch.
point transform(const point &initialPoints) const
Transform the given initial state point by the current motion.
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.
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