Alamo
GB.H
Go to the documentation of this file.
1#ifndef TEST_MODEL_INTERFACE_GB_H
2#define TEST_MODEL_INTERFACE_GB_H
3
4#include "Set/Set.H"
5#include "Model/Interface/GB/GB.H"
6
7namespace Test
8{
9namespace Model
10{
11namespace Interface
12{
13namespace GB
14{
15template <class T>
16class GB
17{
18public:
19 GB() {};
20 bool DerivativeTest1(int verbose)
21 {
22 int failed = 0;
23 amrex::Real small = 1E-12;
24 amrex::Real tolerance = 1E-3;
25
26 T model;
27 model.Randomize();
28
29 for (int i = 0; i<20; i++)
30 {
31 amrex::Real theta = 2.0*Set::Constant::Pi*((amrex::Real)rand()/(amrex::Real)RAND_MAX);
32
33 amrex::Real numerical_DW = (model.W(theta+small) - model.W(theta-small))/(2.0*small);
34 amrex::Real exact_DW = model.DW(theta);
35 if (fabs(numerical_DW-exact_DW)/(numerical_DW+exact_DW) > tolerance)
36 failed += 1;
37 if (verbose)
38 {
39 Util::Message(INFO,"Theta: " , theta);
40 Util::Message(INFO,"DW Exact: " , exact_DW);
41 Util::Message(INFO,"DW Numerical: " , numerical_DW);
42 }
43
44 }
45 return failed;
46 };
47 bool DerivativeTest2(int verbose)
48 {
49 int failed = 0;
50 amrex::Real small = 1E-8;
51 amrex::Real tolerance = 1E-6;
52
53 T model;
54 model.Randomize();
55
56 for (int i = 0; i<20; i++)
57 {
58 amrex::Real theta = 2.0*Set::Constant::Pi*((amrex::Real)rand()/(amrex::Real)RAND_MAX);
59
60 amrex::Real numerical_DDW = (model.DW(theta+small) - model.DW(theta-small))/(2.0*small);
61 amrex::Real exact_DDW = model.DDW(theta);
62 if (fabs((numerical_DDW-exact_DDW)/(numerical_DDW+exact_DDW)) > tolerance)
63 failed += 1;
64
65 if (verbose)
66 {
67 Util::Message(INFO,"Theta: " , theta);
68 Util::Message(INFO,"DDW Exact: " , exact_DDW);
69 Util::Message(INFO,"DDW Numerical: " , numerical_DDW);
70 }
71
72 }
73 return failed;
74 };
75};
76}
77}
78}
79}
80
81#endif
#define INFO
Definition Util.H:20
bool DerivativeTest2(int verbose)
Definition GB.H:47
bool DerivativeTest1(int verbose)
Definition GB.H:20
static const Set::Scalar Pi
Definition Set.H:286
Definition GB.H:8
void Message(std::string file, std::string func, int line, Args const &... args)
Definition Util.H:141