LCPcalc.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                              SOFA :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_HELPER_LCPCALC_H
00028 #define SOFA_HELPER_LCPCALC_H
00029 
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <math.h>
00033 #include <sofa/helper/system/thread/CTime.h>
00034 
00035 namespace sofa
00036 {
00037 
00038 namespace helper
00039 {
00040 
00041 //#define NULL 0
00042 
00043 using namespace system::thread;
00044 
00045 #define EPSILON_LCP     0.00000000001   // epsilon pour tests = 0
00046 #define EPSILON_CONV    0.001           // for GS convergence
00047 #define MAX_BOU 50  // nombre maximal de boucles de calcul
00048 
00049 class LCP
00050 {
00051     private:
00052         int maxConst;
00053         double* dfree;
00054         double** W;
00055         double* f;
00056         double tol;
00057         int numItMax;
00058         bool useInitialF;
00059         double mu;
00060         int dim;
00061         unsigned int nbConst;
00062     public:
00063         LCP(unsigned int maxConstraint);
00064         ~LCP();
00065         void reset(void);
00066         //LCP& operator=(LCP& lcp);
00067         inline double** getW(void) {return W;};
00068         inline double& getMu(void) { return mu;};
00069         inline double* getDfree(void) {return dfree;};
00070         inline double getTolerance(void) {return tol;};
00071         inline double getMaxIter(void) {return numItMax;};
00072         inline double* getF(void) {return f;};
00073         inline bool useInitialGuess(void) {return useInitialF;};
00074         inline unsigned int getNbConst(void) {return nbConst;};
00075         inline unsigned int setNbConst(unsigned int nbC) {nbConst = nbC; return 0;};
00076         inline unsigned int getMaxConst(void) {return maxConst;};
00077 };
00078 
00079 
00080 
00081 inline void set3Dof(double *vector, int index, double &vx, double &vy, double &vz)
00082                         {vector[3*index]=vx; vector[3*index+1]=vy; vector[3*index+2]=vz;}
00083 inline void add3Dof(double *vector, int index, double &vx, double &vy, double &vz)
00084                         {vector[3*index]+=vx; vector[3*index+1]+=vy; vector[3*index+2]+=vz;}
00085 inline double normError(double &f1x, double &f1y, double &f1z, double &f2x, double &f2y, double &f2z)
00086                         {return sqrt( ((f2x-f1x)*(f2x-f1x) + (f2y-f1y)*(f2y-f1y) + (f2z-f1z)*(f2z-f1z)) /
00087                         (f1x*f1x + f1y*f1y + f1z*f1z) ) ; }
00088 
00089 inline double absError(double &f1x, double &f1y, double &f1z, double &f2x, double &f2y, double &f2z)
00090                         {return sqrt ((f2x-f1x)*(f2x-f1x) + (f2y-f1y)*(f2y-f1y) + (f2z-f1z)*(f2z-f1z));}
00091 
00092 
00093 int resoudreLCP(int, double *, double **, double *);
00094 int lcp_lexicolemke(int, double *, double **, double *);
00095 // same with pre-allocated matrix A
00096 int lcp_lexicolemke(int, double *, double **, double **, double *);
00097 
00098 
00099 void afficheSyst(double *q,double **M, int *base, double **mat, int dim);
00100 void afficheLCP(double *q, double **M, int dim);
00101 void afficheLCP(double *q, double **M, double *f, int dim);
00102 
00103 typedef double FemClipsReal;
00104 void gaussSeidelLCP1(int, FemClipsReal *,FemClipsReal **, FemClipsReal *, double , int );
00105 
00106 
00107 
00108 
00109 // inverted SymMatrix 3x3 //
00110 class LocalBlock33 {
00111 public:
00112     LocalBlock33(){computed=false;};
00113     ~LocalBlock33(){};
00114 
00115     void compute(double &w11, double &w12, double &w13, double &w22, double &w23, double &w33);
00116     void stickState(double &dn, double &dt, double &ds, double &fn, double &ft, double &fs);
00117     void slipState(double &mu, double &dn, double &dt, double &ds, double &fn, double &ft, double &fs);
00118 
00119     // computation of a new state using a simple gauss-seidel loop
00120     void GS_State(double &mu, double &dn, double &dt, double &ds, double &fn, double &ft, double &fs);
00121 
00122     void setPreviousForce(double &fn, double &ft, double &fs){f_1[0]=fn; f_1[1]=ft; f_1[2]=fs;}
00123 
00124     bool computed;
00125 public:
00126 
00127     double w[6];
00128     double wInv[6];
00129     double det;
00130     double f_1[3]; // previous value of force
00131 };
00132 
00133 // Gauss-Seidel like algorithm for contacts
00134 int nlcp_gaussseidel(int, double *, double**, double *, double , double , int , bool );
00135 // Timed Gauss-Seidel like algorithm for contacts
00136 int nlcp_gaussseidelTimed(int, double *, double**, double *, double , double , int , bool, double timeout );
00137 } // namespace helper
00138 
00139 } // namespace sofa
00140 
00141 #endif

Generated on Sun Nov 23 02:29:30 2008 for Sofa by  doxygen 1.5.7.1