# isCouplingOngoing error

**URL:** <https://precice.discourse.group/t/iscouplingongoing-error/507>\
**Category:** Using preCICE\
**Tags:** adapters, mbdyn, python\
**Created:** [March 7, 2021, 11:19am UTC](https://precice.discourse.group/t/iscouplingongoing-error/507 "2021-03-07T11:19:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![alicezanella](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/alicezanella/32/589_2.png) [@alicezanella](https://precice.discourse.group/u/alicezanella)\
**Post date:** [March 7, 2021, 11:19am UTC](https://precice.discourse.group/t/iscouplingongoing-error/507/1 "2021-03-07T11:19:40Z")

</div>

Hello everyone,

I’m still a preCICE beginner and I cannot understand what could cause this error. The simulation starts regularly and goes on until the **max-time value** is reached. I even tried to input a bigger max-time value, but the error still shows up.

`ERROR: advance() cannot be called when isCouplingOngoing() returns false`

I’m using a mbdyn adapter written in python (not the one on github) and I’m trying a dummy test case, so mbdyn is the only solver involved.

I hypothesized that the simulation cannot reach the finalize step, but I cannot understand why.

Does anyone of you ever encountered a similar error?

Thank you,

_Alice_

---

<div class="post-metadata">

**Author:** ![ajaust](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/ajaust/32/160_2.png) [@ajaust](https://precice.discourse.group/u/ajaust)\
**Post date:** [March 7, 2021, 12:28pm UTC](https://precice.discourse.group/t/iscouplingongoing-error/507/2 "2021-03-07T12:28:54Z")

</div>

It basically means that you call preCICE to advance the coupling even though your simulation has reached the `max-time` value. Either your simulation is running further then it should, there is some configuration issue or your dummy does something wrong.

When you check the adapter exampled here [Step 6 – Implicit coupling | preCICE - The Coupling Library](https://www.precice.org/couple-your-code-implicit-coupling.html), you see that it looks something like (note that the example is C++, but it would look similar in Python)

```
[...]
while (precice.isCouplingOngoing()){
  [...]
  precice_dt = precice.advance(dt);
  [...]
}

```

So `advance` can only be called when `isCouplingOngoing()` is true. I would assume that you have the `advance` call not inside a loop that checks `isCouplingOngoing()` all the time.

Could you show us your dummy and your configuration files to see what is wrong?

---

<div class="post-metadata">

**Author:** ![alicezanella](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/alicezanella/32/589_2.png) [@alicezanella](https://precice.discourse.group/u/alicezanella)\
**Post date:** [March 8, 2021, 7:58am UTC](https://precice.discourse.group/t/iscouplingongoing-error/507/3 "2021-03-08T07:58:35Z")

</div>

Hi @ajaust

I suspected something like what you’ve just said, but I couldn’t find the error in the code.  
I’m attaching the adapter I’m using (it’s a .txt because it wouldn’t let me upload a .py file)  
[mbdynAdapter.txt](https://precice.discourse.group/uploads/short-url/mrLL8oQz8UqSEM5CNSawuBwocfn.txt) (9.6 KB)  
[mbdynInterface.txt](https://precice.discourse.group/uploads/short-url/7OMEvTDy2ItJaHzeAYrLEAOibWL.txt) (7.9 KB)

Here is also the config:  
[precice-config.xml](https://precice.discourse.group/uploads/short-url/13xlenUN3yYjVS05HESMGRW2n2g.xml) (2.4 KB)

---

<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:** [March 8, 2021, 8:14am UTC](https://precice.discourse.group/t/iscouplingongoing-error/507/4 "2021-03-08T08:14:58Z")

</div>

I see two time-related problems here.

The first one is what you report here. Let’s look at the code:

```python
      is_ongoing = self.interface.is_coupling_ongoing()
      dt_precice = self.interface.advance(dt)

```

The missing key here is that the value of `is_coupling_ongoing()` gets updated during `advance()`, so you need to swap these two statememnts.

The second problem (which will appear later) is that you are currently using an implicit coupling scheme, but are not writing/reading checkpoint (including going back in time).

Have a look at the time logging of MBDyn and of preCICE. I guess that these two report different times.  
preCICE does not know the absolute time, it only knows what timestep size it dictated, and it expects that this timestep size is correctly applied. Therefore, while preCICE expects that you go back in time when a coupling time window has not convered, MBDyn still keeps going further.

---

<div class="post-metadata">

**Author:** ![alicezanella](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/alicezanella/32/589_2.png) [@alicezanella](https://precice.discourse.group/u/alicezanella)\
**Post date:** [March 8, 2021, 8:27am UTC](https://precice.discourse.group/t/iscouplingongoing-error/507/5 "2021-03-08T08:27:58Z")

</div>

Thank you for your reply!  
The first thing you suggested solved the problem and the dummy simulation could properly end with `finalize()`.

The second problem you mentioned is a bit more tricky for me, because I’m not sure which files should I look into. I didn’t build the debug version of preCICE, maybe I should switch to that.

---

<div class="post-metadata">

**Author:** ![ajaust](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/ajaust/32/160_2.png) [@ajaust](https://precice.discourse.group/u/ajaust)\
**Post date:** [March 8, 2021, 8:50am UTC](https://precice.discourse.group/t/iscouplingongoing-error/507/6 "2021-03-08T08:50:19Z")

</div>

Hi @alicezanella!

Did you check out the documentation about implicit coupling [Step 6 – Implicit coupling | preCICE - The Coupling Library](https://www.precice.org/couple-your-code-implicit-coupling.html) or even the full documentation about writing an adapter that starts here [Step 1 – Preparation | preCICE - The Coupling Library](https://www.precice.org/couple-your-code-preparing-your-solver.html)? It explains very nicely what to do and also why. The code examples are in C++. but this should not scare you. The steps you have to implement are the same for the Python-Interface and most of them you have already implemented.

---

<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:** [March 8, 2021, 9:11am UTC](https://precice.discourse.group/t/iscouplingongoing-error/507/7 "2021-03-08T09:11:46Z")

</div>

> [@alicezanella](#):
>
> The second problem you mentioned is a bit more tricky for me, because I’m not sure which files should I look into. I didn’t build the debug version of preCICE, maybe I should switch to that.

You don’t need the debug version for that, the preCICE information messages include the time information. But let’s discuss this in a separate, linked thread if needed. 🙂

---

<div class="post-metadata">

**Author:** ![alicezanella](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/alicezanella/32/589_2.png) [@alicezanella](https://precice.discourse.group/u/alicezanella)\
**Post date:** [March 8, 2021, 3:08pm UTC](https://precice.discourse.group/t/iscouplingongoing-error/507/8 "2021-03-08T15:08:05Z")

</div>

Thank you @Makis! 🙂  
I’ll try and see if I can modify the code with your suggestions and the preCICE documentation and if I have more questions I’ll open a linked thread. 💪

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/precice/original/1X/67d2a5fa6f80e597e2267ff17fa8c1673cd11caa.svg) [@system](https://precice.discourse.group/u/system)\
**Post date:** [March 11, 2021, 3:08pm UTC](https://precice.discourse.group/t/iscouplingongoing-error/507/9 "2021-03-11T15:08:14Z")

</div>

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
