Skip to content

Commit 3ead988

Browse files
committed
Refactor: Remove the GlobalC from sep_cell and vsep_cell
* Removed GlobalC::sep_cell and GlobalC::vsep_cell from GlobalC * Integrated sep_cell into UnitCell * Integrated vsep_cell into esolver_ks_pw * Added empty constructors and destructors for Sep_Pot and Sep_Cell to facilitate unit testing compilation
1 parent 94cebd0 commit 3ead988

File tree

38 files changed

+277
-149
lines changed

38 files changed

+277
-149
lines changed

source/source_cell/module_symmetry/test/symmetry_test_analysis.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
* 1-1. test if the bravis lattice analysis is right;
77
* 1-2. check if matrix-type and vector3-type;
88
* input and optimized lattice vectors are right;
9-
* 1-3. double-check for if `gtrans_convert`
9+
* 1-3. double-check for if `gtrans_convert`
1010
* gives the same results as `veccon`;
1111
* 1-4. check `invmap` function gives the right result;
1212
* 1-5 test if `gmatrix_convert` and `gmatrix_convert_int`
1313
* gives the right result;
1414
* 2. function: `atom_ordering_new:
1515
* test the new atom-sort algorithm gives the right result;
1616
*3. function: `pricell`:
17-
* test if the number of primitive cells are right,
17+
* test if the number of primitive cells are right,
1818
* using cases whose space group
1919
* is different from its point group.
2020
***********************************************/
@@ -34,6 +34,10 @@ UnitCell::UnitCell(){}
3434
UnitCell::~UnitCell(){}
3535
Magnetism::Magnetism(){}
3636
Magnetism::~Magnetism() {}
37+
SepPot::SepPot(){}
38+
SepPot::~SepPot(){}
39+
Sep_Cell::Sep_Cell() noexcept {}
40+
Sep_Cell::~Sep_Cell() noexcept {}
3741

3842
TEST_F(SymmetryTest, AnalySys)
3943
{
@@ -50,8 +54,8 @@ TEST_F(SymmetryTest, AnalySys)
5054
int cal_ibrav = symm.real_brav;
5155
EXPECT_EQ(cal_ibrav, ref_ibrav);
5256
EXPECT_EQ(cal_point_group, ref_point_group) << "ibrav=" << stru_lib[stru].ibrav;
53-
54-
//2. input and optimized lattice, gtrans_convert and veccon
57+
58+
//2. input and optimized lattice, gtrans_convert and veccon
5559
//input lattice
5660
EXPECT_EQ(symm.s1, ucell.a1);
5761
EXPECT_EQ(symm.s2, ucell.a2);
@@ -73,7 +77,7 @@ TEST_F(SymmetryTest, AnalySys)
7377
symm.gtrans_convert(symm.gtrans, gtrans_optconf.data(), symm.nrotk, ucell.latvec, symm.optlat);
7478
symm.veccon(gtrans_veccon, gtrans_optconf_veccon, symm.nrotk, symm.s1, symm.s2, symm.s3, symm.a1, symm.a2, symm.a3);
7579
for(int i=0;i<symm.nrotk;++i)
76-
EXPECT_EQ(gtrans_optconf[i], ModuleBase::Vector3<double>(gtrans_optconf_veccon[i*3],
80+
EXPECT_EQ(gtrans_optconf[i], ModuleBase::Vector3<double>(gtrans_optconf_veccon[i*3],
7781
gtrans_optconf_veccon[i*3+1], gtrans_optconf_veccon[i*3+2]));
7882
delete[] gtrans_veccon;
7983
delete[] gtrans_optconf_veccon;
@@ -108,7 +112,7 @@ TEST_F(SymmetryTest, AnalySys)
108112
symm.gmatrix_convert_int(symm.gmatrix, gmatrix_opt, symm.nrotk, ucell.latvec, symm.optlat); //1->2
109113
symm.gmatrix_convert_int(gmatrix_opt, gmatrix_input_back, symm.nrotk, symm.optlat, ucell.latvec); //2->3
110114
symm.gmatrix_convert_int(gmatrix_input_back, gmatrix_opt_back, symm.nrotk, ucell.latvec, symm.optlat); //3->4
111-
115+
112116
symm.gmatrix_convert(symm.gmatrix, kgmatrix_nonint, symm.nrotk, ucell.latvec, ucell.G);
113117
for (int i=0;i<symm.nrotk;++i)
114118
{
@@ -130,7 +134,7 @@ TEST_F(SymmetryTest, AnalySys)
130134
EXPECT_NEAR(gmatrix_opt[i].e31, gmatrix_opt_back[i].e31, DOUBLETHRESHOLD);
131135
EXPECT_NEAR(gmatrix_opt[i].e23, gmatrix_opt_back[i].e23, DOUBLETHRESHOLD);
132136
EXPECT_NEAR(gmatrix_opt[i].e32, gmatrix_opt_back[i].e32, DOUBLETHRESHOLD);
133-
137+
134138
ModuleBase::Matrix3 tmpA=symm.optlat.Inverse()*gmatrix_opt[i]*symm.optlat; //A^-1*SA*A
135139
ModuleBase::Matrix3 tmpB=ucell.latvec.Inverse()*symm.gmatrix[i]*ucell.latvec;//B^-1*SB*B
136140
ModuleBase::Matrix3 tmpG_int=ucell.G.Inverse()*symm.kgmatrix[i]*ucell.G;//G^-1*SG*G
@@ -168,7 +172,7 @@ TEST_F(SymmetryTest, AnalySys)
168172
EXPECT_NEAR(tmpA.e23, tmpG.e23, DOUBLETHRESHOLD);
169173
EXPECT_NEAR(tmpA.e32, tmpG.e32, DOUBLETHRESHOLD);
170174
}
171-
175+
172176
delete[] gmatrix_input_back;
173177
delete[] gmatrix_opt;
174178
delete[] gmatrix_opt_back;
@@ -180,7 +184,7 @@ TEST_F(SymmetryTest, AnalySys)
180184

181185
TEST_F(SymmetryTest, AtomOrderingNew)
182186
{
183-
// the old function `atom_ordering` has bugs
187+
// the old function `atom_ordering` has bugs
184188
// so here I do not compare with its results
185189
ModuleSymmetry::Symmetry symm;
186190
symm.epsilon=1e-5;
@@ -199,7 +203,7 @@ TEST_F(SymmetryTest, AtomOrderingNew)
199203
}
200204
//ordering
201205
symm.test_atom_ordering(new_pos, nat, subindex);
202-
//check
206+
//check
203207
for (int i=0;i<nat-1;++i)
204208
{
205209
//x[i]<=x[i+1]
@@ -250,7 +254,7 @@ TEST_F(SymmetryTest, SG_Pricell)
250254
std::string cal_point_group = symm.pgname;
251255
std::string ref_space_group = supercell_lib[stru].space_group;
252256
std::string cal_space_group = symm.spgname;
253-
257+
254258
int ref_ncells = supercell_lib[stru].ibrav;
255259
EXPECT_EQ(symm.ncell, ref_ncells);
256260
EXPECT_EQ(cal_point_group, ref_point_group);

source/source_cell/module_symmetry/test/symmetry_test_symtrz.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ UnitCell::UnitCell() {}
1919
UnitCell::~UnitCell() {}
2020
Magnetism::Magnetism() {}
2121
Magnetism::~Magnetism() {}
22+
SepPot::SepPot(){}
23+
SepPot::~SepPot(){}
24+
Sep_Cell::Sep_Cell() noexcept {}
25+
Sep_Cell::~Sep_Cell() noexcept {}
2226

2327
inline std::vector<double> allocate_pos(ModuleSymmetry::Symmetry& symm, UnitCell& ucell)
2428
{
@@ -46,7 +50,7 @@ TEST_F(SymmetryTest, ForceSymmetry)
4650
{
4751
auto check_force = [](stru_& conf, ModuleBase::matrix& force)
4852
{
49-
// 1. check zeros
53+
// 1. check zeros
5054
for (auto iat : conf.force_zero_iat)
5155
for (int j = 0; j < 3; ++j)
5256
EXPECT_NEAR(force(iat, j), 0.0, DOUBLETHRESHOLD);

source/source_cell/sep_cell.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
#include "source_base/global_variable.h"
55
#include "source_base/parallel_common.h"
66
#include "source_base/tool_title.h"
7-
#include "source_cell/unitcell.h"
87

98
#include <algorithm>
109
#include <string>
10+
#include <vector>
1111

12-
namespace GlobalC
13-
{
14-
Sep_Cell sep_cell;
15-
}
12+
// namespace GlobalC
13+
// {
14+
// Sep_Cell sep_cell;
15+
// }
1616

1717
Sep_Cell::Sep_Cell() noexcept : ntype(0), omega(0.0), tpiba2(0.0)
1818
{
@@ -48,7 +48,7 @@ void Sep_Cell::set_omega(const double omega_in, const double tpiba2_in)
4848
int Sep_Cell::read_sep_potentials(std::ifstream& ifpos,
4949
const std::string& pp_dir,
5050
std::ofstream& ofs_running,
51-
UnitCell& ucell)
51+
std::vector<std::string>& ucell_atom_label)
5252
{
5353
ModuleBase::TITLE("Sep_Cell", "read_sep_potentials");
5454

@@ -71,10 +71,10 @@ int Sep_Cell::read_sep_potentials(std::ifstream& ifpos,
7171
ss >> atom_label >> enable_tmp;
7272

7373
// Validate atom label
74-
if (atom_label != ucell.atom_label[i])
74+
if (atom_label != ucell_atom_label[i])
7575
{
7676
GlobalV::ofs_running << "Sep potential and atom order do not match. "
77-
<< "Expected: " << ucell.atoms[i].label << ", Got: " << atom_label << std::endl;
77+
<< "Expected: " << ucell_atom_label[i] << ", Got: " << atom_label << std::endl;
7878
return false;
7979
}
8080
this->sep_enable[i] = enable_tmp;

source/source_cell/sep_cell.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#define SEP_CELL
55

66
#include "source_cell/sep.h"
7-
#include "source_cell/unitcell.h"
87

98
#include <fstream>
9+
#include <string>
1010
#include <vector>
1111

1212
class Sep_Cell
@@ -25,7 +25,7 @@ class Sep_Cell
2525
int read_sep_potentials(std::ifstream& ifpos,
2626
const std::string& pp_dir,
2727
std::ofstream& ofs_running,
28-
UnitCell& ucell);
28+
std::vector<std::string>& ucell_atom_label);
2929

3030
#ifdef __MPI
3131
// Broadcasts the Sep_Cell object to all processes
@@ -66,9 +66,9 @@ class Sep_Cell
6666
double tpiba2; // tpiba ^ 2
6767
};
6868

69-
namespace GlobalC
70-
{
71-
extern Sep_Cell sep_cell;
72-
}
69+
// namespace GlobalC
70+
// {
71+
// extern Sep_Cell sep_cell;
72+
// }
7373

7474
#endif // SEP_CEll

source/source_cell/test/klist_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ Soc::~Soc()
8383
Fcoef::~Fcoef()
8484
{
8585
}
86+
SepPot::SepPot(){}
87+
SepPot::~SepPot(){}
88+
Sep_Cell::Sep_Cell() noexcept {}
89+
Sep_Cell::~Sep_Cell() noexcept {}
8690

8791

8892
/************************************************

source/source_cell/test/klist_test_para.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ Soc::~Soc()
8686
Fcoef::~Fcoef()
8787
{
8888
}
89+
SepPot::SepPot(){}
90+
SepPot::~SepPot(){}
91+
Sep_Cell::Sep_Cell() noexcept {}
92+
Sep_Cell::~Sep_Cell() noexcept {}
8993

9094

9195
/************************************************

source/source_cell/test/sepcell_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ TEST_F(SepCellTest, ReadSepPotentialsSuccess)
134134

135135
sep_cell.init(ucell.ntype);
136136
std::ofstream ofs_running_dummy("dummy_ofs_running.tmp");
137-
int result = sep_cell.read_sep_potentials(ifs, pp_dir, ofs_running_dummy, ucell);
137+
int result = sep_cell.read_sep_potentials(ifs, pp_dir, ofs_running_dummy, ucell.atom_label);
138138
ifs.close();
139139
std::remove("dummy_ofs_running.tmp");
140140

@@ -153,8 +153,8 @@ TEST_F(SepCellTest, ReadSepPotentialsSuccess)
153153
EXPECT_EQ(seps[0].label, ""); // Default value
154154

155155
EXPECT_TRUE(seps[1].is_enable); // Default value
156-
EXPECT_EQ(seps[1].mesh, 1038); // Default value
157-
EXPECT_EQ(seps[1].label, "F"); // Default value
156+
EXPECT_EQ(seps[1].mesh, 1038); // Default value
157+
EXPECT_EQ(seps[1].label, "F"); // Default value
158158
EXPECT_DOUBLE_EQ(seps[1].r_in, 0.0);
159159
EXPECT_DOUBLE_EQ(seps[1].r_out, 2.5);
160160
EXPECT_DOUBLE_EQ(seps[1].r_power, 20.0);
@@ -179,7 +179,7 @@ TEST_F(SepCellTest, ReadSepPotentialsNoSepFilesSection)
179179
std::ofstream ofs_running_dummy("dummy_ofs_running.tmp");
180180

181181
sep_cell.init(ucell.ntype);
182-
int result = sep_cell.read_sep_potentials(ifs, pp_dir, ofs_running_dummy, ucell);
182+
int result = sep_cell.read_sep_potentials(ifs, pp_dir, ofs_running_dummy, ucell.atom_label);
183183
ifs.close();
184184
std::remove("dummy_ofs_running.tmp");
185185

@@ -202,7 +202,7 @@ TEST_F(SepCellTest, BcastSepCell)
202202

203203
sep_cell.init(ucell.ntype);
204204
std::ofstream ofs_running_dummy("dummy_ofs_running.tmp");
205-
int result = sep_cell.read_sep_potentials(ifs, pp_dir, ofs_running_dummy, ucell);
205+
int result = sep_cell.read_sep_potentials(ifs, pp_dir, ofs_running_dummy, ucell.atom_label);
206206
ifs.close();
207207
std::remove("dummy_ofs_running.tmp");
208208

@@ -258,7 +258,7 @@ TEST_F(SepCellTest, BcastSepCell)
258258
EXPECT_DOUBLE_EQ(seps[1].r[0], 3.4643182373e-06);
259259
EXPECT_DOUBLE_EQ(seps[1].rv[0], -2.0868200000e-05);
260260
EXPECT_DOUBLE_EQ(seps[1].r[7], 2.8965849122e-05);
261-
EXPECT_DOUBLE_EQ(seps[1].rv[7], -1.9723800000e-05);
261+
EXPECT_DOUBLE_EQ(seps[1].rv[7], -1.9723800000e-05);
262262
}
263263
#endif // __MPI
264264

source/source_cell/test/support/mock_unitcell.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ UnitCell::~UnitCell() {
1717
delete[] atoms;
1818
}
1919
}
20+
SepPot::SepPot(){}
21+
SepPot::~SepPot(){}
22+
Sep_Cell::Sep_Cell() noexcept {}
23+
Sep_Cell::~Sep_Cell() noexcept {}
2024

2125
void UnitCell::print_cell(std::ofstream& ofs) const {}
2226

source/source_cell/unitcell.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,11 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log)
252252
// readl sep potential, currently using the pseudopotential folder (pseudo_dir in INPUT)
253253
//==========================
254254
if (PARAM.inp.dfthalf_type > 0) {
255-
GlobalC::sep_cell.init(this->ntype);
256-
ok3 = GlobalC::sep_cell.read_sep_potentials(ifa, PARAM.inp.pseudo_dir, GlobalV::ofs_warning, *this);
255+
// GlobalC::sep_cell.init(this->ntype);
256+
// ok3 = GlobalC::sep_cell.read_sep_potentials(ifa, PARAM.inp.pseudo_dir, GlobalV::ofs_warning, this->atom_label);
257+
258+
sep_cell.init(this->ntype);
259+
ok3 = sep_cell.read_sep_potentials(ifa, PARAM.inp.pseudo_dir, GlobalV::ofs_warning, this->atom_label);
257260
}
258261
//==========================
259262
// call read_atom_positions
@@ -281,7 +284,8 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log)
281284

282285
#ifdef __MPI
283286
unitcell::bcast_unitcell(*this);
284-
GlobalC::sep_cell.bcast_sep_cell();
287+
// GlobalC::sep_cell.bcast_sep_cell();
288+
sep_cell.bcast_sep_cell();
285289
#endif
286290

287291
//========================================================
@@ -345,7 +349,8 @@ void UnitCell::setup_cell(const std::string& fn, std::ofstream& log)
345349
//===================================
346350
this->set_iat2itia();
347351

348-
GlobalC::sep_cell.set_omega(this->omega, this->tpiba2);
352+
// GlobalC::sep_cell.set_omega(this->omega, this->tpiba2);
353+
sep_cell.set_omega(this->omega, this->tpiba2);
349354

350355
return;
351356
}

source/source_cell/unitcell.h

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

44
#include "source_base/global_function.h"
55
#include "source_base/global_variable.h"
6+
#include "source_cell/sep_cell.h"
67
#include "source_estate/magnetism.h"
78
#include "source_io/output.h"
89
#include "module_symmetry/symmetry.h"
@@ -16,6 +17,7 @@
1617
class UnitCell {
1718
public:
1819
Atom* atoms = nullptr;
20+
Sep_Cell sep_cell;
1921

2022
bool set_atom_flag = false; // added on 2009-3-8 by mohan
2123
Magnetism magnet; // magnetism Yu Liu 2021-07-03

0 commit comments

Comments
 (0)