Skip to content

Commit 803408d

Browse files
committed
Test: update unittests
1 parent 6f18de4 commit 803408d

File tree

2 files changed

+58
-37
lines changed

2 files changed

+58
-37
lines changed

source/module_elecstate/test/potential_new_test.cpp

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ Charge::Charge()
3838
Charge::~Charge()
3939
{
4040
}
41+
surchem::surchem()
42+
{
43+
}
44+
surchem::~surchem()
45+
{
46+
}
4147

4248
namespace elecstate
4349
{
@@ -101,6 +107,7 @@ class PotentialNewTest : public ::testing::Test
101107
UnitCell* ucell = nullptr;
102108
ModuleBase::matrix* vloc = nullptr;
103109
Structure_Factor* structure_factors = nullptr;
110+
surchem* solvent = nullptr;
104111
double* etxc = nullptr;
105112
double* vtxc = nullptr;
106113
elecstate::Potential* pot = nullptr;
@@ -111,43 +118,56 @@ class PotentialNewTest : public ::testing::Test
111118
ucell = new UnitCell;
112119
vloc = new ModuleBase::matrix;
113120
structure_factors = new Structure_Factor();
121+
solvent = new surchem();
114122
etxc = new double;
115123
vtxc = new double;
116124
elecstate::Set_GlobalV_Default();
117125
}
118126
virtual void TearDown()
119127
{
120-
if (rhopw != nullptr) {
128+
if (rhopw != nullptr)
129+
{
121130
delete rhopw;
122-
}
123-
if (rhodpw != nullptr) {
131+
}
132+
if (rhodpw != nullptr)
133+
{
124134
delete rhodpw;
125-
}
126-
if (ucell != nullptr) {
135+
}
136+
if (ucell != nullptr)
137+
{
127138
delete ucell;
128-
}
129-
if (vloc != nullptr) {
139+
}
140+
if (vloc != nullptr)
141+
{
130142
delete vloc;
131-
}
132-
if (structure_factors != nullptr) {
143+
}
144+
if (structure_factors != nullptr)
145+
{
133146
delete structure_factors;
134-
}
135-
if (etxc != nullptr) {
147+
}
148+
if (solvent != nullptr)
149+
{
150+
delete solvent;
151+
}
152+
if (etxc != nullptr)
153+
{
136154
delete etxc;
137-
}
138-
if (vtxc != nullptr) {
155+
}
156+
if (vtxc != nullptr)
157+
{
139158
delete vtxc;
140-
}
141-
if (pot != nullptr) {
159+
}
160+
if (pot != nullptr)
161+
{
142162
delete pot;
143-
}
163+
}
144164
}
145165
};
146166

