Alamo
Read.H
Go to the documentation of this file.
1 #ifndef MODEL_INTERFACE_GB_READ_H
2 #define MODEL_INTERFACE_GB_READ_H
3 
4 #include <iostream>
5 #include <fstream>
6 #include <vector>
7 
8 #include "AMReX.H"
9 #include "GB.H"
10 
12 
13 #define PI 3.14159265
14 
15 namespace Model
16 {
17 namespace Interface
18 {
19 namespace GB
20 {
21 /// Reads the data from a file and computes energies and its derivates
22 ///
23 class Read : public GB
24 {
25 public:
26  /// \brief Read in data
27  ///
28  /// Reads the data from a file and abort if it is not possible to open the file or if the range of thetas do not give a range between 0 and 2pi. It also computes the derivatives of the energy and stores them in vectors that will be used in W, DW, and DDW
29  ///
30  /// \f[ \int_0^1x^2dx = \frac{1}{3} \f]
31  ///
32  Read() {}
34  Read(IO::ParmParse &pp, std::string name) {pp_queryclass(name,*this);}
35  Read(std::string filename)
36  {
38  }
39 
40  void Define(std::string filename)
41  {
45  return;
46  std::ifstream input;
47  input.open(filename);
48  std::string line;
49  std::vector<Set::Scalar> theta, thetasmall, w, dw, ddw;
50  while(std::getline(input,line))
51  {
52  std::vector<std::string> dat = Util::String::Split(line);
53  theta.push_back(std::stof(dat[0]));
54  w.push_back(std::stof(dat[1]));
55  }
56  for (unsigned int i = 1; i < theta.size()-1; i++)
57  {
58  thetasmall.push_back(theta[i]);
59  dw.push_back((w[i+1] - w[i-1]) / (theta[i+1] - theta[i-1]));
60  ddw.push_back((w[i+1] - 2.0*w[i] + w[i-1]) / ((theta[i+1]-theta[i]) * (theta[i]-theta[i-1])));
61  }
62  m_w.define(w,theta);
63  m_dw.define(dw,thetasmall);
64  m_ddw.define(ddw,thetasmall);
65 
66  for (Set::Scalar t = -0.001; t < 2*Set::Constant::Pi+1.0; t+=0.001)
67  {
68  Set::Scalar w = m_w(t), dw = m_dw(t), ddw = m_ddw(t);
69  if (std::isnan(w) || std::isnan(dw) || std::isnan(ddw) ||
70  std::isinf(w) || std::isinf(dw) || std::isinf(ddw))
71  Util::Abort(INFO,"Error in GB Read: t=",t," w=",w," dw=",dw," ddw=",ddw);
72  }
73  };
74  Set::Scalar W(const Set::Scalar theta) const
75  {
76  return m_w(theta);
77  };
78  Set::Scalar DW(const Set::Scalar theta) const
79  {
80  return m_dw(theta);
81  };
82  Set::Scalar DDW(const Set::Scalar theta) const
83  {
84  return m_ddw(theta);
85  };
86 
87 private:
89 
90 public:
91  static void Parse(Read & value, IO::ParmParse & pp)
92  {
93  std::string filename;
94  pp_query_file("filename",filename); // Filename containing GB data
95  value.Define(filename);
96  }
97 
98 };
99 }
100 }
101 }
102 #endif
Util::filename
std::string filename
Definition: Util.cpp:19
Model::Interface::GB::Read::Read
Read(IO::ParmParse &pp, std::string name)
Definition: Read.H:34
Linear.H
Model::Interface::GB::Read::m_ddw
Numeric::Interpolator::Linear< Set::Scalar > m_ddw
Definition: Read.H:88
Numeric::Interpolator::Linear::define
void define(const std::string a_str)
Definition: Linear.H:71
Model::Interface::GB::GB
Definition: GB.H:18
Util::String::Split
std::vector< std::string > Split(std::string &str, const char delim)
Definition: Util.cpp:291
Model::Interface::GB::Read
Definition: Read.H:23
t
std::time_t t
Definition: FileNameParse.cpp:12
Model::Interface::GB::Read::DW
Set::Scalar DW(const Set::Scalar theta) const
Definition: Read.H:78
Model::Interface::GB::Read::Read
Read(std::string filename)
Definition: Read.H:35
Set::Scalar
amrex::Real Scalar
Definition: Base.H:19
pp_queryclass
#define pp_queryclass(...)
Definition: ParmParse.H:105
Model::Interface::GB::Read::Define
void Define(std::string filename)
Definition: Read.H:40
GB.H
Model::Interface::GB::Read::W
Set::Scalar W(const Set::Scalar theta) const
Definition: Read.H:74
pp_query_file
#define pp_query_file(...)
Definition: ParmParse.H:102
Numeric::Interpolator::Linear< Set::Scalar >
Util::Abort
void Abort(const char *msg)
Definition: Util.cpp:165
Numeric::Interpolator::Linear::Read
static Linear< T > Read(std::string filename, int derivative=0)
Model::Interface::GB::Read::Read
Read(IO::ParmParse &pp)
Definition: Read.H:33
Model::Interface::GB::Read::m_w
Numeric::Interpolator::Linear< Set::Scalar > m_w
Definition: Read.H:85
Set::Constant::Pi
static const Set::Scalar Pi
Definition: Set.H:286
IO::ParmParse
Definition: ParmParse.H:110
Model::Interface::GB::Read::m_dw
Numeric::Interpolator::Linear< Set::Scalar > m_dw
Definition: Read.H:88
Model::Interface::GB::Read::DDW
Set::Scalar DDW(const Set::Scalar theta) const
Definition: Read.H:82
Model::Interface::GB::Read::Parse
static void Parse(Read &value, IO::ParmParse &pp)
Definition: Read.H:91
Model::Interface::GB::Read::Read
Read()
Read in data.
Definition: Read.H:32
INFO
#define INFO
Definition: Util.H:20
Model
Definition: Constant.H:12