Skip to content

Commit 2156598

Browse files
authored
Add new tests in the integrate tests of LCAO gamma only calculations and update the index to count relax/MD steps, now all steps start from 1, not 0 (#6821)
* update the examples of 02_NAO_Gamma * update * udpate * update * update tests in 02_NAO_Gamma * small updates of write_HS.hpp * update the format of H(k) and S(k) * update write_HS.hpp * update * update the number of md steps to make it equal to the input parameter, now md steps starts from 1, originally it starts from 0 * update 02_NAO_Gamma examples * add examples 002 and 003 in 02_NAO_Gamm * update examples 41 and 42 * updates of 43 and 57 examples * update example 17 in 03_NAO_multik * update 44 example of 03_NAO_multik * update 092 in 01_PW * update 01_PW examples * update 04_FF examples * update 05_rtTDDFT examples * update 06_SDFT examples * update 07_OFDFT examples * update 15_rtTDDFT_GPU examples * update 16 and 17 examples in 15_rtTDDFT_GPU * update 02 * fix bug * fix bug * update * update 16_SDFT_GPU * update * update 02 data * update 005 example in 02_NAO_Gamma * add 006 in 02 * update CASES_CPU.txt * fix a bug in 08_EXX 06 * fix bugs * update alllog test
1 parent 06751a0 commit 2156598

File tree

343 files changed

+2629
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

343 files changed

+2629
-670
lines changed

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::runner(UnitCell& ucell, const int istep)
103103
velocity_mat->calculate_vcomm_r();
104104
}
105105
int estep_max = (istep == 0 && !PARAM.inp.mdp.md_restart) ? 1 : PARAM.inp.estep_per_md;
106-
if (PARAM.inp.mdp.md_nstep == 0)
106+
// mohan change md_nstep from 0 to 1, 2026-01-04
107+
if (PARAM.inp.mdp.md_nstep == 1)
107108
{
108109
estep_max = PARAM.inp.estep_per_md + 1;
109110
}
@@ -194,7 +195,8 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::runner(UnitCell& ucell, const int istep)
194195
{
195196
break;
196197
}
197-
if (PARAM.inp.mdp.md_nstep != 0)
198+
// mohan add 2026-01-04, change md_nstep!=0 to md_nstep!=1
199+
if (PARAM.inp.mdp.md_nstep != 1)
198200
{
199201
estep -= 1;
200202
}

