12 std::cout <<
"Test Function!\n";
42 explicit CustomF(
const std::array<double,3>& input) :
43 J_x(input[0]), J_y(input[1]), J_z(input[2]) {}
48 assert(x.size() == 2);
49 const double a = x[0];
50 const double b = x[1];
51 const double FOUR_PI = 4.0*M_PI;
55 return {(FOUR_PI/b) * exp(a) * sinh(b) - 1.0,
56 (FOUR_PI/b/b) * exp(a) * (b * cosh(b) - sinh(b)) - size_J};
62 assert(x.size() == 2);
63 const double a = x[0];
64 const double b = x[1];
65 const double FOUR_PI = 4.0*M_PI;
67 return {{(FOUR_PI/b) * exp(a) * sinh(b),
68 (FOUR_PI/b/b) * exp(a) * (b * cosh(b) - sinh(b))},
69 {(FOUR_PI/b/b) * exp(a) * (b * cosh(b) - sinh(b)),
70 (FOUR_PI/b/b/b) * exp(a) * ((b*b + 2) * sinh(b) - 2 * b * cosh(b))}};
75 double phi = P1_moments[0];
76 double J_x = P1_moments[1];
77 double J_y = P1_moments[2];
78 double J_z = P1_moments[3];
82 double ratio_i = size_J_i/phi;
84 if (phi < 1.0e-10 or ratio_i > 0.9)
85 { J_x *= 0.9 / size_J_i; J_y *= 0.9 / size_J_i; J_z *= 0.9 / size_J_i; }
87 { J_x /= phi; J_y /= phi; J_z /= phi; }
90 double ratio_f = size_J_f;
94 std::stringstream outstr;
95 outstr <<
"P1 moments initial: " <<P1_moments[0]<<
" "
98 <<P1_moments[3]<<
" |J|=";
99 outstr << size_J_i <<
" ratio=" << ratio_i <<
"\n";
100 outstr <<
"P1 moments initial: " <<1.0<<
" "<<J_x<<
" "<<J_y<<
" "<<J_z<<
" |J|=";
101 outstr << size_J_f <<
" ratio=" << ratio_f <<
"\n";
106 if (size_J_f < 1.0e-10)
108 double a = log(phi/4.0/M_PI);
111 if (verbose) {
Chi::log.
Log() <<
"Solution: " << a <<
" " << b; }
117 CustomF custom_function({J_x, J_y, J_z});
125 double a = solution[0];
126 double b = solution[1];
128 if (verbose) {
Chi::log.
Log() <<
"Solution: " << a <<
" " << b; }
LogStream Log(LOG_LVL level=LOG_0)
virtual MatDbl J(const VecDbl &x) const
virtual VecDbl F(const VecDbl &x) const
VecDbl NewtonIteration(const NonLinearFunction &non_linear_function, const VecDbl &x_0, unsigned int max_iters, double epsilon, bool verbose=false)
double Vec2Norm(const VecDbl &x)
std::vector< VecDbl > MatDbl
std::array< double, 2 > MakeExpRepFromP1(const std::array< double, 4 > &P1_moments, bool verbose=false)
std::vector< double > VecDbl