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 
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       /* 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 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       /* INHERITED INTERFACE OF FUNCTION2 */
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       /* GETTER / SETTER */
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       /* INHERITED INTERFACE OF FUNCTION2 */
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       /* GETTER / SETTER */
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       /* INHERITED INTERFACE OF FUNCTION2 */
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       /* GETTER / SETTER */
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       /* INHERITED INTERFACE OF FUNCTION2 */
00231       virtual fmatvec::Vec operator()(const fmatvec::Vec &gd, const double& laN);
00232       virtual void initializeUsingXML(xercesc::DOMElement *element);
00233       /***************************************************/
00234 
00235       /* GETTER / SETTER */
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       /* INHERITED INTERFACE OF FUNCTION2 */
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       /* GETTER / SETTER */
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       /* INHERITED INTERFACE OF FUNCTION2 */
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    * \brief Influence function for flexibility of contour with no influence to other contours (or contour points)
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       /* INHERITED INTERFACE OF FUNCTION2 */
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    * \brief a class for Influence-Functions with constant coupling
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       /* INHERITED INTERFACE OF FUNCTION2 */
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