QMCPACK
LinearGrid Class Reference

Linear Grid inherets from Grid. More...

+ Inheritance diagram for LinearGrid:
+ Collaboration diagram for LinearGrid:

Public Member Functions

GridType Type () override
 Returns the type of the grid (in this case LINEAR) More...
 
int ReverseMap (double r) override
 Returns the index of the nearest point below r. More...
 
void Init (double start, double end, int numpoints)
 Initializes the linear grid. More...
 
void Write (IOSectionClass &outSection) override
 
void Read (IOSectionClass &inSection) override
 
 LinearGrid ()
 Useless constructor. More...
 
LinearGridoperator= (const LinearGrid &lin)
 
 LinearGrid (double start, double end, int numpoints)
 Constructor that sets the number of points, start and end point of the original grid. More...
 
- Public Member Functions inherited from Grid
double operator() (int i) const
 The i'th point in the grid. More...
 
double * data ()
 
Array< double, 1 > & Points ()
 
virtual ~Grid ()
 

Private Member Functions

void CheckRoundingMode ()
 

Private Attributes

double delta
 The value between successive grid points. More...
 
double deltainv
 

Additional Inherited Members

- Public Attributes inherited from Grid
double Start
 First and last grid points. More...
 
double End
 
int NumPoints
 Number of points in the grid. More...
 
- Protected Attributes inherited from Grid
Array< double, 1 > grid
 Contains the grid points. More...
 

Detailed Description

Linear Grid inherets from Grid.

Definition at line 73 of file Grid.h.

Constructor & Destructor Documentation

◆ LinearGrid() [1/2]

LinearGrid ( )
inline

Useless constructor.

Definition at line 119 of file Grid.h.

120  { /* Do nothing */
121  }

◆ LinearGrid() [2/2]

LinearGrid ( double  start,
double  end,
int  numpoints 
)
inline

Constructor that sets the number of points, start and end point of the original grid.

Definition at line 136 of file Grid.h.

References Init().

136 { Init(start, end, numpoints); }
void Init(double start, double end, int numpoints)
Initializes the linear grid.
Definition: Grid.h:88

Member Function Documentation

◆ CheckRoundingMode()

void CheckRoundingMode ( )
inlineprivate

Definition at line 661 of file Grid.h.

Referenced by Init().

662 {
663  for (int i = 0; i < 100; i++)
664  {
665  double x = 100.0 * drand48() - 50.0;
666  if (nearbyint(x) != round(x))
667  {
668  std::cerr << "Error in rounding mode detected in LinearGrid. Abort.\n";
669  abort();
670  }
671  }
672 }

◆ Init()

void Init ( double  start,
double  end,
int  numpoints 
)
inline

Initializes the linear grid.

Definition at line 88 of file Grid.h.

References CheckRoundingMode(), delta, deltainv, Grid::End, Grid::grid, Grid::NumPoints, Array< T, D, ALLOC >::resize(), and Grid::Start.

Referenced by LinearGrid(), and Read().

89  {
90  Start = start;
91  End = end;
92  NumPoints = numpoints;
94  delta = (End - Start) / (double)(NumPoints - 1);
95  deltainv = 1.0 / delta;
96  for (int i = 0; i < NumPoints; i++)
97  grid(i) = Start + (double)i * delta;
99  }
Array< double, 1 > grid
Contains the grid points.
Definition: Grid.h:47
int NumPoints
Number of points in the grid.
Definition: Grid.h:54
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
double deltainv
Definition: Grid.h:77
double Start
First and last grid points.
Definition: Grid.h:51
double delta
The value between successive grid points.
Definition: Grid.h:77
void CheckRoundingMode()
Definition: Grid.h:661
double End
Definition: Grid.h:51

◆ operator=()

LinearGrid& operator= ( const LinearGrid lin)
inline

Definition at line 123 of file Grid.h.

References delta, deltainv, Grid::End, Grid::grid, Array< T, D, ALLOC >::resize(), Array< T, D, ALLOC >::shape(), and Grid::Start.

124  {
125  grid.resize(lin.grid.shape());
126  Start = lin.Start;
127  End = lin.End;
128  grid = lin.grid;
129  delta = lin.delta;
130  deltainv = lin.deltainv;
131  return *this;
132  }
Array< double, 1 > grid
Contains the grid points.
Definition: Grid.h:47
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
double deltainv
Definition: Grid.h:77
double Start
First and last grid points.
Definition: Grid.h:51
double delta
The value between successive grid points.
Definition: Grid.h:77
const std::array< size_t, D > & shape() const
Definition: OhmmsArray.h:56
double End
Definition: Grid.h:51

◆ Read()

void Read ( IOSectionClass inSection)
inlineoverridevirtual

Implements Grid.

Definition at line 110 of file Grid.h.

References Grid::End, Init(), Grid::NumPoints, IOSectionClass::ReadVar(), and Grid::Start.

111  {
112  assert(inSection.ReadVar("Start", Start));
113  assert(inSection.ReadVar("End", End));
114  assert(inSection.ReadVar("NumPoints", NumPoints));
115  Init(Start, End, NumPoints);
116  }
int NumPoints
Number of points in the grid.
Definition: Grid.h:54
void Init(double start, double end, int numpoints)
Initializes the linear grid.
Definition: Grid.h:88
double Start
First and last grid points.
Definition: Grid.h:51
double End
Definition: Grid.h:51
bool ReadVar(std::string name, T &var)
Template function which reads a variable in the present section into the passed-by-reference T variab...
Definition: IO.h:168

◆ ReverseMap()

int ReverseMap ( double  r)
inlineoverridevirtual

Returns the index of the nearest point below r.

Implements Grid.

Definition at line 85 of file Grid.h.

References deltainv, and Grid::Start.

85 { return ((int)nearbyint((r - Start) * deltainv - 0.5)); }
double deltainv
Definition: Grid.h:77
double Start
First and last grid points.
Definition: Grid.h:51

◆ Type()

GridType Type ( )
inlineoverridevirtual

Returns the type of the grid (in this case LINEAR)

Implements Grid.

Definition at line 82 of file Grid.h.

References LINEAR.

82 { return (LINEAR); }
Definition: Grid.h:32

◆ Write()

void Write ( IOSectionClass outSection)
inlineoverridevirtual

Implements Grid.

Definition at line 101 of file Grid.h.

References Grid::End, Grid::grid, Grid::NumPoints, Grid::Start, and IOSectionClass::WriteVar().

102  {
103  outSection.WriteVar("Points", grid);
104  outSection.WriteVar("Type", std::string("Linear"));
105  outSection.WriteVar("Start", Start);
106  outSection.WriteVar("End", End);
107  outSection.WriteVar("NumPoints", NumPoints);
108  }
Array< double, 1 > grid
Contains the grid points.
Definition: Grid.h:47
int NumPoints
Number of points in the grid.
Definition: Grid.h:54
bool WriteVar(std::string name, T val)
Writes a variable under the current section.
Definition: IO.h:184
double Start
First and last grid points.
Definition: Grid.h:51
double End
Definition: Grid.h:51

Member Data Documentation

◆ delta

double delta
private

The value between successive grid points.

Definition at line 77 of file Grid.h.

Referenced by Init(), and operator=().

◆ deltainv

double deltainv
private

Definition at line 77 of file Grid.h.

Referenced by Init(), operator=(), and ReverseMap().


The documentation for this class was generated from the following file: