Bridge++  Version 1.4.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_FFT.cpp
Go to the documentation of this file.
1 
14 #include "Tests/test.h"
15 
16 #include "Tools/fft.h"
17 
18 #include "Field/field_F.h"
20 
21 //====================================================================
23 
28 #ifdef USE_FFTWLIB
29 namespace Test_FFT {
30  const std::string test_name = "FFT.fft";
31 
32  //- test-private parameters
33  namespace {
34  const std::string filename_input = "test_FFT.yaml";
35  }
36 
37  //- prototype declaration
38  int fft(void);
39 
40 #ifdef USE_TESTMANAGER_AUTOREGISTER
41  namespace {
42  static const bool is_registered = TestManager::RegisterTest(
43  test_name,
44  fft
45  );
46  }
47 #endif
48 
49  //====================================================================
50  int fft(void)
51  {
52  // #### parameter setup ####
53  //- global lattice size
54  int Lt = CommonParameters::Lt();
55 
56  //- local size
57  int Nx = CommonParameters::Nx();
58  int Ny = CommonParameters::Ny();
59  int Nz = CommonParameters::Nz();
60  int Nvol = CommonParameters::Nvol();
61 
62  int Nc = CommonParameters::Nc();
63 
64  Parameters params_all = ParameterManager::read(filename_input);
65 
66  Parameters params_test = params_all.lookup("Test_FFT");
67  Parameters params_fft = params_all.lookup("FFT");
68  Parameters params_source = params_all.lookup("Source");
69 
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 string str_fft_type = params_fft.get_string("FFT_type");
76  const string str_source_type = params_source.get_string("source_type");
77 
79 
80 
81  // #### object setup #####
82  unique_ptr<FFT> fft(FFT::New(str_fft_type));
83  fft->set_parameters(params_fft);
84 
85  unique_ptr<Source> source(Source::New(str_source_type));
86  source->set_parameters(params_source);
87 
89  unique_ptr<Timer> timer(new Timer(test_name));
90 
91 
92  // #### Execution main part ####
93  Field_F b;
94  b.set(0.0);
95 
96  int i_spin = 0;
97  int i_color = 0;
98 
99  int idx = i_color + Nc * i_spin;
100  source->set(b, idx);
101  vout.general(vl, "b.norm2(before FFT) = %e\n", b.norm2());
102 
103 
104  timer->start();
105 
106  fft->fft(b);
107  vout.general(vl, "b.norm2(after FFT) = %e\n", b.norm2());
108 
109  double result = 0.0;
110  if (Communicator::nodeid() == 0) {
111  int i_site = index->site(0, 0, 0, 0);
112  result = b.cmp_r(i_color, i_spin, i_site);
113  }
114 
115  timer->report();
116 
117 
118  if (do_check) {
119  return Test::verify(result, expected_result);
120  } else {
121  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
122  return EXIT_SKIP;
123  }
124  }
125 } // namespace Test_FFT
126 #endif
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:495
void detailed(const char *format,...)
Definition: bridgeIO.cpp:212
double norm2() const
Definition: field.cpp:441
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:164
void general(const char *format,...)
Definition: bridgeIO.cpp:195
const std::string test_name
Class for parameters.
Definition: parameters.h:46
Wilson-type fermion field.
Definition: field_F.h:37
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
Lexical site index.
Definition: index_lex.h:34
bool is_set(const string &key) const
Definition: parameters.cpp:396
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
static int nodeid()
alternative name for self().
Definition: communicator.h:92
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:116
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
double cmp_r(const int cc, const int s, const int site, const int e=0) const
Definition: field_F.h:95