|
5 | 5 | #include "source_io/module_parameter/parameter.h" |
6 | 6 |
|
7 | 7 | #include <cmath> |
| 8 | +#include <limits> |
8 | 9 |
|
9 | 10 | namespace elecstate |
10 | 11 | { |
11 | 12 | /// @brief calculate band gap |
12 | 13 | void ElecState::cal_bandgap() |
13 | 14 | { |
14 | 15 | if (this->ekb.nr == 0 || this->ekb.nc == 0) |
15 | | - { // which means no homo and no lumo |
| 16 | + { // which means no vbm and no cbm |
16 | 17 | this->bandgap = 0.0; |
17 | 18 | return; |
18 | 19 | } |
19 | | - // int nbands = PARAM.inp.nbands; |
| 20 | + |
20 | 21 | int nbands = this->ekb.nc; |
21 | 22 | int nks = this->klist->get_nks(); |
22 | | - double homo = this->ekb(0, 0); |
23 | | - double lumo = this->ekb(0, nbands - 1); |
| 23 | + double vbm = -std::numeric_limits<double>::infinity(); // Valence Band Maximum |
| 24 | + double cbm = std::numeric_limits<double>::infinity(); // Conduction Band Minimum |
24 | 25 | for (int ib = 0; ib < nbands; ib++) |
25 | 26 | { |
26 | 27 | for (int ik = 0; ik < nks; ik++) |
27 | 28 | { |
28 | | - if (!(this->ekb(ik, ib) - this->eferm.ef > 1e-5) && homo < this->ekb(ik, ib)) |
| 29 | + if (this->ekb(ik, ib) <= this->eferm.ef && this->ekb(ik, ib) > vbm) |
29 | 30 | { |
30 | | - homo = this->ekb(ik, ib); |
| 31 | + vbm = this->ekb(ik, ib); |
31 | 32 | } |
32 | | - if (this->ekb(ik, ib) - this->eferm.ef > 1e-5 && lumo > this->ekb(ik, ib)) |
| 33 | + if (this->ekb(ik, ib) >= this->eferm.ef && this->ekb(ik, ib) < cbm) |
33 | 34 | { |
34 | | - lumo = this->ekb(ik, ib); |
| 35 | + cbm = this->ekb(ik, ib); |
35 | 36 | } |
36 | 37 | } |
37 | 38 | } |
38 | | - this->bandgap = lumo - homo; |
| 39 | + |
| 40 | +#ifdef __MPI |
| 41 | + Parallel_Reduce::gather_max_double_all(GlobalV::NPROC, vbm); |
| 42 | + Parallel_Reduce::gather_min_double_all(GlobalV::NPROC, cbm); |
| 43 | +#endif |
| 44 | + |
| 45 | + this->bandgap = cbm - vbm; |
39 | 46 | } |
40 | 47 |
|
41 | 48 | /// @brief calculate spin up & down band gap |
42 | 49 | /// @todo add isk[ik] so as to discriminate different spins |
43 | 50 | void ElecState::cal_bandgap_updw() |
44 | 51 | { |
45 | 52 | if (this->ekb.nr == 0 || this->ekb.nc == 0) |
46 | | - { // which means no homo and no lumo |
| 53 | + { // which means no vbm and no cbm |
47 | 54 | this->bandgap_up = 0.0; |
48 | 55 | this->bandgap_dw = 0.0; |
49 | 56 | return; |
50 | 57 | } |
51 | 58 | // int nbands = PARAM.inp.nbands; |
52 | 59 | int nbands = this->ekb.nc; |
53 | 60 | int nks = this->klist->get_nks(); |
54 | | - double homo_up = this->ekb(0, 0); |
55 | | - double lumo_up = this->ekb(0, nbands - 1); |
56 | | - double homo_dw = this->ekb(0, 0); |
57 | | - double lumo_dw = this->ekb(0, nbands - 1); |
| 61 | + double vbm_up = -std::numeric_limits<double>::infinity(); |
| 62 | + double cbm_up = std::numeric_limits<double>::infinity(); |
| 63 | + double vbm_dw = -std::numeric_limits<double>::infinity(); |
| 64 | + double cbm_dw = std::numeric_limits<double>::infinity(); |
58 | 65 | for (int ib = 0; ib < nbands; ib++) |
59 | 66 | { |
60 | 67 | for (int ik = 0; ik < nks; ik++) |
61 | 68 | { |
62 | 69 | if (this->klist->isk[ik] == 0) |
63 | 70 | { |
64 | | - if (!(this->ekb(ik, ib) - this->eferm.ef_up > 1e-5) && homo_up < this->ekb(ik, ib)) |
| 71 | + if (this->ekb(ik, ib) <= this->eferm.ef_up && this->ekb(ik, ib) > vbm_up) |
65 | 72 | { |
66 | | - homo_up = this->ekb(ik, ib); |
| 73 | + vbm_up = this->ekb(ik, ib); |
67 | 74 | } |
68 | | - if (this->ekb(ik, ib) - this->eferm.ef_up > 1e-5 && lumo_up > this->ekb(ik, ib)) |
| 75 | + if (this->ekb(ik, ib) >= this->eferm.ef_up && this->ekb(ik, ib) < cbm_up) |
69 | 76 | { |
70 | | - lumo_up = this->ekb(ik, ib); |
| 77 | + cbm_up = this->ekb(ik, ib); |
71 | 78 | } |
72 | 79 | } |
73 | 80 | if (this->klist->isk[ik] == 1) |
74 | 81 | { |
75 | | - if (!(this->ekb(ik, ib) - this->eferm.ef_dw > 1e-5) && homo_dw < this->ekb(ik, ib)) |
| 82 | + if (this->ekb(ik, ib) <= this->eferm.ef_dw && this->ekb(ik, ib) > vbm_dw) |
76 | 83 | { |
77 | | - homo_dw = this->ekb(ik, ib); |
| 84 | + vbm_dw = this->ekb(ik, ib); |
78 | 85 | } |
79 | | - if (this->ekb(ik, ib) - this->eferm.ef_dw > 1e-5 && lumo_dw > this->ekb(ik, ib)) |
| 86 | + if (this->ekb(ik, ib) >= this->eferm.ef_dw && this->ekb(ik, ib) < cbm_dw) |
80 | 87 | { |
81 | | - lumo_dw = this->ekb(ik, ib); |
| 88 | + cbm_dw = this->ekb(ik, ib); |
82 | 89 | } |
83 | 90 | } |
84 | 91 | } |
85 | 92 | } |
86 | | - this->bandgap_up = lumo_up - homo_up; |
87 | | - this->bandgap_dw = lumo_dw - homo_dw; |
| 93 | + |
| 94 | +#ifdef __MPI |
| 95 | + Parallel_Reduce::gather_max_double_all(GlobalV::NPROC, vbm_up); |
| 96 | + Parallel_Reduce::gather_min_double_all(GlobalV::NPROC, cbm_up); |
| 97 | + Parallel_Reduce::gather_max_double_all(GlobalV::NPROC, vbm_dw); |
| 98 | + Parallel_Reduce::gather_min_double_all(GlobalV::NPROC, cbm_dw); |
| 99 | +#endif |
| 100 | + |
| 101 | + this->bandgap_up = cbm_up - vbm_up; |
| 102 | + this->bandgap_dw = cbm_dw - vbm_dw; |
88 | 103 | } |
89 | 104 |
|
90 | 105 | /// @brief calculate deband |
|
0 commit comments