Skip to content

Commit 171b837

Browse files
committed
Refactor: update unit tests
1 parent 091edef commit 171b837

File tree

10 files changed

+116
-143
lines changed

10 files changed

+116
-143
lines changed

source/module_elecstate/test/charge_mixing_test.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
#include "gmock/gmock.h"
22
#include "gtest/gtest.h"
33
#define private public
4-
#include "module_parameter/parameter.h"
5-
#undef private
6-
#include "module_base/module_mixing/broyden_mixing.h"
7-
#define private public
8-
#include "module_parameter/parameter.h"
94
#include "../module_charge/charge_mixing.h"
5+
#include "module_base/module_mixing/broyden_mixing.h"
106
#include "module_basis/module_pw/pw_basis.h"
117
#include "module_hamilt_general/module_xc/xc_functional.h"
12-
#undef private
8+
#include "module_parameter/parameter.h"
139

1410
#ifdef _OPENMP
1511
#include <omp.h>
1612
#endif
1713

18-
int FUNC_TYPE = 1;
14+
int XC_Functional::func_type = 1;
15+
bool XC_Functional::has_kedf = false;
1916

2017
// mock function
2118
Magnetism::~Magnetism()
@@ -35,10 +32,6 @@ void Charge::set_rhopw(ModulePW::PW_Basis* rhopw_in)
3532
{
3633
this->rhopw = rhopw_in;
3734
}
38-
int XC_Functional::get_func_type()
39-
{
40-
return FUNC_TYPE;
41-
}
4235
#ifdef __LCAO
4336
InfoNonlocal::InfoNonlocal()
4437
{
@@ -232,7 +225,8 @@ TEST_F(ChargeMixingTest, InitMixingTest)
232225
omp_set_num_threads(1);
233226
#endif
234227
PARAM.input.nspin = 1;
235-
FUNC_TYPE = 1;
228+
XC_Functional::func_type = 1;
229+
XC_Functional::has_kedf = false;
236230
Charge_Mixing CMtest;
237231
CMtest.set_rhopw(&pw_basis, &pw_basis);
238232

@@ -275,7 +269,8 @@ TEST_F(ChargeMixingTest, InitMixingTest)
275269
PARAM.input.mixing_dmr,
276270
ucell.omega,
277271
ucell.tpiba);
278-
FUNC_TYPE = 3;
272+
XC_Functional::func_type = 3;
273+
XC_Functional::has_kedf = true;
279274
CMtest.init_mixing();
280275
EXPECT_EQ(CMtest.tau_mdata.length, pw_basis.nrxx);
281276

@@ -826,7 +821,8 @@ TEST_F(ChargeMixingTest, MixRhoTest)
826821
charge.set_rhopw(&pw_basis);
827822
const int nspin = PARAM.input.nspin = 1;
828823
PARAM.sys.domag_z = false;
829-
FUNC_TYPE = 3;
824+
XC_Functional::func_type = 3;
825+
XC_Functional::has_kedf = true;
830826
PARAM.input.mixing_beta = 0.7;
831827
PARAM.input.mixing_ndim = 1;
832828
PARAM.input.mixing_gg0 = 0.0;
@@ -964,7 +960,8 @@ TEST_F(ChargeMixingTest, MixDoubleGridRhoTest)
964960
charge.set_rhopw(&pw_dbasis);
965961
const int nspin = PARAM.input.nspin = 1;
966962
PARAM.sys.domag_z = false;
967-
FUNC_TYPE = 3;
963+
XC_Functional::func_type = 3;
964+
XC_Functional::has_kedf = true;
968965
PARAM.input.mixing_beta = 0.7;
969966
PARAM.input.mixing_ndim = 1;
970967
PARAM.input.mixing_gg0 = 0.0;

source/module_elecstate/test/charge_test.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33

44
#define private public
55
#define protected public
6-
#include "module_parameter/parameter.h"
76
#include "module_cell/unitcell.h"
87
#include "module_elecstate/module_charge/charge.h"
8+
#include "module_hamilt_general/module_xc/xc_functional.h"
9+
#include "module_parameter/parameter.h"
910
#include "prepare_unitcell.h"
10-
#undef protected
11-
#undef private
12-
1311
// mock functions for UnitCell
1412
#ifdef __LCAO
1513
InfoNonlocal::InfoNonlocal()
@@ -31,13 +29,10 @@ Magnetism::~Magnetism()
3129
}
3230

