Skip to content

Commit 22887eb

Browse files
authored
Merge pull request #1048 from YuLiu98/develop
fix: fix warning_quit in md restart
2 parents 778f34d + 6f37fcc commit 22887eb

File tree

4 files changed

+112
-54
lines changed

4 files changed

+112
-54
lines changed

source/module_md/FIRE.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,37 @@ void FIRE::write_restart()
118118

119119
void FIRE::restart()
120120
{
121+
bool ok = true;
122+
121123
if(!GlobalV::MY_RANK)
122124
{
123-
std::stringstream ssc;
124-
ssc << GlobalV::global_out_dir << "Restart_md.dat";
125-
std::ifstream file(ssc.str().c_str());
125+
std::stringstream ssc;
126+
ssc << GlobalV::global_readin_dir << "Restart_md.dat";
127+
std::ifstream file(ssc.str().c_str());
126128

127129
if(!file)
128-
{
129-
std::cout<< "please ensure whether 'Restart_md.dat' exists!" << std::endl;
130-
ModuleBase::WARNING_QUIT("verlet", "no Restart_md.dat !");
131-
}
130+
{
131+
ok = false;
132+
}
133+
134+
if(ok)
135+
{
136+
file >> step_rst_ >> alpha >> negative_count >> dt_max >> mdp.md_dt;
137+
file.close();
138+
}
139+
}
132140

133-
file >> step_rst_ >> alpha >> negative_count >> dt_max >> mdp.md_dt;
141+
#ifdef __MPI
142+
MPI_Bcast(&ok, 1, MPI_INT, 0, MPI_COMM_WORLD);
143+
#endif
134144

135-
file.close();
136-
}
145+
if(!ok)
146+
{
147+
ModuleBase::WARNING_QUIT("verlet", "no Restart_md.dat !");
148+
}
137149

