Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog-entries/676.md
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 11 additions & 18 deletions two-scale-heat-conduction/macro-dumux/appl/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ int main(int argc, char **argv)
problem->applyInitialSolution(x);
auto xOld = x;

auto xCheckpoint = x;
double timeCheckpoint = 0.0;
int timeStepCheckpoint = 0;

// initialize the coupling data
std::vector<double> temperatures;
for (int solIdx = 0; solIdx < numberOfElements; ++solIdx) {
Expand Down Expand Up @@ -227,7 +223,9 @@ int main(int argc, char **argv)
const int vtkOutputInterval = getParam<int>("TimeLoop.OutputInterval");

// initialize preCICE
couplingParticipant.initialize();
if (runWithCoupling) {
couplingParticipant.initialize();
}

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

// initialize adapter checkpointing
if (runWithCoupling) {
couplingParticipant.initializeCheckpoint(x, *gridVariables, *timeLoop);
}

// the assembler with time loop for instationary problem
using Assembler = FVAssembler<TypeTag, DiffMethod::numeric>;
auto assembler = std::make_shared<Assembler>(problem, gridGeometry,
Expand All @@ -272,11 +275,7 @@ int main(int argc, char **argv)
break;

// write checkpoint
if (couplingParticipant.requiresToWriteCheckpoint()) {
xCheckpoint = x;
timeCheckpoint = timeLoop->time();
timeStepCheckpoint = timeLoop->timeStepIndex();
}
couplingParticipant.writeCheckpointIfRequired();

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

// reset to checkpoint if not converged
if (couplingParticipant.requiresToReadCheckpoint()) {
x = xCheckpoint;
xOld = x;
timeLoop->setTime(timeCheckpoint, timeStepCheckpoint);

// TODO: previousTimeStep might be more appropriate, last one could be small
timeLoop->setTimeStepSize(dt);
gridVariables->update(x);
if (couplingParticipant.readCheckpointIfRequired()) {
gridVariables->advanceTimeStep();
xOld = x;
continue;
}
}
Expand Down