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 "fmatvec/function.h"
00024 #include "mbsim/element.h"
00025 #include "mbsim/utils/eps.h"
00026 
00027 namespace MBSim {
00028 
00035   class LinearSpringDamperForce : public fmatvec::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       /* INHERITED INTERFACE OF FUNCTION2 */
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       /* GETTER / SETTER */
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 fmatvec::Function<double(double,double)> {
00073     public:
00077       NonlinearSpringDamperForce() {}
00078 
00084       NonlinearSpringDamperForce(Function<double(double)> * gForceFun_, Function<double(double)> * gdForceFun_) : gForceFun(gForceFun_), gdForceFun(gdForceFun_) {}
00085 
00086       /* INHERITED INTERFACE OF FUNCTION2 */
00087       virtual double operator()(const double& g, const double& gd) { return (*gForceFun)(g) + (*gdForceFun)(gd); }
00088       void initializeUsingXML(xercesc::DOMElement *element);
00089       /***************************************************/
00090 
00091       /* GETTER / SETTER */
00092       void setDistanceFunction(Function<double(double)> * gForceFun_) { gForceFun=gForceFun_; }
00093 
00094       void setVelocityFunction(Function<double(double)> * gdForceFun_) { gdForceFun=gdForceFun_; }
00095       /***************************************************/
00096 
00097     protected:
00101       Function<double(double)> * gForceFun;
00102 
00106       Function<double(double)> * gdForceFun;
00107   };
00108 
00115   class LinearRegularizedUnilateralConstraint: public fmatvec::Function<double(double,double)> {
00116     public:
00120       LinearRegularizedUnilateralConstraint() : c(0), d(0) {}
00121 
00127       LinearRegularizedUnilateralConstraint(double c_, double d_) : c(c_), d(d_) {}
00128 
00129       /* INHERITED INTERFACE OF FUNCTION2 */
00130       virtual double operator()(const double& g, const double& gd) { 
00131         if(g>0)
00132           return 0;
00133         else if(gd<0) 
00134           return -c*g - d*gd;
00135         else
00136           return -c*g;
00137       }
00138       virtual void initializeUsingXML(xercesc::DOMElement *element);
00139       /***************************************************/
00140 
00141       /* GETTER / SETTER */
00142       void setParameter(double c_, double d_) { c=c_; d=d_; }
00143       /***************************************************/
00144 
00145     private:
00149       double c, d;
00150   };
00151 
00158   class LinearRegularizedBilateralConstraint: public fmatvec::Function<double(double,double)> {
00159     public:
00163       LinearRegularizedBilateralConstraint() : c(0), d(0) {}
00164 
00170       LinearRegularizedBilateralConstraint(double c_, double d_) : c(c_), d(d_) {}
00171 
00172       /* INHERITED INTERFACE OF FUNCTION2 */
00173       virtual double operator()(const double& g, const double& gd) { 
00174         return -c*g - d*gd;
00175       }
00176       virtual void initializeUsingXML(xercesc::DOMElement *element);
00177       virtual xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent);
00178 
00179       virtual std::string getType() const { return "LinearRegularizedBilateralConstraint"; }
00180       /***************************************************/
00181 
00182       /* GETTER / SETTER */
00183       void setParameter(double c_, double d_) { c=c_; d=d_; }
00184       /***************************************************/
00185 
00186     private:
00190       double c, d;
00191   };
00192 
00200   class LinearRegularizedCoulombFriction : public fmatvec::Function<fmatvec::Vec(fmatvec::Vec,double)> {
00201     public:
00205       LinearRegularizedCoulombFriction() : mu(0), gdLim(0.01) {}
00206 
00212       LinearRegularizedCoulombFriction(double mu_, double gdLim_=0.01) : mu(mu_), gdLim(gdLim_) {}
00213 
00214       /* INHERITED INTERFACE OF FUNCTION2 */
00215       virtual fmatvec::Vec operator()(const fmatvec::Vec &gd, const double& laN);
00216       virtual void initializeUsingXML(xercesc::DOMElement *element);
00217       /***************************************************/
00218 
00219       /* GETTER / SETTER */
00220       void setFrictionCoefficient(double mu_) { mu=mu_; }
00221       void setMarginalVelocity(double gdLim_) { gdLim=gdLim_; }
00222       /***************************************************/
00223 
00224     protected:
00228       double mu, gdLim;
00229   };
00230 
00238   class LinearRegularizedStribeckFriction : public fmatvec::Function<fmatvec::Vec(fmatvec::Vec,double)> {
00239     public:
00243       LinearRegularizedStribeckFriction() : fmu(NULL), gdLim(0.01) {}
00244 
00250       LinearRegularizedStribeckFriction(fmatvec::Function<double(double)> *fmu_, double gdLim_=0.01) : fmu(fmu_), gdLim(gdLim_) {}
00251 
00252       /* INHERITED INTERFACE OF FUNCTION2 */
00253       virtual fmatvec::Vec operator()(const fmatvec::Vec &gd, const double& laN);
00254       virtual void initializeUsingXML(xercesc::DOMElement *element);
00255       /***************************************************/
00256 
00257       /* GETTER / SETTER */
00258       void setFrictionFunction(fmatvec::Function<double(double)> *fmu_) { fmu=fmu_; }
00259       void setMarginalVelocity(double gdLim_) { gdLim=gdLim_; }
00260       /***************************************************/
00261 
00262     protected:
00266       Function<double(double)> *fmu;
00267       
00271       double gdLim;
00272   };
00273 
00277   class InfluenceFunction : public fmatvec::Function<double(fmatvec::Vec2,fmatvec::Vec2)> {
00278     public:
00279       InfluenceFunction(){}
00280       /* INHERITED INTERFACE OF FUNCTION2 */
00281       virtual double operator()(const fmatvec::Vec2& firstContourLagrangeParameter, const fmatvec::Vec2& secondContourLagrangeParameter)=0;
00282       virtual void initializeUsingXML(xercesc::DOMElement *element);
00283       /***************************************************/
00284   };
00285 
00286   /*
00287    * \brief Influence function for flexibility of contour with no influence to other contours (or contour points)
00288    */
00289   class FlexibilityInfluenceFunction : public InfluenceFunction {
00290     public:
00291       FlexibilityInfluenceFunction() : flexibility(0) {
00292       }
00293       FlexibilityInfluenceFunction(const std::string& ContourName_, const double & flexibility_) :
00294           flexibility(flexibility_) {
00295       }
00296       virtual ~FlexibilityInfluenceFunction() {}
00297       /* INHERITED INTERFACE OF FUNCTION2 */
00298       virtual double operator()(const fmatvec::Vec2& firstContourLagrangeParameter, const fmatvec::Vec2& secondContourLagrangeParameter) {
00299         if(nrm2(firstContourLagrangeParameter - secondContourLagrangeParameter) < macheps())
00300           return flexibility;
00301         else
00302           return 0;
00303       }
00304       virtual void initializeUsingXML(xercesc::DOMElement *element);
00305       /***************************************************/
00306 
00307     protected:
00308       double flexibility;
00309   };
00310 
00311   /*
00312    * \brief a class for Influence-Functions with constant coupling
00313    */
00314   class ConstantInfluenceFunction : public InfluenceFunction {
00315     public:
00316       ConstantInfluenceFunction() : couplingValue(0) {
00317     }
00318       ConstantInfluenceFunction(const double & couplingValue_) :
00319           couplingValue(couplingValue_) {
00320       }
00321       virtual ~ConstantInfluenceFunction() {}
00322       /* INHERITED INTERFACE OF FUNCTION2 */
00323       virtual double operator()(const fmatvec::Vec2& firstContourLagrangeParameter, const fmatvec::Vec2& secondContourLagrangeParameter) {
00324         return couplingValue;
00325       }
00326       virtual void initializeUsingXML(xercesc::DOMElement *element);
00327       /***************************************************/
00328 
00329     protected:
00330       double couplingValue;
00331   };
00332 
00333 }
00334 
00335 #endif