Bridge++  Version 1.4.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 "Tests/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 
58  Parameters params_all = ParameterManager::read(filename_input);
59 
60  Parameters params_test = params_all.lookup("Test_Rational");
61  Parameters params_rational = params_all.lookup("Math_Rational");
62 
63  const string str_vlevel = params_test.get_string("verbose_level");
64 
65  const bool do_check = params_test.is_set("expected_result");
66  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
67 
68  const int n_exp = params_rational.get_int("exponent_numerator");
69  const int d_exp = params_rational.get_int("exponent_denominator");
70  const double x_min = params_rational.get_double("lower_bound");
71  const double x_max = params_rational.get_double("upper_bound");
72  const int Npoint = params_rational.get_int("number_of_partitions");
73 
75 
76  //- print input parameters
77  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
78  vout.general(vl, " n_exp = %d\n", n_exp);
79  vout.general(vl, " d_exp = %d\n", d_exp);
80  vout.general(vl, " x_min = %12.8f\n", x_min);
81  vout.general(vl, " x_max = %12.8f\n", x_max);
82  vout.general(vl, " Npoint = %d\n", Npoint);
83  vout.general(vl, "\n");
84 
85 
86  // #### object setup ####
87  Math_Rational rational;
88  rational.set_parameters(params_rational);
89 
90  unique_ptr<Timer> timer(new Timer(test_name));
91 
92 
93  // #### Execution main part ####
94  timer->start();
95 
96  double x = x_min;
97  double dx = (x_max - x_min) / Npoint;
98  double p_exp = ((double)n_exp) / ((double)d_exp);
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  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:495
const std::string test_name
void detailed(const char *format,...)
Definition: bridgeIO.cpp:212
void general(const char *format,...)
Definition: bridgeIO.cpp:195
void set_parameters(const Parameters &params)
int get_int(const string &key) const
Definition: parameters.cpp:87
Class for parameters.
Definition: parameters.h:46
Determionation of coefficients of rational approximation.
Definition: math_Rational.h:41
Parameters lookup(const string &key) const
Definition: parameters.h:78
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:70
double func(double x)
bool is_set(const string &key) const
Definition: parameters.cpp:396
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
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:42
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:116
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