00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _KINETIC_FUNCTIONS_H_
00021 #define _KINETIC_FUNCTIONS_H_
00022
00023 #include "mbsim/functions/function.h"
00024 #include "mbsim/element.h"
00025 #include "mbsim/utils/eps.h"
00026
00027 namespace MBSim {
00028
00035 class LinearSpringDamperForce : public Function<double(double,double)> {
00036 public:
00040 LinearSpringDamperForce() {}
00041
00048 LinearSpringDamperForce(double c_, double d_, double l0_) : c(c_), d(d_), l0(l0_) {}
00049
00050
00051 virtual double operator()(const double& g, const double& gd) { return c*(g-l0) + d*gd; }
00052 void initializeUsingXML(xercesc::DOMElement *element);
00053
00054
00055
00056 void setParameters(double c_, double d_, double l0_) { c=c_; d=d_; l0=l0_; }
00057
00058
00059 protected:
00063 double c, d, l0;
00064 };
00065
00072 class NonlinearSpringDamperForce : public Function<double(double,double)> {
00073 public:
00077 NonlinearSpringDamperForce() {}
00078
00084 NonlinearSpringDamperForce(Function<double(double)> * gForceFun_, Function<double(double)> * gdForceFun_) : gForceFun(gForceFun_), gdForceFun(gdForceFun_) {
00085 gForceFun->setParent(this);
00086 gdForceFun->setParent(this);
00087 }
00088
00089
00090 virtual double operator()(const double& g, const double& gd) { return (*gForceFun)(g) + (*gdForceFun)(gd); }
00091 void initializeUsingXML(xercesc::DOMElement *element);
00092 void init(Element::InitStage stage) {
00093 Function<double(double,double)>::init(stage);
00094 gForceFun->init(stage);
00095 gdForceFun->init(stage);
00096 }
00097
00098
00099
00100 void setDistanceFunction(Function<double(double)> * gForceFun_) {
00101 gForceFun=gForceFun_;
00102 gForceFun->setParent(this);
00103 gForceFun->setName("Distance");
00104 }
00105
00106 void setVelocityFunction(Function<double(double)> * gdForceFun_) {
00107 gdForceFun=gdForceFun_;
00108 gdForceFun->setParent(this);
00109 gdForceFun->setName("Velocity");
00110 }
00111
00112
00113 protected:
00117 Function<double(double)> * gForceFun;
00118
00122 Function<double(double)> * gdForceFun;
00123 };
00124
00131 class LinearRegularizedUnilateralConstraint: public Function<double(double,double)> {
00132 public:
00136 LinearRegularizedUnilateralConstraint() : c(0), d(0) {}
00137
00143 LinearRegularizedUnilateralConstraint(double c_, double d_) : c(c_), d(d_) {}
00144
00145
00146 virtual double operator()(const double& g, const double& gd) {
00147 if(g>0)
00148 return 0;
00149 else if(gd<0)
00150 return -c*g - d*gd;
00151 else
00152 return -c*g;
00153 }
00154 virtual void initializeUsingXML(xercesc::DOMElement *element);
00155
00156
00157
00158 void setParameter(double c_, double d_) { c=c_; d=d_; }
00159
00160
00161 private:
00165 double c, d;
00166 };
00167
00174 class LinearRegularizedBilateralConstraint: public Function<double(double,double)> {
00175 public:
00179 LinearRegularizedBilateralConstraint() : c(0), d(0) {}
00180
00186 LinearRegularizedBilateralConstraint(double c_, double d_) : c(c_), d(d_) {}
00187
00188
00189 virtual double operator()(const double& g, const double& gd) {
00190 return -c*g - d*gd;
00191 }
00192 virtual void initializeUsingXML(xercesc::DOMElement *element);
00193 virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent);
00194
00195 virtual std::string getType() const { return "LinearRegularizedBilateralConstraint"; }
00196
00197
00198
00199 void setParameter(double c_, double d_) { c=c_; d=d_; }
00200
00201
00202 private:
00206 double c, d;
00207 };
00208
00216 class LinearRegularizedCoulombFriction : public Function<fmatvec::Vec(fmatvec::Vec,double)> {
00217 public:
00221 LinearRegularizedCoulombFriction() : mu(0), gdLim(0.01) {}
00222
00228 LinearRegularizedCoulombFriction(double mu_, double gdLim_=0.01) : mu(mu_), gdLim(gdLim_) {}
00229
00230
00231 virtual fmatvec::Vec operator()(const fmatvec::Vec &gd, const double& laN);
00232 virtual void initializeUsingXML(xercesc::DOMElement *element);
00233
00234
00235
00236 void setFrictionCoefficient(double mu_) { mu=mu_; }
00237 void setMarginalVelocity(double gdLim_) { gdLim=gdLim_; }
00238
00239
00240 protected:
00244 double mu, gdLim;
00245 };
00246
00254 class LinearRegularizedStribeckFriction : public Function<fmatvec::Vec(fmatvec::Vec,double)> {
00255 public:
00259 LinearRegularizedStribeckFriction() : fmu(NULL), gdLim(0.01) {}
00260
00266 LinearRegularizedStribeckFriction(Function<double(double)> *fmu_, double gdLim_=0.01) : fmu(fmu_), gdLim(gdLim_) {
00267 fmu->setParent(this);
00268 }
00269
00270
00271 virtual fmatvec::Vec operator()(const fmatvec::Vec &gd, const double& laN);
00272 virtual void initializeUsingXML(xercesc::DOMElement *element);
00273 virtual void init(Element::InitStage stage) {
00274 Function<fmatvec::Vec(fmatvec::Vec,double)>::init(stage);
00275 fmu->init(stage);
00276 }
00277
00278
00279
00280 void setFrictionFunction(Function<double(double)> *fmu_) {
00281 fmu=fmu_;
00282 fmu->setParent(this);
00283 fmu->setName("Friction");
00284 }
00285 void setMarginalVelocity(double gdLim_) { gdLim=gdLim_; }
00286
00287
00288 protected:
00292 Function<double(double)> *fmu;
00293
00297 double gdLim;
00298 };
00299
00303 class InfluenceFunction : public Function<double(fmatvec::Vec2,fmatvec::Vec2)> {
00304 public:
00305 InfluenceFunction(){}
00306
00307 virtual double operator()(const fmatvec::Vec2& firstContourLagrangeParameter, const fmatvec::Vec2& secondContourLagrangeParameter)=0;
00308 virtual void initializeUsingXML(xercesc::DOMElement *element);
00309
00310 };
00311
00312
00313
00314
00315 class FlexibilityInfluenceFunction : public InfluenceFunction {
00316 public:
00317 FlexibilityInfluenceFunction() : flexibility(0) {
00318 }
00319 FlexibilityInfluenceFunction(const std::string& ContourName_, const double & flexibility_) :
00320 flexibility(flexibility_) {
00321 }
00322 virtual ~FlexibilityInfluenceFunction() {}
00323
00324 virtual double operator()(const fmatvec::Vec2& firstContourLagrangeParameter, const fmatvec::Vec2& secondContourLagrangeParameter) {
00325 if(nrm2(firstContourLagrangeParameter - secondContourLagrangeParameter) < macheps())
00326 return flexibility;
00327 else
00328 return 0;
00329 }
00330 virtual void initializeUsingXML(xercesc::DOMElement *element);
00331
00332
00333 protected:
00334 double flexibility;
00335 };
00336
00337
00338
00339
00340 class ConstantInfluenceFunction : public InfluenceFunction {
00341 public:
00342 ConstantInfluenceFunction() : couplingValue(0) {
00343 }
00344 ConstantInfluenceFunction(const double & couplingValue_) :
00345 couplingValue(couplingValue_) {
00346 }
00347 virtual ~ConstantInfluenceFunction() {}
00348
00349 virtual double operator()(const fmatvec::Vec2& firstContourLagrangeParameter, const fmatvec::Vec2& secondContourLagrangeParameter) {
00350 return couplingValue;
00351 }
00352 virtual void initializeUsingXML(xercesc::DOMElement *element);
00353
00354
00355 protected:
00356 double couplingValue;
00357 };
00358
00359 }
00360
00361 #endif