mbsim 4.0.0 MBSim Kernel

directional_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 _DIRECTIONAL_SPRING_DAMPER_H_
20 #define _DIRECTIONAL_SPRING_DAMPER_H_
21
22 #include "mbsim/links/floating_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
28 namespace MBSim {
29
34 class DirectionalSpringDamper : public FloatingFrameLink {
35 protected:
36 double dist;
37 Function<double(double,double)> *func;
38 double l0{0};
39 std::shared_ptr<OpenMBVCoilSpring> ombvCoilSpring;
40 std::shared_ptr<OpenMBV::CoilSpring> coilspringOpenMBV;
41 #ifndef SWIG
42 double (DirectionalSpringDamper::*evalOMBVColorRepresentation[5])();
43 #endif
44 double evalNone() { return 0; }
45 double evalDeflection() { return evalGeneralizedRelativePosition()(0)-l0; }
46 double evalTensileForce() { return -evalGeneralizedForce()(0); }
47 double evalCompressiveForce() { return evalGeneralizedForce()(0); }
48 double evalAbsoluteForce() { return fabs(evalGeneralizedForce()(0)); }
49 public:
50 DirectionalSpringDamper(const std::string &name="");
51 ~DirectionalSpringDamper() override;
52
53 void updatePositions(Frame *frame) override;
54 void updateGeneralizedPositions() override;
55 void updateGeneralizedVelocities() override;
56 void updatelaF() override;
57
58 /*INHERITED INTERFACE OF LINK*/
59 bool isActive() const override { return true; }
60 bool gActiveChanged() override { return false; }
61 bool isSingleValued() const override { return true; }
62 void init(InitStage stage, const InitConfigSet &config) override;
63 /*****************************/
64
70 void setForceFunction(Function<double(double,double)> *func_) {
71 func=func_;
72 func->setParent(this);
73 func->setName("Force");
74 }
75
77 void setUnloadedLength(double l0_) { l0 = l0_; }
78
82 void setForceDirection(const fmatvec::Vec3 &dir) { forceDir <<= dir; }
83
84 void plot() override;
85 void initializeUsingXML(xercesc::DOMElement *element) override;
86
87 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))) {
88 ombvCoilSpring = std::shared_ptr<OpenMBVCoilSpring>(new OpenMBVCoilSpring(springRadius,crossSectionRadius,1,numberOfCoils,nominalLength,type,colorRepresentation,minimalColorValue,maximalColorValue,diffuseColor,transparency,pointSize,lineWidth));
89 }
90 };
91
92 }
93
94 #endif
MBSim::FloatingFrameLink
floating frame link
Definition: floating_frame_link.h:32
MBSim::DirectionalSpringDamper::setUnloadedLength
void setUnloadedLength(double l0_)
Set unloaded length.
Definition: directional_spring_damper.h:77
MBSim::DirectionalSpringDamper::isSingleValued
bool isSingleValued() const override
asks the link if it contains single valued force laws that contribute to the right-hand side vector h
Definition: directional_spring_damper.h:61
MBSim::FrameLink::frame
std::vector< Frame * > frame
array in which all frames are listed, connecting bodies via a link
Definition: frame_link.h:83
MBSim::DirectionalSpringDamper
A spring damper force law. This class connects two frames and applies a force in it,...
Definition: directional_spring_damper.h:34
MBSim::DirectionalSpringDamper::setForceDirection
void setForceDirection(const fmatvec::Vec3 &dir)
Definition: directional_spring_damper.h:82
MBSim::DirectionalSpringDamper::setForceFunction
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: directional_spring_damper.h:70
MBSim::DirectionalSpringDamper::gActiveChanged
bool gActiveChanged() override
Definition: directional_spring_damper.h:60
MBSim::DirectionalSpringDamper::plot
void plot() override
plots time dependent data
Definition: directional_spring_damper.cc:81
MBSim::DirectionalSpringDamper::isActive
bool isActive() const override
Definition: directional_spring_damper.h:59
MBSim::FloatingFrameLink::forceDir
fmatvec::Mat3xV forceDir
directions of force and moment in frame of reference
Definition: floating_frame_link.h:80
MBSim::Element::InitStage
InitStage
The stages of the initialization.
Definition: element.h:62
MBSim::Function
Definition: contact_kinematics.h:32
MBSim::Element::name
std::string name
name of element
Definition: element.h:260
MBSim::DirectionalSpringDamper::init
void init(InitStage stage, const InitConfigSet &config) override
plots time series header
Definition: directional_spring_damper.cc:69
MBSim::Frame
cartesian frame on bodies used for application of e.g. links and loads
Definition: frame.h:39
MBSim::Element::setName
void setName(const std::string &str)
Definition: element.h:115
MBSim
namespace MBSim
Definition: bilateral_constraint.cc:30