| 1 |
#include "stk_middle_mesh/newton.hpp" |
| 2 |
#include "gtest/gtest.h" |
| 3 |
|
| 4 |
namespace stk { |
| 5 |
namespace middle_mesh { |
| 6 |
namespace impl { |
| 7 |
|
| 8 |
TEST(Newton, Solve) |
| 9 |
{ |
| 10 |
auto func = [](const std::vector<double>& x, std::vector<double>& rhs) { |
| 11 |
rhs[0] = std::pow(x[0], 4); |
| 12 |
rhs[1] = std::pow(x[1] - 1, 4); |
| 13 |
}; |
| 14 |
auto jacTest = [](const std::vector<double>& x, utils::impl::Matrix<double>& jac) { |
| 15 |
jac(0, 0) = 4 * std::pow(x[0], 3); |
| 16 |
jac(0, 1) = 0; |
| 17 |
jac(1, 0) = 0; |
| 18 |
jac(1, 1) = 4 * std::pow(x[1] - 1, 3); |
| 19 |
}; |
| 20 |
|
| 21 |
std::vector<double> x0 = {2, 2}; |
| 22 |
|
| 23 |
utils::impl::Newton newton(2, 1e-60, 1000); |
| 24 |
int retVal = newton.solve(func, jacTest, x0); |
| 25 |
|
| 26 |
EXPECT_EQ(retVal, 0); |
| 27 |
EXPECT_NEAR(x0[0], 0.0, 1e-13); |
| 28 |
EXPECT_NEAR(x0[1], 1.0, 1e-13); |
| 29 |
} |
| 30 |
} // namespace impl |
| 31 |
} // namespace middle_mesh |
| 32 |
} // namespace stk |