00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MATH_MBD_DEFAULT_UBLAS_MATH_POLICY_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MATH_MBD_DEFAULT_UBLAS_MATH_POLICY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012
00013 #include <OpenTissue/core/math/big/big_types.h>
00014 #include <OpenTissue/core/math/big/big_prod.h>
00015 #include <OpenTissue/core/math/big/big_prod_row.h>
00016 #include <OpenTissue/core/math/big/big_prod_add_rhs.h>
00017 #include <OpenTissue/core/math/big/big_prod_sub_rhs.h>
00018 #include <OpenTissue/core/math/big/big_prod_sub.h>
00019 #include <OpenTissue/core/math/big/big_prod_add.h>
00020 #include <OpenTissue/core/math/big/big_prod_trans.h>
00021
00022 #include <OpenTissue/core/math/big/io/big_matlab_write.h>
00023
00024 #include <OpenTissue/core/math/math_basic_types.h>
00025
00026 namespace OpenTissue
00027 {
00028 namespace mbd
00029 {
00030
00040 template< typename real_type_>
00041 class default_ublas_math_policy
00042 : public OpenTissue::math::BasicMathTypes<real_type_,size_t>
00043 {
00044 public:
00045 typedef typename OpenTissue::math::BasicMathTypes<real_type_, size_t> basic_math_types;
00046 typedef typename basic_math_types::real_type real_type;
00047 typedef typename basic_math_types::index_type index_type;
00048
00049 public:
00050
00051 typedef ublas::compressed_matrix<real_type_> matrix_type;
00052 typedef ublas::vector<real_type_> vector_type;
00053 typedef typename vector_type::size_type size_type;
00054 typedef ublas::vector<index_type> idx_vector_type;
00055 typedef matrix_type system_matrix_type;
00056 typedef ublas::vector_range< vector_type > vector_range;
00057 typedef ublas::matrix_range< matrix_type > matrix_range;
00058 typedef ublas::vector_range< idx_vector_type > idx_vector_range;
00059
00060 public:
00061
00062 static matrix_range subrange(
00063 matrix_type & M
00064 , size_type start1
00065 , size_type stop1
00066 , size_type start2
00067 , size_type stop2
00068 )
00069 {
00070 return ublas::subrange(M,start1,stop1,start2,stop2);
00071 }
00072
00073 static vector_range subrange(vector_type & v, size_type start, size_type stop )
00074 {
00075 return ublas::subrange(v,start,stop);
00076 }
00077
00078 static idx_vector_range subrange(idx_vector_type & v, size_type start, size_type stop )
00079 {
00080 return ublas::subrange(v,start,stop);
00081 }
00082
00083 static void get_dimension(vector_type const & v, size_type & n)
00084 {
00085 n = v.size();
00086 }
00087
00088 static void get_dimensions(matrix_type const & A,size_type & m, size_type & n)
00089 {
00090 m = A.size1();
00091 n = A.size2();
00092 }
00093
00094 static void resize(vector_type & x,size_type n)
00095 {
00096 x.resize(n);
00097 x.clear();
00098 }
00099
00100 static void resize(idx_vector_type & x,size_type n)
00101 {
00102 x.resize(n);
00103 x.clear();
00104 }
00105
00106 static void resize(matrix_type & A,size_type m,size_type n)
00107 {
00108 A.resize(m,n,false);
00109 A.clear();
00110 }
00111
00115 static void prod(matrix_type const & A,vector_type const & x, vector_type const & b, vector_type & y)
00116 {
00117 y.resize(A.size1(),false);
00118 OpenTissue::math::big::prod_add_rhs(A,x,b,y);
00119 }
00120
00124 static void prod_minus(matrix_type const & A,vector_type const & x, vector_type const & b, vector_type & y)
00125 {
00126 y.resize(A.size1(),false);
00127 OpenTissue::math::big::prod_sub_rhs(A,x,b,y);
00128 }
00129
00133 static void prod(matrix_type const & A,vector_type const & x, vector_type & y)
00134 {
00135 y.resize(A.size1(),false);
00136 OpenTissue::math::big::prod(A,x,y);
00137 }
00138
00142 static void prod_add(matrix_type const & A,vector_type const & x, vector_type & y)
00143 {
00144 y.resize(A.size1(),false);
00145 OpenTissue::math::big::prod_add(A,x,y);
00146 }
00147
00151 static void prod(matrix_type const & A,vector_type const & x, vector_type & y, real_type const & s)
00152 {
00153 y.resize(A.size1(),false);
00154 OpenTissue::math::big::prod(A,x,s,y);
00155 }
00156
00160 static void prod_add(matrix_type const & A,vector_type const & x, vector_type & y, real_type const & s)
00161 {
00162 y.resize(A.size1(),false);
00163 OpenTissue::math::big::prod_add(A,x,s,y);
00164 }
00165
00169 static void prod_trans(matrix_type const & A,vector_type const & x, vector_type & y)
00170 {
00171 y.resize(A.size2(),false);
00172 OpenTissue::math::big::prod_trans(A,x,y);
00173 }
00174
00178 static void prod_trans(matrix_type const & A,vector_type const & x, vector_type const & b, vector_type & y)
00179 {
00180 y.resize(A.size2(),false);
00181 OpenTissue::math::big::prod_trans(A,x,b,y);
00182 }
00183
00184
00188 static void prod(vector_type & x, real_type const & s )
00189 {
00190 x *= s;
00191 }
00192
00196 static void assign_minus(vector_type const & y, vector_type & x)
00197 {
00198 x = -y;
00199 }
00200
00201 static void compute_system_matrix(matrix_type const & invM, matrix_type const & J, system_matrix_type & A)
00202 {
00203 A.resize(J.size1(), J.size1(),false);
00204
00205
00206
00207
00208
00209
00210
00211 matrix_type JT;
00212 JT.resize(J.size2(), J.size1(), false);
00213 ublas::noalias(JT) = ublas::trans(J);
00214 matrix_type WJT;
00215 WJT.resize(invM.size1(), JT.size2(), false);
00216 ublas::noalias(WJT) = ublas::sparse_prod<matrix_type>( invM, JT);
00217 ublas::noalias(A) = ublas::sparse_prod<matrix_type>(J, WJT );
00218 }
00219
00220 public:
00221
00223
00224 static real_type row_prod(system_matrix_type const & A,size_type i,vector_type const & x)
00225 {
00226 return OpenTissue::math::big::prod_row(A,x,i);
00227 }
00228
00232 static void init_system_matrix(system_matrix_type & A, vector_type const & x)
00233 {
00234
00235 }
00236
00240 static void update_system_matrix(system_matrix_type & A, size_type i, real_type const & dx)
00241 {
00242
00243 }
00244
00245 };
00246
00247 }
00248 }
00249
00250 #endif