Skip to content

Commit 5fcf9c6

Browse files
authored
Switch to adapter-based checkpointing in the two-scale heat conduction tutorial (#676)
* Switch to DuMuX adapter checkpointing functionality * Remove manual checkpointing of time as the adapter handles this internally * Checkpoint timestepping * Add changelog entry * Move initialize() call before time settings
1 parent 65f010d commit 5fcf9c6

File tree

2 files changed

+12
-18
lines changed
  • changelog-entries
  • two-scale-heat-conduction/macro-dumux/appl

2 files changed

+12
-18
lines changed

changelog-entries/676.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Switched to adapter-based checkpointing in the macro-dumux participant of the two-scale heat conduction tutorial [#676](https://github.com/precice/tutorials/pull/676)

two-scale-heat-conduction/macro-dumux/appl/main.cc

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,6 @@ int main(int argc, char **argv)
173173
problem->applyInitialSolution(x);
174174
auto xOld = x;
175175

176-
auto xCheckpoint = x;
177-
double timeCheckpoint = 0.0;
178-
int timeStepCheckpoint = 0;
179-
180176
// initialize the coupling data
181177
std::vector<double> temperatures;
182178
for (int solIdx = 0; solIdx < numberOfElements; ++solIdx) {
@@ -227,7 +223,9 @@ int main(int argc, char **argv)
227223
const int vtkOutputInterval = getParam<int>("TimeLoop.OutputInterval");
228224

229225
// initialize preCICE
230-
couplingParticipant.initialize();
226+
if (runWithCoupling) {
227+
couplingParticipant.initialize();
228+
}
231229

232230
// time loop parameters
233231
const auto tEnd = getParam<Scalar>("TimeLoop.TEnd");
@@ -246,6 +244,11 @@ int main(int argc, char **argv)
246244
auto timeLoop = std::make_shared<TimeLoop<Scalar>>(0.0, dt, tEnd);
247245
timeLoop->setMaxTimeStepSize(getParam<Scalar>("TimeLoop.MaxDt"));
248246

247+
// initialize adapter checkpointing
248+
if (runWithCoupling) {
249+
couplingParticipant.initializeCheckpoint(x, *gridVariables, *timeLoop);
250+
}
251+
249252
// the assembler with time loop for instationary problem
250253
using Assembler = FVAssembler<TypeTag, DiffMethod::numeric>;
251254
auto assembler = std::make_shared<Assembler>(problem, gridGeometry,
@@ -272,11 +275,7 @@ int main(int argc, char **argv)
272275
break;
273276

274277
// write checkpoint
275-
if (couplingParticipant.requiresToWriteCheckpoint()) {
276-
xCheckpoint = x;
277-
timeCheckpoint = timeLoop->time();
278-
timeStepCheckpoint = timeLoop->timeStepIndex();
279-
}
278+
couplingParticipant.writeCheckpointIfRequired();
280279

281280
preciceDt = couplingParticipant.getMaxTimeStepSize();
282281
solverDt = std::min(nonLinearSolver.suggestTimeStepSize(timeLoop->timeStepSize()),
@@ -357,15 +356,9 @@ int main(int argc, char **argv)
357356
couplingParticipant.advance(dt);
358357

359358
// reset to checkpoint if not converged
360-
if (couplingParticipant.requiresToReadCheckpoint()) {
361-
x = xCheckpoint;
362-
xOld = x;
363-
timeLoop->setTime(timeCheckpoint, timeStepCheckpoint);
364-
365-
// TODO: previousTimeStep might be more appropriate, last one could be small
366-
timeLoop->setTimeStepSize(dt);
367-
gridVariables->update(x);
359+
if (couplingParticipant.readCheckpointIfRequired()) {
368360
gridVariables->advanceTimeStep();
361+
xOld = x;
369362
continue;
370363
}
371364
}

0 commit comments

Comments
 (0)