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
15namespace Model
16{
17namespace Interface
18{
19namespace GB
20{
21/// Reads the data from a file and computes energies and its derivates
22///
23class Read : public GB
24{
25public:
26 static constexpr const char* name = "read";
27
28
29 /// \brief Read in data
30 ///
31 /// 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
32 ///
33 /// \f[ \int_0^1x^2dx = \frac{1}{3} \f]
34 ///
35 Read() {}
37 Read(IO::ParmParse &pp, std::string name) {pp_queryclass(name,*this);}
38 Read(std::string filename)
39 {
40 Define(filename);
41 }
42
43 void Define(std::string filename)
44 {
48 return;
49 std::ifstream input;
50 input.open(filename);
51 std::string line;
52 std::vector<Set::Scalar> theta, thetasmall, w, dw, ddw;
53 while(std::getline(input,line))
54 {
55 std::vector<std::string> dat = Util::String::Split(line);
56 theta.push_back(std::stof(dat[0]));
57 w.push_back(std::stof(dat[1]));
58 }
59 for (unsigned int i = 1; i < theta.size()-1; i++)
60 {
61 thetasmall.push_back(theta[i]);
62 dw.push_back((w[i+1] - w[i-1]) / (theta[i+1] - theta[i-1]));
63 ddw.push_back((w[i+1] - 2.0*w[i] + w[i-1]) / ((theta[i+1]-theta[i]) * (theta[i]-theta[i-1])));
64 }
65 m_w.define(w,theta);
66 m_dw.define(dw,thetasmall);
67 m_ddw.define(ddw,thetasmall);
68
69 for (Set::Scalar t = -0.001; t < 2*Set::Constant::Pi+1.0; t+=0.001)
70 {
71 Set::Scalar w = m_w(t), dw = m_dw(t), ddw = m_ddw(t);
72 if (std::isnan(w) || std::isnan(dw) || std::isnan(ddw) ||
73 std::isinf(w) || std::isinf(dw) || std::isinf(ddw))
74 Util::Abort(INFO,"Error in GB Read: t=",t," w=",w," dw=",dw," ddw=",ddw);
75 }
76 };
77 Set::Scalar W(const Set::Scalar theta) const
78 {
79 return m_w(theta);
80 };
81 Set::Scalar DW(const Set::Scalar theta) const
82 {
83 return m_dw(theta);
84 };
85 Set::Scalar DDW(const Set::Scalar theta) const
86 {
87 return m_ddw(theta);
88 };
89
90private:
92
93public:
94 static void Parse(Read & value, IO::ParmParse & pp)
95 {
96 std::string filename;
97 pp_query_file("filename",filename); // Filename containing GB data
98 value.Define(filename);
99 }
100
101};
102}
103}
104}
105#endif
std::time_t t
#define pp_query_file(...)
Definition ParmParse.H:102
#define pp_queryclass(...)
Definition ParmParse.H:107
#define INFO
Definition Util.H:20
Reads the data from a file and computes energies and its derivates.
Definition Read.H:24
static void Parse(Read &value, IO::ParmParse &pp)
Definition Read.H:94
Read()
Read in data.
Definition Read.H:35
Numeric::Interpolator::Linear< Set::Scalar > m_w
Definition Read.H:91
Numeric::Interpolator::Linear< Set::Scalar > m_dw
Definition Read.H:91
Read(IO::ParmParse &pp)
Definition Read.H:36
Read(IO::ParmParse &pp, std::string name)
Definition Read.H:37
Set::Scalar DDW(const Set::Scalar theta) const
Definition Read.H:85
static constexpr const char * name
Definition Read.H:26
Read(std::string filename)
Definition Read.H:38
void Define(std::string filename)
Definition Read.H:43
Set::Scalar DW(const Set::Scalar theta) const
Definition Read.H:81
Numeric::Interpolator::Linear< Set::Scalar > m_ddw
Definition Read.H:91
Set::Scalar W(const Set::Scalar theta) const
Definition Read.H:77
void define(const std::string a_str)
Definition Linear.H:71
static Linear< T > Read(std::string filename, int derivative=0)
static const Set::Scalar Pi
Definition Set.H:286
amrex::Real Scalar
Definition Base.H:19
std::vector< std::string > Split(std::string &str, const char delim)
Definition Util.cpp:296
void Abort(const char *msg)
Definition Util.cpp:170