Skip to content

Commit 05e9cc7

Browse files
committed
update md print out information
1 parent 8718960 commit 05e9cc7

File tree

11 files changed

+67
-129
lines changed

11 files changed

+67
-129
lines changed

source/module_io/berryphase.cpp

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ void berryphase::get_occupation_bands()
3636
ModuleBase::WARNING_QUIT("berryphase::get_occupation_bands",
3737
"not enough bands for berryphase, increase band numbers.");
3838
}
39-
// GlobalV::ofs_running << "the berryphase's occ_nbands is " << occ_nbands << std::endl;
4039
}
4140

4241
#ifdef __LCAO
@@ -214,25 +213,6 @@ void berryphase::set_kpoints(const K_Vectors& kv, const int direction)
214213

215214
nppstr = mp_z + 1;
216215
}
217-
218-
// test by jingan
219-
/*
220-
GlobalV::ofs_running << "direction is " << direction << std::endl;
221-
GlobalV::ofs_running << "nppstr = " << nppstr << std::endl;
222-
GlobalV::ofs_running << "total std::string is " << total_string << std::endl;
223-
for(int istring = 0; istring < total_string; istring++)
224-
{
225-
GlobalV::ofs_running << " the std::string is " << istring << std::endl;
226-
for(int count = 0; count < nppstr; count++)
227-
{
228-
GlobalV::ofs_running << "(" << kv.kvec_c[ k_index[istring][count] ].x << ","
229-
<< kv.kvec_c[ k_index[istring][count] ].y << ","
230-
<< kv.kvec_c[ k_index[istring][count] ].z << ")" << std::endl;
231-
}
232-
233-
}
234-
*/
235-
// test by jingan
236216
}
237217

238218
#include "../module_base/complexmatrix.h"
@@ -251,7 +231,6 @@ double berryphase::stringPhase(const UnitCell& ucell,
251231
int ik_2 = 0;
252232
ModuleBase::Vector3<double> G(0.0, 0.0, 0.0);
253233
ModuleBase::Vector3<double> dk = kv.kvec_c[k_index[index_str][1]] - kv.kvec_c[k_index[index_str][0]];
254-
// GlobalV::ofs_running << "the std::string index is " << index_str << std::endl;
255234

256235
for (int k_start = 0; k_start < (nppstr - 1); k_start++)
257236
{
@@ -351,45 +330,11 @@ double berryphase::stringPhase(const UnitCell& ucell,
351330
{
352331
if (PARAM.inp.nspin != 4)
353332
{
354-
// std::complex<double> my_det = lcao_method.det_berryphase(ik_1,ik_2,dk,nbands);
355333
zeta = zeta * lcao_method.det_berryphase(ucell,ik_1, ik_2, dk, nbands, *(this->paraV), psi_in, kv);
356-
// test by jingan
357-
// GlobalV::ofs_running << "methon 1: det = " << my_det << std::endl;
358-
// test by jingan
359334
}
360335
else
361336
{
362337
}
363-
364-
// test by jingan
365-
/*
366-
for (int mb = 0; mb < nbands; mb++)
367-
{
368-
369-
for (int nb = 0; nb < nbands; nb++)
370-
{
371-
372-
mat(nb, mb) = lcao_method.unkdotp_LCAO(ik_1,ik_2,nb,mb,dk,kv);
373-
}
374-
}
375-
376-
std::complex<double> det(1.0,0.0);
377-
int info = 0;
378-
int *ipiv = new int[nbands];
379-
LapackConnector::zgetrf(nbands, nbands, mat, nbands, ipiv, &info);
380-
for (int ib = 0; ib < nbands; ib++)
381-
{
382-
if (ipiv[ib] != (ib+1)) det = -det * mat(ib,ib);
383-
else det = det * mat(ib,ib);
384-
}
385-
386-
zeta = zeta*det;
387-
388-
GlobalV::ofs_running << "methon 2: det = " << det << std::endl;
389-
390-
delete[] ipiv;
391-
*/
392-
// test by jingan
393338
}
394339
#endif
395340
}
@@ -441,9 +386,6 @@ void berryphase::Berry_Phase(const UnitCell& ucell,
441386
dtheta = atan2(cphik[istring].imag(), cphik[istring].real());
442387
phik[istring] = (theta0 + dtheta) / (2 * ModuleBase::PI);
443388
phik_ave = phik_ave + wistring[istring] * phik[istring];
444-
// test by jingan
445-
// GlobalV::ofs_running << "phik[" << istring << "] = " << phik[istring] << std::endl;
446-
// test by jingan
447389
}
448390

449391
if (PARAM.inp.nspin == 1)
@@ -466,7 +408,6 @@ void berryphase::Berry_Phase(const UnitCell& ucell,
466408
mod_elec_tot = 1;
467409
}
468410

469-
// GlobalV::ofs_running << "Berry_Phase end " << std::endl;
470411
}
471412

472413
void berryphase::Macroscopic_polarization(const UnitCell& ucell,
@@ -574,20 +515,16 @@ void berryphase::Macroscopic_polarization(const UnitCell& ucell,
574515
polarization_ion[2] = polarization_ion[2] - 2.0 * round(polarization_ion[2] / 2.0);
575516
}
576517

577-
// delete[] mod_ion;
578-
// delete[] pdl_ion_R1;
579-
// delete[] pdl_ion_R2;
580-
// delete[] pdl_ion_R3;
581-
582518
// ion polarization end
583519

584520
// calculate Macroscopic polarization modulus because berry phase
585521
int modulus = 0;
586-
if ((!lodd) && (PARAM.inp.nspin == 1)) {
587-
modulus = 2;
588-
} else {
589-
modulus = 1;
590-
}
522+
if ((!lodd) && (PARAM.inp.nspin == 1))
523+
{
524+
modulus = 2;
525+
} else {
526+
modulus = 1;
527+
}
591528

592529
// test by jingan
593530
// GlobalV::ofs_running << "ion polarization end" << std::endl;
@@ -736,8 +673,6 @@ void berryphase::Macroscopic_polarization(const UnitCell& ucell,
736673
}
737674
}
738675

739-
// GlobalV::ofs_running << "the Macroscopic_polarization is over" << std::endl;
740-
741676
return;
742677
}
743678

