88 inline void Init(
double start,
double end,
int numpoints)
104 outSection.
WriteVar(
"Type", std::string(
"Linear"));
136 LinearGrid(
double start,
double end,
int numpoints) {
Init(start, end, numpoints); }
161 int i = (hi + lo) >> 1;
166 done = (hi - lo) < 2;
175 outSection.
WriteVar(
"Type", std::string(
"General"));
216 return ((
int)
floor(r / (
a *
b) + 0.5) - 1);
218 return ((
int)
floor(
log(r /
a + 1.0) /
b + 0.5) - 1);
234 void Init(
int numpoints,
double rmax,
double bval)
249 void Init(
double aval,
double bval,
int numPoints)
270 outSection.
WriteVar(
"Type", std::string(
"Optimal"));
280 if (inSection.
ReadVar(
"a", aval))
282 assert(inSection.
ReadVar(
"b", bval));
283 assert(inSection.
ReadVar(
"NumPoints", numPoints));
284 Init(aval, bval, numPoints);
289 assert(inSection.
ReadVar(
"Z", Z));
290 assert(inSection.
ReadVar(
"rmax", rmax));
300 b =
log(ratio) / (double)(numpoints - 2);
301 a = end / (
exp(
b * (
double)(numpoints - 1)) - 1);
313 void Init(
double Z,
double rmax)
368 return ((
int)
floor(log1p((r -
c) /
a) /
b));
395 grid(i) =
c +
a * expm1(
b * i);
398 void Init(
double start,
double end,
double ratio,
int numpoints)
405 b =
log(ratio) / (double)(numpoints - 2);
407 a = (end -
c) / expm1(
b * (
double)(numpoints - 1));
412 grid(i) =
c +
a * expm1(
b * i);
417 OptimalGrid2(
double start,
double end,
double ratio,
int numpoints) {
Init(start, end, ratio, numpoints); }
422 outSection.
WriteVar(
"Type", std::string(
"Optimal2"));
431 double start, end, ratio;
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);
464 void Init(
double start,
double end,
double ratio,
int numPoints)
469 center = 0.5 * (start + end);
472 Odd = ((numPoints % 2) == 1);
484 double sign = (i < 0) ? -1.0 : 1.0;
492 a = 0.5 * (end - start) / expm1(
b * (-0.5 +
HalfPoints));
496 double sign = (i < 0) ? -1.0 : 1.0;
523 void Init(
double R0,
double spacing,
int numpoints)
541 outSection.
WriteVar(
"Type", std::string(
"Log"));
548 double tempr0, tempSpacing;
550 assert(inSection.
ReadVar(
"r0", tempr0));
551 assert(inSection.
ReadVar(
"Spacing", tempSpacing));
552 assert(inSection.
ReadVar(
"NumPoints", tempNumPoints));
553 Init(tempr0, tempSpacing, tempNumPoints);
556 LogGrid(
double R0,
double spacing,
int numpoints) {
Init(R0, spacing, numpoints); }
558 LogGrid(
int numpoints,
double z,
double R0,
double spacing)
590 void Init(
double start,
double end,
double cluster,
int numpoints)
608 outSection.
WriteVar(
"Type", std::string(
"Cluster"));
617 double start, end, cluster;
619 assert(inSection.
ReadVar(
"Start", start));
620 assert(inSection.
ReadVar(
"End", end));
621 assert(inSection.
ReadVar(
"Cluster", cluster));
622 assert(inSection.
ReadVar(
"NumPoints", numpoints));
623 Init(start, end, cluster, numpoints);
626 ClusterGrid(
double start,
double end,
double cluster,
int numpoints) {
Init(start, end, cluster, numpoints); }
636 assert(inSection.
ReadVar(
"Type", Type));
638 std::shared_ptr<Grid> newGrid;
639 if (Type ==
"Linear")
640 newGrid = std::make_shared<LinearGrid>();
641 else if (Type ==
"General")
642 newGrid = std::make_shared<GeneralGrid>();
643 else if (Type ==
"Optimal")
644 newGrid = std::make_shared<OptimalGrid>();
645 else if (Type ==
"Optimal2")
646 newGrid = std::make_shared<OptimalGrid2>();
647 else if (Type ==
"Log")
648 newGrid = std::make_shared<LogGrid>();
649 else if (Type ==
"Cluster")
650 newGrid = std::make_shared<ClusterGrid>();
653 std::cerr <<
"Unrecognized Grid type " << Type <<
"\n";
656 newGrid->Read(inSection);
663 for (
int i = 0; i < 100; i++)
665 double x = 100.0 * drand48() - 50.0;
666 if (nearbyint(x) != round(x))
668 std::cerr <<
"Error in rounding mode detected in LinearGrid. Abort.\n";
OptimalGrid(double Z, double rmax)
double Getb() const
Returns b parameter.
void Init(double start, double end, double ratio, int numPoints)
std::shared_ptr< Grid > ReadGrid(IOSectionClass &inSection)
void Write(IOSectionClass &outSection) override
GridType Type() override
Returns the type of the grid (in this case LINEAR)
void Read(IOSectionClass &inSection) override
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
Array< double, 1 > grid
Contains the grid points.
Parent class for all grids.
int ReverseMap(double r) override
Returns the index of the nearest point below r.
OptimalGrid(double aval, double bval, int numPoints)
This form of the constructor takes a, b, and the number of points.
int NumPoints
Number of points in the grid.
void Write(IOSectionClass &out) override
void Write(IOSectionClass &outSection) override
Array< double, 1 > & Points()
void Write(IOSectionClass &outSection) override
double Geta() const
Returns a parameter.
GridType Type() override
Returns the type of the grid (i.e. linear, optimal, etc)
void Init(double start, double end, double ratio, int numpoints)
void Read(IOSectionClass &inSection) override
void Init(Array< double, 1 > &points)
int ReverseMap(double r) override
Returns the index of the nearest point below r.
General Grid inherets from Grid.
bool WriteVar(std::string name, T val)
Writes a variable under the current section.
GridType Type() override
Returns the type of the grid (i.e. linear, optimal, etc)
void resize(const std::array< SIZET, D > &dims)
Resize the container.
void Read(IOSectionClass &inSection) override
double Getb() const
Returns b parameter.
void Init(double aval, double bval, int numPoints)
void Init(double start, double end, double cluster, int numpoints)
LogGrid(double R0, double spacing, int numpoints)
ClusterGrid is a function whose gridpoints are clustered tightly around the origin.
void Write(IOSectionClass &outSection) override
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
virtual void Read(IOSectionClass &inSection)=0
OptimalGrid & operator=(const OptimalGrid &opt)
MakeReturn< UnaryNode< FnCeil, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t ceil(const Vector< T1, C1 > &l)
virtual GridType Type()=0
Returns the type of the grid (i.e. linear, optimal, etc)
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...
void Init(double start, double end, int numpoints)
Initializes the linear grid.
void Write(IOSectionClass &outSection) override
void Read(IOSectionClass &inSection) override
GeneralGrid()
Useless constructor.
The OptimalGrid class stores a grid which has linear spacing at the origin and exponential spacing fu...
void Init(double Z, double rmax)
This form of the constructor takes a nuclear charge and a maxmimum radius and chooses an appropriate ...
GridType Type() override
Returns the type of the grid (in this case GENERAL)
virtual int ReverseMap(double r)=0
Returns the index of the nearest point below r.
OptimalGrid2(double start, double end, double ratio, int numpoints)
This form of the constructor takes a, b, and the number of points.
Linear Grid inherets from Grid.
double Geta() const
Returns a parameter.
void Read(IOSectionClass &in) override
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
void Read(IOSectionClass &inSection) override
LinearGrid & operator=(const LinearGrid &lin)
void InitRatio(double end, double ratio, int numpoints)
OptimalGrid(int numPoints, double rmax, double bval)
GridType Type() override
Returns the type of the grid (i.e. linear, optimal, etc)
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
GridType Type() override
Returns the type of the grid (i.e. linear, optimal, etc)
LogGrid is a function whose gridpoints increase exponentially with the index.
ClusterGrid(double start, double end, double cluster, int numpoints)
LinearGrid()
Useless constructor.
GridType
The different types of grids that we currently allow.
The OptimalGrid class stores a grid which has linear spacing at the origin and exponential spacing fu...
int ReverseMap(double x) override
Returns the index of the nearest point below r.
double Start
First and last grid points.
double operator()(int i) const
The i'th point in the grid.
int ReverseMap(double r) override
Returns the index of the nearest point below r.
LinearGrid(double start, double end, int numpoints)
Constructor that sets the number of points, start and end point of the original grid.
Wrapper class for IOTreeClass that gives a nearly identical interface as the OutputSectionClass.
int ReverseMap(double r) override
Returns the index of the nearest point below r.
int ReverseMap(double r) override
Returns the index of the nearest point below r.
GridType Type() override
Returns the type of the grid (i.e. linear, optimal, etc)
virtual void Write(IOSectionClass &out)=0
LogGrid(int numpoints, double z, double R0, double spacing)
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...
void Read(IOSectionClass &inSection) override
double delta
The value between successive grid points.
const std::array< size_t, D > & shape() const
void Write(IOSectionClass &outSection) override
void Init(double R0, double spacing, int numpoints)
bool ReadVar(std::string name, T &var)
Template function which reads a variable in the present section into the passed-by-reference T variab...
MakeReturn< UnaryNode< FnFloor, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t floor(const Vector< T1, C1 > &l)
int ReverseMap(double r) override
Returns the index of the nearest point below r.