Bridge++  Ver. 1.3.x
test_Rational_Approx.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "math_Rational.h"
17 
18 //====================================================================
20 
29 namespace Test_Rational {
30  const std::string test_name = "Rational.Approx";
31 
32  //- test-private parameters
33  namespace {
34  const std::string filename_input = "test_Rational_Approx.yaml";
35  const std::string filename_output = "stdout";
36 
37  class Parameters_Test_Rational : public Parameters {
38  public:
39  Parameters_Test_Rational()
40  {
41  Register_string("verbose_level", "NULL");
42 
43  Register_double("expected_result", 0.0);
44  }
45  };
46  }
47 
48  //- prototype declaration
49  int approx(void);
50 
51 #ifdef USE_TESTMANAGER_AUTOREGISTER
52  namespace {
53 #if defined(USE_GROUP_SU2)
54  // Nc=2 is not available.
55 #else
56  static const bool is_registered = TestManager::RegisterTest(
57  test_name,
58  approx
59  );
60 #endif
61  }
62 #endif
63 
64  //====================================================================
65  int approx(void)
66  {
67  // #### parameter setup ####
68  unique_ptr<Parameters> params_test(new Parameters_Test_Rational);
70  unique_ptr<Parameters> params_all(new Parameters);
71 
72  params_all->Register_Parameters("Test_Rational", params_test);
73  params_all->Register_Parameters("Math_Rational", params_rational);
74 
75  ParameterManager::read(filename_input, params_all);
76 
77  const string str_vlevel = params_test->get_string("verbose_level");
78 
79  const bool do_check = params_test->is_set("expected_result");
80  const double expected_result = do_check ? params_test->get_double("expected_result") : 0.0;
81 
82  const int n_exp = params_rational->get_int("exponent_numerator");
83  const int d_exp = params_rational->get_int("exponent_denominator");
84  const double x_min = params_rational->get_double("lower_bound");
85  const double x_max = params_rational->get_double("upper_bound");
86  const int Npoint = params_rational->get_int("number_of_partitions");
87 
89 
90  //- print input parameters
91  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
92  vout.general(vl, " n_exp = %d\n", n_exp);
93  vout.general(vl, " d_exp = %d\n", d_exp);
94  vout.general(vl, " x_min = %12.8f\n", x_min);
95  vout.general(vl, " x_max = %12.8f\n", x_max);
96  vout.general(vl, " Npoint = %d\n", Npoint);
97  vout.general(vl, "\n");
98 
99 
100  // #### object setup ####
101  Math_Rational rational;
102  rational.set_parameters(*params_rational);
103 
104  unique_ptr<Timer> timer(new Timer(test_name));
105 
106 
107  // #### Execution main part ####
108  timer->start();
109 
110  double x = x_min;
111  double dx = (x_max - x_min) / Npoint;
112  double p_exp = ((double)n_exp) / ((double)d_exp);
113 
114  for (int j = 0; j < Npoint + 1; ++j) {
115  double y1 = rational.func(x);
116  double y2 = pow(x, p_exp);
117 
118  vout.general(vl, "x,rational,x^(n/d) = %12.8f %12.8f %12.8f \n", x, y1, y2);
119 
120  x += dx;
121  }
122 
123  double result = x;
124 
125  timer->report();
126 
127 
128  if (do_check) {
129  return Test::verify(result, expected_result);
130  } else {
131  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
132  return EXIT_SKIP;
133  }
134  }
135 } // namespace Test_Rational
#define EXIT_SKIP
Definition: test.h:17
Determionation of coefficients of rational approximation.
Definition: math_Rational.h:41
BridgeIO vout
Definition: bridgeIO.cpp:278
const std::string test_name
void detailed(const char *format,...)
Definition: bridgeIO.cpp:82
void general(const char *format,...)
Definition: bridgeIO.cpp:65
void set_parameters(const Parameters &params)
int get_int(const string &key) const
Definition: parameters.cpp:42
Class for parameters.
Definition: parameters.h:38
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:80
bool is_set(const string &) const
Definition: parameters.cpp:372
double get_double(const string &key) const
Definition: parameters.cpp:27
double func(double x)
void start()
Definition: timer.cpp:44
void Register_Parameters(const string &, Parameters *const)
Definition: parameters.cpp:358
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Test of rational approximation of fermion operators.
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:39
static void read(const std::string &params_file, Parameters *params)
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:87
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:28