# Deadlock during multi-coupling

**URL:** https://precice.discourse.group/t/deadlock-during-multi-coupling/835
**Category:** Using preCICE
**Tags:** openfoam, communication, fsi
**Created:** [December 17, 2021, 7:37pm UTC](https://precice.discourse.group/t/deadlock-during-multi-coupling/835 "2021-12-17T19:37:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![arslansadiq](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/arslansadiq/32/849_2.png) [@arslansadiq](https://precice.discourse.group/u/arslansadiq)
#### Post date: [December 17, 2021, 7:37pm UTC](https://precice.discourse.group/t/deadlock-during-multi-coupling/835/1 "2021-12-17T19:37:55Z")

</div>

Hi,  
I am trying to work with an FSI problem which involves 3 participants:

- Solid
- Fluid1
- Fluid2 (openfoam adapter `pimplefoam`)

like this:

 ![Screenshot from 2021-12-17 20-07-47](https://global.discourse-cdn.com/free1/uploads/precice/original/2X/f/ff23a3eb961d1239a8c0a56c445e24ee0130ac13.png)

Fluid1 talks to Solid and Fluid2. Solid talks to Fluid1 only and Fluid2 talks to Fluid1 only.

I am using **multi-coupling scheme** and Fluid1 is controller participant.

My problem is that, when I try to run the simulation, it sticks into a deadlock and doesn’t move ahead.

I am attching following content here:

- preCICE config file  
[precice-config.xml](https://precice.discourse.group/uploads/short-url/yvqV7U3w4Ekfg72yYR5S3gCDBY1.xml) (8.6 KB)

- log file for Fluid1 participant  
[fluid1.log](https://precice.discourse.group/uploads/short-url/t7vBOllb6a5RMFeEllYfOS2mJDB.log) (106.0 KB)

- log file for Fluid2 participant  
[fluid2.log](https://precice.discourse.group/uploads/short-url/pIRXe9BnC0ITFMwBYI7ZmRLaYLF.log) (89.0 KB)

- log file for Solid participant  
[solid.log](https://precice.discourse.group/uploads/short-url/hETL8RySZrxPNI1pEoXOwhcuWOa.log) (83.9 KB)

**CODE**

- code from main solver loop of Fluid1
- code from main solver loop of Solid

it seems to me that, fluid2 and solid enters into receive and the code runs into a deadlock. The Fluid2 is using and openfoam solver: pimplefoam.

**CODE:**

The main sover loop for **`Fluid1`** is:

```
while (interface.is_coupling_ongoing()):# and interface.is_coupling_ongoing()):
    # When an implicit coupling scheme is used, checkpointing is required
    if interface.is_action_required(action_write_iteration_checkpoint()):
        interface.mark_action_fulfilled(action_write_iteration_checkpoint())
    
    velocity, pressure, success = perform_partitioned_implicit_euler_step(
        velocity_old, pressure_old, crossSectionLength_old, crossSectionLength, dx, precice_dt, velocity_in(
            t + precice_dt), custom_coupling=True)
    interface.write_vector_data(velocityID_fluid, vertexIDs_fluid1tofluid2, [0.0, 0.0, velocity[-1]])
    pressure_solid_send = pressure[0:51]
    interface.write_block_scalar_data(pressureID_solid, vertexIDs_fluid1tosolid, pressure_solid_send)

    interface.advance(precice_dt)
    
    pressure[-1] = interface.read_scalar_data(pressureID_fluid, vertexIDs_fluid1tofluid2)

    crossSectionLength_recv = interface.read_block_scalar_data(
        crossSectionLengthID, vertexIDs_fluid1tosolid)
    crossSectionLength[0:51] = crossSectionLength_recv
   
    # i.e. not yet converged
    if interface.is_action_required(action_read_iteration_checkpoint()):
        interface.mark_action_fulfilled(action_read_iteration_checkpoint())
    else: # converged, timestep complete
        t += precice_dt
        velocity_old = np.copy(velocity)
        pressure_old = np.copy(pressure)
        crossSectionLength_old = np.copy(crossSectionLength)
        time_it += 1

```

the main solver loop for the **`Solid`** participant is:

```
while interface.is_coupling_ongoing():
    # When an implicit coupling scheme is used, checkpointing is required
    if interface.is_action_required(action_write_iteration_checkpoint()):
        interface.mark_action_fulfilled(action_write_iteration_checkpoint())

    crossSectionLength = crossSection0 * (
        (pressure0 - 2.0 * c_mk **2)** 2 / (pressure - 2.0 * c_mk **2)** 2)
    interface.write_block_scalar_data(crossSectionLengthID, vertexIDs, crossSectionLength)
    precice_dt = interface.advance(precice_dt)
    pressure = interface.read_block_scalar_data(pressureID, vertexIDs)

    if interface.is_action_required(action_read_iteration_checkpoint()): # i.e. not yet converged
        interface.mark_action_fulfilled(action_read_iteration_checkpoint())
    else:
        t += precice_dt

```

Please let me know if there anything which I am missing either from config file or code.

For ease, following is the config visualization:

 ![Screenshot from 2021-12-17 20-36-23](https://global.discourse-cdn.com/free1/uploads/precice/original/2X/e/e80844822b8f6903e02c38c449c90a3a5e475a5e.png)

---

<div class="post-metadata">

### Author: ![uekerman](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/uekerman/32/2199_2.png) [@uekerman](https://precice.discourse.group/u/uekerman)
#### Post date: [December 19, 2021, 1:32pm UTC](https://precice.discourse.group/t/deadlock-during-multi-coupling/835/2 "2021-12-19T13:32:00Z")

</div>

Hi @arslansadiq 👋

I didn’t spot any any obvious mistakes in your setup.

What happens if you use

```xml
initialize="true"

```

in all `exchange` tags. I could imagine this could indeed be buggy in preCICE.

Other recommendations:

- Try to restrict your logging to make it more readable. The first example from [Logging configuration | preCICE - The Coupling Library](https://precice.org/configuration-logging.html#examples) is a good setting to start with.
- Personal taste: I find the naming scheme you use a bit confusing. `PressureSolid` for example sounds like the pressure of the solid. Or `SolidToFluid-Mesh` sounds like a mapping. Maybe names like `PressureBack`, `PressureOutflow`, `PressureUpstream`, `FluidRadialMesh`, `FluidOuterWallMesh` etc could help.

---

<div class="post-metadata">

### Author: ![arslansadiq](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/arslansadiq/32/849_2.png) [@arslansadiq](https://precice.discourse.group/u/arslansadiq)
#### Post date: [December 19, 2021, 3:54pm UTC](https://precice.discourse.group/t/deadlock-during-multi-coupling/835/3 "2021-12-19T15:54:48Z")

</div>

Hi,  
thank you for your suggestion. By putting initialization tag it works as intended. BTW can you tell me what difference does this make?

---

<div class="post-metadata">

### Author: ![uekerman](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/uekerman/32/2199_2.png) [@uekerman](https://precice.discourse.group/u/uekerman)
#### Post date: [December 20, 2021, 8:41am UTC](https://precice.discourse.group/t/deadlock-during-multi-coupling/835/4 "2021-12-20T08:41:04Z")

</div>

OK, then this is indeed a bug. It should be allowed that you initialize some, but not all data. If you only couple two participants this work. But if you couple three, the third participant does not get informed (apparently). I guess this is simply a case we never had before. Could you please open an issue? Please attach the “good” and the “bad” config.

Information on data initialization: [Step 7 - Data initialization | preCICE - The Coupling Library](https://precice.org/couple-your-code-initializing-coupling-data.html)

---

<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: [December 20, 2021, 8:56am UTC](https://precice.discourse.group/t/deadlock-during-multi-coupling/835/5 "2021-12-20T08:56:25Z")

</div>

> [@uekerman](#):
>
> I guess this is simply a case we never had before.

But this is the same as the multiple perpendicular flaps tutorial, right? [Multiple perpendicular flaps | preCICE - The Coupling Library](https://precice.org/tutorials-multiple-perpendicular-flaps.html)

---

<div class="post-metadata">

### Author: ![uekerman](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/uekerman/32/2199_2.png) [@uekerman](https://precice.discourse.group/u/uekerman)
#### Post date: [December 20, 2021, 9:07am UTC](https://precice.discourse.group/t/deadlock-during-multi-coupling/835/6 "2021-12-20T09:07:10Z")

</div>

No, there we don’t initialize any data:

```xml
      <exchange data="Stress1" mesh="Fluid1-Mesh-Centers" from="Fluid" to="Solid1" />
      <exchange data="Stress2" mesh="Fluid2-Mesh-Centers" from="Fluid" to="Solid2" />
      <exchange data="Displacement1" mesh="Solid1-Mesh" from="Solid1" to="Fluid" />
      <exchange data="Displacement2" mesh="Solid2-Mesh" from="Solid2" to="Fluid" />

```

---

<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: [December 20, 2021, 9:54am UTC](https://precice.discourse.group/t/deadlock-during-multi-coupling/835/7 "2021-12-20T09:54:14Z")

</div>

Ah, I now see that we are actually initializing the CrossSectionLength and I understand that this is the untested situation, then.
