# Tiny max-time-step-size problem

**URL:** <https://precice.discourse.group/t/tiny-max-time-step-size-problem/2420>\
**Category:** Using preCICE\
**Created:** [April 6, 2025, 2:05pm UTC](https://precice.discourse.group/t/tiny-max-time-step-size-problem/2420 "2025-04-06T14:05:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ya\_Squall](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/ya_squall/32/2265_2.png) [@Ya\_Squall](https://precice.discourse.group/u/Ya_Squall)\
**Post date:** [April 6, 2025, 2:05pm UTC](https://precice.discourse.group/t/tiny-max-time-step-size-problem/2420/1 "2025-04-06T14:05:27Z")

</div>

After conducting dozens of coupling test runs using **PreCICE v3.1.2** , I observed that occasionally, an _extremely small max-time-step-size_ issue arises, causing the simulation to hang indefinitely. This occurs because once the time step becomes excessively small, OpenFOAM gradually increases its allowed step size, leading to negligible progress in physical time—effectively stalling the simulation.

To mitigate this issue, I implemented a temporary variable (`timestepBeforeTiny_`) to store the normal OpenFOAM-determined time step (`timestepSolverDetermined`) just before the problem occurs. This allows me to force OpenFOAM to revert to the previously recorded stable step size, quickly restoring normal simulation progress.

I noticed that this problem happens more frequently when I use relatively large time-window-size and more participants. For instance, in the tests involving 4 participants, this problems happens every 3 out of 10 runs.

---

<div class="post-metadata">

**Author:** ![Makis](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/makis/32/25_2.png) [@Makis](https://precice.discourse.group/u/Makis)\
**Post date:** [April 9, 2025, 6:50am UTC](https://precice.discourse.group/t/tiny-max-time-step-size-problem/2420/2 "2025-04-09T06:50:16Z")

</div>

@Ya_Squall thank you for reporting this! There were a couple of related bugs in v3.1.2, which must have been fixed in [v3.2.0](https://github.com/precice/precice/releases/tag/v3.2.0). I strongly suggest that you upgrade. Read the announcement:

> [@Highlights of the new preCICE release v3.2](https://precice.discourse.group/t/highlights-of-the-new-precice-release-v3-2/2410):
>
> [[DOI]](https://doi.org/10.5281/zenodo.15125573) Summary: Important long-term features see great progress with the [new release preCICE release v3.2](https://github.com/precice/precice/releases/tag/v3.2.0), such as different options to handle dynamic meshes. Other features were finally wrapped up and integrated, for instance, performance improvements in quasi-Newton filtering and preconditioning that we [published 3 years ago](https://www.mdpi.com/2297-8747/27/3/40). Read this blog article to learn about the highlights. Just-in-time data mapping You can now read and write data at temporary coordinates instead of static vertex IDs. T…

Regarding the change in the OpenFOAM adapter, feel free to open a pull request if you think this is something we should anyway add:

[https://github.com/precice/openfoam-adapter/pulls](https://github.com/precice/openfoam-adapter/pulls)

---

<div class="post-metadata">

**Author:** ![fsimonis](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/fsimonis/32/6_2.png) [@fsimonis](https://precice.discourse.group/u/fsimonis)\
**Post date:** [April 9, 2025, 1:55pm UTC](https://precice.discourse.group/t/tiny-max-time-step-size-problem/2420/3 "2025-04-09T13:55:15Z")

</div>

In some situations you may need to extend a substep to prevent a tiny final substep.

This is covered here:

> **[Step 5 – Non-matching time step sizes](https://precice.org/couple-your-code-time-step-sizes.html#possible-subcycling-pitfall)**
>
> In this step, you learn how preCICE handles non-matching time step sizes and a few more things about simulation time.

In essence, you define a min timestep size and check if the remainder of the time window is larger than the desired time step plus the min time step size. If that is not the case, then you finish the time window.

dt = \begin{cases} dt\_{solver}, & \text{if } dt\_{solver} + dt\_{min} \lt dt\_{preCICE} \\ dt\_{preCICE}, & \text{otherwise} \end{cases}

---

<div class="post-metadata">

**Author:** ![Ya\_Squall](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/ya_squall/32/2265_2.png) [@Ya\_Squall](https://precice.discourse.group/u/Ya_Squall)\
**Post date:** [April 9, 2025, 2:22pm UTC](https://precice.discourse.group/t/tiny-max-time-step-size-problem/2420/4 "2025-04-09T14:22:09Z")

</div>

I believe this is already implemented in the OpenFOAM adaptor, and also in my own code:

```
    double tolerance = 1e-12;
    if (precice_->getMaxTimeStepSize() - timestepSolverDetermined > tolerance)
    {
        timestepSolver_ = timestepSolverDetermined;
    }
    else if (timestepSolverDetermined - precice_->getMaxTimeStepSize() > tolerance)
    {
        timestepSolver_ = precice_->getMaxTimeStepSize();
    }
    else
    {
        adapterInfo("The solver's timestep is the same as the "
                          "coupling timestep.", "info");
        timestepSolver_ = precice_->getMaxTimeStepSize();
    }
    if (precice_->getMaxTimeStepSize() <= tolerance)
    {
        //- Such a small value can happen if you use many substeps per time window over multiple time windows due to added-up differences of machine precision.
        timestepBeforeTiny_ = timestepSolverDetermined;
        tinyStepHappened_ = true;
    }

```
