25#ifndef __RADIAL_GRID_HPP__
26#define __RADIAL_GRID_HPP__
101 int index_of(T x__)
const
109 while (i1 - i0 > 1) {
110 int i = (i1 + i0) >> 1;
111 if (x__ >=
x_[i0] && x__ <
x_[i]) {
123 return static_cast<int>(
x_.
size());
141 assert(i < (
int)
x_.
size());
146 inline T
x(
const int i)
const
152 inline T
dx(
const int i)
const
163 inline std::string
const& name()
const
168 void copy_to_device()
170 x_.
allocate(sddk::memory_t::device).copy_to(sddk::memory_t::device);
171 dx_.
allocate(sddk::memory_t::device).copy_to(sddk::memory_t::device);
174 sddk::mdarray<T, 1>
const&
x()
const
179 sddk::mdarray<T, 1>
const&
dx()
const
184 Radial_grid<T> segment(
int num_points__)
const
186 assert(num_points__ >= 0 && num_points__ <= (
int)
x_.
size());
188 r.name_ =
name_ +
" (segment)";
189 r.x_ = sddk::mdarray<T, 1>(num_points__);
190 r.dx_ = sddk::mdarray<T, 1>(num_points__ - 1);
191 r.x_inv_ = sddk::mdarray<T, 1>(num_points__);
193 std::memcpy(&r.x_(0), &
x_(0), num_points__ *
sizeof(T));
194 std::memcpy(&r.dx_(0), &
dx_(0), (num_points__ - 1) *
sizeof(T));
195 std::memcpy(&r.x_inv_(0), &
x_inv_(0), num_points__ *
sizeof(T));
200 std::vector<real_type<T>> values()
const
209 uint64_t hash()
const
230 for (
int i = 0; i < this->
num_points(); i++) {
231 T t =
static_cast<T
>(i) / (this->
num_points() - 1);
232 this->x_[i] = rmin__ + (rmax__ - rmin__) * std::pow(t, p__);
234 this->x_[0] = rmin__;
235 this->x_[num_points__ - 1] = rmax__;
239 this->name_ =
"power" + s.str();
250 this->name_ =
"linear";
262 for (
int i = 0; i < this->
num_points(); i++) {
263 T t =
static_cast<T
>(i) / (this->
num_points() - 1);
264 this->x_[i] = rmin__ * std::pow(rmax__ / rmin__, std::pow(t, p__));
266 this->x_[0] = rmin__;
267 this->x_[num_points__ - 1] = rmax__;
269 this->name_ =
"exponential";
284 T beta = 1e-6 * this->
num_points() / (rmax__ - rmin__);
285 T A = 1.0 / (std::exp(
static_cast<T
>(1)) + beta -
static_cast<T
>(1));
286 for (
int i = 0; i < this->
num_points(); i++) {
287 T t =
static_cast<T
>(i) / (this->
num_points() - 1);
289 rmin__ + (rmax__ - rmin__) * (beta * t + std::exp(std::pow(t, alpha)) -
static_cast<T
>(1)) * A;
297 this->x_[0] = rmin__;
298 this->x_[num_points__ - 1] = rmax__;
300 this->name_ =
"linear_exponential";
312 for (
int i = 0; i < this->
num_points(); i++) {
313 this->x_[i] = data__[i];
316 this->name_ =
"external";
325 switch (grid_type__) {
326 case radial_grid_t::linear: {
330 case radial_grid_t::exponential: {
331 rgrid = Radial_grid_exp<T>(num_points__, rmin__, rmax__, p__);
334 case radial_grid_t::power: {
335 rgrid = Radial_grid_pow<T>(num_points__, rmin__, rmax__, p__);
338 case radial_grid_t::lin_exp: {
339 rgrid = Radial_grid_lin_exp<T>(num_points__, rmin__, rmax__, p__);
343 throw std::runtime_error(
"wrong radial grid type");
349inline std::pair<radial_grid_t, double> get_radial_grid_t(std::string str__)
351 auto pos = str__.find(
",");
352 if (pos == std::string::npos) {
354 s <<
"wrong string for the radial grid type: " << str__;
355 throw std::runtime_error(s.str());
358 std::string name = str__.substr(0, pos);
359 double p = std::stod(str__.substr(pos + 1));
361 const std::map<std::string, radial_grid_t> map_to_type = {{
"linear", radial_grid_t::linear},
362 {
"exponential", radial_grid_t::exponential},
363 {
"power", radial_grid_t::power},
364 {
"lin_exp", radial_grid_t::lin_exp}};
366 return std::make_pair(map_to_type.at(name), p);
External radial grid provided as a list of points.
Base class for radial grids.
T last() const
Last point of the grid.
sddk::mdarray< T, 1 > x_
Radial grid points.
T dx(const int i) const
Return .
sddk::mdarray< T, 1 > x_inv_
Inverse values of radial grid points.
T first() const
First point of the grid.
void init()
Initialize the grid.
std::string name_
Name of the grid type.
sddk::mdarray< T, 1 > dx_
Radial grid points difference.
T operator[](const int i) const
Return .
T x(const int i) const
Return .
T x_inv(const int i) const
Return .
int num_points() const
Number of grid points.
Radial_grid(int num_points__)
Constructor.
Radial_grid()
Constructor of the empty object.
mdarray< T, N > & allocate(memory_t memory__)
Allocate memory for array.
size_t size() const
Return total size (number of elements) of the array.
Memory management functions and classes.
Namespace of the SIRIUS library.
radial_grid_t
Types of radial grid.
Contains typedefs, enums and simple descriptors.