QMCPACK
OptimalGrid2 Class Reference

The OptimalGrid class stores a grid which has linear spacing at the origin and exponential spacing further out. More...

+ Inheritance diagram for OptimalGrid2:
+ Collaboration diagram for OptimalGrid2:

Public Member Functions

GridType Type () override
 Returns the type of the grid (i.e. linear, optimal, etc) More...
 
int ReverseMap (double r) override
 Returns the index of the nearest point below r. More...
 
double Geta () const
 Returns a parameter. More...
 
double Getb () const
 Returns b parameter. More...
 
 OptimalGrid2 ()
 
 OptimalGrid2 (int numpoints, double rmax, double bval)
 This form of the constructor takes the number of points, the maximum radius and the value of b. More...
 
void Init (double start, double end, double ratio, int numpoints)
 
 OptimalGrid2 (double start, double end, double ratio, int numpoints)
 This form of the constructor takes a, b, and the number of points. More...
 
void Write (IOSectionClass &outSection) override
 
void Read (IOSectionClass &inSection) override
 
- 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 Attributes

double a
 
double b
 
double c
 
double Ratio
 

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

The OptimalGrid class stores a grid which has linear spacing at the origin and exponential spacing further out.

It has the analytic form

\[r_k = a\left(e^{kb}-1\right)\]

.

Definition at line 354 of file Grid.h.

Constructor & Destructor Documentation

◆ OptimalGrid2() [1/3]

OptimalGrid2 ( )
inline

Definition at line 377 of file Grid.h.

378  {
379  // Do nothing
380  }

◆ OptimalGrid2() [2/3]

OptimalGrid2 ( int  numpoints,
double  rmax,
double  bval 
)
inline

This form of the constructor takes the number of points, the maximum radius and the value of b.

Definition at line 384 of file Grid.h.

References a, b, c, Grid::End, qmcplusplus::exp(), Grid::grid, Grid::NumPoints, Array< T, D, ALLOC >::resize(), and Grid::Start.

385  {
386  NumPoints = numpoints;
387  b = bval;
388  End = rmax;
389  a = End / (exp(b * (double)NumPoints) - 1.0);
390  Start = a * (exp(b) - 1.0);
392  c = 0.0;
393 
394  for (int i = 0; i < NumPoints; i++)
395  grid(i) = c + a * expm1(b * i);
396  }
Array< double, 1 > grid
Contains the grid points.
Definition: Grid.h:47
int NumPoints
Number of points in the grid.
Definition: Grid.h:54
double c
Definition: Grid.h:357
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
double b
Definition: Grid.h:357
double a
Definition: Grid.h:357
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
double Start
First and last grid points.
Definition: Grid.h:51
double End
Definition: Grid.h:51

◆ OptimalGrid2() [3/3]

OptimalGrid2 ( double  start,
double  end,
double  ratio,
int  numpoints 
)
inline

This form of the constructor takes a, b, and the number of points.

Definition at line 417 of file Grid.h.

References Init().

417 { Init(start, end, ratio, numpoints); }
void Init(double start, double end, double ratio, int numpoints)
Definition: Grid.h:398

Member Function Documentation

◆ Geta()

double Geta ( ) const
inline

Returns a parameter.

Definition at line 372 of file Grid.h.

References a.

372 { return (a); }
double a
Definition: Grid.h:357

◆ Getb()

double Getb ( ) const
inline

Returns b parameter.

Definition at line 375 of file Grid.h.

References b.

375 { return (b); }
double b
Definition: Grid.h:357

◆ Init()

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

Definition at line 398 of file Grid.h.

References a, b, c, Grid::End, Grid::grid, qmcplusplus::log(), Grid::NumPoints, Ratio, Array< T, D, ALLOC >::resize(), and Grid::Start.

Referenced by OptimalGrid2(), and Read().

399  {
400  Start = start;
401  End = end;
402  Ratio = ratio;
403  NumPoints = numpoints;
404 
405  b = log(ratio) / (double)(numpoints - 2);
406  c = Start;
407  a = (end - c) / expm1(b * (double)(numpoints - 1));
408 
410 
411  for (int i = 0; i < NumPoints; i++)
412  grid(i) = c + a * expm1(b * i);
413  }
Array< double, 1 > grid
Contains the grid points.
Definition: Grid.h:47
int NumPoints
Number of points in the grid.
Definition: Grid.h:54
double c
Definition: Grid.h:357
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
double b
Definition: Grid.h:357
double a
Definition: Grid.h:357
double Ratio
Definition: Grid.h:358
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
double Start
First and last grid points.
Definition: Grid.h:51
double End
Definition: Grid.h:51

◆ Read()

void Read ( IOSectionClass inSection)
inlineoverridevirtual

Implements Grid.

Definition at line 429 of file Grid.h.

References Init(), and IOSectionClass::ReadVar().

430  {
431  double start, end, ratio;
432  int numPoints;
433  assert(inSection.ReadVar("Start", start));
434  assert(inSection.ReadVar("End", end));
435  assert(inSection.ReadVar("Ratio", ratio));
436  assert(inSection.ReadVar("NumPoints", numPoints));
437  Init(start, end, ratio, numPoints);
438  }
void Init(double start, double end, double ratio, int numpoints)
Definition: Grid.h:398
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 363 of file Grid.h.

References a, b, c, and qmcplusplus::floor().

364  {
365  // if ((r/a) < 1e-6)
366  // return ((int)floor(r/(a*b)));
367  // else
368  return ((int)floor(log1p((r - c) / a) / b));
369  }
double c
Definition: Grid.h:357
double b
Definition: Grid.h:357
double a
Definition: Grid.h:357
MakeReturn< UnaryNode< FnFloor, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t floor(const Vector< T1, C1 > &l)

◆ Type()

GridType Type ( )
inlineoverridevirtual

Returns the type of the grid (i.e. linear, optimal, etc)

Implements Grid.

Definition at line 361 of file Grid.h.

References OPTIMAL2.

361 { return (OPTIMAL2); }
Definition: Grid.h:34

◆ Write()

void Write ( IOSectionClass outSection)
inlineoverridevirtual

Implements Grid.

Definition at line 419 of file Grid.h.

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

420  {
421  outSection.WriteVar("Points", grid);
422  outSection.WriteVar("Type", std::string("Optimal2"));
423  outSection.WriteVar("Start", Start);
424  outSection.WriteVar("End", End);
425  outSection.WriteVar("Ratio", Ratio);
426  outSection.WriteVar("NumPoints", NumPoints);
427  }
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 Ratio
Definition: Grid.h:358
double Start
First and last grid points.
Definition: Grid.h:51
double End
Definition: Grid.h:51

Member Data Documentation

◆ a

double a
private

Definition at line 357 of file Grid.h.

Referenced by Geta(), Init(), OptimalGrid2(), and ReverseMap().

◆ b

double b
private

Definition at line 357 of file Grid.h.

Referenced by Getb(), Init(), OptimalGrid2(), and ReverseMap().

◆ c

double c
private

Definition at line 357 of file Grid.h.

Referenced by Init(), OptimalGrid2(), and ReverseMap().

◆ Ratio

double Ratio
private

Definition at line 358 of file Grid.h.

Referenced by Init(), and Write().


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