Skip to content

Commit

Permalink
Refactor:Use PARAM instead of GlobalV::test* (#5065)
Browse files Browse the repository at this point in the history
* Delete global variable global_in_card in global_variable.cpp and global_variable.h
  • Loading branch information
A-006 authored Sep 10, 2024
1 parent 870f01e commit a476772
Show file tree
Hide file tree
Showing 87 changed files with 286 additions and 510 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ add_subdirectory(source)
target_link_libraries(
${ABACUS_BIN_NAME}
base
parameter
cell
symmetry
md
Expand All @@ -705,7 +706,6 @@ target_link_libraries(
psi_initializer
esolver
vdw
parameter
device
container)
if(ENABLE_LCAO)
Expand Down
42 changes: 0 additions & 42 deletions source/module_base/global_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,48 +104,6 @@ void DONE(std::ofstream &ofs, const std::string &description, const bool only_ra
return;
}

//==========================================================
// GLOBAL FUNCTION :
// NAME : TEST_LEVEL
// control the test_level
//==========================================================
void TEST_LEVEL(const std::string &name, bool disable=true)
{
if (disable) return;

if (name == "none")
{
GlobalV::test_wf = 0;
GlobalV::test_potential = 0;
GlobalV::test_charge = 0;
}
else if (name == "init_potential")
{
GlobalV::test_wf = 1;
GlobalV::test_potential = 1;
GlobalV::test_charge = 1;
}
else if (name == "init_read")
{
GlobalV::test_input = 1;
GlobalV::test_winput = 1;
GlobalV::test_kpoint = 1;
GlobalV::test_atom = 1;
GlobalV::test_unitcell = 1;
#ifndef __EPM
GlobalV::test_pseudo_cell = 1;
#else
test_epm_unitcell = 1;
#endif
}
else if (name == "pw_init")
{
GlobalV::test_pw = 1;
}

return;
}

bool SCAN_BEGIN(std::ifstream &ifs, const std::string &TargetName, const bool restart, const bool ifwarn)
{
std::string SearchName;
Expand Down
26 changes: 0 additions & 26 deletions source/module_base/global_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ std::string global_kpoint_card = "KPT";


// std::string global_pseudo_type = "auto";
std::string global_epm_pseudo_card;
std::string global_out_dir;
std::string global_readin_dir; // zhengdy modified
std::string global_stru_dir;
Expand All @@ -90,40 +89,15 @@ std::ofstream ofs_device; // output device info
//----------------------------------------------------------
// EXPLAIN : test level for each class
//----------------------------------------------------------
int test_input = 0;
int test_winput = 0;
int test_kpoint = 0;
int test_atom = 0;
int test_unitcell = 0;
int test_symmetry = 0;

int test_pw = 0;

int test_wf = 0;
int test_charge = 0;
int test_potential = 0;
int test_energy = 0;
//----------------------------------------------------------
// module_hamilt_lcao/hamilt_lcaodft
//----------------------------------------------------------
int test_atom_input = 0;
int test_grid = 0; // 4 now
int test_grid_driver = 0; // 4 now
int test_overlap = 0;
int TEST_FORCE = 0; // mohan add 2011-03-18
int TEST_STRESS = 0; // zhengdy add 2018-05-16
int test_gridt = 0; // mohan add 2011-03-17
//----------------------------------------------------------
// src_pseudo
//----------------------------------------------------------
int test_pseudo_cell = 0; // 2 : output readin data
int test_pp = 0; // pp: pseudopotential
int test_kmesh = 0;
int test_relax_method = 0;
//----------------------------------------------------------
// src_tools
//----------------------------------------------------------
int test_deconstructor = 0;

// added by zhengdy-soc
bool NONCOLIN = false;
Expand Down
24 changes: 0 additions & 24 deletions source/module_base/global_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,40 +128,16 @@ extern std::ofstream ofs_device;
//==========================================================
// EXPLAIN : test level for each class
//==========================================================
extern int test_input;
extern int test_winput;
extern int test_kpoint;
extern int test_atom;
extern int test_unitcell;
extern int test_symmetry;

extern int test_pw;

extern int test_wf;
extern int test_charge;
extern int test_potential;
extern int test_energy;
//==========================================================
// src_onscaling
//==========================================================
extern int test_atom_input;
extern int test_grid;
extern int test_grid_driver;
extern int test_overlap;
extern int TEST_FORCE; // mohan add 2011-03-18
extern int TEST_STRESS; // zhengdy add 2018-05-16
extern int test_gridt; // mohan add 2011-03-17
//==========================================================
// src_pseudo
//==========================================================
extern int test_pseudo_cell;
extern int test_pp;
extern int test_kmesh;
extern int test_relax_method;
//==========================================================
// src_tools
//==========================================================
extern int test_deconstructor;


extern bool deepks_out_labels; // (need libnpy) prints energy and force labels
Expand Down
2 changes: 1 addition & 1 deletion source/module_base/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ AddTest(
)
ADDTest(
TARGET base_global_function
LIBS ${math_libs}
LIBS ${math_libs} parameter
SOURCES global_function_test.cpp ../global_function.cpp ../tool_quit.cpp ../global_variable.cpp ../global_file.cpp ../memory.cpp ../timer.cpp
)
AddTest(
Expand Down
33 changes: 3 additions & 30 deletions source/module_base/test/global_function_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "../global_function.h"
#include "../global_variable.h"
#define private public
#include "module_parameter/parameter.h"
#undef private
#include "../vector3.h"
#include "../blas_connector.h"
#include "../tool_quit.h"
Expand Down Expand Up @@ -685,36 +688,6 @@ TEST_F(GlobalFunctionTest,MemAvailable)
}
}

TEST_F(GlobalFunctionTest,TEST_LEVEL)
{
std::string name;
bool test_bool=false;
name="none";
ModuleBase::GlobalFunc::TEST_LEVEL(name,test_bool);
EXPECT_EQ(GlobalV::test_wf,0);
EXPECT_EQ(GlobalV::test_potential,0);
EXPECT_EQ(GlobalV::test_charge,0);
name="init_potential";
ModuleBase::GlobalFunc::TEST_LEVEL(name,test_bool);
EXPECT_EQ(GlobalV::test_wf,1);
EXPECT_EQ(GlobalV::test_potential,1);
EXPECT_EQ(GlobalV::test_charge,1);
name="init_read";
ModuleBase::GlobalFunc::TEST_LEVEL(name,test_bool);
EXPECT_EQ(GlobalV::test_input,1);
EXPECT_EQ(GlobalV::test_winput,1);
EXPECT_EQ(GlobalV::test_kpoint,1);
EXPECT_EQ(GlobalV::test_atom,1);
EXPECT_EQ(GlobalV::test_unitcell,1);
#ifndef __EPM
EXPECT_EQ(GlobalV::test_pseudo_cell,1);
#else
EXPECT_EQ(test_epm_unitcell,1);
#endif
name="pw_init";
ModuleBase::GlobalFunc::TEST_LEVEL(name,test_bool);
EXPECT_EQ(GlobalV::test_pw,1);
}

TEST_F(GlobalFunctionTest,BlockHere)
{
Expand Down
2 changes: 1 addition & 1 deletion source/module_basis/module_ao/ORB_atomic.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ORB_atomic.h"

#include "module_parameter/parameter.h"
Numerical_Orbital_AtomRelation Numerical_Orbital::NOAR;

Numerical_Orbital::Numerical_Orbital()
Expand All @@ -25,7 +26,6 @@ void Numerical_Orbital::set_orbital_info(const int& type_in,
const int* nchi_in,
const int& total_nchi_in)
{
// what is GlobalV::test_overlap
ModuleBase::TITLE("Numerical_Orbital", "set_type_info");

// (1) set type,label,lmax
Expand Down
5 changes: 1 addition & 4 deletions source/module_cell/atom_spec.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "atom_spec.h"

#include "module_parameter/parameter.h"
#include <cstdlib>

Atom::Atom()
Expand Down Expand Up @@ -121,9 +121,6 @@ void Atom::print_Atom(std::ofstream& ofs)
#ifdef __MPI
void Atom::bcast_atom(void)
{
if (GlobalV::test_atom)
ModuleBase::TITLE("Atom", "bcast_atom");

Parallel_Common::bcast_int(type);
Parallel_Common::bcast_int(na);
Parallel_Common::bcast_int(nwl);
Expand Down
1 change: 0 additions & 1 deletion source/module_cell/atom_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Atom
// Coulomb potential v(r) = z/r
// It is a local potentail, and has no non-local potential parts.
bool coulomb_potential = false;

void print_Atom(std::ofstream &ofs);
void update_force(ModuleBase::matrix &fcs);
#ifdef __MPI
Expand Down
3 changes: 0 additions & 3 deletions source/module_cell/klist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,6 @@ double K_Vectors::Monkhorst_Pack_formula(const int& k_type, const double& offset
// add by dwan
void K_Vectors::Monkhorst_Pack(const int* nmp_in, const double* koffset_in, const int k_type)
{
if (GlobalV::test_kpoint) {
ModuleBase::TITLE("K_Vectors", "Monkhorst_Pack");
}
const int mpnx = nmp_in[0];
const int mpny = nmp_in[1];
const int mpnz = nmp_in[2];
Expand Down
5 changes: 3 additions & 2 deletions source/module_cell/module_neighbor/sltk_adjacent_set.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdexcept>
#include <string>
#include "module_parameter/parameter.h"
#include "sltk_adjacent_set.h"


Expand Down Expand Up @@ -91,7 +92,7 @@ void AdjacentSet::getBox
now = now - 3 * (y + 1);
z = now - 1;

// if (GlobalV::test_grid > 3) GlobalV::ofs_running << "\n value=" << value << " x=" << x << " y=" << y << " z=" << z;
// if (PARAM.inp.test_grid > 3) GlobalV::ofs_running << "\n value=" << value << " x=" << x << " y=" << y << " z=" << z;
}
else
{
Expand All @@ -113,7 +114,7 @@ void AdjacentSet::getBox
return;
}
//2015-05-07
void AdjacentSet::delete_vector(void)
void AdjacentSet::delete_vector()
{
std::vector<int>().swap(box);
std::vector<int>().swap(offset);
Expand Down
5 changes: 3 additions & 2 deletions source/module_cell/module_neighbor/sltk_atom_input.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sltk_atom_input.h"
#include "sltk_grid.h"
#include "module_parameter/parameter.h"
#include "module_base/memory.h"

//==========================================================
Expand Down Expand Up @@ -75,7 +76,7 @@ Atom_input::Atom_input
vec3[1] = ucell.latvec.e32;
vec3[2] = ucell.latvec.e33;

if(GlobalV::test_grid)
if(PARAM.inp.test_grid)
{
ofs_in << " Output lattice vectors now (unit:lat0):" << std::endl;
ofs_in << " " << std::setw(5) << "Vec1"
Expand Down Expand Up @@ -173,7 +174,7 @@ Atom_input::Atom_input
this->Expand_Grid(ucell, ntype);
}

if(GlobalV::test_grid) ModuleBase::GlobalFunc::OUT(ofs_in, "expand_flag", expand_flag);
if(PARAM.inp.test_grid) ModuleBase::GlobalFunc::OUT(ofs_in, "expand_flag", expand_flag);

//----------------------------------------------------------
// CALL MEMBER FUNCTION :
Expand Down
2 changes: 2 additions & 0 deletions source/module_cell/module_neighbor/sltk_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Grid
public:

// Constructors and destructor
// Grid is Global class,so init it with constant number
Grid():test_grid(0){};
Grid(const int &test_grid_in);
virtual ~Grid();

Expand Down
Loading

0 comments on commit a476772

Please sign in to comment.