source/module_io/write_wfc_pw.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ void ModuleIO::write_wfc_pw(const std::string& fn,
4747
}
4848
}
4949
}
50-
// if(GlobalV::MY_RANK!=0) std::cout.clear();
51-
// std::cout<<"Hello"<<std::endl;
52-
// if(GlobalV::MY_RANK!=0) std::cout.setstate(ios::failbit);
50+
5351
#ifdef __MPI
5452
MPI_Barrier(MPI_COMM_WORLD);
5553

source/module_md/fire.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ void FIRE::print_md(std::ofstream& ofs, const bool& cal_stress)
7676
{
7777
MD_base::print_md(ofs, cal_stress);
7878

79-
ofs << "\n Largest gradient in force is " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << " eV/A." << std::endl;
80-
ofs << " Threshold is " << PARAM.inp.force_thr_ev << " eV/A." << std::endl;
81-
std::cout << " LARGEST GRAD (eV/A) : " << max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU << std::endl;
79+
const double max_force = max * ModuleBase::Hartree_to_eV * ModuleBase::ANGSTROM_AU;
80+
81+
ofs << " LARGEST FORCE (eV/A) : " << max_force << std::endl;
82+
std::cout << " LARGEST FORCE (eV/A) : " << max_force << std::endl;
8283

8384
return;
8485
}

source/module_md/md_base.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void MD_base::update_vel(const ModuleBase::Vector3<double>* force)
142142

143143
void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress)
144144
{
145-
if (my_rank)
145+
if (my_rank!=0)
146146
{
147147
return;
148148
}
@@ -158,6 +158,7 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress)
158158
press += stress(i, i) / 3;
159159
}
160160

161+
// screen output
161162
std::cout << " ------------------------------------------------------------------------------------------------"
162163
<< std::endl;
163164
std::cout << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)"
@@ -182,9 +183,9 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress)
182183
std::cout << " ------------------------------------------------------------------------------------------------"
183184
<< std::endl;
184185

