Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_SOLVERS_MBD_MERIT_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_SOLVERS_MBD_MERIT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012
00013 namespace OpenTissue
00014 {
00015 namespace mbd
00016 {
00017
00028 template<typename matrix_type, typename vector_type, typename math_policy>
00029 typename vector_type::value_type merit(
00030 matrix_type const & A
00031 , vector_type const & x
00032 , vector_type const & b
00033 , vector_type const & lo
00034 , vector_type const & hi
00035 , math_policy const &
00036 )
00037 {
00038 using std::min;
00039 using std::max;
00040
00041 typedef typename math_policy::value_traits value_traits;
00042 typedef typename vector_type::size_type size_type;
00043 typedef typename vector_type::value_type real_type;
00044
00045 vector_type y;
00046 size_type n;
00047 math_policy::get_dimension(b,n);
00048 math_policy::resize(y,n);
00049 math_policy::prod(A,x,b,y);
00050 real_type theta = value_traits::zero();
00051 for (size_type i = 0; i < n; ++ i)
00052 {
00053 real_type H_i = min(x(i) - lo(i), max(x(i) - hi(i), y(i) ));
00054 theta += H_i*H_i;
00055 }
00056 theta /= value_traits::two();
00057 return theta;
00058 }
00059
00060 }
00061 }
00062
00063
00064 #endif