Skip to content

Commit c404f51

Browse files
committed
remove dependence of DensityMatrix on K_Vectors
1 parent 6b81902 commit c404f51

File tree

18 files changed

+65
-93
lines changed

18 files changed

+65
-93
lines changed

source/module_elecstate/elecstate_lcao.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
131131
template <typename TK>
132132
void ElecStateLCAO<TK>::init_DM(const K_Vectors* kv, const Parallel_Orbitals* paraV, const int nspin)
133133
{
134-
this->DM = new DensityMatrix<TK, double>(kv, paraV, nspin);
134+
const int nspin_dm = std::map<int, int>({ {1, 1}, {2, 2}, {4, 1} })[nspin];
135+
this->DM = new DensityMatrix<TK, double>(paraV, nspin_dm, kv->kvec_d, kv->get_nks() / nspin_dm);
135136
}
136137

137138
template <>

source/module_elecstate/module_dm/density_matrix.cpp

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,62 +24,24 @@ DensityMatrix<TK, TR>::~DensityMatrix()
2424
}
2525
}
2626

27-
// constructor for multi-k
2827
template <typename TK, typename TR>
29-
DensityMatrix<TK, TR>::DensityMatrix(const K_Vectors* kv_in, const Parallel_Orbitals* paraV_in, const int nspin)
28+
DensityMatrix<TK, TR>::DensityMatrix(const Parallel_Orbitals* paraV_in, const int nspin, const std::vector<ModuleBase::Vector3<double>>& kvec_d, const int nk)
29+
: _paraV(paraV_in), _nspin(nspin), _kvec_d(kvec_d), _nks((nk > 0 && nk <= _kvec_d.size()) ? nk : _kvec_d.size())
3030
{
3131
ModuleBase::TITLE("DensityMatrix", "DensityMatrix-MK");
32-
this->_kv = kv_in;
33-
this->_paraV = paraV_in;
34-
// set this->_nspin
35-
if (nspin == 1 || nspin == 4)
36-
{
37-
this->_nspin = 1;
38-
}
39-
else if (nspin == 2)
40-
{
41-
this->_nspin = 2;
42-
#ifdef __DEBUG
43-
assert(kv_in->get_nks() % 2 == 0);
44-
#endif
45-
}
46-
else
47-
{
48-
throw std::string("nspin must be 1, 2 or 4");
49-
}
50-
// set this->_nks, which is real number of k-points
51-
this->_nks = kv_in->get_nks() / this->_nspin;
52-
// allocate memory for _DMK
53-
this->_DMK.resize(this->_kv->get_nks());
54-
for (int ik = 0; ik < this->_kv->get_nks(); ik++)
32+
const int nks = _nks * _nspin;
33+
this->_DMK.resize(nks);
34+
for (int ik = 0; ik < nks; ik++)
5535
{
5636
this->_DMK[ik].resize(this->_paraV->get_row_size() * this->_paraV->get_col_size());
5737
}
5838
ModuleBase::Memory::record("DensityMatrix::DMK", this->_DMK.size() * this->_DMK[0].size() * sizeof(TK));
5939
}
6040

