QMCPACK
GeneralGrid.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File created by: Paul R. C. Kent, kentpr@ornl.gov, Oak Ridge National Laboratory
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #ifndef SIMPLE_GRID_H
15 #define SIMPLE_GRID_H
16 
17 #include <vector>
18 
19 
21 {
22 private:
23  std::vector<double> grid;
24 
25 public:
26  inline int NumPoints() { return grid.size(); }
27 
28  inline std::vector<double>& Points() { return grid; }
29 
30  inline double operator[](int i) { return grid[i]; }
31 
32  /// Returns the index of the nearest point below r.
33  int ReverseMap(double r)
34  {
35  int n = grid.size();
36  if (r <= grid[0])
37  return (0);
38  else if (r >= grid[n - 1])
39  return n - 1;
40  else
41  {
42  int hi = n - 1;
43  int lo = 0;
44  bool done = false;
45  while (!done)
46  {
47  int i = (hi + lo) >> 1;
48  if (grid[i] > r)
49  hi = i;
50  else
51  lo = i;
52  done = (hi - lo) < 2;
53  }
54  if (grid[lo] >= r)
55  lo--;
56  return (lo);
57  }
58  }
59 
60  inline double Start() { return grid[0]; }
61 
62  inline double End() { return grid[grid.size() - 1]; }
63 
64  void Init(std::vector<double>& points)
65  {
66  grid.resize(points.size());
67  grid = points;
68  }
69 
70  /// Useless constructor
72  { /* Do nothing */
73  }
74 };
75 
76 #endif
std::vector< double > & Points()
Definition: GeneralGrid.h:28
double End()
Definition: GeneralGrid.h:62
void Init(std::vector< double > &points)
Definition: GeneralGrid.h:64
std::vector< double > grid
Definition: GeneralGrid.h:23
int NumPoints()
Definition: GeneralGrid.h:26
double operator[](int i)
Definition: GeneralGrid.h:30
constexpr double done
Definition: BLAS.hpp:48
SimpleGrid()
Useless constructor.
Definition: GeneralGrid.h:71
int ReverseMap(double r)
Returns the index of the nearest point below r.
Definition: GeneralGrid.h:33
double Start()
Definition: GeneralGrid.h:60