ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
gint_helper.h
Go to the documentation of this file.
1#ifndef ABACUS_SOURCE_HAMILT_MODULE_GINT_GINT_HELPER_H
2#define ABACUS_SOURCE_HAMILT_MODULE_GINT_GINT_HELPER_H
3
4#include "gint_type.h"
5#include <cmath>
6#include <memory>
7
8namespace ModuleGint
9{
10enum class GintPrecision
11{
14};
15
16inline int index3Dto1D(
17 const int id_x,
18 const int id_y,
19 const int id_z,
20 const int dim_x,
21 const int dim_y,
22 const int dim_z)
23{
24 return id_z + id_y * dim_z + id_x * dim_y * dim_z;
25}
26
28 const int index_1d,
29 const int dim_x,
30 const int dim_y,
31 const int dim_z)
32{
33 int id_x = index_1d / (dim_y * dim_z);
34 int id_y = (index_1d - id_x * dim_y * dim_z) / dim_z;
35 int id_z = index_1d % dim_z;
36 return Vec3i(id_x, id_y, id_z);
37}
38
39// if exponent is an integer between 0 and 5 (the most common cases in gint) and
40// and exp is a variable that cannot be determined at compile time (which means the compiler cannot optimize the code),
41// pow_int is much faster than std::pow
42inline double pow_int(const double base, const int exp)
43{
44 switch (exp)
45 {
46 case 0:
47 return 1.0;
48 case 1:
49 return base;
50 case 2:
51 return base * base;
52 case 3:
53 return base * base * base;
54 case 4:
55 return base * base * base * base;
56 case 5:
57 return base * base * base * base * base;
58 default:
59 double result = std::pow(base, exp);
60 return result;
61 }
62}
63
64inline int floor_div(const int a, const int b)
65{
66 // a ^ b < 0 means a and b have different signs
67 return a / b - (a % b != 0 && (a ^ b) < 0);
68}
69
70inline int ceil_div(const int a, const int b) { return a / b + (a % b != 0 && (a ^ b) > 0); }
71
72} // namespace ModuleGint
73
74#endif // ABACUS_SOURCE_HAMILT_MODULE_GINT_GINT_HELPER_H
Definition batch_biggrid.cpp:4
int floor_div(const int a, const int b)
Definition gint_helper.h:64
int index3Dto1D(const int id_x, const int id_y, const int id_z, const int dim_x, const int dim_y, const int dim_z)
Definition gint_helper.h:16
GintPrecision
Definition gint_helper.h:11
@ fp64
Definition gint_helper.h:12
@ fp32
Definition gint_helper.h:13
double pow_int(const double base, const int exp)
Definition gint_helper.h:42
int ceil_div(const int a, const int b)
Definition gint_helper.h:70
Vec3i index1Dto3D(const int index_1d, const int dim_x, const int dim_y, const int dim_z)
Definition gint_helper.h:27
ModuleBase::Vector3< int > Vec3i
Definition gint_type.h:12
Definition allocator.h:6