Alamo
Test.cpp
Go to the documentation of this file.
1 #include "Test.H"
2 #include "Linear.H"
3 #include "Util/Util.H"
4 #include "Set/Set.H"
5 #include "Util/Color.H"
6 
7 namespace Numeric
8 {
9 namespace Interpolator
10 {
11 
12 template<>
13 int Test<Linear<Set::Scalar> >::Match(int verbose)
14 {
15  // Test function:
16  //
17  // y(x) = { -1 x < -1
18  // { 2*x + 1 -1 < x < 0
19  // { 1-x 0 < x < 1
20  // { 0 1 < x
21 
22  std::vector<Set::Scalar> xs;
23  std::vector<Set::Scalar> ys;
24  xs.push_back(-1.0); ys.push_back(-1.0);
25  xs.push_back(0.0); ys.push_back(1.0);
26  xs.push_back(1.0); ys.push_back(0.0);
27 
28  Linear<Set::Scalar> interp(ys,xs);
29 
30  Set::Scalar normsq = 0.0;
31  const Set::Scalar dx = 0.01;
32  for (Set::Scalar x = -2.0; x < -1.0; x+=dx)
33  {
34  Set::Scalar exact = -1.0;
35  normsq += pow((interp(x) - exact)/dx,2.0);
36  if (verbose>0) Util::Message(INFO,(normsq>1E-8 ? Color::FG::Red : Color::Reset), "x = ", x , "\texact = ", exact, "\tinterp = ", interp(x), " normsq = ", normsq,Color::Reset);
37  }
38  for (Set::Scalar x = -1.0; x < -0; x+=dx)
39  {
40  Set::Scalar exact = 2*x + 1;
41  normsq += pow((interp(x) - exact)/dx,2.0);
42  if (verbose>0) Util::Message(INFO,(normsq>1E-8 ? Color::FG::Red : Color::Reset), "x = ", x , "\texact = ", exact, "\tinterp = ", interp(x), " normsq = ", normsq,Color::Reset);
43  }
44  for (Set::Scalar x = 0; x < 1.0; x+=dx)
45  {
46  Set::Scalar exact = 1.0 - x;
47  normsq += pow((interp(x) - exact)/dx,2.0);
48  if (verbose>0) Util::Message(INFO,(normsq>1E-8 ? Color::FG::Red : Color::Reset), "x = ", x , "\texact = ", exact, "\tinterp = ", interp(x), " normsq = ", normsq,Color::Reset);
49  }
50  for (Set::Scalar x = 1.0; x < 2.0; x+=dx)
51  {
52  Set::Scalar exact = 0.0;
53  normsq += pow((interp(x) - exact)/dx,2.0);
54  if (verbose>0) Util::Message(INFO,(normsq>1E-8 ? Color::FG::Red : Color::Reset), "x = ", x , "\texact = ", exact, "\tinterp = ", interp(x), " normsq = ", normsq,Color::Reset);
55  }
56 
57  if (normsq > 1E-8) return 1;
58  else return 0;
59 }
60 }
61 }
Numeric::Interpolator::Test
Definition: Test.H:9
Color::FG::Red
static std::string Red
Definition: Color.H:20
Util.H
Linear.H
Set::Scalar
amrex::Real Scalar
Definition: Base.H:19
Numeric::Interpolator::Linear< Set::Scalar >
Color::Reset
static std::string Reset
Definition: Color.H:8
Set.H
Test.H
Numeric
This namespace contains some numerical tools.
Definition: Function.H:5
INFO
#define INFO
Definition: Util.H:20
Color.H
Util::Message
void Message(std::string file, std::string func, int line, Args const &... args)
Definition: Util.H:133