36TEST(NewtonInversion, NewtonSolve)
43 Real initial_guess = 11;
44 auto func = [&](Real x1, Real x2, Real & z, Real & dzdx1, Real & dzdx2)
53 EXPECT_NEAR(
y, soln,
tol);
56 auto func2 = [&](Real x1, Real x2, Real & z, Real & dzdx1, Real & dzdx2)
60 z = 0.8749124087762432;
64 EXPECT_NEAR(
y, soln,
tol);
102TEST(NewtonInversion, NewtonSolve2D)
120 auto func1 = [&](Real
x, Real
y, Real &
f, Real & dfdx, Real & dfdy)
122 auto func2 = [&](Real
x, Real
y, Real & g, Real & dgdx, Real & dgdy)
124 auto func3 = [&](Real
x, Real
y, Real & g, Real & dgdx, Real & dgdy)
127 y1, y2, guess1, guess2, return_x1, return_x2, 1e-8, 1e-8, func1, func2);
131 EXPECT_NEAR(return_x1, x1_soln,
tol);
132 EXPECT_NEAR(return_x2, x2_soln,
tol);
136 y2 = 1.1196002982765987;
138 y1, y2, guess1, guess2, return_x1, return_x2, 1e-8, 1e-8, func1, func3);
141 EXPECT_NEAR(return_x1, x1_soln,
tol);
142 EXPECT_NEAR(return_x2, x2_soln,
tol);
145 y2 = 1.1196002982765987;
147 y1, y2, guess1, guess2, return_x1, return_x2, 1e-8, 1e-8, func2, func3);
150 EXPECT_NEAR(return_x1, x1_soln,
tol);
151 EXPECT_NEAR(return_x2, x2_soln,
tol);
159 auto func2_with_cte = [&](Real
x, Real
y, Real & g, Real & dgdx, Real & dgdy)
167 y1, y2, guess1, x2_soln, return_x1, return_x2, 1e-8, 1e-8, func1, func2_with_cte);
168 EXPECT_NEAR(return_x1, x1_soln,
tol);
169 EXPECT_NEAR(return_x2, x2_soln,
tol);
177 y1, y2, guess1, guess2, return_x1, return_x2, 1e-8, 1e-8, func1, func3);
std::pair< T, T > NewtonSolve(const T &x, const T &y, const Real z_initial_guess, const Real tolerance, const Functor &y_from_x_z, const std::string &caller_name, const unsigned int max_its=100, const bool verbose=false)
NewtonSolve does a 1D Newton Solve to solve the equation y = f(x, z) for variable z.
void NewtonSolve2D(const T &f, const T &g, const Real x0, const Real y0, T &x_final, T &y_final, const Real f_tol, const Real g_tol, const Functor1 &f_from_x_y, const Functor2 &g_from_x_y, const std::string &caller_name="", const unsigned int max_its=100, bool debug=false)
NewtonSolve2D does a 2D Newton Solve to solve for the x and y such that: f = f_from_x_y(x,...