linearSpring.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2019 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 {
39 
41  (
42  restraint,
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 rigidBodyModelState& state
79 ) const
80 {
81  point attachmentPt = bodyPoint(refAttachmentPt_);
82 
83  // Current axis of the spring
84  vector r = attachmentPt - anchor_;
85  scalar magR = mag(r);
86  r /= (magR + vSmall);
87 
88  // Velocity of the attached end of the spring
89  vector v = bodyPointVelocity(refAttachmentPt_).l();
90 
91  // Force and moment on the master body including optional damping
92  vector force
93  (
94  (allowSlack_ && magR < restLength_)
95  ? -damping_*(r & v)*r
96  : (-stiffness_*(magR - restLength_) - damping_*(r & v))*r
97  );
98 
99  vector moment(attachmentPt ^ force);
100 
101  if (model_.debug)
102  {
103  Info<< " attachmentPt " << attachmentPt
104  << " attachmentPt - anchor " << r*magR
105  << " spring length " << magR
106  << " allow slack " << allowSlack_
107  << " force " << force
108  << " moment " << moment
109  << endl;
110  }
111 
112  // Accumulate the force for the restrained body
113  fx[bodyIndex_] += spatialVector(moment, force);
114 }
115 
116 
118 (
119  const dictionary& dict
120 )
121 {
123 
124  coeffs_.lookup("anchor") >> anchor_;
125  coeffs_.lookup("refAttachmentPt") >> refAttachmentPt_;
126  coeffs_.lookup("stiffness") >> stiffness_;
127  coeffs_.lookup("damping") >> damping_;
128  coeffs_.lookup("restLength") >> restLength_;
129  allowSlack_ = coeffs_.lookupOrDefault<Switch>("allowSlack", false);
130 
131  return true;
132 }
133 
134 
136 (
137  Ostream& os
138 ) const
139 {
140  restraint::write(os);
141 
142  writeEntry(os, "anchor", anchor_);
143 
144  writeEntry(os, "refAttachmentPt", refAttachmentPt_);
145 
146  writeEntry(os, "stiffness", stiffness_);
147 
148  writeEntry(os, "damping", damping_);
149 
150  writeEntry(os, "restLength", restLength_);
151 
152  writeEntry(os, "allowSlack", allowSlack_);
153 }
154 
155 
156 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Base class for defining restraints for rigid-body dynamics.
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
virtual void write(Ostream &) const =0
Write.
Linear spring restraint.
Definition: linearSpring.H:56
virtual void write(Ostream &) const
Write.
Definition: linearSpring.C:136
virtual bool read(const dictionary &dict)
Update properties from given dictionary.
Definition: linearSpring.C:118
virtual void restrain(scalarField &tau, Field< spatialVector > &fx, const rigidBodyModelState &state) const
Accumulate the retraint internal joint forces into the tau field and.
Definition: linearSpring.C:75
virtual ~linearSpring()
Destructor.
Definition: linearSpring.C:68
linearSpring(const word &name, const dictionary &dict, const rigidBodyModel &model)
Construct from components.
Definition: linearSpring.C:54
Holds the motion state of rigid-body model.
Basic rigid-body model representing a system of rigid-bodies connected by 1-6 DoF joints.
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A class for handling words, derived from string.
Definition: word.H:62
addToRunTimeSelectionTable(restraint, externalForce, dictionary)
defineTypeNameAndDebug(externalForce, 0)
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
SpatialVector< scalar > spatialVector
SpatialVector of scalars.
Definition: spatialVector.H:47
dimensioned< scalar > mag(const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dictionary dict