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