Skip to content

Commit 32c6bb8

Browse files
committed
fix UTs
1 parent b454fa1 commit 32c6bb8

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

source/module_hsolver/diago_iter_assist.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void DiagoIterAssist<T, Device>::diagH_subspace(const hamilt::Hamilt<T, Device>*
5353
const int dmax = psi.get_nbasis();
5454

5555
T* temp = nullptr;
56-
bool in_place = false;
56+
bool in_place = false; ///< if temp and evc share the same memory
5757
if (psi.get_pointer() != evc.get_pointer() && psi.get_nbands() == evc.get_nbands())
5858
{ // use memory of evc as temp
5959
temp = evc.get_pointer();
@@ -62,7 +62,6 @@ void DiagoIterAssist<T, Device>::diagH_subspace(const hamilt::Hamilt<T, Device>*
6262
else
6363
{
6464
resmem_complex_op()(ctx, temp, nstart * dmax, "DiagSub::temp");
65-
setmem_complex_op()(ctx, temp, 0, nstart * dmax);
6665
}
6766

6867
{ // code block to calculate hcc and scc

source/module_psi/test/psi_initializer_unit_test.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class PsiIntializerUnitTest : public ::testing::Test {
132132
this->p_ucell->a2 = {0.0, 10.0, 0.0};
133133
this->p_ucell->a3 = {0.0, 0.0, 10.0};
134134
this->p_ucell->lat0 = 1.0;
135+
this->p_ucell->omega = 1000.0;
135136
this->p_ucell->latvec.e11 = 10.0; this->p_ucell->latvec.e12 = 0.0; this->p_ucell->latvec.e13 = 0.0;
136137
this->p_ucell->latvec.e21 = 0.0; this->p_ucell->latvec.e22 = 10.0; this->p_ucell->latvec.e23 = 0.0;
137138
this->p_ucell->latvec.e31 = 0.0; this->p_ucell->latvec.e32 = 0.0; this->p_ucell->latvec.e33 = 10.0;
@@ -141,14 +142,14 @@ class PsiIntializerUnitTest : public ::testing::Test {
141142
this->p_ucell->tpiba = 2.0 * M_PI / this->p_ucell->lat0;
142143
this->p_ucell->tpiba2 = this->p_ucell->tpiba * this->p_ucell->tpiba;
143144
// atom
144-
if(this->p_ucell->atom_label != nullptr) { delete[] this->p_ucell->atom_label;
145-
}
145+
delete[] this->p_ucell->atom_label;
146146
this->p_ucell->atom_label = new std::string[1];
147147
this->p_ucell->atom_label[0] = "Si";
148148
// atom properties
149149
this->p_ucell->nat = 1;
150150
this->p_ucell->ntype = 1;
151151
this->p_ucell->atoms = new Atom[1];
152+
this->p_ucell->set_atom_flag = true;
152153
this->p_ucell->atoms[0].label = "Si";
153154
this->p_ucell->atoms[0].mass = 28.0855;
154155
this->p_ucell->atoms[0].na = 1;
@@ -165,19 +166,20 @@ class PsiIntializerUnitTest : public ::testing::Test {
165166
this->p_ucell->pseudo_fn[0] = "Si_NCSR_ONCVPSP_v0.5_dojo.upf";
166167
this->p_ucell->natomwfc = 4;
167168
this->p_ucell->atoms[0].ncpp.nchi = 2;
168-
this->p_ucell->atoms[0].ncpp.mesh = 10;
169-
this->p_ucell->atoms[0].ncpp.msh = 10;
169+
this->p_ucell->atoms[0].ncpp.els = std::vector<std::string>(2, "");
170+
this->p_ucell->atoms[0].ncpp.mesh = 11;
171+
this->p_ucell->atoms[0].ncpp.msh = 11;
170172
this->p_ucell->atoms[0].ncpp.lmax = 2;
171173
//if(this->p_ucell->atoms[0].ncpp.rab != nullptr) delete[] this->p_ucell->atoms[0].ncpp.rab;
172-
this->p_ucell->atoms[0].ncpp.rab = std::vector<double>(10, 0.0);
173-
for(int i = 0; i < 10; ++i) { this->p_ucell->atoms[0].ncpp.rab[i] = 0.01;
174+
this->p_ucell->atoms[0].ncpp.rab = std::vector<double>(11, 0.0);
175+
for(int i = 0; i < 11; ++i) { this->p_ucell->atoms[0].ncpp.rab[i] = 0.01;
174176
}
175177
//if(this->p_ucell->atoms[0].ncpp.r != nullptr) delete[] this->p_ucell->atoms[0].ncpp.r;
176-
this->p_ucell->atoms[0].ncpp.r = std::vector<double>(10, 0.0);
177-
for(int i = 0; i < 10; ++i) { this->p_ucell->atoms[0].ncpp.r[i] = 0.01*i;
178+
this->p_ucell->atoms[0].ncpp.r = std::vector<double>(11, 0.0);
179+
for(int i = 0; i < 11; ++i) { this->p_ucell->atoms[0].ncpp.r[i] = 0.01*i;
178180
}
179-
this->p_ucell->atoms[0].ncpp.chi.create(2, 10);
180-
for(int i = 0; i < 2; ++i) { for(int j = 0; j < 10; ++j) { this->p_ucell->atoms[0].ncpp.chi(i, j) = 0.01;
181+
this->p_ucell->atoms[0].ncpp.chi.create(2, 11);
182+
for(int i = 0; i < 2; ++i) { for(int j = 0; j < 11; ++j) { this->p_ucell->atoms[0].ncpp.chi(i, j) = 0.01;
181183
}
182184
}
183185
//if(this->p_ucell->atoms[0].ncpp.lchi != nullptr) delete[] this->p_ucell->atoms[0].ncpp.lchi;
@@ -259,20 +261,21 @@ class PsiIntializerUnitTest : public ::testing::Test {
259261
this->p_pw_wfc->kvec_d = new ModuleBase::Vector3<double>[1];
260262
this->p_pw_wfc->kvec_d[0] = {0.0, 0.0, 0.0};
261263

262-
this->p_pspot_vnl->lmaxkb = 0;
264+
this->p_pspot_vnl->lmaxkb = 1;
263265

264266
this->p_parakpts->startk_pool.resize(1);
265267
this->p_parakpts->startk_pool[0] = 0;
266268

267269
}
268270
void TearDown() override
269271
{
272+
delete this->psi_init;
270273
delete this->p_sf;
271274
delete this->p_pw_wfc;
272275
delete this->p_ucell;
273276
delete this->p_pspot_vnl;
274277
delete this->p_parakpts;
275-
}
278+
}
276279
};
277280

278281
TEST_F(PsiIntializerUnitTest, ConstructorRandom) {
@@ -327,7 +330,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigRandom) {
327330
const int nbasis = this->p_pw_wfc->npwk_max * PARAM.globalv.npol;
328331
psi::Psi<std::complex<double>>* psi = new psi::Psi<std::complex<double>>(1, nbands_start, nbasis, nullptr);
329332
this->psi_init->init_psig(psi->get_pointer(), 0);
330-
EXPECT_NEAR(0, psi->operator()(0,0,0).real(), 1e-12);
333+
EXPECT_NEAR(-0.66187696761064307, psi->operator()(0,0,0).real(), 1e-4);
331334
delete psi;
332335
}
333336

0 commit comments

Comments
 (0)