Debian Codegraph @

packages/stk/stk_unit_tests/stk_middle_mesh/test_newton2.cpp

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