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