00001 #ifndef MATRIX_SETUP_H
00002 #define MATRIX_SETUP_H
00003
00004
00005
00006
00007 #include <OpenTissue/configuration.h>
00008
00009 #include <boost/cast.hpp>
00010
00011 #include <ctime>
00012 #include <cstdlib>
00013
00014 template<typename size_type, typename matrix_type>
00015 void matrix_setup(size_type bodies, size_type contacts, matrix_type & W, matrix_type & J)
00016 {
00017 typedef matrix_type::value_type real_type;
00018
00019 std::srand(static_cast<unsigned int>(std::time(0)));
00020
00021
00022 size_type m = 3*contacts;
00023 size_type n = 6*bodies;
00024
00025 J.resize(m,n,false);
00026 W.resize(n,n,false);
00027
00028
00029 for(size_type i=0;i<bodies;++i)
00030 {
00031 size_type j = i*6;
00032
00033 W(j,j) = 1.0;
00034 W(j+1,j+1) = 1.0;
00035 W(j+2,j+2) = 1.0;
00036 W(j+3,j+3) = 1.0; W(j+3,j+4) = 0.5; W(j+3,j+5) = 0.5;
00037 W(j+4,j+3) = 0.5; W(j+4,j+4) = 1.0; W(j+4,j+5) = 0.5;
00038 W(j+5,j+3) = 0.5; W(j+5,j+4) = 0.5; W(j+5,j+5) = 1.0;
00039 }
00040
00041
00042 for(size_type i=0;i<contacts;++i)
00043 {
00044 size_type j = i*3;
00045
00046 double rnd = rand()/(1.0*RAND_MAX);
00047 size_type tmp = boost::numeric_cast<size_type>( bodies*rnd );
00048
00049 size_type b1 = tmp%bodies;
00050 size_type b2 = (tmp+1)%bodies;
00051
00052 b1 *= 6;
00053 b2 *= 6;
00054
00055 J(j ,b1) = 1.0; J(j ,b1+1) = 1.0; J(j ,b1+2) = 1.0; J(j ,b1+3) = 1.0; J(j ,b1+4) = 1.0; J(j ,b1+5) = 1.0;
00056 J(j+1,b1) = 1.0; J(j+1,b1+1) = 1.0; J(j+1,b1+2) = 1.0; J(j+1,b1+3) = 1.0; J(j+1,b1+4) = 1.0; J(j+1,b1+5) = 1.0;
00057 J(j+2,b1) = 1.0; J(j+2,b1+1) = 1.0; J(j+2,b1+2) = 1.0; J(j+2,b1+3) = 1.0; J(j+2,b1+4) = 1.0; J(j+2,b1+5) = 1.0;
00058
00059 J(j ,b2) = 1.0; J(j ,b2+1) = 1.0; J(j ,b2+2) = 1.0; J(j ,b2+3) = 1.0; J(j ,b2+4) = 1.0; J(j ,b2+5) = 1.0;
00060 J(j+1,b2) = 1.0; J(j+1,b2+1) = 1.0; J(j+1,b2+2) = 1.0; J(j+1,b2+3) = 1.0; J(j+1,b2+4) = 1.0; J(j+1,b2+5) = 1.0;
00061 J(j+2,b2) = 1.0; J(j+2,b2+1) = 1.0; J(j+2,b2+2) = 1.0; J(j+2,b2+3) = 1.0; J(j+2,b2+4) = 1.0; J(j+2,b2+5) = 1.0;
00062 }
00063 }
00064
00065
00066 #endif