MBSim

Project Page
kinetic_functions.h
00001 /* Copyright (C) 2004-2009 MBSim Development Team
00002  *
00003  * This library is free software; you can redistribute it and/or 
00004  * modify it under the terms of the GNU Lesser General Public 
00005  * License as published by the Free Software Foundation; either 
00006  * version 2.1 of the License, or (at your option) any later version. 
00007  *  
00008  * This library is distributed in the hope that it will be useful, 
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00011  * Lesser General Public License for more details. 
00012  *  
00013  * You should have received a copy of the GNU Lesser General Public 
00014  * License along with this library; if not, write to the Free Software 
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
00016  *
00017  * Contact: markus.ms.schneider@gmail.com
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 
00029   class Contour;
00030   class ContourPointData;
00031 
00038   class LinearSpringDamperForce : public Function<double(double,double)> {
00039     public:
00043       LinearSpringDamperForce() {}
00044 
00051       LinearSpringDamperForce(double c_, double d_, double l0_) : c(c_), d(d_), l0(l0_) {}
00052 
00053       /* INHERITED INTERFACE OF FUNCTION2 */
00054       virtual double operator()(const double& g, const double& gd) { return c*(g-l0) + d*gd; }
00055       void initializeUsingXML(xercesc::DOMElement *element);
00056       /***************************************************/
00057 
00058       /* GETTER / SETTER */
00059       void setParameters(double c_, double d_, double l0_) { c=c_; d=d_; l0=l0_; }
00060       /***************************************************/
00061 
00062     protected:
00066       double c, d, l0;
00067   };
00068 
00075   class NonlinearSpringDamperForce : public Function<double(double,double)> {
00076     public:
00080       NonlinearSpringDamperForce() {}
00081 
00087       NonlinearSpringDamperForce(Function<double(double)> * gForceFun_, Function<double(double)> * gdForceFun_) : gForceFun(gForceFun_), gdForceFun(gdForceFun_) {
00088         gForceFun->setParent(this);
00089         gdForceFun->setParent(this);
00090       }
00091 
00092       /* INHERITED INTERFACE OF FUNCTION2 */
00093       virtual double operator()(const double& g, const double& gd) { return (*gForceFun)(g) + (*gdForceFun)(gd); }
00094       void initializeUsingXML(xercesc::DOMElement *element);
00095       void init(Element::InitStage stage) {
00096         Function<double(double,double)>::init(stage);
00097         gForceFun->init(stage);
00098         gdForceFun->init(stage);
00099       }
00100       /***************************************************/
00101 
00102       /* GETTER / SETTER */
00103       void setDistanceFunction(Function<double(double)> * gForceFun_) {
00104         gForceFun=gForceFun_;
00105         gForceFun->setParent(this);
00106         gForceFun->setName("Distance");
00107       }
00108 
00109       void setVelocityFunction(Function<double(double)> * gdForceFun_) {
00110         gdForceFun=gdForceFun_;
00111         gdForceFun->setParent(this);
00112         gdForceFun->setName("Velocity");
00113       }
00114       /***************************************************/
00115 
00116     protected:
00120       Function<double(double)> * gForceFun;
00121 
00125       Function<double(double)> * gdForceFun;
00126   };
00127 
00134   class LinearRegularizedUnilateralConstraint: public Function<double(double,double)> {
00135     public:
00139       LinearRegularizedUnilateralConstraint() : c(0), d(0) {}
00140 
00146       LinearRegularizedUnilateralConstraint(double c_, double d_) : c(c_), d(d_) {}
00147 
00148       /* INHERITED INTERFACE OF FUNCTION2 */
00149       virtual double operator()(const double& g, const double& gd) { 
00150         if(g>0)
00151           return 0;
00152         else if(gd<0) 
00153           return -c*g - d*gd;
00154         else
00155           return -c*g;
00156       }
00157       virtual void initializeUsingXML(xercesc::DOMElement *element);
00158       /***************************************************/
00159 
00160       /* GETTER / SETTER */
00161       void setParameter(double c_, double d_) { c=c_; d=d_; }
00162       /***************************************************/
00163 
00164     private:
00168       double c, d;
00169   };
00170 
00177   class LinearRegularizedBilateralConstraint: public Function<double(double,double)> {
00178     public:
00182       LinearRegularizedBilateralConstraint() : c(0), d(0) {}
00183 
00189       LinearRegularizedBilateralConstraint(double c_, double d_) : c(c_), d(d_) {}
00190 
00191       /* INHERITED INTERFACE OF FUNCTION2 */
00192       virtual double operator()(const double& g, const double& gd) { 
00193         return -c*g - d*gd;
00194       }
00195       virtual void initializeUsingXML(xercesc::DOMElement *element);
00196       virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent);
00197 
00198       virtual std::string getType() const { return "LinearRegularizedBilateralConstraint"; }
00199       /***************************************************/
00200 
00201       /* GETTER / SETTER */
00202       void setParameter(double c_, double d_) { c=c_; d=d_; }
00203       /***************************************************/
00204 
00205     private:
00209       double c, d;
00210   };
00211 
00219   class LinearRegularizedCoulombFriction : public Function<fmatvec::Vec(fmatvec::Vec,double)> {
00220     public:
00224       LinearRegularizedCoulombFriction() : mu(0), gdLim(0.01) {}
00225 
00231       LinearRegularizedCoulombFriction(double mu_, double gdLim_=0.01) : mu(mu_), gdLim(gdLim_) {}
00232 
00233       /* INHERITED INTERFACE OF FUNCTION2 */
00234       virtual fmatvec::Vec operator()(const fmatvec::Vec &gd, const double& laN);
00235       virtual void initializeUsingXML(xercesc::DOMElement *element);
00236       /***************************************************/
00237 
00238       /* GETTER / SETTER */
00239       void setFrictionCoefficient(double mu_) { mu=mu_; }
00240       void setMarginalVelocity(double gdLim_) { gdLim=gdLim_; }
00241       /***************************************************/
00242 
00243     protected:
00247       double mu, gdLim;
00248   };
00249 
00257   class LinearRegularizedStribeckFriction : public Function<fmatvec::Vec(fmatvec::Vec,double)> {
00258     public:
00262       LinearRegularizedStribeckFriction() : fmu(NULL), gdLim(0.01) {}
00263 
00269       LinearRegularizedStribeckFriction(Function<double(double)> *fmu_, double gdLim_=0.01) : fmu(fmu_), gdLim(gdLim_) {
00270         fmu->setParent(this);
00271       }
00272 
00273       /* INHERITED INTERFACE OF FUNCTION2 */
00274       virtual fmatvec::Vec operator()(const fmatvec::Vec &gd, const double& laN);
00275       virtual void initializeUsingXML(xercesc::DOMElement *element);
00276       virtual void init(Element::InitStage stage) {
00277         Function<fmatvec::Vec(fmatvec::Vec,double)>::init(stage);
00278         fmu->init(stage);
00279       }
00280       /***************************************************/
00281 
00282       /* GETTER / SETTER */
00283       void setFrictionFunction(Function<double(double)> *fmu_) {
00284         fmu=fmu_;
00285         fmu->setParent(this);
00286         fmu->setName("Friction");
00287       }
00288       void setMarginalVelocity(double gdLim_) { gdLim=gdLim_; }
00289       /***************************************************/
00290 
00291     protected:
00295       Function<double(double)> *fmu;
00296       
00300       double gdLim;
00301   };
00302 
00306   class InfluenceFunction : public Function<double(std::pair<Contour*, ContourPointData>, std::pair<Contour*, ContourPointData>)> {
00307     public:
00308       InfluenceFunction(){}
00309       virtual ~InfluenceFunction() {}
00310       /* INHERITED INTERFACE OF FUNCTION2 */
00311       virtual double operator()(const std::pair<Contour*, ContourPointData>& firstContourInfo, const std::pair<Contour*, ContourPointData>& secondContourInfo)=0;
00312       virtual void initializeUsingXML(xercesc::DOMElement *element);
00313       /***************************************************/
00314     protected:
00315       fmatvec::Vec2 computeLagrangeParameter(const std::pair<Contour*, ContourPointData>& contourInfo);
00316   };
00317 
00318   /*
00319    * \brief Influence function for flexibility of contour with no influence to other contours (or contour points)
00320    */
00321   class FlexibilityInfluenceFunction : public InfluenceFunction {
00322     public:
00323       FlexibilityInfluenceFunction() : flexibility(0) {
00324       }
00325       FlexibilityInfluenceFunction(const std::string& ContourName_, const double & flexibility_) :
00326           flexibility(flexibility_) {
00327       }
00328       virtual ~FlexibilityInfluenceFunction() {}
00329       /* INHERITED INTERFACE OF FUNCTION2 */
00330       virtual double operator()(const std::pair<Contour*, ContourPointData>& firstContourInfo, const std::pair<Contour*, ContourPointData>& secondContourInfo) {
00331         if(nrm2(computeLagrangeParameter(firstContourInfo)- computeLagrangeParameter(secondContourInfo)) < macheps())
00332           return flexibility;
00333         else
00334           return 0;
00335       }
00336       virtual void initializeUsingXML(xercesc::DOMElement *element);
00337       /***************************************************/
00338 
00339     protected:
00340       double flexibility;
00341   };
00342 
00343   /*
00344    * \brief a class for Influence-Functions with constant coupling
00345    */
00346   class ConstantInfluenceFunction : public InfluenceFunction {
00347     public:
00348       ConstantInfluenceFunction() : couplingValue(0) {
00349     }
00350       ConstantInfluenceFunction(const double & couplingValue_) :
00351           couplingValue(couplingValue_) {
00352       }
00353       virtual ~ConstantInfluenceFunction() {}
00354       /* INHERITED INTERFACE OF FUNCTION2 */
00355       virtual double operator()(const std::pair<Contour*, ContourPointData>& firstContourInfo, const std::pair<Contour*, ContourPointData>& secondContourInfo) {
00356         return couplingValue;
00357       }
00358       virtual void initializeUsingXML(xercesc::DOMElement *element);
00359       /***************************************************/
00360 
00361     protected:
00362       double couplingValue;
00363   };
00364 
00365 }
00366 
00367 #endif