Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Rational_Approx.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "Tools/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  }
36 
37  //- prototype declaration
38  int approx(void);
39 
40 #ifdef USE_TESTMANAGER_AUTOREGISTER
41  namespace {
42 #if defined(USE_GROUP_SU2)
43  // Nc=2 is not available.
44 #else
45  static const bool is_registered = TestManager::RegisterTest(
46  test_name,
47  approx
48  );
49 #endif
50  }
51 #endif
52 
53  //====================================================================
54  int approx(void)
55  {
56  // #### parameter setup ####
57  const Parameters params_all = ParameterManager::read(filename_input);
58 
59  const Parameters params_test = params_all.lookup("Test_Rational");
60  const Parameters params_rational = params_all.lookup("Math_Rational");
61 
62  const string str_vlevel = params_test.get_string("verbose_level");
63 
64  const bool do_check = params_test.is_set("expected_result");
65  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
66 
67  const int n_exp = params_rational.get_int("exponent_numerator");
68  const int d_exp = params_rational.get_int("exponent_denominator");
69  const double x_min = params_rational.get_double("lower_bound");
70  const double x_max = params_rational.get_double("upper_bound");
71  const int Npoint = params_rational.get_int("number_of_partitions");
72 
73  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
74 
75  //- print input parameters
76  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
77  vout.general(vl, " n_exp = %d\n", n_exp);
78  vout.general(vl, " d_exp = %d\n", d_exp);
79  vout.general(vl, " x_min = %12.8f\n", x_min);
80  vout.general(vl, " x_max = %12.8f\n", x_max);
81  vout.general(vl, " Npoint = %d\n", Npoint);
82  vout.general(vl, "\n");
83 
84 
85  // #### object setup ####
86  Math_Rational rational;
87  rational.set_parameters(params_rational);
88 
89  const unique_ptr<Timer> timer(new Timer(test_name));
90 
91 
92  // #### Execution main part ####
93  timer->start();
94 
95  const double dx = (x_max - x_min) / Npoint;
96  const double p_exp = ((double)n_exp) / ((double)d_exp);
97 
98  double x = x_min;
99 
100  for (int j = 0; j < Npoint + 1; ++j) {
101  double y1 = rational.func(x);
102  double y2 = pow(x, p_exp);
103 
104  vout.general(vl, "x,rational,x^(n/d) = %12.8f %12.8f %12.8f \n", x, y1, y2);
105 
106  x += dx;
107  }
108 
109  const double result = x;
110 
111  timer->report();
112 
113 
114  if (do_check) {
115  return Test::verify(result, expected_result);
116  } else {
117  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
118  return EXIT_SKIP;
119  }
120  }
121 } // namespace Test_Rational
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:503
const std::string test_name
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
void general(const char *format,...)
Definition: bridgeIO.cpp:197
void set_parameters(const Parameters &params)
int get_int(const string &key) const
Definition: parameters.cpp:192
Class for parameters.
Definition: parameters.h:46
Determionation of coefficients of rational approximation.
Definition: math_Rational.h:40
Parameters lookup(const string &key) const
Definition: parameters.h:79
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69
double get_double(const string &key) const
Definition: parameters.cpp:175
bool is_set(const string &key) const
Definition: parameters.cpp:528
void start()
Definition: timer.cpp:44
static void read(const std::string &params_file, Parameters &params)
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:221
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
double func(const double x)