00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
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
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
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
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];
00131 };
00132
00133
00134 int nlcp_gaussseidel(int, double *, double**, double *, double , double , int , bool );
00135
00136 int nlcp_gaussseidelTimed(int, double *, double**, double *, double , double , int , bool, double timeout );
00137 }
00138
00139 }
00140
00141 #endif