# Does the OpenFOAM adapter support implicit coupling?

**URL:** <https://precice.discourse.group/t/does-the-openfoam-adapter-support-implicit-coupling/36>\
**Category:** Official adapters and tutorials\
**Tags:** openfoam, adapters, faq\
**Created:** [October 7, 2019, 4:52pm UTC](https://precice.discourse.group/t/does-the-openfoam-adapter-support-implicit-coupling/36 "2019-10-07T16:52:54Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [October 7, 2019, 4:52pm UTC](https://precice.discourse.group/t/does-the-openfoam-adapter-support-implicit-coupling/36/1 "2019-10-07T16:52:54Z")

</div>

The OpenFOAM adapter has the form of an [OpenFOAM function object](https://www.openfoam.com/documentation/guides/latest/doc/guide-function-objects.html). This mechanism is commonly used only for post-processing, so a reasonable question is:

> Does the OpenFOAM adapter also take care of the checkpointing? In other words, can a function object go back in time?

---

<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:** [October 8, 2019, 12:34pm UTC](https://precice.discourse.group/t/does-the-openfoam-adapter-support-implicit-coupling/36/2 "2019-10-08T12:34:53Z")

</div>

Good news: yes! You don’t need to implement anything else, the official OpenFOAM adapter is really meant to be a plugin, fully compatible with all the features of preCICE.

## But how can a function object travel back in time?

So, you are ready to dive into [the code](https://github.com/precice/openfoam-adapter). Let’s have a look into the method [`preciceAdapter::Adapter::readCheckpoint()`](https://github.com/precice/openfoam-adapter/blob/6dc2f7a30a5a0dff50a1c259f7b47a2ce868b3b3/Adapter.C#L1461):

The first thing that this method does is to overwrite the time value, restoring it to the checkpointed value, using the `setTime()` method of OpenFOAM:

```
const_cast<Time&>(runTime_).setTime(couplingIterationTimeValue_, couplingIterationTimeIndex_);

```

Good practices dictate that we should avoid using `const_cast` at all cost. However, since we don’t want to modify any line of OpenFOAM itself or of the solver, this is our only solution.

## What else is checkpointed?

After restoring the time value, the mesh points are moved to their previous locations, in a similar manner:

```
const_cast<fvMesh&>(mesh_).movePoints(meshPoints_);

```

Afterwards, every object of type `volScalarField`, `volVectorField`, `surfaceScalarField`, `surfaceVectorField`, `pointScalarField`, `pointVectorField`, `volTensorField`, `surfaceTensorField`, `pointTensorField`, `volSymmTensorField` is reloaded.

The respective methods have grown quite a while since the adapter was first written and a redesign is due, as described in [https://github.com/precice/openfoam-adapter/issues/55](https://github.com/precice/openfoam-adapter/issues/55).

For more details, you can have a look in my thesis (section 5.3.4):  
G. Chourdakis: **[A general OpenFOAM adapter for the coupling library preCICE](https://www5.in.tum.de/pub/Chourdakis2017_Thesis.pdf) [[PDF](https://www5.in.tum.de/pub/Chourdakis2017_Thesis.pdf)][[BibTeX](https://mediatum.ub.tum.de/services/export/node/1462269/?format=template_test&mask=bibtex&lang=de&template=%24%24%5Bdefaultexport%5D%24%24&mimetype=text/plain)][[MediaTum](https://mediatum.ub.tum.de/1462269)]**, Master’s thesis, Technical University of Munich, Department of Informatics, October 2017.
