Step 5 – Non-matching time step sizes
In previous steps, you have already seen that there are quite some things going on with time step sizes. Let us now have a look at what is actually happening.
...
double solverDt; // solver time step size
double preciceDt; // maximum precice time step size
double dt; // actual time step size
precice.initialize();
while (not simulationDone()){ // time loop
preciceDt = precice.getMaxTimeStepSize();
solverDt = beginTimeStep(); // e.g. compute adaptive dt
dt = min(preciceDt, solverDt);
solveTimeStep(dt);
precice.advance(dt);
endTimeStep(); // e.g. update variables, increment time
}
...
solver_dt = 0 # solver time step size
precice_dt = 0 # maximum precice time step size
dt = 0 # actual time step size
precice.initialize()
while not simulation_done(): # time loop
precice_dt = precice.get_max_time_step_size()
solver_dt = begin_time_step() # e.g. compute adaptive dt
dt = min(precice_dt, solver_dt)
solve_time_step(dt)
precice.advance(dt)
end_time_step() # e.g. update variables, increment time
Good thing to know: in this step, you do really not have to alter your code. Everything needed is already there and can be configured. :relieved:
There are basically two options to choose from in the configuration.
<time-window-size value="..." method="..."/>
method can be:
fixed: A fixed time window with sizevalueis prescribed, during which both participants can use whatever time step sizes they want. Communication of coupling data happens only after each time window.first-participant: The first participant prescribes the time step size for the second one. Communication of coupling data happens after each time step. This option is only available for serial coupling schemes (more about configuration of coupling schemes ). The attributevalueis not applicable.
Let us take a closer look at both options. This section covers only the basics. You can find more information in the advanced section .
Fixed time window
The preCICE configuration defines a fixed time window. Both participants can use smaller time step sizes, but then they subcycle, i.e. coupling data is only communicated at the end of each time window. The figure below illustrates this procedure (k is the subcycling index, the dashed lines mark the time window):

After each time step, both participants tell preCICE which time step size
dtthey just used by callingprecice.advance(dt). This way, preCICE can keep track of the total time.preciceDtis the remainder time to the next window:preciceDt = precice.getMaxTimeStepSize(); ```precice_dt = precice.get_max_time_step_size() ```Both participants compute their next (adaptive) time step size. It can be larger or smaller than the remainder
preciceDt.solverDt = beginTimeStep(); ```solver_dt = begin_time_step() ```If it is larger, the remainder
preciceDtis used instead (orange participant, dark orange is used). If it is smaller, the participant’s time step sizesolverDtcan be used (blue participant, dark blue is used). These two cases are reflected in:dt = min(preciceDt, solverDt) ```dt = min(precice_dt, solver_dt) ```Once both participants reach the end of the time window, coupling data is exchanged.
First participant prescribes time step size
The first participant sets the time step size. This requires that the second participant runs after the first one. Thus, as stated above, this option is only applicable for serial coupling.

The blue participant B is
firstand computes a step with its time step size (Step 1).In
advance, this time step size is given to preCICE (Step 2).precice.advance(dt); ```precice.advance(dt) ```preCICE has tracked the time level of the orange participant A and returns the remainder to reach B’s time step size.
preciceDt = precice.getMaxTimeStepSize(); ```precice_dt = precice.get_max_time_step_size() ```A computes its next (adaptive) time step size. It can now be larger or smaller than the remainder.
solverDt = beginTimeStep(); ```solver_dt = begin_time_step() ```If it is larger, the remainder
preciceDtis used instead (the case below in Step 3, dark orange is used). If it is smaller, the participant’s time step sizesolverDtcan be used (not visualized). These two cases are again reflected in the formula:dt = min(preciceDt, solverDt); ```dt = min(precice_dt, solver_dt) ```The procedure starts over with the blue participant B.
preciceDt on the blue side is always infinity such that min(solverDt,preciceDt)==solverDt.fixed and first-participant time-stepping. Everything can be configured. Even if implicit coupling is used.Steering the end of the simulation
One last thing about time. There is also a helper function in preCICE that allows you to steer the end of a coupled simulation:
bool isCouplingOngoing();
is_ongoing = is_coupling_ongoing()
This functions looks at max-time-windows and max-time as defined in the preCICE configuration and knows when it is time to go. Then, you should call finalize. It replaces your simulationDone().
while (precice.isCouplingOngoing()){ // time loop
...
}
precice.finalize();
while precice.is_coupling_ongoing(): # time loop
...
precice.finalize()