QMCPACK
SkParserBase.cpp
Go to the documentation of this file.
1 #include "SkParserBase.h"
2 #include "Message/Communicate.h"
4 
5 namespace qmcplusplus
6 {
7 SkParserBase::SkParserBase() : isParseSuccess(false), isGridComputed(false), isSkComputed(false), skname("SkAll")
8 {
9  skraw.resize(0);
10  sk.resize(0);
11  skerr.resize(0);
12  skerr_raw.resize(0);
13  kgridraw.resize(0);
14  kgrid.resize(0);
15 }
16 
18 {
19  if (!isParseSuccess)
20  APP_ABORT("SkParserBase::compute_grid(..) : Initial parse failed");
21 
22  // cout<<" We're about to get grid info...\n";
23  RealType lx(0), rx(0);
24  RealType ly(0), ry(0);
25  RealType lz(0), rz(0);
26 
27  RealType dx(0), dy(0), dz(0);
28  IndexType Nx(0), Ny(0), Nz(0);
29  get_gridinfo_from_posgrid(kgridraw, 0, lx, rx, dx, Nx);
30  get_gridinfo_from_posgrid(kgridraw, 1, ly, ry, dy, Ny);
31  get_gridinfo_from_posgrid(kgridraw, 2, lz, rz, dz, Nz);
32 
33  // cout<<" Done with grid info...\n";
34  kgrid.resize(Nx * Ny * Nz);
35 
36  xgrid.set(lx, rx, Nx);
37  ygrid.set(ly, ry, Ny);
38  zgrid.set(lz, rz, Nz);
39 
40 
41  isGridComputed = true;
42 }
43 
44 void SkParserBase::set_grid(const std::vector<TinyVector<IndexType, OHMMS_DIM>>& kgridraw1)
45 {
46  if (skraw.size() != kgridraw1.size())
47  APP_ABORT("SkParserBase::set_grid: S(k) and k-grid don't match");
48  kgridraw.resize(kgridraw1.size());
49  for (IndexType i = 0; i < kgridraw.size(); i++)
50  for (IndexType j = 0; j < OHMMS_DIM; j++)
51  kgridraw[i][j] = RealType(kgridraw1[i][j]);
52  compute_grid();
53 }
54 
55 void SkParserBase::set_grid(const std::vector<PosType>& kgridraw1)
56 {
57  if (skraw.size() != kgridraw1.size())
58  APP_ABORT("SkParserBase::set_grid: S(k) and k-grid don't match");
59  kgridraw = kgridraw1;
60  compute_grid();
61 }
62 
63 void SkParserBase::get_grid(Grid_t& xgrid_i, Grid_t& ygrid_i, Grid_t& zgrid_i)
64 {
65  // cout<<"In get_grid(..)\n";
66  if (!isGridComputed)
67  compute_grid();
68  // cout<<"done with compute_grid()\n";
69  xgrid_i.set(xgrid.rmin(), xgrid.rmax(), xgrid.size());
70  ygrid_i.set(ygrid.rmin(), ygrid.rmax(), ygrid.size());
71  zgrid_i.set(zgrid.rmin(), zgrid.rmax(), zgrid.size());
72 }
73 
75 {
76  if (!isParseSuccess)
77  APP_ABORT("SkParserBase::compute_sk() : Initial parse failed");
78  // cout<<"In compute_sk()\n";
79 
80  if (kgridraw.size() != skraw.size())
81  APP_ABORT("SkParserBase::compute_sk() : Kgrid and SK not the same size");
82 
83  if (!isGridComputed)
84  compute_grid();
85 
86  IndexType nx(0), ny(0), nz(0);
87  IndexType Nx(0), Ny(0), Nz(0);
88  IndexType newindex(0);
89 
90  Nx = xgrid.size();
91  Ny = ygrid.size();
92  Nz = zgrid.size();
93 
94  sk.resize(Nx * Ny * Nz);
95  skerr.resize(Nx * Ny * Nz);
96 
97  //set k=(0,0,0), S(0)=0, Serr(0)=0
98 
99  nx = xgrid.getIndex(0);
100  ny = ygrid.getIndex(0);
101  nz = zgrid.getIndex(0);
102 
103  newindex = nx * Ny * Nz + ny * Nz + nz;
104 
105  kgrid[newindex] = 0;
106  sk[newindex] = 0.0;
107  skerr[newindex] = 0.0;
108 
109  for (IndexType i = 0; i < kgridraw.size(); i++)
110  {
111  nx = xgrid.getIndex(kgridraw[i][0]);
112  ny = ygrid.getIndex(kgridraw[i][1]);
113  nz = zgrid.getIndex(kgridraw[i][2]);
114 
115  newindex = nx * Ny * Nz + ny * Nz + nz;
116  kgrid[newindex] = kgridraw[i];
117  sk[newindex] = skraw[i];
118  skerr[newindex] = skerr_raw[i];
119  }
120 
121  isSkComputed = true;
122 }
123 
124 void SkParserBase::get_sk(std::vector<RealType>& sk_i, std::vector<RealType>& skerr_i)
125 {
126  // cout<<"In get_sk(..)\n";
127  if (!isSkComputed)
128  compute_sk();
129 
130  sk_i = sk;
131  skerr_i = skerr;
132 }
133 
134 } // namespace qmcplusplus
std::vector< RealType > skerr_raw
Definition: SkParserBase.h:60
T rmin() const
return the first grid point
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
void get_sk(std::vector< RealType > &sk, std::vector< RealType > &skerr)
void set(T ri, T rf, int n) override
Set the grid given the parameters.
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
std::vector< PosType > kgridraw
Definition: SkParserBase.h:61
std::vector< RealType > skraw
Definition: SkParserBase.h:59
#define OHMMS_DIM
Definition: config.h:64
std::vector< PosType > kgrid
Definition: SkParserBase.h:65
QMCTraits::IndexType IndexType
Definition: FSUtilities.h:11
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
OHMMS_INDEXTYPE IndexType
define other types
Definition: Configuration.h:65
int size() const
returns the size of the grid
T rmax() const
return the last grid point
void get_grid(Grid_t &xgrid, Grid_t &ygrid, Grid_t &zgrid)
void set_grid(const std::vector< PosType > &gridpoints)
void get_gridinfo_from_posgrid(const std::vector< PosType > &posgridlist, const IndexType &axis, RealType &lx, RealType &rx, RealType &dx, IndexType &Nx)
Definition: FSUtilities.cpp:6
std::vector< RealType > sk
Definition: SkParserBase.h:63
std::vector< RealType > skerr
Definition: SkParserBase.h:64