mbsim  4.0.0
MBSim Kernel
spring_damper.h
1/* Copyright (C) 2004-2009 MBSim Development Team
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * Contact: martin.o.foerg@googlemail.com
17 */
18
19#ifndef _SPRING_DAMPER_H_
20#define _SPRING_DAMPER_H_
21
22#include "mbsim/links/fixed_frame_link.h"
23#include "mbsim/functions/function.h"
24
25#include "mbsim/utils/boost_parameters.h"
26#include "mbsim/utils/openmbv_utils.h"
27
28namespace MBSim {
29
30 extern const PlotFeatureEnum deflection;
31
37 protected:
38 Function<double(double,double)> *func;
39 double l0;
40 std::shared_ptr<OpenMBVCoilSpring> ombvCoilSpring;
41 std::shared_ptr<OpenMBV::CoilSpring> coilspringOpenMBV;
42#ifndef SWIG
43 double (SpringDamper::*evalOMBVColorRepresentation[5])();
44#endif
45 double evalNone() { return 0; }
46 double evalDeflection() { return evalGeneralizedRelativePosition()(0)-l0; }
47 double evalTensileForce() { return -evalGeneralizedForce()(0); }
48 double evalCompressiveForce() { return evalGeneralizedForce()(0); }
49 double evalAbsoluteForce() { return fabs(evalGeneralizedForce()(0)); }
50 public:
51 SpringDamper(const std::string &name="");
53
54 void updatelaF();
55
56 bool isActive() const { return true; }
57 bool gActiveChanged() { return false; }
58 bool isSingleValued() const { return true; }
59 void init(InitStage stage, const InitConfigSet &config);
60
66 void setForceFunction(Function<double(double,double)> *func_) {
67 func=func_;
68 func->setParent(this);
69 func->setName("Force");
70 }
71
73 void setUnloadedLength(double l0_) { l0 = l0_; }
74
75 void plot();
76 void initializeUsingXML(xercesc::DOMElement *element);
77
79 BOOST_PARAMETER_MEMBER_FUNCTION( (void), enableOpenMBV, tag, (optional (numberOfCoils,(int),3)(springRadius,(double),1)(crossSectionRadius,(double),-1)(nominalLength,(double),-1)(type,(OpenMBVCoilSpring::Type),OpenMBVCoilSpring::tube)(colorRepresentation,(OpenMBVCoilSpring::ColorRepresentation),OpenMBVCoilSpring::none)(minimalColorValue,(double),0)(maximalColorValue,(double),1)(diffuseColor,(const fmatvec::Vec3&),fmatvec::Vec3(std::vector<double>{-1,1,1}))(transparency,(double),0)(pointSize,(double),0)(lineWidth,(double),0))) {
80 ombvCoilSpring = std::shared_ptr<OpenMBVCoilSpring>(new OpenMBVCoilSpring(springRadius,crossSectionRadius,1,numberOfCoils,nominalLength,type,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
81 }
82 };
83
84}
85
86#endif
InitStage
The stages of the initialization.
Definition: element.h:62
std::string name
name of element
Definition: element.h:260
void setName(const std::string &str)
Definition: element.h:115
Definition: function.h:53
Definition: openmbv_utils.h:183
A spring damper force law. This class connects two frames and applies a force in it,...
Definition: spring_damper.h:36
BOOST_PARAMETER_MEMBER_FUNCTION((void), enableOpenMBV, tag,(optional(numberOfCoils,(int), 3)(springRadius,(double), 1)(crossSectionRadius,(double),-1)(nominalLength,(double),-1)(type,(OpenMBVCoilSpring::Type), OpenMBVCoilSpring::tube)(colorRepresentation,(OpenMBVCoilSpring::ColorRepresentation), OpenMBVCoilSpring::none)(minimalColorValue,(double), 0)(maximalColorValue,(double), 1)(diffuseColor,(const fmatvec::Vec3 &), fmatvec::Vec3(std::vector< double >{-1, 1, 1}))(transparency,(double), 0)(pointSize,(double), 0)(lineWidth,(double), 0)))
Visualise the SpringDamper using a OpenMBV::CoilSpring.
Definition: spring_damper.h:79
void init(InitStage stage, const InitConfigSet &config)
plots time series header
Definition: spring_damper.cc:59
bool isSingleValued() const
asks the link if it contains single valued force laws that contribute to the right-hand side vector h
Definition: spring_damper.h:58
void setUnloadedLength(double l0_)
Set unloaded length.
Definition: spring_damper.h:73
void plot()
plots time dependent data
Definition: spring_damper.cc:73
bool gActiveChanged()
Definition: spring_damper.h:57
void setForceFunction(Function< double(double, double)> *func_)
Set function for the force calculation. The first input parameter to that function is the distance re...
Definition: spring_damper.h:66
bool isActive() const
Definition: spring_damper.h:56
namespace MBSim
Definition: bilateral_constraint.cc:30