138150
#ifdef __MPI
139-
MPI_Bcast(&step_rst_, 1, MPI_INT, 0, MPI_COMM_WORLD);
151+
MPI_Bcast(&step_rst_, 1, MPI_INT, 0, MPI_COMM_WORLD);
140152
MPI_Bcast(&alpha, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
141153
MPI_Bcast(&negative_count, 1, MPI_INT, 0, MPI_COMM_WORLD);
142154
MPI_Bcast(&dt_max, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);

source/module_md/MSST.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,34 @@ void MSST::write_restart()
187187

188188
void MSST::restart()
189189
{
190+
bool ok = true;
191+
190192
if(!GlobalV::MY_RANK)
191193
{
192-
std::stringstream ssc;
193-
ssc << GlobalV::global_out_dir << "Restart_md.dat";
194-
std::ifstream file(ssc.str().c_str());
194+
std::stringstream ssc;
195+
ssc << GlobalV::global_readin_dir << "Restart_md.dat";
196+
std::ifstream file(ssc.str().c_str());
195197

196198
if(!file)
197-
{
198-
std::cout<< "please ensure whether 'Restart_md.dat' exists!" << std::endl;
199-
ModuleBase::WARNING_QUIT("MSST", "no Restart_md.dat !");
200-
}
199+
{
200+
ok = false;
201+
}
201202

202-
file >> step_rst_ >> omega[mdp.msst_direction] >> e0 >> v0 >> p0 >> lag_pos;
203+
if(ok)
204+
{
205+
file >> step_rst_ >> omega[mdp.msst_direction] >> e0 >> v0 >> p0 >> lag_pos;
206+
file.close();
207+
}
208+
}
203209

204-
file.close();
205-
}
210+
#ifdef __MPI
211+
MPI_Bcast(&ok, 1, MPI_INT, 0, MPI_COMM_WORLD);
212+
#endif
213+
214+
if(!ok)
215+
{
216+
ModuleBase::WARNING_QUIT("verlet", "no Restart_md.dat !");
217+
}
206218

207219
#ifdef __MPI
208220
MPI_Bcast(&step_rst_, 1, MPI_INT, 0, MPI_COMM_WORLD);

source/module_md/NVT_NHC.cpp

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ NVT_NHC::NVT_NHC(MD_parameters& MD_para_in, UnitCell_pseudo &unit_in) : Verlet(M
99
{
1010
if(mdp.md_tfirst == 0)
1111
{
12-
std::cout << " md_tfirst must be larger than 0 in NHC !!! " << std::endl;
1312
ModuleBase::WARNING_QUIT("NVT_NHC", " md_tfirst must be larger than 0 in NHC !!! ");
1413
}
1514

@@ -122,35 +121,59 @@ void NVT_NHC::write_restart()
122121

123122
void NVT_NHC::restart()
124123
{
124+
bool ok = true;
125+
bool ok2 = true;
126+
125127
if(!GlobalV::MY_RANK)
126128
{
127-
std::stringstream ssc;
128-
ssc << GlobalV::global_out_dir << "Restart_md.dat";
129-
std::ifstream file(ssc.str().c_str());
129+
std::stringstream ssc;
130+
ssc << GlobalV::global_readin_dir << "Restart_md.dat";
131+
std::ifstream file(ssc.str().c_str());
130132

131133
if(!file)
132-
{
133-
std::cout<< "Please ensure whether 'Restart_md.dat' exists !" << std::endl;
134-
ModuleBase::WARNING_QUIT("NVT_NHC", "no Restart_md.dat !");
135-
}
136-
double Mnum;
137-
file >> step_rst_ >> Mnum;
138-
if(Mnum != mdp.md_mnhc)
139-
{
140-
std::cout<< "Num of NHC is not the same !" << std::endl;
141-
ModuleBase::WARNING_QUIT("NVT_NHC", "no Restart_md.dat !");
142-
}
143-
for(int i=0; i<mdp.md_mnhc; ++i)
144134
{
145-
file >> eta[i];
135+
ok = false;
146136
}
147-
for(int i=0; i<mdp.md_mnhc; ++i)
137+
138+
if(ok)
148139
{
149-
file >> veta[i];
140+
double Mnum;
141+
file >> step_rst_ >> Mnum;
142+
143+
if( Mnum != mdp.md_mnhc )
144+
{
145+
ok2 = false;
146+
}
147+
148+
if(ok2)
149+
{
150+
for(int i=0; i<mdp.md_mnhc; ++i)
151+
{
152+
file >> eta[i];
153+
}
154+
for(int i=0; i<mdp.md_mnhc; ++i)
155+
{
156+
file >> veta[i];
157+
}
158+
}
159+
160+
file.close();
150161
}
162+
}
151163

152-
file.close();
153-
}
164+
#ifdef __MPI
165+
MPI_Bcast(&ok, 1, MPI_INT, 0, MPI_COMM_WORLD);
166+
MPI_Bcast(&ok2, 1, MPI_INT, 0, MPI_COMM_WORLD);
167+
#endif
168+
169+
if(!ok)
170+
{
171+
ModuleBase::WARNING_QUIT("verlet", "no Restart_md.dat !");
172+
}
173+
if(!ok2)
174+
{
175+
ModuleBase::WARNING_QUIT("verlet", "Num of NHC is not the same !");
176+
}
154177

155178
#ifdef __MPI
156179
MPI_Bcast(&step_rst_, 1, MPI_INT, 0, MPI_COMM_WORLD);
@@ -196,7 +219,6 @@ void NVT_NHC::integrate()
196219
scale *= exp(-veta[0]*delta/2.0);
197220
if(!isfinite(scale))
198221
{
199-
std::cout << " Please set a proper md_tfreq !!! " << std::endl;
200222
ModuleBase::WARNING_QUIT("NVT_NHC", " Please set a proper md_tfreq !!! ");
201223
}
202224

source/module_md/verlet.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,36 @@ void Verlet::write_restart()
190190

191191
void Verlet::restart()
192192
{
193+
bool ok = true;
194+
193195
if(!GlobalV::MY_RANK)
194196
{
195-
std::stringstream ssc;
196-
ssc << GlobalV::global_out_dir << "Restart_md.dat";
197-
std::ifstream file(ssc.str().c_str());
197+
std::stringstream ssc;
198+
ssc << GlobalV::global_readin_dir << "Restart_md.dat";
199+
std::ifstream file(ssc.str().c_str());
198200

199201
if(!file)
200-
{
201-
std::cout<< "please ensure whether 'Restart_md.dat' exists!" << std::endl;
202-
ModuleBase::WARNING_QUIT("verlet", "no Restart_md.dat !");
203-
}
202+
{
203+
ok = false;
204+
}
204205

205-
file >> step_rst_;
206+
if(ok)
207+
{
208+
file >> step_rst_;
209+
file.close();
210+
}
211+
}
206212

207-
file.close();
208-
}
213+
#ifdef __MPI
214+
MPI_Bcast(&ok, 1, MPI_INT, 0, MPI_COMM_WORLD);
215+
#endif
216+
217+
if(!ok)
218+
{
219+
ModuleBase::WARNING_QUIT("verlet", "no Restart_md.dat !");
220+
}
209221

210222
#ifdef __MPI
211-
MPI_Bcast(&step_rst_, 1, MPI_INT, 0, MPI_COMM_WORLD);
223+
MPI_Bcast(&step_rst_, 1, MPI_INT, 0, MPI_COMM_WORLD);
212224
#endif
213225
}

0 commit comments

Comments
 (0)