Skip to content

Commit 2169cdd

Browse files
committed
Test: Update Unit Tests.
1 parent 747011e commit 2169cdd

File tree

7 files changed

+24
-21
lines changed

7 files changed

+24
-21
lines changed

source/module_cell/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ list(APPEND cell_simple_srcs
2626
../read_pp_blps.cpp
2727
../check_atomic_stru.cpp
2828
../../module_elecstate/read_pseudo.cpp
29+
../../module_elecstate/cal_nelec_nband.cpp
2930
)
3031

3132
add_library(cell_info OBJECT ${cell_simple_srcs})

source/module_cell/test/unitcell_test_readpp.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Magnetism::~Magnetism() { delete[] this->start_magnetization; }
9090
* possible of an element
9191
* - CalNelec: UnitCell::cal_nelec
9292
* - calculate the total number of valence electrons from psp files
93-
* - CalNbands: elecstate::ElecState::cal_nbands()
93+
* - CalNbands: elecstate::cal_nbands()
9494
* - calculate the number of bands
9595
*/
9696

@@ -406,22 +406,22 @@ TEST_F(UcellTest, CalNelec) {
406406
EXPECT_EQ(1, ucell->atoms[0].na);
407407
EXPECT_EQ(2, ucell->atoms[1].na);
408408
double nelec = 0;
409-
cal_nelec(ucell->atoms, ucell->ntype, nelec);
409+
elecstate::cal_nelec(ucell->atoms, ucell->ntype, nelec);
410410
EXPECT_DOUBLE_EQ(6, nelec);
411411
}
412412

413413
TEST_F(UcellTest, CalNbands)
414414
{
415415
std::vector<double> nelec_spin(2, 5.0);
416-
cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
416+
elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
417417
EXPECT_EQ(PARAM.input.nbands, 6);
418418
}
419419

420420
TEST_F(UcellTest, CalNbandsFractionElec)
421421
{
422422
PARAM.input.nelec = 9.5;
423423
std::vector<double> nelec_spin(2, 5.0);
424-
cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
424+
elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
425425
EXPECT_EQ(PARAM.input.nbands, 6);
426426
}
427427

@@ -430,22 +430,22 @@ TEST_F(UcellTest, CalNbandsSOC)
430430
PARAM.input.lspinorb = true;
431431
PARAM.input.nbands = 0;
432432
std::vector<double> nelec_spin(2, 5.0);
433-
cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
433+
elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
434434
EXPECT_EQ(PARAM.input.nbands, 20);
435435
}
436436

437437
TEST_F(UcellTest, CalNbandsSDFT)
438438
{
439439
PARAM.input.esolver_type = "sdft";
440440
std::vector<double> nelec_spin(2, 5.0);
441-
EXPECT_NO_THROW(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands));
441+
EXPECT_NO_THROW(elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands));
442442
}
443443

444444
TEST_F(UcellTest, CalNbandsLCAO)
445445
{
446446
PARAM.input.basis_type = "lcao";
447447
std::vector<double> nelec_spin(2, 5.0);
448-
EXPECT_NO_THROW(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands));
448+
EXPECT_NO_THROW(elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands));
449449
}
450450

451451
TEST_F(UcellTest, CalNbandsLCAOINPW)
@@ -454,7 +454,7 @@ TEST_F(UcellTest, CalNbandsLCAOINPW)
454454
PARAM.sys.nlocal = PARAM.input.nbands - 1;
455455
std::vector<double> nelec_spin(2, 5.0);
456456
testing::internal::CaptureStdout();
457-
EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
457+
EXPECT_EXIT(elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
458458
output = testing::internal::GetCapturedStdout();
459459
EXPECT_THAT(output, testing::HasSubstr("NLOCAL < NBANDS"));
460460
}
@@ -464,7 +464,7 @@ TEST_F(UcellTest, CalNbandsWarning1)
464464
PARAM.input.nbands = PARAM.input.nelec / 2 - 1;
465465
std::vector<double> nelec_spin(2, 5.0);
466466
testing::internal::CaptureStdout();
467-
EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
467+
EXPECT_EXIT(elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
468468
output = testing::internal::GetCapturedStdout();
469469
EXPECT_THAT(output, testing::HasSubstr("Too few bands!"));
470470
}
@@ -477,7 +477,7 @@ TEST_F(UcellTest, CalNbandsWarning2)
477477
nelec_spin[0] = (PARAM.input.nelec + PARAM.input.nupdown ) / 2.0;
478478
nelec_spin[1] = (PARAM.input.nelec - PARAM.input.nupdown ) / 2.0;
479479
testing::internal::CaptureStdout();
480-
EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
480+
EXPECT_EXIT(elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
481481
output = testing::internal::GetCapturedStdout();
482482
EXPECT_THAT(output, testing::HasSubstr("Too few spin up bands!"));
483483
}
@@ -490,7 +490,7 @@ TEST_F(UcellTest, CalNbandsWarning3)
490490
nelec_spin[0] = (PARAM.input.nelec + PARAM.input.nupdown ) / 2.0;
491491
nelec_spin[1] = (PARAM.input.nelec - PARAM.input.nupdown ) / 2.0;
492492
testing::internal::CaptureStdout();
493-
EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
493+
EXPECT_EXIT(elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
494494
output = testing::internal::GetCapturedStdout();
495495
EXPECT_THAT(output, testing::HasSubstr("Too few spin down bands!"));
496496
}
@@ -500,7 +500,7 @@ TEST_F(UcellTest, CalNbandsSpin1)
500500
PARAM.input.nspin = 1;
501501
PARAM.input.nbands = 0;
502502
std::vector<double> nelec_spin(2, 5.0);
503-
cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
503+
elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
504504
EXPECT_EQ(PARAM.input.nbands, 15);
505505
}
506506