3331
// mock functions for Charge
32+
int XC_Functional::func_type = 1;
33+
bool XC_Functional::has_kedf = false;
3434
namespace elecstate
3535
{
36-
int tmp_xc_func_type = 1;
37-
int XC_Functional::get_func_type()
38-
{
39-
return tmp_xc_func_type;
40-
}
4136
double tmp_ucell_omega = 500.0;
4237
double tmp_gridecut = 80.0;
4338
void Set_GlobalV_Default()
@@ -118,7 +113,8 @@ TEST_F(ChargeTest, Allocate)
118113
EXPECT_EQ(rhopw->npwtot, 3143);
119114
// call Charge::allocate()
120115
PARAM.input.test_charge = 2;
121-
elecstate::tmp_xc_func_type = 3;
116+
XC_Functional::func_type = 3;
117+
XC_Functional::has_kedf = true;
122118
charge->set_rhopw(rhopw);
123119
EXPECT_FALSE(charge->allocate_rho);
124120
charge->allocate(PARAM.input.nspin);
@@ -202,7 +198,8 @@ TEST_F(ChargeTest, SaveRhoBeforeSumBand)
202198
}
203199
}
204200
EXPECT_EQ(PARAM.input.nelec, 8);
205-
elecstate::tmp_xc_func_type = 3;
201+
XC_Functional::func_type = 3;
202+
XC_Functional::has_kedf = true;
206203
charge->set_omega(&ucell->omega);;
207204
charge->renormalize_rho();
208205
charge->save_rho_before_sum_band();
@@ -212,7 +209,8 @@ TEST_F(ChargeTest, SaveRhoBeforeSumBand)
212209
TEST_F(ChargeTest, InitFinalScf)
213210
{
214211
charge->set_rhopw(rhopw);
215-
elecstate::tmp_xc_func_type = 1;
212+
XC_Functional::func_type = 1;
213+
XC_Functional::has_kedf = false;
216214
PARAM.input.test_charge = 2;
217215
charge->init_final_scf();
218216
EXPECT_TRUE(charge->allocate_rho_final_scf);

source/module_elecstate/test/elecstate_energy_test.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22
#include "gmock/gmock.h"
33
#include "gtest/gtest.h"
44
#define private public
5-
#include "module_parameter/parameter.h"
6-
#undef private
75
#include "module_elecstate/elecstate.h"
6+
#include "module_hamilt_general/module_xc/xc_functional.h"
7+
#include "module_parameter/parameter.h"
88

99
#include <string>
1010
Parameter PARMA;
1111

1212
// mock functions
13+
int XC_Functional::func_type = 1;
14+
bool XC_Functional::has_kedf = false;
1315
namespace elecstate
1416
{
15-
int tmp_xc_func_type = 1;
16-
int XC_Functional::get_func_type()
17-
{
18-
return tmp_xc_func_type;
19-
}
2017
void Potential::get_vnew(Charge const*, ModuleBase::matrix&)
2118
{
2219
return;

source/module_elecstate/test/elecstate_print_test.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#include "gmock/gmock.h"
44
#include "gtest/gtest.h"
55
#define private public
6-
#include "module_parameter/parameter.h"
7-
#undef private
86
#include "module_cell/klist.h"
97
#include "module_elecstate/elecstate.h"
108
#include "module_elecstate/module_charge/charge.h"
119
#include "module_elecstate/potentials/efield.h"
1210
#include "module_elecstate/potentials/gatefield.h"
11+
#include "module_hamilt_general/module_xc/xc_functional.h"
12+
#include "module_parameter/parameter.h"
1313

1414
/***************************************************************
1515
* mock functions
@@ -40,10 +40,9 @@ Charge::Charge()
4040
Charge::~Charge()
4141
{
4242
}
43-
int XC_Functional::get_func_type()
44-
{
45-
return 0;
46-
}
43+
44+
int XC_Functional::func_type = 0;
45+
bool XC_Functional::has_kedf = false;
4746

4847
/***************************************************************
4948
* unit test of functions in elecstate_print.cpp

source/module_elecstate/test/elecstate_pw_test.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@
33
#include "gmock/gmock.h"
44
#include "gtest/gtest.h"
55
#define private public
6-
#include "module_parameter/parameter.h"
7-
#undef private
86
#define protected public
97
#include "module_elecstate/elecstate_pw.h"
8+
#include "module_hamilt_general/module_xc/xc_functional.h"
109
#include "module_hamilt_pw/hamilt_pwdft/VL_in_pw.h"
11-
#undef protected
10+
#include "module_parameter/parameter.h"
1211
// mock functions for testing
12+
int XC_Functional::func_type = 1;
1313
namespace elecstate
1414
{
15-
int tmp_xc_func_type = 1;
16-
int XC_Functional::get_func_type()
17-
{
18-
return tmp_xc_func_type;
19-
}
2015
void Potential::init_pot(int, Charge const*)
2116
{
2217
}
@@ -272,7 +267,7 @@ TEST_F(ElecStatePWTest, ConstructorSingle)
272267

273268
TEST_F(ElecStatePWTest, InitRhoDataDouble)
274269
{
275-
elecstate::tmp_xc_func_type = 3;
270+
XC_Functional::func_type = 3;
276271
chg->nrxx = 1000;
277272
elecstate_pw_d = new elecstate::ElecStatePW<std::complex<double>, base_device::DEVICE_CPU>(wfcpw,
278273
chg,
@@ -291,7 +286,7 @@ TEST_F(ElecStatePWTest, InitRhoDataDouble)
291286
TEST_F(ElecStatePWTest, InitRhoDataSingle)
292287
{
293288
PARAM.input.precision = "single";
294-
elecstate::tmp_xc_func_type = 3;
289+
XC_Functional::func_type = 3;
295290
chg->nspin = PARAM.input.nspin;
296291
chg->nrxx = 1000;
297292
elecstate_pw_s = new elecstate::ElecStatePW<std::complex<float>, base_device::DEVICE_CPU>(wfcpw,

source/module_elecstate/test/potential_new_test.cpp

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include <vector>
33

44
#define private public
5-
#include "module_parameter/parameter.h"
65
#include "module_elecstate/potentials/potential_new.h"
7-
#undef private
6+
#include "module_hamilt_general/module_xc/xc_functional.h"
7+
#include "module_parameter/parameter.h"
88
// mock functions
99
Structure_Factor::Structure_Factor()
1010
{
@@ -44,14 +44,10 @@ surchem::surchem()
4444
surchem::~surchem()
4545
{
4646
}
47-
47+
int XC_Functional::func_type = 1;
48+
bool XC_Functional::has_kedf = false;
4849
namespace elecstate
4950
{
50-
int tmp_xc_func_type = 1;
51-
int XC_Functional::get_func_type()
52-
{
53-
return tmp_xc_func_type;
54-
}
5551

5652
PotBase* Potential::get_pot_type(const std::string& pot_type)
5753
{
@@ -197,7 +193,8 @@ TEST_F(PotentialNewTest, ConstructorNRXX0)
197193

198194
TEST_F(PotentialNewTest, ConstructorXC3)
199195
{
200-
elecstate::tmp_xc_func_type = 3;
196+
XC_Functional::func_type = 3;
197+
XC_Functional::has_kedf = true;
201198
rhopw->nrxx = 100;
202199
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
203200
EXPECT_TRUE(pot->fixed_mode);
@@ -463,7 +460,8 @@ TEST_F(PotentialNewTest, GetEffectiveVarrayNullptr)
463460
TEST_F(PotentialNewTest, GetEffectiveVofkmatrix)
464461
{
465462
// construct potential
466-
elecstate::tmp_xc_func_type = 3;
463+
XC_Functional::func_type = 3;
464+
XC_Functional::has_kedf = true;
467465
rhopw->nrxx = 100;
468466
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
469467
//
@@ -532,7 +530,8 @@ TEST_F(PotentialNewTest, GetVeffSmooth)
532530
{
533531
// construct potential
534532
rhopw->nrxx = 100;
535-
elecstate::tmp_xc_func_type = 3;
533+
XC_Functional::func_type = 3;
534+
XC_Functional::has_kedf = true;
536535
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
537536
//
538537
ModuleBase::matrix veff_smooth_tmp = pot->get_veff_smooth();
@@ -576,28 +575,29 @@ TEST_F(PotentialNewTest, GetVofkSmooth)
576575
TEST_F(PotentialNewTest, InterpolateVrsDoubleGrids)
577576
{
578577
PARAM.sys.double_grid = true;
579-
elecstate::tmp_xc_func_type = 3;
580-
// Init pw_basis
581-
rhopw->initgrids(4, ModuleBase::Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1), 4);
582-
rhopw->initparameters(false, 4);
583-
rhopw->setuptransform();
584-
rhopw->collect_local_pw();
585-
586-
rhodpw->initgrids(4, ModuleBase::Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1), 6);
587-
rhodpw->initparameters(false, 6);
588-
static_cast<ModulePW::PW_Basis_Sup*>(rhodpw)->setuptransform(rhopw);
589-
rhodpw->collect_local_pw();
590-
591-
pot = new elecstate::Potential(rhodpw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
592-
593-
for (int ir = 0; ir < pot->v_effective.nr; ir++)
594-
{
595-
for (int ic = 0; ic < pot->v_effective.nc; ic++)
596-
{
597-
pot->v_effective(ir,ic) = ir+ic;
598-
pot->vofk_effective(ir,ic) = ir+2*ic;
599-
}
600-
}
578+
XC_Functional::func_type = 3;
579+
XC_Functional::has_kedf = true;
580+
// Init pw_basis
581+
rhopw->initgrids(4, ModuleBase::Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1), 4);
582+
rhopw->initparameters(false, 4);
583+
rhopw->setuptransform();
584+
rhopw->collect_local_pw();
585+
586+
rhodpw->initgrids(4, ModuleBase::Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1), 6);
587+
rhodpw->initparameters(false, 6);
588+
static_cast<ModulePW::PW_Basis_Sup*>(rhodpw)->setuptransform(rhopw);
589+
rhodpw->collect_local_pw();
590+
591+
pot = new elecstate::Potential(rhodpw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
592+
593+
for (int ir = 0; ir < pot->v_effective.nr; ir++)
594+
{
595+
for (int ic = 0; ic < pot->v_effective.nc; ic++)
596+
{
597+
pot->v_effective(ir, ic) = ir + ic;
598+
pot->vofk_effective(ir, ic) = ir + 2 * ic;
599+
}
600+
}
601601

602602
pot->interpolate_vrs();
603603

@@ -641,23 +641,24 @@ TEST_F(PotentialNewTest, InterpolateVrsWarningQuit)
641641
TEST_F(PotentialNewTest, InterpolateVrsSingleGrids)
642642
{
643643
PARAM.sys.double_grid = false;
644-
elecstate::tmp_xc_func_type = 3;
645-
// Init pw_basis
646-
rhopw->initgrids(4, ModuleBase::Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1), 4);
647-
rhopw->initparameters(false, 4);
648-
rhopw->setuptransform();
649-
rhopw->collect_local_pw();
650-
651-
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
652-
653-
for (int ir = 0; ir < pot->v_effective.nr; ir++)
654-
{
655-
for (int ic = 0; ic < pot->v_effective.nc; ic++)
656-
{
657-
pot->v_effective(ir,ic) = ir+ic;
658-
pot->vofk_effective(ir,ic) = ir+2*ic;
659-
}
660-
}
644+
XC_Functional::func_type = 3;
645+
XC_Functional::has_kedf = true;
646+
// Init pw_basis
647+
rhopw->initgrids(4, ModuleBase::Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1), 4);
648+
rhopw->initparameters(false, 4);
649+
rhopw->setuptransform();
650+
rhopw->collect_local_pw();
651+
652+
pot = new elecstate::Potential(rhopw, rhopw, ucell, vloc, structure_factors, solvent, etxc, vtxc);
653+
654+
for (int ir = 0; ir < pot->v_effective.nr; ir++)
655+
{
656+
for (int ic = 0; ic < pot->v_effective.nc; ic++)
657+
{
658+
pot->v_effective(ir, ic) = ir + ic;
659+
pot->vofk_effective(ir, ic) = ir + 2 * ic;
660+
}
661+
}
661662

662663
pot->interpolate_vrs();
663664

0 commit comments

Comments
 (0)