Skip to content

Commit

Permalink
Merge branch 'develop' into elf
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanchen committed Sep 23, 2024
2 parents 53c1794 + acb792d commit aab3182
Show file tree
Hide file tree
Showing 103 changed files with 716 additions and 636 deletions.
26 changes: 0 additions & 26 deletions source/module_base/global_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,30 +274,4 @@ void ModuleBase::Global_File::close_all_log(const int rank, const bool out_alllo
#endif
return;
}

void ModuleBase::Global_File::delete_tmp_files()
{
if (GlobalV::MY_RANK == 0)
{
for (int is = 0; is < PARAM.inp.nspin; ++is)
{
std::string tmp_chg_1 = PARAM.globalv.global_out_dir + "NOW_SPIN" + std::to_string(is + 1) + "_CHG.cube";
std::string tmp_chg_2 = PARAM.globalv.global_out_dir + "OLD1_SPIN" + std::to_string(is + 1) + "_CHG.cube";
std::string tmp_chg_3 = PARAM.globalv.global_out_dir + "OLD2_SPIN" + std::to_string(is + 1) + "_CHG.cube";

if (access(tmp_chg_1.c_str(), 0) == 0)
{
std::remove(tmp_chg_1.c_str());
}
if (access(tmp_chg_2.c_str(), 0) == 0)
{
std::remove(tmp_chg_2.c_str());
}
if (access(tmp_chg_3.c_str(), 0) == 0)
{
std::remove(tmp_chg_3.c_str());
}
}
}
}
}
8 changes: 1 addition & 7 deletions source/module_base/global_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ namespace Global_File
void make_dir_atom(const std::string &label);
void open_log ( std::ofstream &ofs, const std::string &fn, const std::string &calculation, const bool &restart);
void close_log( std::ofstream &ofs, const std::string &fn);
void close_all_log(const int rank, const bool out_alllog = false,const std::string &calculation = "md");

/**
* @brief delete tmperary files
*
*/
void delete_tmp_files();
void close_all_log(const int rank, const bool out_alllog = false, const std::string& calculation = "md");
}
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions source/module_base/global_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ T ddot_real(const int& dim, const std::complex<T>* psi_L, const std::complex<T>*
// NAME : IS_COLUMN_MAJOR_KS_SOLVER
// check ks_solver requires column major or not
//==========================================================
static inline bool IS_COLUMN_MAJOR_KS_SOLVER()
static inline bool IS_COLUMN_MAJOR_KS_SOLVER(std::string ks_solver)
{
return GlobalV::KS_SOLVER == "genelpa" || GlobalV::KS_SOLVER == "elpa" || GlobalV::KS_SOLVER == "scalapack_gvx" || GlobalV::KS_SOLVER == "cusolver"
|| GlobalV::KS_SOLVER == "cusolvermp" || GlobalV::KS_SOLVER == "cg_in_lcao" || GlobalV::KS_SOLVER == "pexsi" || GlobalV::KS_SOLVER == "lapack";
return ks_solver == "genelpa" || ks_solver == "elpa" || ks_solver == "scalapack_gvx" || ks_solver == "cusolver"
|| ks_solver == "cusolvermp" || ks_solver == "cg_in_lcao" || ks_solver == "pexsi" || ks_solver == "lapack";
}

} // namespace GlobalFunc
Expand Down
6 changes: 3 additions & 3 deletions source/module_base/sph_bessel_recursive.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define SPH_BESSEL_RECURSIVE_H

#include <vector>
#include"stddef.h"
#include<cstddef>

namespace ModuleBase
{
Expand All @@ -32,7 +32,7 @@ class Sph_Bessel_Recursive::D1

private:
std::vector<std::vector<double>> jlx; // jlx[l][x]
double dx;
double dx = 0.0;
bool finish_set_dx = false;

void cal_jlx_0( const int l_size );
Expand All @@ -56,7 +56,7 @@ class Sph_Bessel_Recursive::D2

private:
std::vector<std::vector<std::vector<double>>> jlx; // jlx[l][x1][x2]
double dx;
double dx = 0.0;
bool finish_set_dx = false;

void cal_jlx_0( const int l_size, const size_t ix1_size, const size_t ix2_size );
Expand Down
22 changes: 0 additions & 22 deletions source/module_base/test/global_file_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,4 @@ TEST_F(GlobalFile,closealllog)
}
remove("running.log");
remove("warning.log");
}

TEST_F(GlobalFile, DeleteTmpFiles)
{

std::string tmp_chg_1 = PARAM.sys.global_out_dir + "NOW_SPIN1_CHG.cube";
std::string tmp_chg_2 = PARAM.sys.global_out_dir + "OLD1_SPIN1_CHG.cube";
std::string tmp_chg_3 = PARAM.sys.global_out_dir + "OLD2_SPIN1_CHG.cube";
std::ofstream ofs1(tmp_chg_1.c_str());
std::ofstream ofs2(tmp_chg_2.c_str());
std::ofstream ofs3(tmp_chg_3.c_str());
ofs1.close();
ofs2.close();
ofs3.close();
EXPECT_TRUE(access(tmp_chg_1.c_str(), 0) == 0);
EXPECT_TRUE(access(tmp_chg_2.c_str(), 0) == 0);
EXPECT_TRUE(access(tmp_chg_3.c_str(), 0) == 0);

ModuleBase::Global_File::delete_tmp_files();
EXPECT_TRUE(access(tmp_chg_1.c_str(), 0) == -1);
EXPECT_TRUE(access(tmp_chg_2.c_str(), 0) == -1);
EXPECT_TRUE(access(tmp_chg_3.c_str(), 0) == -1);
}
15 changes: 8 additions & 7 deletions source/module_base/test/global_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <time.h>
#include <ctime>

