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 | Copyright (C) 2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "linearSpring.H"
27 #include "rigidBodyModel.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace RBD
35 {
36 namespace restraints
37 {
38  defineTypeNameAndDebug(linearSpring, 0);
39 
41  (
42  restraint,
43  linearSpring,
44  dictionary
45  );
46 }
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const word& name,
56  const dictionary& dict,
57  const rigidBodyModel& model
58 )
59 :
60  restraint(name, dict, model)
61 {
62  read(dict);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
69 {}
70 
71 
72 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
73 
75 (
76  scalarField& tau,
78 ) const
79 {
80  point attachmentPt = bodyPoint(refAttachmentPt_);
81 
82  // Current axis of the spring
83  vector r = attachmentPt - anchor_;
84  scalar magR = mag(r);
85  r /= (magR + VSMALL);
86 
87  // Velocity of the attached end of the spring
88  vector v = bodyPointVelocity(refAttachmentPt_).l();
89 
90  // Force and moment on the master body including optional damping
91  vector force
92  (
93  (-stiffness_*(magR - restLength_) - damping_*(r & v))*r
94  );
95 
96  vector moment(attachmentPt ^ force);
97 
98  if (model_.debug)
99  {
100  Info<< " attachmentPt " << attachmentPt
101  << " attachmentPt - anchor " << r*magR
102  << " spring length " << magR
103  << " force " << force
104  << " moment " << moment
105  << endl;
106  }
107 
108  // Accumulate the force for the restrained body
109  fx[bodyIndex_] += spatialVector(moment, force);
110 }
111 
112 
114 (
115  const dictionary& dict
116 )
117 {
118  restraint::read(dict);
119 
120  coeffs_.lookup("anchor") >> anchor_;
121  coeffs_.lookup("refAttachmentPt") >> refAttachmentPt_;
122  coeffs_.lookup("stiffness") >> stiffness_;
123  coeffs_.lookup("damping") >> damping_;
124  coeffs_.lookup("restLength") >> restLength_;
125 
126  return true;
127 }
128 
129 
131 (
132  Ostream& os
133 ) const
134 {
135  restraint::write(os);
136 
137  os.writeKeyword("anchor")
138  << anchor_ << token::END_STATEMENT << nl;
139 
140  os.writeKeyword("refAttachmentPt")
141  << refAttachmentPt_ << token::END_STATEMENT << nl;
142 
143  os.writeKeyword("stiffness")
144  << stiffness_ << token::END_STATEMENT << nl;
145 
146  os.writeKeyword("damping")
147  << damping_ << token::END_STATEMENT << nl;
148 
149  os.writeKeyword("restLength")
150  << restLength_ << token::END_STATEMENT << nl;
151 }
152 
153 
154 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
linearSpring(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from components.
Definition: linearSpring.C:54
Base class for defining restraints for rigid-body dynamics.
virtual void write(Ostream &) const
Write.
Definition: linearSpring.C:131
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
Definition: linearSpring.C:114
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Macros for easy insertion into run-time selection tables.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
A class for handling words, derived from string.
Definition: word.H:59
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:47
virtual void restrain(scalarField &tau, Field< spatialVector > &fx) const
Accumulate the retraint internal joint forces into the tau field and.
Definition: linearSpring.C:75
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
virtual ~linearSpring()
Destructor.
Definition: linearSpring.C:68
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(linearAxialAngularSpring, 0)
addToRunTimeSelectionTable(restraint, linearAxialAngularSpring, dictionary)
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints...
virtual void write(Ostream &) const =0
Write.
Namespace for OpenFOAM.