QMCPACK
OptimalGrid Class Reference

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

+ Inheritance diagram for OptimalGrid:
+ Collaboration diagram for OptimalGrid:

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...
 
 OptimalGrid ()
 
void Init (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...
 
 OptimalGrid (int numPoints, double rmax, double bval)
 
void Init (double aval, double bval, int numPoints)
 
 OptimalGrid (double aval, double bval, 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
 
void InitRatio (double end, double ratio, int numpoints)
 
void Init (double Z, double rmax)
 This form of the constructor takes a nuclear charge and a maxmimum radius and chooses an appropriate number of points for that atom. More...
 
OptimalGridoperator= (const OptimalGrid &opt)
 
 OptimalGrid (double Z, double rmax)
 
- 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
 

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 205 of file Grid.h.

Constructor & Destructor Documentation

◆ OptimalGrid() [1/4]

OptimalGrid ( )
inline

Definition at line 227 of file Grid.h.

228  {
229  // Do nothing
230  }

◆ OptimalGrid() [2/4]

OptimalGrid ( int  numPoints,
double  rmax,
double  bval 
)
inline

Definition at line 247 of file Grid.h.

References Init().

247 { Init(numPoints, rmax, bval); }
void Init(int numpoints, double rmax, double bval)
This form of the constructor takes the number of points, the maximum radius and the value of b...
Definition: Grid.h:234

◆ OptimalGrid() [3/4]

OptimalGrid ( double  aval,
double  bval,
int  numPoints 
)
inline

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

Definition at line 265 of file Grid.h.

References Init().

265 { Init(aval, bval, numPoints); }
void Init(int numpoints, double rmax, double bval)
This form of the constructor takes the number of points, the maximum radius and the value of b...
Definition: Grid.h:234

◆ OptimalGrid() [4/4]

OptimalGrid ( double  Z,
double  rmax 
)
inline

Definition at line 347 of file Grid.h.

References Init().

347 { Init(Z, rmax); }
void Init(int numpoints, double rmax, double bval)
This form of the constructor takes the number of points, the maximum radius and the value of b...
Definition: Grid.h:234

Member Function Documentation

◆ Geta()

double Geta ( ) const
inline

Returns a parameter.

Definition at line 222 of file Grid.h.

References a.

222 { return (a); }
double a
Definition: Grid.h:208

◆ Getb()

double Getb ( ) const
inline

Returns b parameter.

Definition at line 225 of file Grid.h.

References b.

225 { return (b); }
double b
Definition: Grid.h:208

◆ Init() [1/3]

void Init ( 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 234 of file Grid.h.

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

Referenced by OptimalGrid(), and Read().

235  {
236  NumPoints = numpoints;
237  b = bval;
238  End = rmax;
239  a = End / (exp(b * (double)NumPoints) - 1.0);
240  Start = a * (exp(b) - 1.0);
242 
243  for (int i = 0; i < NumPoints; i++)
244  grid(i) = a * (exp(b * (i + 1)) - 1.0);
245  }
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 a
Definition: Grid.h:208
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
double b
Definition: Grid.h:208
double Start
First and last grid points.
Definition: Grid.h:51
double End
Definition: Grid.h:51

◆ Init() [2/3]

void Init ( double  aval,
double  bval,
int  numPoints 
)
inline

Definition at line 249 of file Grid.h.

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

250  {
251  a = aval;
252  b = bval;
253  NumPoints = numPoints;
254  Start = a * (exp(b) - 1.0);
255  End = a * (exp(b * NumPoints) - 1.0);
256 
258 
259  for (int i = 0; i < NumPoints; i++)
260  grid(i) = a * (exp(b * (i + 1)) - 1.0);
261  }
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 a
Definition: Grid.h:208
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
double b
Definition: Grid.h:208
double Start
First and last grid points.
Definition: Grid.h:51
double End
Definition: Grid.h:51

◆ Init() [3/3]

void Init ( double  Z,
double  rmax 
)
inline

This form of the constructor takes a nuclear charge and a maxmimum radius and chooses an appropriate number of points for that atom.

Definition at line 313 of file Grid.h.

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

314  {
315  a = 4.34e-6 / Z;
316  //a = 4.0e-2;
317  b = 0.002304;
318  //b = 0.004;
319 
320  NumPoints = (int)ceil(log(rmax / a + 1.0) / b);
321  b = log(rmax / a + 1.0) / (double)NumPoints;
322  Start = a * (exp(b) - 1.0);
323  End = rmax;
324  //End = a * (exp(b*NumPoints) - 1.0);
325 
327 
328  for (int i = 0; i < NumPoints; i++)
329  {
330  grid(i) = a * (exp(b * (i + 1)) - 1.0);
331  //fprintf (stdout, "%1.12e\n", grid(i));
332  }
333  }
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
MakeReturn< UnaryNode< FnCeil, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t ceil(const Vector< T1, C1 > &l)
double a
Definition: Grid.h:208
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
double b
Definition: Grid.h:208
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

◆ InitRatio()

void InitRatio ( double  end,
double  ratio,
int  numpoints 
)
inline

Definition at line 295 of file Grid.h.

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

296  {
297  End = end;
298  NumPoints = numpoints;
299 
300  b = log(ratio) / (double)(numpoints - 2);
301  a = end / (exp(b * (double)(numpoints - 1)) - 1);
302 
304 
305  for (int i = 0; i < NumPoints; i++)
306  grid(i) = a * (exp(b * i) - 1.0);
307  }
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 a
Definition: Grid.h:208
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
double b
Definition: Grid.h:208
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
double End
Definition: Grid.h:51

◆ operator=()

OptimalGrid& operator= ( const OptimalGrid opt)
inline

Definition at line 335 of file Grid.h.

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

336  {
337  grid.resize(opt.grid.shape());
338  a = opt.a;
339  b = opt.b;
340  NumPoints = opt.NumPoints;
341  Start = opt.Start;
342  End = opt.End;
343  grid = opt.grid;
344  return *this;
345  }
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 a
Definition: Grid.h:208
double b
Definition: Grid.h:208
double Start
First and last grid points.
Definition: Grid.h:51
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 276 of file Grid.h.

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

277  {
278  double aval, bval;
279  int numPoints;
280  if (inSection.ReadVar("a", aval))
281  {
282  assert(inSection.ReadVar("b", bval));
283  assert(inSection.ReadVar("NumPoints", numPoints));
284  Init(aval, bval, numPoints);
285  }
286  else
287  {
288  double Z, rmax;
289  assert(inSection.ReadVar("Z", Z));
290  assert(inSection.ReadVar("rmax", rmax));
291  Init(Z, rmax);
292  }
293  }
void Init(int numpoints, double rmax, double bval)
This form of the constructor takes the number of points, the maximum radius and the value of b...
Definition: Grid.h:234
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 213 of file Grid.h.

References a, b, qmcplusplus::Units::charge::e, qmcplusplus::floor(), and qmcplusplus::log().

214  {
215  if ((r / a) < 1e-6)
216  return ((int)floor(r / (a * b) + 0.5) - 1);
217  else
218  return ((int)floor(log(r / a + 1.0) / b + 0.5) - 1);
219  }
double a
Definition: Grid.h:208
double b
Definition: Grid.h:208
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
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 211 of file Grid.h.

References OPTIMAL.

211 { return (OPTIMAL); }
Definition: Grid.h:33

◆ Write()

void Write ( IOSectionClass outSection)
inlineoverridevirtual

Implements Grid.

Definition at line 267 of file Grid.h.

References a, b, Grid::grid, Grid::NumPoints, and IOSectionClass::WriteVar().

268  {
269  outSection.WriteVar("Points", grid);
270  outSection.WriteVar("Type", std::string("Optimal"));
271  outSection.WriteVar("a", a);
272  outSection.WriteVar("b", b);
273  outSection.WriteVar("NumPoints", NumPoints);
274  }
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 a
Definition: Grid.h:208
double b
Definition: Grid.h:208

Member Data Documentation

◆ a

double a
private

Definition at line 208 of file Grid.h.

Referenced by Geta(), Init(), InitRatio(), operator=(), ReverseMap(), and Write().

◆ b

double b
private

Definition at line 208 of file Grid.h.

Referenced by Getb(), Init(), InitRatio(), operator=(), ReverseMap(), and Write().


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