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