From cb858fc9411b2c23609c6c50f545db9f8aec764a Mon Sep 17 00:00:00 2001 From: Ishaan Desai Date: Tue, 21 Oct 2025 09:41:33 +0200 Subject: [PATCH 1/5] Switch to DuMuX adapter checkpointing functionality --- .../macro-dumux/appl/main.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/two-scale-heat-conduction/macro-dumux/appl/main.cc b/two-scale-heat-conduction/macro-dumux/appl/main.cc index d36090d31..447fc89ba 100644 --- a/two-scale-heat-conduction/macro-dumux/appl/main.cc +++ b/two-scale-heat-conduction/macro-dumux/appl/main.cc @@ -173,7 +173,6 @@ int main(int argc, char **argv) problem->applyInitialSolution(x); auto xOld = x; - auto xCheckpoint = x; double timeCheckpoint = 0.0; int timeStepCheckpoint = 0; @@ -226,8 +225,11 @@ int main(int argc, char **argv) // output every vtkOutputInterval time step const int vtkOutputInterval = getParam("TimeLoop.OutputInterval"); - // initialize preCICE - couplingParticipant.initialize(); + // initialize preCICE and the adapter checkpointing + if (runWithCoupling) { + couplingParticipant.initialize(); + couplingParticipant.initializeCheckpoint(x, *gridVariables); + } // time loop parameters const auto tEnd = getParam("TimeLoop.TEnd"); @@ -272,8 +274,7 @@ int main(int argc, char **argv) break; // write checkpoint - if (couplingParticipant.requiresToWriteCheckpoint()) { - xCheckpoint = x; + if (couplingParticipant.writeCheckpointIfRequired()) { timeCheckpoint = timeLoop->time(); timeStepCheckpoint = timeLoop->timeStepIndex(); } @@ -357,9 +358,7 @@ int main(int argc, char **argv) couplingParticipant.advance(dt); // reset to checkpoint if not converged - if (couplingParticipant.requiresToReadCheckpoint()) { - x = xCheckpoint; - xOld = x; + if (couplingParticipant.readCheckpointIfRequired()) { timeLoop->setTime(timeCheckpoint, timeStepCheckpoint); // TODO: previousTimeStep might be more appropriate, last one could be small From e9365a13c54437e138d993fe11c9ff252d5cbfc5 Mon Sep 17 00:00:00 2001 From: Ishaan Desai Date: Tue, 21 Oct 2025 13:44:18 +0200 Subject: [PATCH 2/5] Remove manual checkpointing of time as the adapter handles this internally --- two-scale-heat-conduction/macro-dumux/appl/main.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/two-scale-heat-conduction/macro-dumux/appl/main.cc b/two-scale-heat-conduction/macro-dumux/appl/main.cc index 447fc89ba..12f989e74 100644 --- a/two-scale-heat-conduction/macro-dumux/appl/main.cc +++ b/two-scale-heat-conduction/macro-dumux/appl/main.cc @@ -173,8 +173,7 @@ int main(int argc, char **argv) problem->applyInitialSolution(x); auto xOld = x; - double timeCheckpoint = 0.0; - int timeStepCheckpoint = 0; + int timeStepCheckpoint = 0; // initialize the coupling data std::vector temperatures; @@ -275,7 +274,6 @@ int main(int argc, char **argv) // write checkpoint if (couplingParticipant.writeCheckpointIfRequired()) { - timeCheckpoint = timeLoop->time(); timeStepCheckpoint = timeLoop->timeStepIndex(); } @@ -359,11 +357,8 @@ int main(int argc, char **argv) // reset to checkpoint if not converged if (couplingParticipant.readCheckpointIfRequired()) { - timeLoop->setTime(timeCheckpoint, timeStepCheckpoint); - // TODO: previousTimeStep might be more appropriate, last one could be small timeLoop->setTimeStepSize(dt); - gridVariables->update(x); gridVariables->advanceTimeStep(); continue; } From 4afaba84481a2c6fea788910fca972336d9934cc Mon Sep 17 00:00:00 2001 From: Ishaan Desai Date: Wed, 22 Oct 2025 13:28:03 +0200 Subject: [PATCH 3/5] Checkpoint timestepping --- .../macro-dumux/appl/main.cc | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/two-scale-heat-conduction/macro-dumux/appl/main.cc b/two-scale-heat-conduction/macro-dumux/appl/main.cc index 12f989e74..b58efc070 100644 --- a/two-scale-heat-conduction/macro-dumux/appl/main.cc +++ b/two-scale-heat-conduction/macro-dumux/appl/main.cc @@ -173,8 +173,6 @@ int main(int argc, char **argv) problem->applyInitialSolution(x); auto xOld = x; - int timeStepCheckpoint = 0; - // initialize the coupling data std::vector temperatures; for (int solIdx = 0; solIdx < numberOfElements; ++solIdx) { @@ -224,12 +222,6 @@ int main(int argc, char **argv) // output every vtkOutputInterval time step const int vtkOutputInterval = getParam("TimeLoop.OutputInterval"); - // initialize preCICE and the adapter checkpointing - if (runWithCoupling) { - couplingParticipant.initialize(); - couplingParticipant.initializeCheckpoint(x, *gridVariables); - } - // time loop parameters const auto tEnd = getParam("TimeLoop.TEnd"); double preciceDt = couplingParticipant.getMaxTimeStepSize(); @@ -247,6 +239,12 @@ int main(int argc, char **argv) auto timeLoop = std::make_shared>(0.0, dt, tEnd); timeLoop->setMaxTimeStepSize(getParam("TimeLoop.MaxDt")); + // initialize preCICE and the adapter checkpointing + if (runWithCoupling) { + couplingParticipant.initialize(); + couplingParticipant.initializeCheckpoint(x, *gridVariables, timeLoop); + } + // the assembler with time loop for instationary problem using Assembler = FVAssembler; auto assembler = std::make_shared(problem, gridGeometry, @@ -273,9 +271,7 @@ int main(int argc, char **argv) break; // write checkpoint - if (couplingParticipant.writeCheckpointIfRequired()) { - timeStepCheckpoint = timeLoop->timeStepIndex(); - } + couplingParticipant.writeCheckpointIfRequired(); preciceDt = couplingParticipant.getMaxTimeStepSize(); solverDt = std::min(nonLinearSolver.suggestTimeStepSize(timeLoop->timeStepSize()), @@ -357,9 +353,8 @@ int main(int argc, char **argv) // reset to checkpoint if not converged if (couplingParticipant.readCheckpointIfRequired()) { - // TODO: previousTimeStep might be more appropriate, last one could be small - timeLoop->setTimeStepSize(dt); gridVariables->advanceTimeStep(); + xOld = x; continue; } } From e05c405225030426370ff39a160131087f1daab7 Mon Sep 17 00:00:00 2001 From: Ishaan Desai Date: Wed, 22 Oct 2025 14:32:25 +0200 Subject: [PATCH 4/5] Add changelog entry --- changelog-entries/676.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog-entries/676.md diff --git a/changelog-entries/676.md b/changelog-entries/676.md new file mode 100644 index 000000000..f26fa19c8 --- /dev/null +++ b/changelog-entries/676.md @@ -0,0 +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) From 7d8a5d0d7a8304ac235c6f8c95fe202e87f257e3 Mon Sep 17 00:00:00 2001 From: Ishaan Desai Date: Wed, 22 Oct 2025 17:42:04 +0200 Subject: [PATCH 5/5] Move initialize() call before time settings --- two-scale-heat-conduction/macro-dumux/appl/main.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/two-scale-heat-conduction/macro-dumux/appl/main.cc b/two-scale-heat-conduction/macro-dumux/appl/main.cc index b58efc070..5932dd22e 100644 --- a/two-scale-heat-conduction/macro-dumux/appl/main.cc +++ b/two-scale-heat-conduction/macro-dumux/appl/main.cc @@ -222,6 +222,11 @@ int main(int argc, char **argv) // output every vtkOutputInterval time step const int vtkOutputInterval = getParam("TimeLoop.OutputInterval"); + // initialize preCICE + if (runWithCoupling) { + couplingParticipant.initialize(); + } + // time loop parameters const auto tEnd = getParam("TimeLoop.TEnd"); double preciceDt = couplingParticipant.getMaxTimeStepSize(); @@ -239,10 +244,9 @@ int main(int argc, char **argv) auto timeLoop = std::make_shared>(0.0, dt, tEnd); timeLoop->setMaxTimeStepSize(getParam("TimeLoop.MaxDt")); - // initialize preCICE and the adapter checkpointing + // initialize adapter checkpointing if (runWithCoupling) { - couplingParticipant.initialize(); - couplingParticipant.initializeCheckpoint(x, *gridVariables, timeLoop); + couplingParticipant.initializeCheckpoint(x, *gridVariables, *timeLoop); } // the assembler with time loop for instationary problem