Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MATH_COMPUTE_WJT_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MATH_COMPUTE_WJT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_is_number.h>
00013
00014 #include <cassert>
00015
00016 namespace OpenTissue
00017 {
00018 namespace mbd
00019 {
00020 namespace math
00021 {
00022
00033 template<typename matrix_type>
00034 void compute_WJT(matrix_type const & W, matrix_type const & J, matrix_type & WJT)
00035 {
00036 typedef typename matrix_type::value_type real_type;
00037 typedef typename matrix_type::size_type size_type;
00038
00039 assert(W.size1()>0 || !"compute_WJT(): W was empty");
00040 assert(W.size2()>0 || !"compute_WJT(): W was empty");
00041 assert(J.size1()>0 || !"compute_WJT(): J was empty");
00042 assert(J.size2()>0 || !"compute_WJT(): J was empty");
00043 assert(W.size2() == J.size2() || !"compute_WJT(): incorrect dimensions");
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 WJT.resize(J.size1(), J.size2(),false);
00085
00086 size_type k[2];
00087 for (size_type i = 0; i < J.size1 (); ++i)
00088 {
00089 size_type begin = J.index1_data()[i];
00090 size_type end = J.index1_data()[i+1];
00091
00092 assert((end-begin)==12 || !"compute_WJT(): J cannot be a jacobian matrix?");
00093
00094 k[0] = begin;
00095 k[1] = end-6;
00096 for(size_type body=0;body<2;++body)
00097 {
00098 size_type j = k[body];
00099
00100 real_type const & j1 = J.value_data()[j];
00101 size_type const & c1 = J.index2_data()[j];
00102 ++j;
00103
00104 real_type const & j2 = J.value_data()[j];
00105 size_type const & c2 = J.index2_data()[j];
00106 ++j;
00107
00108 real_type const & j3 = J.value_data()[j];
00109 size_type const & c3 = J.index2_data()[j];
00110 ++j;
00111
00112 real_type const & j4 = J.value_data()[j];
00113 size_type const & c4 = J.index2_data()[j];
00114 ++j;
00115
00116 real_type const & j5 = J.value_data()[j];
00117 size_type const & c5 = J.index2_data()[j];
00118 ++j;
00119
00120 real_type const & j6 = J.value_data()[j];
00121 size_type const & c6 = J.index2_data()[j];
00122
00123 real_type const & m = W( c1, c1 );
00124 real_type const & i00 = W( c4, c4 );
00125 real_type const & i01 = W( c4, c5 );
00126 real_type const & i02 = W( c4, c6 );
00127 real_type const & i11 = W( c5, c5 );
00128 real_type const & i12 = W( c5, c6 );
00129 real_type const & i22 = W( c6, c6 );
00130
00131 assert(is_number(j1) || !"compute_WJT(): not a number encountered");
00132 assert(is_number(j2) || !"compute_WJT(): not a number encountered");
00133 assert(is_number(j3) || !"compute_WJT(): not a number encountered");
00134 assert(is_number(j4) || !"compute_WJT(): not a number encountered");
00135 assert(is_number(j5) || !"compute_WJT(): not a number encountered");
00136 assert(is_number(j6) || !"compute_WJT(): not a number encountered");
00137
00138 assert(is_number(m) || !"compute_WJT(): not a number encountered");
00139 assert(is_number(i00) || !"compute_WJT(): not a number encountered");
00140 assert(is_number(i01) || !"compute_WJT(): not a number encountered");
00141 assert(is_number(i02) || !"compute_WJT(): not a number encountered");
00142 assert(is_number(i11) || !"compute_WJT(): not a number encountered");
00143 assert(is_number(i12) || !"compute_WJT(): not a number encountered");
00144 assert(is_number(i22) || !"compute_WJT(): not a number encountered");
00145
00146 WJT(i,c1) = j1*m;
00147 WJT(i,c2) = j2*m;
00148 WJT(i,c3) = j3*m;
00149 WJT(i,c4) = j4*i00 + j5*i01 + j6*i02;
00150 WJT(i,c5) = j4*i01 + j5*i11 + j6*i12;
00151 WJT(i,c6) = j4*i02 + j5*i12 + j6*i22;
00152
00153 assert(is_number(WJT(i,c1)) || !"compute_WJT(): not a number encountered");
00154 assert(is_number(WJT(i,c2)) || !"compute_WJT(): not a number encountered");
00155 assert(is_number(WJT(i,c3)) || !"compute_WJT(): not a number encountered");
00156 assert(is_number(WJT(i,c4)) || !"compute_WJT(): not a number encountered");
00157 assert(is_number(WJT(i,c5)) || !"compute_WJT(): not a number encountered");
00158 assert(is_number(WJT(i,c6)) || !"compute_WJT(): not a number encountered");
00159 }
00160 assert((WJT.index1_data()[i+1]-WJT.index1_data()[i])==12 || !"compute_WJT(): WJT did not have jacobian format?");
00161 }
00162 }
00163
00164 }
00165 }
00166 }
00167
00168 #endif