出自手册:11.7 Checkpointing: saving and loading the state of a simulation
codesByTopic/io/checkPointing.cpp
using namespace std;
……
plint iniT, endT;
if (argc != 3) {
pcout << "Error; the syntax is \"" << argv[0] << " start-iter end-iter\"," << endl;
return -1;
}
stringstream iniTstr, endTstr;
iniTstr << argv[1]; iniTstr >> iniT;
endTstr << argv[2]; endTstr >> endT;
案例给出的方法是,需要手动输入加载的迭代数量,如果这个值大于0,在后续就会加载流场数据。
if (iniT>0) { //loadRawMultiBlock(lattice, “checkpoint.dat”); loadBinaryBlock(lattice, “checkpoint.dat”); }
与此同时,程序也会每checkPointIter迭代步保存一下流场数据。
if (iT%checkPointIter==0 && iT>iniT) {
pcout << "Saving the state of the simulation ..." << endl;
//saveRawMultiBlock(lattice, "checkpoint.dat");
saveBinaryBlock(lattice, "checkpoint.dat");
}
我稍微修改了一下,只用输入起始It即可:
plint iniT;
if (argc != 2) {
pcout << "Error; the syntax is \"" << argv[0] << " start-iter\"," << endl;
return -1;
}
stringstream iniTstr;
iniTstr << argv[1];
iniTstr >> iniT;
if (iniT>0) {
loadBinaryBlock(*lattice, "checkpoint.dat");
}
需要注意的是,加载数据要在边界条件等设置之后。一般把它放到总体那个for循环之前即可。 for循环也需要修改一下,方便后续记录正确的it数值: 如
for (plint iT = 0; iT < param.maxIter; iT++) {
改成
for (plint iT = iniT; iT < param.maxIter; iT++) {
|