186+
// running_log output
185187
ofs.unsetf(std::ios::fixed);
186-
ofs << std::setprecision(8) << std::endl;
187-
ofs << std::endl;
188+
ofs << std::setprecision(8);
188189
ofs << " ------------------------------------------------------------------------------------------------"
189190
<< std::endl;
190191
ofs << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)"
@@ -214,9 +215,6 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress)
214215
MD_func::print_stress(ofs, virial, stress);
215216
}
216217

217-
ofs << std::endl;
218-
ofs << std::endl;
219-
220218
return;
221219
}
222220

source/module_md/md_func.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ void print_stress(std::ofstream& ofs, const ModuleBase::matrix& virial, const Mo
299299

300300
const double unit_transform = ModuleBase::HARTREE_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8;
301301

302-
ofs << " MD PRESSURE (ELECTRONS+IONS) : " << stress_scalar * unit_transform << " KBAR" << std::endl;
303-
ofs << " ELECTRONIC PART OF STRESS: " << virial_scalar * unit_transform << " KBAR" << std::endl;
304-
ofs << " IONIC (KINETIC) PART OF STRESS: " << (stress_scalar - virial_scalar) * unit_transform << " KBAR" << std::endl;
302+
ofs << " MD PRESSURE (ELECTRONS+IONS) : " << stress_scalar * unit_transform << " kbar" << std::endl;
303+
ofs << " ELECTRONIC PART OF STRESS: " << virial_scalar * unit_transform << " kbar" << std::endl;
304+
ofs << " IONIC (KINETIC) PART OF STRESS: " << (stress_scalar - virial_scalar) * unit_transform << " kbar" << std::endl;
305305

306306
// one should use 'print_stress' function in ../source/module_io/output_log.cpp
307307
/*

source/module_md/test/fire_test.cpp

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,41 +177,54 @@ TEST_F(FIREtest, Restart)
177177

178178
TEST_F(FIREtest, PrintMD)
179179
{
180-
std::ofstream ofs("running.log");
180+
std::ofstream ofs("running_fire.log");
181181
mdrun->print_md(ofs, true);
182182
ofs.close();
183183

184-
std::ifstream ifs("running.log");
184+
std::ifstream ifs("running_fire.log");
185185
std::string output_str;
186+
187+
// Line 1
186188
getline(ifs, output_str);
187-
getline(ifs, output_str);
188-
getline(ifs, output_str);
189-
EXPECT_THAT(
190-
output_str,
189+
EXPECT_THAT(output_str,
191190
testing::HasSubstr(
192191
" ------------------------------------------------------------------------------------------------"));
192+
193+
// Line 2
193194
getline(ifs, output_str);
194-
EXPECT_THAT(
195-
output_str,
195+
EXPECT_THAT(output_str,
196196
testing::HasSubstr(
197197
" Energy (Ry) Potential (Ry) Kinetic (Ry) Temperature (K) Pressure (kbar) "));
198+
199+
// Line 3
198200
getline(ifs, output_str);
199-
EXPECT_THAT(
200-
output_str,
201+
EXPECT_THAT(output_str,
201202
testing::HasSubstr(
202203
" -0.015365236 -0.023915637 0.0085504016 300 1.0846391 "));
204+
205+
// Line 4
203206
getline(ifs, output_str);
204207
EXPECT_THAT(
205208
output_str,
206209
testing::HasSubstr(
207210
" ------------------------------------------------------------------------------------------------"));
208-
for (int i = 0; i < 11; ++i)
209-
{
210-
getline(ifs, output_str);
211-
}
212-
EXPECT_THAT(output_str, testing::HasSubstr(" Largest gradient in force is 0.049479926 eV/A"));
211+
212+
// Line 5
213+
getline(ifs, output_str);
214+
EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391 kbar"));
215+
216+
// Line 6
217+
getline(ifs, output_str);
218+
EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar"));
219+
220+
// Line 7
213221
getline(ifs, output_str);
214-
EXPECT_THAT(output_str, testing::HasSubstr(" Threshold is -1 eV/A."));
222+
EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.83853919 kbar"));
223+
224+
// Line 8
225+
getline(ifs, output_str);
226+
EXPECT_THAT(output_str, testing::HasSubstr(" LARGEST FORCE (eV/A) : 0.049479926"));
227+
215228
ifs.close();
216-
remove("running.log");
229+
//remove("running_fire.log");
217230
}

source/module_md/test/langevin_test.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,13 @@ TEST_F(Langevin_test, restart)
163163

164164
TEST_F(Langevin_test, print_md)
165165
{
166-
std::ofstream ofs("running.log");
166+
std::ofstream ofs("running_langevin.log");
167167
mdrun->print_md(ofs, true);
168168
ofs.close();
169169

170-
std::ifstream ifs("running.log");
170+
std::ifstream ifs("running_langevin.log");
171171
std::string output_str;
172172
getline(ifs, output_str);
173-
getline(ifs, output_str);
174-
getline(ifs, output_str);
175173
EXPECT_THAT(
176174
output_str,
177175
testing::HasSubstr(
@@ -192,5 +190,5 @@ TEST_F(Langevin_test, print_md)
192190
testing::HasSubstr(
193191
" ------------------------------------------------------------------------------------------------"));
194192
ifs.close();
195-
remove("running.log");
193+
remove("running_langevin.log");
196194
}

source/module_md/test/md_func_test.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,12 @@ TEST_F(MD_func_test, print_stress)
385385
std::ifstream ifs("running.log");
386386
std::string output_str;
387387
getline(ifs, output_str);
388-
EXPECT_THAT(output_str, testing::HasSubstr("Virtual Pressure is 0 kbar "));
388+
EXPECT_THAT(output_str, testing::HasSubstr("MD PRESSURE (ELECTRONS+IONS) : 0 kbar"));
389389
getline(ifs, output_str);
390-
EXPECT_THAT(output_str, testing::HasSubstr("Virial Term is 0 kbar "));
390+
EXPECT_THAT(output_str, testing::HasSubstr("ELECTRONIC PART OF STRESS: 0 kbar"));
391391
getline(ifs, output_str);
392-
EXPECT_THAT(output_str, testing::HasSubstr("Kinetic Term is 0 kbar "));
392+
EXPECT_THAT(output_str, testing::HasSubstr("IONIC (KINETIC) PART OF STRESS: 0 kbar"));
393+
/*
393394
getline(ifs, output_str);
394395
getline(ifs, output_str);
395396
getline(ifs, output_str);
@@ -409,6 +410,7 @@ TEST_F(MD_func_test, print_stress)
409410
EXPECT_THAT(output_str, testing::HasSubstr(" 0 0 0"));
410411
getline(ifs, output_str);
411412
EXPECT_THAT(output_str, testing::HasSubstr(" 0 0 0"));
413+
*/
412414

413415
ifs.close();
414416
remove("running.log");
@@ -438,4 +440,4 @@ TEST_F(MD_func_test, current_step_warning)
438440
int istep = 0;
439441
double temperature = 0.0;
440442
EXPECT_EXIT(MD_func::current_md_info(0, file_dir, istep, temperature), ::testing::ExitedWithCode(1), "");
441-
}
443+
}

source/module_md/test/msst_test.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,13 @@ TEST_F(MSST_test, restart)
219219

220220
TEST_F(MSST_test, print_md)
221221
{
222-
std::ofstream ofs("running.log");
222+
std::ofstream ofs("running_msst.log");
223223
mdrun->print_md(ofs, true);
224224
ofs.close();
225225

226-
std::ifstream ifs("running.log");
226+
std::ifstream ifs("running_msst.log");
227227
std::string output_str;
228228
getline(ifs, output_str);
229-
getline(ifs, output_str);
230-
getline(ifs, output_str);
231229
EXPECT_THAT(
232230
output_str,
233231
testing::HasSubstr(
@@ -248,5 +246,5 @@ TEST_F(MSST_test, print_md)
248246
testing::HasSubstr(
249247
" ------------------------------------------------------------------------------------------------"));
250248
ifs.close();
251-
remove("running.log");
249+
// remove("running_msst.log");
252250
}

0 commit comments

Comments
 (0)