61-
// constructor for Gamma-Only
6241
template <typename TK, typename TR>
63-
DensityMatrix<TK, TR>::DensityMatrix(const Parallel_Orbitals* paraV_in, const int nspin)
42+
DensityMatrix<TK, TR>::DensityMatrix(const Parallel_Orbitals* paraV_in, const int nspin) :_paraV(paraV_in), _nspin(nspin), _kvec_d({ ModuleBase::Vector3<double>(0,0,0) }), _nks(1)
6443
{
6544
ModuleBase::TITLE("DensityMatrix", "DensityMatrix-GO");
66-
this->_paraV = paraV_in;
67-
// set this->_nspin
68-
if (nspin == 1 || nspin == 4)
69-
{
70-
this->_nspin = 1;
71-
}
72-
else if (nspin == 2)
73-
{
74-
this->_nspin = 2;
75-
}
76-
else
77-
{
78-
throw std::string("nspin must be 1, 2 or 4");
79-
}
80-
// set this->_nks, which is real number of k-points
81-
this->_nks = 1;
82-
// allocate memory for _DMK
8345
this->_DMK.resize(_nspin);
8446
for (int ik = 0; ik < this->_nspin; ik++)
8547
{
@@ -328,10 +290,9 @@ template <typename TK, typename TR>
328290
int DensityMatrix<TK, TR>::get_DMK_nks() const
329291
{
330292
#ifdef __DEBUG
331-
assert(this->_DMK.size() != 0);
332-
assert(this->_kv != nullptr);
293+
assert(this->_DMK.size() == _nks * _nspin);
333294
#endif
334-
return this->_kv->get_nks();
295+
return _nks * _nspin;
335296
}
336297

337298
template <typename TK, typename TR>
@@ -440,7 +401,7 @@ void DensityMatrix<TK, TR>::cal_DMR_test()
440401
// cal k_phase
441402
// if TK==std::complex<double>, kphase is e^{ikR}
442403
const ModuleBase::Vector3<double> dR(r_index[0], r_index[1], r_index[2]);
443-
const double arg = (this->_kv->kvec_d[ik] * dR) * ModuleBase::TWO_PI;
404+
const double arg = (this->_kvec_d[ik] * dR) * ModuleBase::TWO_PI;
444405
double sinp, cosp;
445406
ModuleBase::libm::sincos(arg, &sinp, &cosp);
446407
std::complex<double> kphase = std::complex<double>(cosp, sinp);
@@ -515,7 +476,7 @@ void DensityMatrix<std::complex<double>, double>::cal_DMR()
515476
// cal k_phase
516477
// if TK==std::complex<double>, kphase is e^{ikR}
517478
const ModuleBase::Vector3<double> dR(r_index[0], r_index[1], r_index[2]);
518-
const double arg = (this->_kv->kvec_d[ik] * dR) * ModuleBase::TWO_PI;
479+
const double arg = (this->_kvec_d[ik] * dR) * ModuleBase::TWO_PI;
519480
double sinp, cosp;
520481
ModuleBase::libm::sincos(arg, &sinp, &cosp);
521482
std::complex<double> kphase = std::complex<double>(cosp, sinp);
@@ -561,7 +522,7 @@ void DensityMatrix<std::complex<double>, double>::cal_DMR()
561522
// cal k_phase
562523
// if TK==std::complex<double>, kphase is e^{ikR}
563524
const ModuleBase::Vector3<double> dR(r_index[0], r_index[1], r_index[2]);
564-
const double arg = (this->_kv->kvec_d[ik] * dR) * ModuleBase::TWO_PI;
525+
const double arg = (this->_kvec_d[ik] * dR) * ModuleBase::TWO_PI;
565526
double sinp, cosp;
566527
ModuleBase::libm::sincos(arg, &sinp, &cosp);
567528
std::complex<double> kphase = std::complex<double>(cosp, sinp);
@@ -678,7 +639,7 @@ void DensityMatrix<std::complex<double>, double>::cal_DMR(const int ik)
678639
// cal k_phase
679640
// if TK==std::complex<double>, kphase is e^{ikR}
680641
const ModuleBase::Vector3<double> dR(r_index[0], r_index[1], r_index[2]);
681-
const double arg = (this->_kv->kvec_d[ik] * dR) * ModuleBase::TWO_PI;
642+
const double arg = (this->_kvec_d[ik] * dR) * ModuleBase::TWO_PI;
682643
double sinp, cosp;
683644
ModuleBase::libm::sincos(arg, &sinp, &cosp);
684645
std::complex<double> kphase = std::complex<double>(cosp, sinp);
@@ -855,9 +816,9 @@ void DensityMatrix<TK, TR>::read_DMK(const std::string directory, const int ispi
855816
// quit the program or not.
856817
bool quit = false;
857818

858-
ModuleBase::CHECK_DOUBLE(ifs, this->_kv->kvec_d[ik].x, quit);
859-
ModuleBase::CHECK_DOUBLE(ifs, this->_kv->kvec_d[ik].y, quit);
860-
ModuleBase::CHECK_DOUBLE(ifs, this->_kv->kvec_d[ik].z, quit);
819+
ModuleBase::CHECK_DOUBLE(ifs, this->_kvec_d[ik].x, quit);
820+
ModuleBase::CHECK_DOUBLE(ifs, this->_kvec_d[ik].y, quit);
821+
ModuleBase::CHECK_DOUBLE(ifs, this->_kvec_d[ik].z, quit);
861822
ModuleBase::CHECK_INT(ifs, this->_paraV->nrow);
862823
ModuleBase::CHECK_INT(ifs, this->_paraV->ncol);
863824
} // If file exist, read in data.
@@ -890,7 +851,7 @@ void DensityMatrix<double, double>::write_DMK(const std::string directory, const
890851
{
891852
ModuleBase::WARNING("elecstate::write_dmk", "Can't create DENSITY MATRIX File!");
892853
}
893-
ofs << this->_kv->kvec_d[ik].x << " " << this->_kv->kvec_d[ik].y << " " << this->_kv->kvec_d[ik].z << std::endl;
854+
ofs << this->_kvec_d[ik].x << " " << this->_kvec_d[ik].y << " " << this->_kvec_d[ik].z << std::endl;
894855
ofs << "\n " << this->_paraV->nrow << " " << this->_paraV->ncol << std::endl;
895856

896857
ofs << std::setprecision(3);
@@ -927,7 +888,7 @@ void DensityMatrix<std::complex<double>, double>::write_DMK(const std::string di
927888
{
928889
ModuleBase::WARNING("elecstate::write_dmk", "Can't create DENSITY MATRIX File!");
929890
}
930-
ofs << this->_kv->kvec_d[ik].x << " " << this->_kv->kvec_d[ik].y << " " << this->_kv->kvec_d[ik].z << std::endl;
891+
ofs << this->_kvec_d[ik].x << " " << this->_kvec_d[ik].y << " " << this->_kvec_d[ik].z << std::endl;
931892
ofs << "\n " << this->_paraV->nrow << " " << this->_paraV->ncol << std::endl;
932893

933894
ofs << std::setprecision(3);

source/module_elecstate/module_dm/density_matrix.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <string>
55

6-
#include "module_cell/klist.h"
76
#include "module_cell/module_neighbor/sltk_grid_driver.h"
87
#include "module_hamilt_lcao/hamilt_lcaodft/record_adj.h"
98
#include "module_hamilt_lcao/module_hcontainer/hcontainer.h"
@@ -45,16 +44,20 @@ class DensityMatrix
4544

4645
/**
4746
* @brief Constructor of class DensityMatrix for multi-k calculation
48-
* @param _kv pointer of K_Vectors object
4947
* @param _paraV pointer of Parallel_Orbitals object
50-
* @param nspin spin setting (1 - none spin; 2 - spin; 4 - SOC)
48+
* @param nspin number of spin of the density matrix, set by user according to global nspin
49+
* (usually {nspin_global -> nspin_dm} = {1->1, 2->2, 4->1}, but sometimes 2->1 like in LR-TDDFT)
50+
* @param kvec_d direct coordinates of kpoints
51+
* @param nk number of k-points, not always equal to K_Vectors::get_nks()/nspin_dm.
52+
* if remains default or large than kvec_d.size(), it will be set to kvec_d.size()
5153
*/
52-
DensityMatrix(const K_Vectors* _kv, const Parallel_Orbitals* _paraV, const int nspin);
54+
DensityMatrix(const Parallel_Orbitals* _paraV, const int nspin, const std::vector<ModuleBase::Vector3<double>>& kvec_d, const int nk = -1);
5355

5456
/**
5557
* @brief Constructor of class DensityMatrix for gamma-only calculation, where kvector is not required
5658
* @param _paraV pointer of Parallel_Orbitals object
57-
* @param nspin spin setting (1 - none spin; 2 - spin; 4 - SOC)
59+
* @param nspin number of spin of the density matrix, set by user according to global nspin
60+
* (usually {nspin_global -> nspin_dm} = {1->1, 2->2, 4->1}, but sometimes 2->1 like in LR-TDDFT)
5861
*/
5962
DensityMatrix(const Parallel_Orbitals* _paraV, const int nspin);
6063

@@ -169,7 +172,7 @@ class DensityMatrix
169172
*/
170173
const Parallel_Orbitals* get_paraV_pointer() const {return this->_paraV;}
171174

172-
const K_Vectors* get_kv_pointer() const {return this->_kv;}
175+
const std::vector<ModuleBase::Vector3<double>>& get_kvec_d() const { return this->_kvec_d; }
173176

174177
/**
175178
* @brief calculate density matrix DMR from dm(k) using blas::axpy
@@ -249,7 +252,7 @@ class DensityMatrix
249252
/**
250253
* @brief K_Vectors object, which is used to get k-point information
251254
*/
252-
const K_Vectors* _kv;
255+
const std::vector<ModuleBase::Vector3<double>> _kvec_d;
253256

254257
/**
255258
* @brief Parallel_Orbitals object, which contain all information of 2D block cyclic distribution
@@ -268,7 +271,7 @@ class DensityMatrix
268271
* _nks is not equal to _kv->get_nks() when spin-polarization is considered
269272
* _nks = kv->_nks / nspin
270273
*/
271-
int _nks = 0;
274+
int _nks = 0; // comment by lunasea: I want to rename it as nk
272275

273276

274277
};

source/module_elecstate/module_dm/test/test_cal_dm_R.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class DMTest : public testing::Test
7474
init_parav();
7575
}
7676

77-
void TearDown()
77+
void TearDown() override
7878
{
7979
delete paraV;
8080
delete[] ucell.atoms[0].tau;
@@ -129,7 +129,7 @@ TEST_F(DMTest, cal_DMR_test)
129129
kv->set_nks(nks);
130130
kv->kvec_d.resize(nks);
131131
// construct DM
132-
elecstate::DensityMatrix<double, double> DM(kv, paraV, nspin);
132+
elecstate::DensityMatrix<double, double> DM(paraV, nspin, kv->kvec_d, kv->get_nks() / nspin);
133133
// set this->_DMK
134134
for (int is = 1; is <= nspin; is++)
135135
{
@@ -198,7 +198,7 @@ TEST_F(DMTest, cal_DMR_blas_double)
198198
kv->set_nks(nks);
199199
kv->kvec_d.resize(nks);
200200
// construct DM
201-
elecstate::DensityMatrix<double, double> DM(kv, paraV, nspin);
201+
elecstate::DensityMatrix<double, double> DM(paraV, nspin, kv->kvec_d, kv->get_nks() / nspin);
202202
// set this->_DMK
203203
for (int is = 1; is <= nspin; is++)
204204
{
@@ -269,7 +269,7 @@ TEST_F(DMTest, cal_DMR_blas_complex)
269269
kv->kvec_d[1].x = 0.5;
270270
kv->kvec_d[3].x = 0.5;
271271
// construct DM
272-
elecstate::DensityMatrix<std::complex<double>, double> DM(kv, paraV, nspin);
272+
elecstate::DensityMatrix<std::complex<double>, double> DM(paraV, nspin, kv->kvec_d, kv->get_nks() / nspin);
273273
// set this->_DMK
274274
for (int is = 1; is <= nspin; is++)
275275
{

source/module_elecstate/module_dm/test/test_dm_R_init.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class DMTest : public testing::Test
7474
init_parav();
7575
}
7676

77-
void TearDown()
77+
void TearDown() override
7878
{
7979
delete paraV;
8080
delete[] ucell.atoms[0].tau;
@@ -118,7 +118,7 @@ TEST_F(DMTest, DMInit1)
118118
// construct DM
119119
std::cout << "dim0: " << paraV->dim0 << " dim1:" << paraV->dim1 << std::endl;
120120
std::cout << "nrow: " << paraV->nrow << " ncol:" << paraV->ncol << std::endl;
121-
elecstate::DensityMatrix<double, double> DM(kv, paraV, nspin);
121+
elecstate::DensityMatrix<double, double> DM(paraV, nspin, kv->kvec_d);
122122
// initialize this->_DMR
123123
Grid_Driver gd(0,0);
124124
DM.init_DMR(&gd, &ucell);
@@ -145,7 +145,7 @@ TEST_F(DMTest, DMInit2)
145145
// construct DM
146146
std::cout << "dim0: " << paraV->dim0 << " dim1:" << paraV->dim1 << std::endl;
147147
std::cout << "nrow: " << paraV->nrow << " ncol:" << paraV->ncol << std::endl;
148-
elecstate::DensityMatrix<double, double> DM(kv, paraV, nspin);
148+
elecstate::DensityMatrix<double, double> DM(paraV, nspin, kv->kvec_d);
149149
// initialize Record_adj using Grid_Driver
150150
Grid_Driver gd(0,0);
151151
Record_adj ra;
@@ -208,12 +208,12 @@ TEST_F(DMTest, DMInit3)
208208
kv->kvec_d[1].x = 0.5;
209209
kv->kvec_d[3].x = 0.5;
210210
// construct a DM
211-
elecstate::DensityMatrix<std::complex<double>, double> DM(kv, paraV, nspin);
211+
elecstate::DensityMatrix<std::complex<double>, double> DM(paraV, nspin, kv->kvec_d, kv->get_nks() / nspin);
212212
Grid_Driver gd(0, 0);
213213
DM.init_DMR(&gd, &ucell);
214214
std::cout << "dim0: " << paraV->dim0 << " dim1:" << paraV->dim1 << std::endl;
215215
// construct another DM
216-
elecstate::DensityMatrix<std::complex<double>, double> DM1(kv, paraV, nspin);
216+
elecstate::DensityMatrix<std::complex<double>, double> DM1(paraV, nspin, kv->kvec_d, kv->get_nks() / nspin);
217217
DM1.init_DMR(*DM.get_DMR_pointer(1));
218218
// compare
219219
EXPECT_EQ(DM1.get_DMR_pointer(2)->size_atom_pairs(), test_size * test_size);
@@ -266,7 +266,7 @@ TEST_F(DMTest, DMInit4)
266266
}
267267
}
268268
// construct a DM from this HContainer
269-
elecstate::DensityMatrix<std::complex<double>, double> DM(kv, paraV, nspin);
269+
elecstate::DensityMatrix<std::complex<double>, double> DM(paraV, nspin, kv->kvec_d, kv->get_nks() / nspin);
270270
DM.init_DMR(*tmp_DMR);
271271
std::cout << "dim0: " << paraV->dim0 << " dim1:" << paraV->dim1 << std::endl;
272272
// compare
@@ -292,11 +292,11 @@ TEST_F(DMTest, saveDMR)
292292
kv->kvec_d[1].x = 0.5;
293293
kv->kvec_d[3].x = 0.5;
294294
// construct a DM
295-
elecstate::DensityMatrix<std::complex<double>, double> DM(kv, paraV, nspin);
295+
elecstate::DensityMatrix<std::complex<double>, double> DM(paraV, nspin, kv->kvec_d, kv->get_nks() / nspin);
296296
Grid_Driver gd(0, 0);
297297
DM.init_DMR(&gd, &ucell);
298298
// construct another DM
299-
elecstate::DensityMatrix<std::complex<double>, double> DM_test(kv, paraV, nspin);
299+
elecstate::DensityMatrix<std::complex<double>, double> DM_test(paraV, nspin, kv->kvec_d, kv->get_nks() / nspin);
300300
DM_test.init_DMR(*DM.get_DMR_pointer(1));
301301
DM_test.save_DMR();
302302
EXPECT_EQ(DM_test.get_DMR_pointer(1)->get_nnr(), DM.get_DMR_pointer(1)->get_nnr());

source/module_elecstate/module_dm/test/test_dm_constructor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ TEST_F(DMTest, DMConstructor_nspin1)
127127
std::cout << "dim0: " << paraV->dim0 << " dim1:" << paraV->dim1 << std::endl;
128128
std::cout << "nrow: " << paraV->nrow << " ncol:" << paraV->ncol << std::endl;
129129
int nspin = 1;
130-
elecstate::DensityMatrix<double, double> DM(kv, paraV, nspin);
130+
elecstate::DensityMatrix<double, double> DM(paraV, nspin, kv->kvec_d);
131131
// compare
132132
EXPECT_EQ(DM.get_DMK_nks(), kv->get_nks());
133133
EXPECT_EQ(DM.get_DMK_nrow(), paraV->nrow);
@@ -196,7 +196,7 @@ TEST_F(DMTest, DMConstructor_nspin2)
196196
// construct DM
197197
std::cout << "dim0: " << paraV->dim0 << " dim1:" << paraV->dim1 << std::endl;
198198
std::cout << "nrow: " << paraV->nrow << " ncol:" << paraV->ncol << std::endl;
199-
elecstate::DensityMatrix<double, double> DM(kv, paraV, nspin);
199+
elecstate::DensityMatrix<double, double> DM(paraV, nspin, kv->kvec_d, kv->get_nks() / nspin);
200200
// compare
201201
EXPECT_EQ(DM.get_DMK_nks(), kv->get_nks());
202202
EXPECT_EQ(DM.get_DMK_nrow(), paraV->nrow);

source/module_elecstate/module_dm/test/test_dm_io.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ TEST_F(DMTest, DMConstructor1)
142142
int nspin = 1;
143143
// construct DM
144144
std::cout << paraV->nrow << paraV->ncol << std::endl;
145-
elecstate::DensityMatrix<double, double> DM(kv, paraV, nspin);
145+
elecstate::DensityMatrix<double, double> DM(paraV, nspin, kv->kvec_d);
146146
// read DMK
147147
std::string directory = "./support/";
148148
for (int is = 1; is <= nspin; ++is)
@@ -162,7 +162,7 @@ TEST_F(DMTest, DMConstructor1)
162162
}
163163
}
164164
// construct a new DM
165-
elecstate::DensityMatrix<double, double> DM1(kv, paraV, nspin);
165+
elecstate::DensityMatrix<double, double> DM1(paraV, nspin, kv->kvec_d);
166166
directory = "./support/output";
167167
for (int is = 1; is <= nspin; ++is)
168168
{

source/module_hamilt_lcao/hamilt_lcaodft/fedm_k.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ void Force_LCAO<std::complex<double>>::cal_fedm(const bool isforce,
4242
ModuleBase::timer::tick("Force_LCAO", "cal_fedm");
4343

4444
const int nspin = PARAM.inp.nspin;
45+
const int nspin_dm = std::map<int, int>({ {1,1},{2,2},{4,1} })[nspin];
4546
const int nbands = PARAM.inp.nbands;
4647

4748
// construct a DensityMatrix object
48-
elecstate::DensityMatrix<std::complex<double>, double> edm(kv, &pv, nspin);
49+
elecstate::DensityMatrix<std::complex<double>, double> edm(&pv, nspin_dm, kv->kvec_d, kv->get_nks() / nspin_dm);
4950

5051
//--------------------------------------------
5152
// calculate the energy density matrix here.

source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_HAMILT_LCAODFT_HAMILT_LCAO_H
33

44
#include "module_basis/module_nao/two_center_bundle.h"
5+
#include "module_cell/klist.h"
56
#include "module_elecstate/module_dm/density_matrix.h"
67
#include "module_elecstate/potentials/potential_new.h"
78
#include "module_hamilt_general/hamilt.h"

source/module_io/get_pchg_lcao.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ void IState_Charge::begin(Gint_k& gk,
219219
if (bands_picked_[ib])
220220
{
221221
// Using new density matrix inplementation (multi-k)
222-
elecstate::DensityMatrix<std::complex<double>, double> DM(&kv, this->ParaV, nspin);
222+
const int nspin_dm = std::map<int, int>({ {1,1},{2,2},{4,1} })[nspin];
223+
elecstate::DensityMatrix<std::complex<double>, double> DM(this->ParaV, nspin_dm, kv.kvec_d, kv.get_nks() / nspin_dm);
223224

224225
#ifdef __MPI
225226
this->idmatrix(ib, nspin, nelec, nlocal, wg, DM, kv, if_separate_k);

0 commit comments

Comments
 (0)