Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Gauge_EnergyDensity.cpp
Go to the documentation of this file.
1 
13 #include "test.h"
14 
15 #include "IO/gaugeConfig.h"
16 
18 
20 
21 //====================================================================
23 
28 namespace Test_Gauge {
29  const std::string test_name = "Gauge.EnergyDensity";
30 
31  //- test-private parameters
32  namespace {
33  const std::string filename_input = "test_Gauge_EnergyDensity.yaml";
34  }
35 
36  //- prototype declaration
37  int energy_density(void);
38 
39 #ifdef USE_TESTMANAGER_AUTOREGISTER
40  namespace {
41 #if defined(USE_GROUP_SU2)
42  // Nc=2 is not available.
43 #else
44  static const bool is_registered = TestManager::RegisterTest(
45  test_name,
47  );
48 #endif
49  }
50 #endif
51 
52  //====================================================================
53  int energy_density(void)
54  {
55  // #### parameter setup ####
56  const int Nvol = CommonParameters::Nvol();
57  const int Ndim = CommonParameters::Ndim();
58  const int Nc = CommonParameters::Nc();
59 
60  const Parameters params_all = ParameterManager::read(filename_input);
61 
62  const Parameters params_test = params_all.lookup("Test_Gauge_EnergyDensity");
63  const Parameters params_energy_density = params_all.lookup("EnergyDensity");
64 
65  const string str_gconf_status = params_test.get_string("gauge_config_status");
66  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
67  const string readfile = params_test.get_string("config_filename_input");
68  const string str_rand_type = params_test.get_string("random_number_type");
69  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
70  const string str_vlevel = params_test.get_string("verbose_level");
71 
72  const bool do_check = params_test.is_set("expected_result");
73  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
74 
75  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
76 
77  //- print input parameters
78  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
79  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
80  vout.general(vl, " readfile = %s\n", readfile.c_str());
81  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
82  vout.general(vl, " seed = %lu\n", seed);
83  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
84  vout.general(vl, "\n");
85 
86  //- input parameter check
87  int err = 0;
88  err += ParameterCheck::non_NULL(str_gconf_status);
89 
90  if (err) {
91  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
92  exit(EXIT_FAILURE);
93  }
94 
95 
96  RandomNumberManager::initialize(str_rand_type, seed);
97 
98 
99  // #### object setup #####
100  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
101 
102  if (str_gconf_status == "Continue") {
103  GaugeConfig(str_gconf_read).read(U, readfile);
104  } else if (str_gconf_status == "Cold_start") {
105  GaugeConfig("Unit").read(U);
106  } else if (str_gconf_status == "Hot_start") {
107  GaugeConfig("Random").read(U);
108  } else {
109  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
110  exit(EXIT_FAILURE);
111  }
112 
114  energy_density->set_parameters(params_energy_density);
115 
116  const unique_ptr<Timer> timer(new Timer(test_name));
117 
118 
119  // #### Execution main part ####
120  timer->start();
121 
122  const double result = energy_density->E_clover(*U);
123 
124  timer->report();
125 
127 
128 
129  if (do_check) {
130  return Test::verify(result, expected_result);
131  } else {
132  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
133  return EXIT_SKIP;
134  }
135  }
136 } // namespace Test_Gauge_EnergyDensity
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
void general(const char *format,...)
Definition: bridgeIO.cpp:197
double E_clover(const Field_G &U)
Class for parameters.
Definition: parameters.h:46
virtual void set_parameters(const Parameters &params)
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
const std::string test_name
static bool initialize(const std::string &rng_type, unsigned long seed)
SU(N) gauge field.
Definition: field_G.h:38
void read(Field_G *U, const string &filename=string())
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
double get_double(const string &key) const
Definition: parameters.cpp:175
energy density measurement.
Definition: energyDensity.h:29
int non_NULL(const std::string v)
bool is_set(const string &key) const
Definition: parameters.cpp:528
void start()
Definition: timer.cpp:44
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
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
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:78
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