Skip to content

Commit 37597db

Browse files
1041176461dyzheng
andauthored
Feature: output R matrix at each MD step (#1825)
* Use template to reconstruct parse_expression * Feature: output R matrix at each MD step * Modify'matrix_HS' to 'matrix' for R matrix output --------- Co-authored-by: dyzheng <[email protected]>
1 parent 4e8a87c commit 37597db

File tree

10 files changed

+32
-17
lines changed

10 files changed

+32
-17
lines changed

source/module_base/global_file.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void ModuleBase::Global_File::make_dir_out(
2020
const std::string &suffix,
2121
const std::string &calculation,
2222
const bool &out_hs,
23+
const bool &out_r,
2324
const int rank,
2425
const bool &restart,
2526
const bool out_alllog)
@@ -43,7 +44,7 @@ void ModuleBase::Global_File::make_dir_out(
4344

4445
GlobalV::global_out_dir = prefix + suffix + "/";
4546
GlobalV::global_stru_dir = GlobalV::global_out_dir + "STRU/";
46-
GlobalV::global_matrix_dir = GlobalV::global_out_dir + "matrix_HS/";
47+
GlobalV::global_matrix_dir = GlobalV::global_out_dir + "matrix/";
4748

4849
#ifdef __MPI
4950
MPI_Barrier(MPI_COMM_WORLD);
@@ -123,7 +124,7 @@ void ModuleBase::Global_File::make_dir_out(
123124
}
124125

125126
// make dir for HS matrix output in md calculation
126-
if(out_hs && calculation == "md")
127+
if((out_hs || out_r) && calculation == "md")
127128
{
128129
int make_dir_matrix = 0;
129130
std::string command1 = "test -d " + GlobalV::global_matrix_dir + " || mkdir " + GlobalV::global_matrix_dir;

source/module_base/global_file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Global_File
2424
void make_dir_out(const std::string &suffix,
2525
const std::string &calculation,
2626
const bool &out_hs,
27+
const bool &out_r,
2728
const int rank,
2829
const bool &restart,
2930
const bool out_alllog = false);

source/module_base/global_variable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ extern std::string global_out_dir;
163163
extern std::string global_orbital_dir; // liuyu add 2021-08-14
164164
extern std::string global_readin_dir; // zhengdy modified
165165
extern std::string global_stru_dir; // liuyu add 2022-05-24 for MD STRU
166-
extern std::string global_matrix_dir; // liuyu add 2022-09-19 for HS matrix output
166+
extern std::string global_matrix_dir; // liuyu add 2022-09-19 for HS matrix outpu, jiyy modified 2023-01-23 for R matrix output
167167

168168
extern std::ofstream ofs_running;
169169
extern std::ofstream ofs_warning;

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,11 @@ void ESolver_KS_LCAO::afterscf(const int istep)
906906

907907
if (hsolver::HSolverLCAO::out_mat_hsR)
908908
{
909-
r_matrix.out_rR_other(this->LM.output_R_coor);
909+
r_matrix.out_rR_other(istep, this->LM.output_R_coor);
910910
}
911911
else
912912
{
913-
r_matrix.out_rR();
913+
r_matrix.out_rR(istep);
914914
}
915915
}
916916

source/module_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,11 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep)
423423

424424
if (hsolver::HSolverLCAO::out_mat_hsR)
425425
{
426-
r_matrix.out_rR_other(this->LM.output_R_coor);
426+
r_matrix.out_rR_other(istep, this->LM.output_R_coor);
427427
}
428428
else
429429
{
430-
r_matrix.out_rR();
430+
r_matrix.out_rR(istep);
431431
}
432432
}
433433
}

source/module_io/cal_r_overlap_R.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void cal_r_overlap_R::init(const Parallel_Orbitals &pv)
226226
}
227227

228228

