41 #ifndef DTK_NEWTONSOLVER_IMPL_HPP 42 #define DTK_NEWTONSOLVER_IMPL_HPP 49 #include <Teuchos_ScalarTraits.hpp> 51 #include <Intrepid_RealSpaceTools.hpp> 59 template <
typename NonlinearProblem>
61 NonlinearProblem &problem,
62 const double tolerance,
65 DTK_REQUIRE( 2 == u.rank() );
68 int d0 = u.dimension( 0 );
69 int d1 = u.dimension( 1 );
71 MDArray J( d0, d1, d1 );
72 MDArray J_inv( d0, d1, d1 );
73 MDArray update( d0, d1 );
75 MDArray conv_check( d0 );
78 NPT::updateState( problem, u );
81 NPT::evaluateResidual( problem, u, F );
82 Intrepid::RealSpaceTools<Scalar>::scale(
83 F, -Teuchos::ScalarTraits<Scalar>::one() );
86 NPT::evaluateJacobian( problem, u, J );
92 Intrepid::RealSpaceTools<Scalar>::det( det, J );
93 if ( std::abs( det( 0 ) ) < tolerance )
95 for (
int m = 0; m < d0; ++m )
97 for (
int n = 0; n < d1; ++n )
99 u( m, n ) = std::numeric_limits<Scalar>::max();
106 for (
int k = 0; k < max_iters; ++k )
109 Intrepid::RealSpaceTools<Scalar>::inverse( J_inv, J );
110 Intrepid::RealSpaceTools<Scalar>::matvec( update, J_inv, F );
113 Intrepid::RealSpaceTools<Scalar>::add( u, update );
116 Intrepid::RealSpaceTools<Scalar>::subtract( u_old, u );
117 Intrepid::RealSpaceTools<Scalar>::vectorNorm( conv_check, u_old,
118 Intrepid::NORM_TWO );
119 if ( tolerance > conv_check( 0 ) )
129 NPT::updateState( problem, u );
132 NPT::evaluateResidual( problem, u, F );
133 Intrepid::RealSpaceTools<Scalar>::scale(
134 F, -Teuchos::ScalarTraits<Scalar>::one() );
137 NPT::evaluateJacobian( problem, u, J );
141 DTK_ENSURE( tolerance > conv_check( 0 ) );
150 #endif // end DTK_NEWTONSOLVER_IMPL_HPP static void solve(MDArray &u, NonlinearProblem &problem, const double tolerance, const int max_iters)
Get the center of the reference cell of the given topology.
Assertions and Design-by-Contract for error handling.