147167
TEST_F(PotentialNewTest, ConstructorCPUDouble)
148168
{
149169
rhopw->nrxx = 100;
150-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
170+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
151171
EXPECT_TRUE(pot->fixed_mode);
152172
EXPECT_TRUE(pot->dynamic_mode);
153173
EXPECT_EQ(pot->v_effective_fixed.size(), 100);
@@ -159,7 +179,7 @@ TEST_F(PotentialNewTest, ConstructorCPUSingle)
159179
{
160180
rhopw->nrxx = 100;
161181
PARAM.input.precision = "single";
162-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
182+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
163183
EXPECT_TRUE(pot->fixed_mode);
164184
EXPECT_TRUE(pot->dynamic_mode);
165185
EXPECT_EQ(pot->v_effective_fixed.size(), 100);
@@ -170,7 +190,7 @@ TEST_F(PotentialNewTest, ConstructorCPUSingle)
170190
TEST_F(PotentialNewTest, ConstructorNRXX0)
171191
{
172192
rhopw->nrxx = 0;
173-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
193+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
174194
EXPECT_TRUE(pot->fixed_mode);
175195
EXPECT_TRUE(pot->dynamic_mode);
176196
}
@@ -179,7 +199,7 @@ TEST_F(PotentialNewTest, ConstructorXC3)
179199
{
180200
elecstate::tmp_xc_func_type = 3;
181201
rhopw->nrxx = 100;
182-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
202+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
183203
EXPECT_TRUE(pot->fixed_mode);
184204
EXPECT_TRUE(pot->dynamic_mode);
185205
EXPECT_EQ(pot->v_effective_fixed.size(), 100);
@@ -194,7 +214,7 @@ TEST_F(PotentialNewTest, ConstructorGPUDouble)
194214
// this is just a trivial call to the GPU code
195215
rhopw->nrxx = 100;
196216
PARAM.input.device = "gpu";
197-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
217+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
198218
EXPECT_TRUE(pot->fixed_mode);
199219
EXPECT_TRUE(pot->dynamic_mode);
200220
EXPECT_EQ(pot->v_effective_fixed.size(), 100);
@@ -208,7 +228,7 @@ TEST_F(PotentialNewTest, ConstructorGPUSingle)
208228
rhopw->nrxx = 100;
209229
PARAM.input.device = "gpu";
210230
PARAM.input.precision = "single";
211-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
231+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
212232
EXPECT_TRUE(pot->fixed_mode);
213233
EXPECT_TRUE(pot->dynamic_mode);
214234
EXPECT_EQ(pot->v_effective_fixed.size(), 100);
@@ -251,7 +271,7 @@ TEST_F(PotentialNewTest, CalFixedV)
251271
{
252272
// construct potential
253273
rhopw->nrxx = 100;
254-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
274+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
255275
//
256276
std::vector<std::string> compnents_list = {
257277
"local",
@@ -279,7 +299,7 @@ TEST_F(PotentialNewTest, CalVeff)
279299
{
280300
// construct potential
281301
rhopw->nrxx = 100;
282-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
302+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
283303
//
284304
std::vector<std::string> compnents_list = {
285305
"local",
@@ -309,7 +329,7 @@ TEST_F(PotentialNewTest, UpdateFromCharge)
309329
{
310330
// construct potential
311331
rhopw->nrxx = 100;
312-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
332+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
313333
//
314334
std::vector<std::string> compnents_list = {
315335
"local",
@@ -337,7 +357,7 @@ TEST_F(PotentialNewTest, InitPot)
337357
{
338358
// construct potential
339359
rhopw->nrxx = 100;
340-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
360+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
341361
//
342362
std::vector<std::string> compnents_list = {
343363
"local",
@@ -365,7 +385,7 @@ TEST_F(PotentialNewTest, GetVnew)
365385
{
366386
// construct potential
367387
rhopw->nrxx = 100;
368-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
388+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
369389
//
370390
std::vector<std::string> compnents_list = {
371391
"local",
@@ -394,7 +414,7 @@ TEST_F(PotentialNewTest, GetEffectiveVmatrix)
394414
{
395415
// construct potential
396416
rhopw->nrxx = 100;
397-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
417+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
398418
//
399419
ModuleBase::matrix v_eff_tmp = pot->get_effective_v();
400420
const ModuleBase::matrix v_eff_tmp_const = pot->get_effective_v();
@@ -416,7 +436,7 @@ TEST_F(PotentialNewTest, GetEffectiveVarray)
416436
{
417437
// construct potential
418438
rhopw->nrxx = 100;
419-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
439+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
420440
//
421441
double* v_eff_tmp = pot->get_effective_v(0);
422442
const double* v_eff_tmp_const = pot->get_effective_v(0);
@@ -445,7 +465,7 @@ TEST_F(PotentialNewTest, GetEffectiveVofkmatrix)
445465
// construct potential
446466
elecstate::tmp_xc_func_type = 3;
447467
rhopw->nrxx = 100;
448-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
468+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
449469
//
450470
ModuleBase::matrix vofk_eff_tmp = pot->get_effective_vofk();
451471
const ModuleBase::matrix vofk_eff_tmp_const = pot->get_effective_vofk();
@@ -467,7 +487,7 @@ TEST_F(PotentialNewTest, GetEffectiveVofkarray)
467487
{
468488
// construct potential
469489
rhopw->nrxx = 100;
470-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
490+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
471491
//
472492
double* vofk_eff_tmp = pot->get_effective_vofk(0);
473493
const double* vofk_eff_tmp_const = pot->get_effective_vofk(0);
@@ -494,7 +514,7 @@ TEST_F(PotentialNewTest, GetEffectiveVofkarrayNullptr)
494514
TEST_F(PotentialNewTest, GetFixedV)
495515
{
496516
rhopw->nrxx = 100;
497-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
517+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
498518
EXPECT_TRUE(pot->fixed_mode);
499519
EXPECT_TRUE(pot->dynamic_mode);
500520
EXPECT_EQ(pot->v_effective_fixed.size(), 100);
@@ -513,7 +533,7 @@ TEST_F(PotentialNewTest, GetVeffSmooth)
513533
// construct potential
514534
rhopw->nrxx = 100;
515535
elecstate::tmp_xc_func_type = 3;
516-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
536+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
517537
//
518538
ModuleBase::matrix veff_smooth_tmp = pot->get_veff_smooth();
519539
const ModuleBase::matrix veff_smooth_const_tmp = pot->get_veff_smooth();
@@ -535,7 +555,7 @@ TEST_F(PotentialNewTest, GetVofkSmooth)
535555
{
536556
// construct potential
537557
rhopw->nrxx = 100;
538-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
558+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
539559
//
540560
ModuleBase::matrix vofk_smooth_tmp = pot->get_veff_smooth();
541561
const ModuleBase::matrix vofk_smooth_const_tmp = pot->get_veff_smooth();
@@ -568,7 +588,7 @@ TEST_F(PotentialNewTest, InterpolateVrsDoubleGrids)
568588
static_cast<ModulePW::PW_Basis_Sup*>(rhodpw)->setuptransform(rhopw);
569589
rhodpw->collect_local_pw();
570590

571-
pot = new elecstate::Potential(rhodpw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
591+
pot = new elecstate::Potential(rhodpw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
572592

573593
for (int ir = 0; ir < pot->v_effective.nr; ir++)
574594
{
@@ -613,7 +633,7 @@ TEST_F(PotentialNewTest, InterpolateVrsWarningQuit)
613633
rhodpw->collect_local_pw();
614634
rhodpw->gamma_only = true;
615635

616-
pot = new elecstate::Potential(rhodpw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
636+
pot = new elecstate::Potential(rhodpw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
617637

618638
EXPECT_EXIT(pot->interpolate_vrs(), ::testing::ExitedWithCode(1), "");
619639
}
@@ -628,7 +648,7 @@ TEST_F(PotentialNewTest, InterpolateVrsSingleGrids)
628648
rhopw->setuptransform();
629649
rhopw->collect_local_pw();
630650

631-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, etxc, vtxc);
651+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
632652

633653
for (int ir = 0; ir < pot->v_effective.nr; ir++)
634654
{

source/module_hamilt_general/module_surchem/test/setcell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "module_cell/module_neighbor/sltk_atom_arrange.h"
88
#include "module_cell/module_neighbor/sltk_grid_driver.h"
99
#include "module_cell/unitcell.h"
10+
#include "module_hamilt_pw/hamilt_pwdft/parallel_grid.h"
1011
#include "module_hamilt_pw/hamilt_pwdft/structure_factor.h"
1112

1213
namespace GlobalC

0 commit comments

Comments
 (0)