229-
void cal_r_overlap_R::out_rR()
229+
void cal_r_overlap_R::out_rR(const int &istep)
230230
{
231231
ModuleBase::TITLE("cal_r_overlap_R", "out_rR");
232232
ModuleBase::timer::tick("cal_r_overlap_R", "out_rR");
@@ -406,7 +406,10 @@ void cal_r_overlap_R::out_rR()
406406
{
407407
std::ofstream out_r;
408408
std::stringstream ssr;
409-
ssr << GlobalV::global_out_dir << "data-rR-sparse.csr";
409+
if(GlobalV::CALCULATION == "md")
410+
ssr << GlobalV::global_matrix_dir << istep << "_" << "data-rR-sparse.csr";
411+
else
412+
ssr << GlobalV::global_out_dir << "data-rR-sparse.csr";
410413

411414
if (binary)
412415
{
@@ -443,7 +446,7 @@ void cal_r_overlap_R::out_rR()
443446
}
444447

445448

446-
void cal_r_overlap_R::out_rR_other(const std::set<Abfs::Vector3_Order<int>> &output_R_coor)
449+
void cal_r_overlap_R::out_rR_other(const int &istep, const std::set<Abfs::Vector3_Order<int>> &output_R_coor)
447450
{
448451
ModuleBase::TITLE("cal_r_overlap_R", "out_rR_other");
449452
ModuleBase::timer::tick("cal_r_overlap_R", "out_rR_other");
@@ -456,7 +459,10 @@ void cal_r_overlap_R::out_rR_other(const std::set<Abfs::Vector3_Order<int>> &out
456459

457460
std::ofstream out_r;
458461
std::stringstream ssr;
459-
ssr << GlobalV::global_out_dir << "data-rR-sparse.csr";
462+
if(GlobalV::CALCULATION == "md")
463+
ssr << GlobalV::global_matrix_dir << istep << "_" << "data-rR-sparse.csr";
464+
else
465+
ssr << GlobalV::global_out_dir << "data-rR-sparse.csr";
460466

461467
if (GlobalV::DRANK == 0)
462468
{

source/module_io/cal_r_overlap_R.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class cal_r_overlap_R
3434
bool binary = false;
3535

3636
void init(const Parallel_Orbitals &pv);
37-
void out_rR();
38-
void out_rR_other(const std::set<Abfs::Vector3_Order<int>> &output_R_coor);
37+
void out_rR(const int &istep);
38+
void out_rR_other(const int &istep, const std::set<Abfs::Vector3_Order<int>> &output_R_coor);
3939

4040
private:
4141
void initialize_orb_table();

source/module_io/input.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void Input::Init(const std::string &fn)
5757
ModuleBase::Global_File::make_dir_out(this->suffix,
5858
this->calculation,
5959
this->out_mat_hs2,
60+
this->out_mat_r,
6061
GlobalV::MY_RANK,
6162
this->mdp.md_restart,
6263
this->out_alllog); // xiaohui add 2013-09-01

source/module_io/input_conv.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
#include "module_elecstate/potentials/gatefield.h"
2828
#include "module_psi/kernels/device.h"
2929

30-
void Input_Conv::parse_expression(const std::string &fn, std::vector<double> &vec)
30+
template <typename T>
31+
void Input_Conv::parse_expression(const std::string &fn, std::vector<T> &vec)
3132
{
3233
ModuleBase::TITLE("Input_Conv", "parse_expression");
3334
ModuleBase::timer::tick("Input_Conv", "parse_expression");
@@ -73,7 +74,7 @@ void Input_Conv::parse_expression(const std::string &fn, std::vector<double> &ve
7374
{
7475
int pos = sub_str.find("*");
7576
int num = stoi(sub_str.substr(0, pos));
76-
double occ = stof(sub_str.substr(pos + 1, sub_str.size()));
77+
T occ = stof(sub_str.substr(pos + 1, sub_str.size()));
7778
// std::vector<double> ocp_temp(num, occ);
7879
// const std::vector<double>::iterator dest = vec.begin() + count;
7980
// copy(ocp_temp.begin(), ocp_temp.end(), dest);
@@ -85,7 +86,11 @@ void Input_Conv::parse_expression(const std::string &fn, std::vector<double> &ve
8586
{
8687
// vec[count] = stof(sub_str);
8788
// count += 1;
88-
vec.emplace_back(stof(sub_str));
89+
std::stringstream convert;
90+
convert << sub_str;
91+
T occ;
92+
convert >> occ;
93+
vec.emplace_back(occ);
8994
}
9095
}
9196
}

source/module_io/input_conv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace Input_Conv
2424
// Function `parse_expression` is used to parse input parameters as expressions into vectors
2525
// fn (string): expressions such as "3*1 0 2*0.5 3*0"
2626
// arr (vector): stores parsing results, for example, "3*1 0 2*0.5 1*1.5" can be parsed as [1, 1, 1, 0, 0.5, 0.5, 1.5]
27-
void parse_expression(const std::string &fn, std::vector<double> &arr);
27+
template<typename T>
28+
void parse_expression(const std::string &fn, std::vector<T> &arr);
2829
}
2930

3031

0 commit comments

Comments
 (0)