@@ -510,7 +510,7 @@ TEST_F(UcellTest, CalNbandsSpin1LCAO)
510510
PARAM.input.nbands = 0;
511511
PARAM.input.basis_type = "lcao";
512512
std::vector<double> nelec_spin(2, 5.0);
513-
cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
513+
elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
514514
EXPECT_EQ(PARAM.input.nbands, 6);
515515
}
516516

@@ -519,7 +519,7 @@ TEST_F(UcellTest, CalNbandsSpin4)
519519
PARAM.input.nspin = 4;
520520
PARAM.input.nbands = 0;
521521
std::vector<double> nelec_spin(2, 5.0);
522-
cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
522+
elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
523523
EXPECT_EQ(PARAM.input.nbands, 30);
524524
}
525525

@@ -529,7 +529,7 @@ TEST_F(UcellTest, CalNbandsSpin4LCAO)
529529
PARAM.input.nbands = 0;
530530
PARAM.input.basis_type = "lcao";
531531
std::vector<double> nelec_spin(2, 5.0);
532-
cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
532+
elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
533533
EXPECT_EQ(PARAM.input.nbands, 6);
534534
}
535535

@@ -538,7 +538,7 @@ TEST_F(UcellTest, CalNbandsSpin2)
538538
PARAM.input.nspin = 2;
539539
PARAM.input.nbands = 0;
540540
std::vector<double> nelec_spin(2, 5.0);
541-
cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
541+
elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
542542
EXPECT_EQ(PARAM.input.nbands, 16);
543543
}
544544

@@ -548,7 +548,7 @@ TEST_F(UcellTest, CalNbandsSpin2LCAO)
548548
PARAM.input.nbands = 0;
549549
PARAM.input.basis_type = "lcao";
550550
std::vector<double> nelec_spin(2, 5.0);
551-
cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
551+
elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands);
552552
EXPECT_EQ(PARAM.input.nbands, 6);
553553
}
554554

@@ -558,7 +558,7 @@ TEST_F(UcellTest, CalNbandsGaussWarning)
558558
std::vector<double> nelec_spin(2, 5.0);
559559
PARAM.input.smearing_method = "gaussian";
560560
testing::internal::CaptureStdout();
561-
EXPECT_EXIT(cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
561+
EXPECT_EXIT(elecstate::cal_nbands(PARAM.input.nelec, PARAM.sys.nlocal, nelec_spin, PARAM.input.nbands), ::testing::ExitedWithCode(1), "");
562562
output = testing::internal::GetCapturedStdout();
563563
EXPECT_THAT(output, testing::HasSubstr("for smearing, num. of bands > num. of occupied bands"));
564564
}

source/module_cell/test_pw/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ AddTest(
1313
LIBS parameter ${math_libs} base device
1414
SOURCES unitcell_test_pw.cpp ../unitcell.cpp ../read_atoms.cpp ../atom_spec.cpp
1515
../atom_pseudo.cpp ../pseudo.cpp ../read_pp.cpp ../read_pp_complete.cpp ../read_pp_upf201.cpp ../read_pp_upf100.cpp
16-
../read_pp_vwr.cpp ../read_pp_blps.cpp ../../module_io/output.cpp ../../module_elecstate/read_pseudo.cpp
16+
../read_pp_vwr.cpp ../read_pp_blps.cpp ../../module_io/output.cpp ../../module_elecstate/read_pseudo.cpp ../../module_elecstate/cal_nelec_nband.cpp
1717
)
1818

1919
find_program(BASH bash)

source/module_elecstate/read_pseudo.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "module_parameter/parameter.h"
33
#include "module_base/global_file.h"
44
#include "module_cell/read_pp.h"
5-
#include "module_cell/cal_atoms_info.h"
65
#include "module_base/element_elec_config.h"
76
#include "module_base/parallel_common.h"
87

source/module_elecstate/read_pseudo.h

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define READ_PSEUDO_H
33

44
#include "module_cell/unitcell.h"
5+
#include "module_cell/cal_atoms_info.h"
56

67
namespace elecstate {
78

source/module_hamilt_lcao/module_deepks/test/Makefile.Objects

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@ sltk_atom_input.o\
7474
sltk_grid.o\
7575
sltk_grid_driver.o
7676

77-
OBJS_ELECSTATE=read_pseudo.o\
77+
OBJS_ELECSTATE=read_pseudo.o\
78+
cal_nelec_nband.o\

source/module_md/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ list(APPEND depend_files
4747
../../module_base/parallel_global.cpp
4848
../../module_base/parallel_comm.cpp
4949
../../module_elecstate/read_pseudo.cpp
50+
../../module_elecstate/cal_nelec_nband.cpp
5051
)
5152

5253
AddTest(

0 commit comments

Comments
 (0)