00001 #ifndef OPENTISSUE_CORE_MATH_OPTIMIZATION_STATIONARY_POINT_H 00002 #define OPENTISSUE_CORE_MATH_OPTIMIZATION_STATIONARY_POINT_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/core/math/big/big_types.h> 00013 #include <OpenTissue/core/math/math_value_traits.h> 00014 #include <OpenTissue/core/math/math_is_number.h> 00015 #include <cassert> 00016 00017 namespace OpenTissue 00018 { 00019 namespace math 00020 { 00021 namespace optimization 00022 { 00023 00041 template < typename T > 00042 inline bool stationary_point( ublas::vector<T> const & gradient, T const & tolerance, T & length ) 00043 { 00044 typedef OpenTissue::math::ValueTraits<T> value_traits; 00045 00046 assert( is_number( tolerance ) || !"stationary_point(): internal error, NAN is encountered?"); 00047 assert( tolerance>=value_traits::zero() || !"stationary_point(): internal error, NAN is encountered?"); 00048 00049 length = ublas::norm_2( gradient) ; 00050 00051 assert( is_number( length ) || !"stationary_point(): internal error, NAN is encountered?"); 00052 00053 if( length <= tolerance) 00054 return true; 00055 return false; 00056 } 00057 00058 } // namespace optimization 00059 } // namespace math 00060 } // namespace OpenTissue 00061 00062 // OPENTISSUE_CORE_MATH_OPTIMIZATION_STATIONARY_POINT_H 00063 #endif