# Understanding implementation of Forces in OpenFOAM adapter

**URL:** <https://precice.discourse.group/t/understanding-implementation-of-forces-in-openfoam-adapter/1967>\
**Category:** Official adapters and tutorials\
**Tags:** openfoam, adapters\
**Created:** [June 14, 2024, 1:39pm UTC](https://precice.discourse.group/t/understanding-implementation-of-forces-in-openfoam-adapter/1967 "2024-06-14T13:39:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![openFoe](https://avatars.discourse-cdn.com/v4/letter/o/a9a28c/32.png) [@openFoe](https://precice.discourse.group/u/openFoe)\
**Post date:** [June 14, 2024, 1:39pm UTC](https://precice.discourse.group/t/understanding-implementation-of-forces-in-openfoam-adapter/1967/1 "2024-06-14T13:39:17Z")

</div>

Hello,  
I am running preCICE 3.1.1 and OpenFOAM v2312 and am working on implementing a custom adapter.  
I have a question regarding the implementation of the Forces module. In Forces.C we check whether some other part of OpenFOAM (forces functionObject, solids4Foam) has already calculated the forces, correct?

```
 // Check if a force field with the requested name exists.
 // If yes (e.g., solids4Foam), bind Force_ to that field.
 // If not (e.g., pimpleFoam without the Forces function object), create it.
 if (mesh_.foundObject<volVectorField>(nameForce))
 {
     Force_ =
         &const_cast<volVectorField&>(
             mesh_.lookupObject<volVectorField>(nameForce));
 }

```

`nameForce` defaults to `Force` according to FSI.C

```
    nameForce_ = FSIdict.lookupOrDefault<word>("nameForce", "Force");
    DEBUG(adapterInfo(" force field name : " + nameForce_));

```

However, in forces.C (from functionObject) the name of the forces volVectorField is `force`

```
        forcePtr = new volVectorField
        (
            IOobject
            (
                scopedName("force"),
                time_.timeName(),
                mesh_,
                IOobject::NO_READ,
                IOobject::NO_WRITE,
                IOobject::REGISTER
            ),
            mesh_,
            dimensionedVector(dimForce, Zero)
        );

```

So it seems to me, like we want to benefit from taking the pre-calculated forces from those sources, but we don’t due to the wrong `nameForce`.  
Am I missing something?

Thanks  
David

---

<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:** [July 18, 2024, 1:25pm UTC](https://precice.discourse.group/t/understanding-implementation-of-forces-in-openfoam-adapter/1967/2 "2024-07-18T13:25:09Z")

</div>

We currently compute the forces independently, indeed (though we would like to offload that the the `forces` function object: [FSI: Delegate the force calculation to the forces function object · Issue #143 · precice/openfoam-adapter · GitHub](https://github.com/precice/openfoam-adapter/issues/143)).

Have you already tried configuring a different name (`force`) for the coupled variable?

> **[Configure the OpenFOAM adapter](https://precice.org/adapter-openfoam-config.html#parameters-and-fields-with-different-names)**
>
> Write a system/preciceDict, set compatible boundary conditions, and activate the adapter in your system/controlDict.

The main target here was to cover the `solidForce` that the solid solver of solids4Foam uses.

---

<div class="post-metadata">

**Author:** ![openFoe](https://avatars.discourse-cdn.com/v4/letter/o/a9a28c/32.png) [@openFoe](https://precice.discourse.group/u/openFoe)\
**Post date:** [July 18, 2024, 2:33pm UTC](https://precice.discourse.group/t/understanding-implementation-of-forces-in-openfoam-adapter/1967/3 "2024-07-18T14:33:12Z")

</div>

Aaah ok. So the current default is to use the forces calculated by the adapter, but it should be possible to use the forces calculated by either solids4Foam or the forces functionObject by specifying a different name. I haven’t tried using `force` as a name yet.