source/source_io/filename.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,33 @@ std::string filename_output(
4747

4848
// spin part
4949
std::string spin_block;
50-
if(nspin == 1)
51-
{
52-
}
53-
else if(nspin == 2)
50+
51+
// mohan add 2026-01-04, overlap matrix is the same for any spin
52+
if(property != "sk")
5453
{
55-
const int half_k = nkstot/2;
56-
if(ik0 >= half_k)
54+
if(nspin == 1)
5755
{
58-
is0 = 2;
59-
ik0 -= half_k;
56+
// do nothing
6057
}
61-
else
58+
else if(nspin == 2)
6259
{
63-
is0 = 1;
60+
const int half_k = nkstot/2;
61+
if(ik0 >= half_k)
62+
{
63+
is0 = 2;
64+
ik0 -= half_k;
65+
}
66+
else
67+
{
68+
is0 = 1;
69+
}
70+
spin_block = "s" + std::to_string(is0);
71+
}
72+
else if(nspin==4)
73+
{
74+
is0 = 4;
75+
spin_block = "s" + std::to_string(is0);
6476
}
65-
spin_block = "s" + std::to_string(is0);
66-
}
67-
else if(nspin==4)
68-
{
69-
is0 = 4;
70-
spin_block = "s" + std::to_string(is0);
7177
}
7278

7379

source/source_io/td_current_io.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,14 @@ void ModuleIO::write_current(const UnitCell& ucell,
180180
// write end
181181
if (GlobalV::MY_RANK == 0)
182182
{
183-
std::string filename = PARAM.globalv.global_out_dir + "current_total.txt";
183+
std::string filename = PARAM.globalv.global_out_dir + "current_tot.txt";
184184
std::ofstream fout;
185185
fout.open(filename, std::ios::app);
186186
fout << std::setprecision(16);
187187
fout << std::scientific;
188-
fout << istep << " " << current_total[0]/omega << " " << current_total[1]/omega << " " << current_total[2]/omega << std::endl;
188+
fout << istep+1 << " " << current_total[0]/omega
189+
<< " " << current_total[1]/omega
190+
<< " " << current_total[2]/omega << std::endl;
189191
fout.close();
190192
}
191193

@@ -559,26 +561,30 @@ void ModuleIO::write_current_eachk(const UnitCell& ucell,
559561
// MPI_Reduce(local_current_ik, current_ik, 3, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
560562
if (GlobalV::MY_RANK == 0 && TD_info::out_current_k)
561563
{
562-
std::string filename = PARAM.globalv.global_out_dir + "current_spin" + std::to_string(is) + "_ik"
563-
+ std::to_string(ik) + ".txt";
564+
std::string filename = PARAM.globalv.global_out_dir + "current_s" + std::to_string(is) + "k"
565+
+ std::to_string(ik+1) + ".txt";
564566
std::ofstream fout;
565567
fout.open(filename, std::ios::app);
566568
fout << std::setprecision(16);
567569
fout << std::scientific;
568-
fout << istep << " " << current_ik[0]/omega << " " << current_ik[1]/omega << " " << current_ik[2]/omega << std::endl;
570+
fout << istep+1 << " " << current_ik[0]/omega
571+
<< " " << current_ik[1]/omega
572+
<< " " << current_ik[2]/omega << std::endl;
569573
fout.close();
570574
}
571575
// write end
572576
} // end nks
573577
} // end is
574578
if (GlobalV::MY_RANK == 0)
575579
{
576-
std::string filename = PARAM.globalv.global_out_dir + "current_total.txt";
580+
std::string filename = PARAM.globalv.global_out_dir + "current_tot.txt";
577581
std::ofstream fout;
578582
fout.open(filename, std::ios::app);
579583
fout << std::setprecision(16);
580584
fout << std::scientific;
581-
fout << istep << " " << current_total[0]/omega << " " << current_total[1]/omega << " " << current_total[2]/omega << std::endl;
585+
fout << istep+1 << " " << current_total[0]/omega
586+
<< " " << current_total[1]/omega
587+
<< " " << current_total[2]/omega << std::endl;
582588
fout.close();
583589
}
584590

source/source_io/write_HS.hpp

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,19 @@ void ModuleIO::save_mat(const int istep,
111111
ModuleBase::TITLE("ModuleIO", "save_mat");
112112
ModuleBase::timer::tick("ModuleIO", "save_mat");
113113

114-
// print out .dat file
114+
const bool gamma_only = std::is_same<T, double>::value;
115+
116+
// write .dat file
115117
if (bit)
116118
{
119+
// write .dat file with MPI
117120
#ifdef __MPI
118-
FILE* g = nullptr;
121+
FILE* out_matrix = nullptr;
119122

120123
if (drank == 0)
121124
{
122-
g = fopen(filename.c_str(), "wb");
123-
fwrite(&dim, sizeof(int), 1, g);
125+
out_matrix = fopen(filename.c_str(), "wb");
126+
fwrite(&dim, sizeof(int), 1, out_matrix);
124127
}
125128

126129
int ir=0;
@@ -162,7 +165,7 @@ void ModuleIO::save_mat(const int istep,
162165
{
163166
for (int j = (tri ? i : 0); j < dim; ++j)
164167
{
165-
fwrite(&line[tri ? j - i : j], sizeof(T), 1, g);
168+
fwrite(&line[tri ? j - i : j], sizeof(T), 1, out_matrix);
166169
}
167170
}
168171
delete[] line;
@@ -172,39 +175,47 @@ void ModuleIO::save_mat(const int istep,
172175

173176
if (drank == 0)
174177
{
175-
fclose(g);
178+
fclose(out_matrix);
176179
}
180+
// write .dat file without MPI
177181
#else
178-
FILE* g = fopen(filename.c_str(), "wb");
182+
FILE* out_matrix = fopen(filename.c_str(), "wb");
179183

180-
fwrite(&dim, sizeof(int), 1, g);
184+
fwrite(&dim, sizeof(int), 1, out_matrix);
181185

182186
for (int i = 0; i < dim; i++)
183187
{
184188
for (int j = (tri ? i : 0); j < dim; j++)
185189
{
186-
fwrite(&mat[i * dim + j], sizeof(T), 1, g);
190+
fwrite(&mat[i * dim + j], sizeof(T), 1, out_matrix);
187191
}
188192
}
189-
fclose(g);
193+
fclose(out_matrix);
190194
#endif
191-
} // end .dat file
192-
else // .txt file
195+
} // end writing .dat file
196+
else // write .txt file
193197
{
194-
std::ofstream g;
195-
g << std::setprecision(precision);
198+
std::ofstream out_matrix;
199+
out_matrix << std::scientific << std::setprecision(precision);
196200
#ifdef __MPI
197201
if (drank == 0)
198202
{
199203
if (app && istep > 0)
200204
{
201-
g.open(filename.c_str(), std::ofstream::app);
205+
out_matrix.open(filename.c_str(), std::ofstream::app);
202206
}
203207
else
204208
{
205-
g.open(filename.c_str());
209+
out_matrix.open(filename.c_str());
206210
}
207-
g << dim;
211+
out_matrix << "#------------------------------------------------------------------------" << std::endl;
212+
out_matrix << "# ionic step " << istep+1 << std::endl; // istep starts from 0
213+
out_matrix << "# filename " << filename << std::endl;
214+
out_matrix << "# gamma only " << gamma_only << std::endl;
215+
out_matrix << "# rows " << dim << std::endl;
216+
out_matrix << "# columns " << dim << std::endl;
217+
out_matrix << "#------------------------------------------------------------------------" << std::endl;
218+
208219
}
209220

210221
int ir=0;
@@ -223,7 +234,7 @@ void ModuleIO::save_mat(const int istep,
223234
ic = pv.global2local_col(j);
224235
if (ic >= 0)
225236
{
226-
int iic;
237+
int iic=0;
227238
if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver))
228239
{
229240
iic = ir + ic * pv.nrow;
@@ -244,40 +255,50 @@ void ModuleIO::save_mat(const int istep,
244255

245256
if (drank == 0)
246257
{
258+
out_matrix << "Row " << i+1 << std::endl;
259+
size_t count = 0;
247260
for (int j = (tri ? i : 0); j < dim; j++)
248261
{
249-
g << " " << line[tri ? j - i : j];
262+
out_matrix << " " << line[tri ? j - i : j];
263+
++count;
264+
if(count%8==0)
265+
{
266+
if(j!=dim-1)
267+
{
268+
out_matrix << std::endl;
269+
}
270+
}
250271
}
251-
g << std::endl;
272+
out_matrix << std::endl;
252273
}
253274
delete[] line;
254275
}
255276

256277
if (drank == 0)
257-
{ // Peize Lin delete ; at 2020.01.31
258-
g.close();
278+
{
279+
out_matrix.close();
259280
}
260281
#else
261282
if (app)
262283
{
263-
std::ofstream g(filename.c_str(), std::ofstream::app);
284+
std::ofstream out_matrix(filename.c_str(), std::ofstream::app);
264285
}
265286
else
266287
{
267-
std::ofstream g(filename.c_str());
288+
std::ofstream out_matrix(filename.c_str());
268289
}
269290

270-
g << dim;
271-
g << std::setprecision(precision);
291+
out_matrix << dim;
292+
out_matrix << std::setprecision(precision);
272293
for (int i = 0; i < dim; i++)
273294
{
274295
for (int j = (tri ? i : 0); j < dim; j++)
275296
{
276-
g << " " << mat[i * dim + j];
297+
out_matrix << " " << mat[i * dim + j];
277298
}
278-
g << std::endl;
299+
out_matrix << std::endl;
279300
}
280-
g.close();
301+
out_matrix.close();
281302
#endif
282303
}
283304
ModuleBase::timer::tick("ModuleIO", "save_mat");

source/source_md/md_base.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ void MD_base::setup(ModuleESolver::ESolver* p_esolver, const std::string& global
6060
restart(global_readin_dir);
6161
}
6262

63-
ModuleIO::print_screen(0, 0, step_ + step_rst_);
63+
// mohan add 2026-01-04
64+
const int stress_step = 0;
65+
const int force_step = 0;
66+
const int istep_print = step_ + step_rst_ + 1;
67+
68+
ModuleIO::print_screen(stress_step, force_step, istep_print);
6469

6570
MD_func::force_virial(p_esolver, step_, ucell, potential, force, cal_stress, virial);
6671
MD_func::compute_stress(ucell, vel, allmass, cal_stress, virial, stress);

source/source_md/run_md.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void md_line(UnitCell& unit_in, ModuleESolver::ESolver* p_esolver, const Paramet
2121
ModuleBase::timer::tick("Run_MD", "md_line");
2222

2323
/// determine the md_type
24-
MD_base* mdrun;
24+
MD_base* mdrun = nullptr;
2525
if (param_in.mdp.md_type == "fire")
2626
{
2727
mdrun = new FIRE(param_in, unit_in);
@@ -47,16 +47,20 @@ void md_line(UnitCell& unit_in, ModuleESolver::ESolver* p_esolver, const Paramet
4747
ModuleBase::WARNING_QUIT("md_line", "no such md_type!");
4848
}
4949

50-
/// md cycle
51-
while ((mdrun->step_ + mdrun->step_rst_) <= param_in.mdp.md_nstep && !mdrun->stop)
50+
/// md cycle, mohan update 2026-01-04, change '<=' to '<'
51+
while ((mdrun->step_ + mdrun->step_rst_) < param_in.mdp.md_nstep && !mdrun->stop)
5252
{
5353
if (mdrun->step_ == 0)
5454
{
5555
mdrun->setup(p_esolver, PARAM.globalv.global_readin_dir);
5656
}
5757
else
5858
{
59-
ModuleIO::print_screen(0, 0, mdrun->step_ + mdrun->step_rst_);
59+
// mohan add 2026-01-04
60+
const int stress_step = 0;
61+
const int force_step = 0;
62+
const int istep_print = mdrun->step_ + mdrun->step_rst_ + 1;
63+
ModuleIO::print_screen(stress_step, force_step, istep_print);
6064
mdrun->first_half(GlobalV::ofs_running);
6165

6266
/// update force and virial due to the update of atom positions
@@ -130,4 +134,4 @@ void md_line(UnitCell& unit_in, ModuleESolver::ESolver* p_esolver, const Paramet
130134
return;
131135
}
132136

133-
} // namespace Run_MD
137+
} // namespace Run_MD

tests/01_PW/092_PW_MSST/INPUT

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
INPUT_PARAMETERS
22
#Parameters (General)
33
suffix autotest
4-
pseudo_dir ../../PP_ORB
4+
pseudo_dir ../../PP_ORB
55

66
nbands 8
77
calculation md
88
read_file_dir ./
99

1010
#Parameters (Accuracy)
1111
ecutwfc 20
12-
scf_nmax 20
12+
scf_nmax 20
1313

1414
basis_type pw
15-
md_nstep 3
15+
md_nstep 3
1616

17-
smearing_method gauss
18-
smearing_sigma 0.001
17+
smearing_method gauss
18+
smearing_sigma 0.001
1919

20-
cal_stress 1
21-
cal_force 1
20+
cal_stress 1
21+
cal_force 1
2222

2323
ks_solver cg
2424
mixing_type broyden
2525
mixing_beta 0.7
2626

27-
md_type msst
28-
md_tfirst 10
29-
md_dt 1
30-
md_restart 0
31-
init_vel 1
27+
md_type msst
28+
md_tfirst 10
29+
md_dt 1
30+
md_restart 0
31+
init_vel 1
3232

33-
msst_qmass 1
34-
msst_vel 10
33+
msst_qmass 1
34+
msst_vel 10
3535

36-
pw_seed 1
36+
pw_seed 1

0 commit comments

Comments
 (0)