/************************************************
* unit test of functions in global_function
Expand Down Expand Up @@ -57,7 +57,7 @@
* - print out warning info in running.log file
* - COPYARRAY
* - copy complex or double arrays
* - IS_COLUMN_MAJOR_KS_SOLVER()
* - IS_COLUMN_MAJOR_KS_SOLVER(PARAM.input.ks_solver)
* - judge whether the KS_SOLVER is column major
* - VECTOR_TO_PTR
* - get a copy of the ptr of a vector
Expand Down Expand Up @@ -300,7 +300,8 @@ TEST_F(GlobalFunctionTest, OutV2)
{
tmp_para += "a";
length = tmp_para.size()+1;
if (length == 32) EXPECT_THAT(str, testing::HasSubstr(tmp_para));
if (length == 32) { EXPECT_THAT(str, testing::HasSubstr(tmp_para));
}
}
ifs.close();
}
Expand Down Expand Up @@ -430,8 +431,8 @@ TEST_F(GlobalFunctionTest, MakeDir)
TEST_F(GlobalFunctionTest, OutTime)
{
std::string name = "scf";
start = time(NULL);
end = time(NULL) + 200;
start = time(nullptr);
end = time(nullptr) + 200;
ModuleBase::GlobalFunc::OUT_TIME(name, start, end);
GlobalV::ofs_warning.close();
ifs.open("warning.log");
Expand Down Expand Up @@ -654,8 +655,8 @@ TEST_F(GlobalFunctionTest, COPYARRAY)

TEST_F(GlobalFunctionTest,IsColumnMajor)
{
GlobalV::KS_SOLVER = "genelpa";
EXPECT_TRUE(ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER());
PARAM.input.ks_solver = "genelpa";
EXPECT_TRUE(ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.input.ks_solver));
}

TEST_F(GlobalFunctionTest,Vector2Ptr)
Expand Down
75 changes: 75 additions & 0 deletions source/module_cell/cal_atoms_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef CAL_ATOMS_INFO_H
#define CAL_ATOMS_INFO_H
#include "module_parameter/parameter.h"
#include "unitcell.h"
class CalAtomsInfo
{
public:
CalAtomsInfo(){};
~CalAtomsInfo(){};

/**
* @brief Calculate the atom information from pseudopotential to set Parameter
*
* @param atoms [in] Atom pointer
* @param ntype [in] number of atom types
* @param para [out] Parameter object
*/
void cal_atoms_info(const Atom* atoms, const int& ntype, Parameter& para)
{
// calculate initial total magnetization when NSPIN=2
if (para.inp.nspin == 2 && !para.globalv.two_fermi)
{
for (int it = 0; it < ntype; ++it)
{
for (int ia = 0; ia < atoms[it].na; ++ia)
{
GlobalV::nupdown += atoms[it].mag[ia];
}
}
GlobalV::ofs_running << " The readin total magnetization is " << GlobalV::nupdown << std::endl;
}

if (!para.inp.use_paw)
{
// decide whether to be USPP
for (int it = 0; it < ntype; ++it)
{
if (atoms[it].ncpp.tvanp)
{
GlobalV::use_uspp = true;
}
}

// calculate the total number of local basis
GlobalV::NLOCAL = 0;
for (int it = 0; it < ntype; ++it)
{
const int nlocal_it = atoms[it].nw * atoms[it].na;
if (para.inp.nspin != 4)
{
GlobalV::NLOCAL += nlocal_it;
}
else
{
GlobalV::NLOCAL += nlocal_it * 2; // zhengdy-soc
}
}
}

// calculate the total number of electrons
cal_nelec(atoms, ntype, GlobalV::nelec);

// autoset and check GlobalV::NBANDS
std::vector<double> nelec_spin(2, 0.0);
if (para.inp.nspin == 2)
{
nelec_spin[0] = (GlobalV::nelec + GlobalV::nupdown) / 2.0;
nelec_spin[1] = (GlobalV::nelec - GlobalV::nupdown) / 2.0;
}
cal_nbands(GlobalV::nelec, GlobalV::NLOCAL, nelec_spin, GlobalV::NBANDS);

return;
}
};
#endif
4 changes: 2 additions & 2 deletions source/module_cell/module_neighbor/test/prepare_unitcell.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ UcellTestPrepare::UcellTestPrepare(std::string latname_in,
coor_type(coor_type_in),
coordinates(coordinates_in)
{
mbl = {0};
velocity = {0};
mbl = std::valarray<double>(0.0, coordinates_in.size());
velocity = std::valarray<double>(0.0, coordinates_in.size());
}

UcellTestPrepare::UcellTestPrepare(std::string latname_in,
Expand Down
4 changes: 2 additions & 2 deletions source/module_cell/test/prepare_unitcell.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ UcellTestPrepare::UcellTestPrepare(std::string latname_in,
coor_type(coor_type_in),
coordinates(coordinates_in)
{
mbl = {0};
velocity = {0};
mbl = std::valarray<double>(0.0, coordinates_in.size());
velocity = std::valarray<double>(0.0, coordinates_in.size());
}

UcellTestPrepare::UcellTestPrepare(std::string latname_in,
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/test/support/mock_unitcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ void UnitCell::setup(const std::string& latname_in,
const int& lmaxmax_in,
const bool& init_vel_in,
const std::string& fixed_axes_in) {}
void UnitCell::cal_nelec(double& nelec) {}
void cal_nelec(const Atom* atoms, const int& ntype, double& nelec) {}
void UnitCell::compare_atom_labels(std::string label1, std::string label2) {}
Loading

0 comments on commit aab3182

Please sign in to comment.