# Using another solver to modify OpenFOAM-Nutils CHT tutorial

**URL:** <https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360>\
**Category:** Official adapters and tutorials\
**Tags:** openfoam, nutils\
**Created:** [October 20, 2020, 12:36pm UTC](https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360 "2020-10-20T12:36:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CarsvO](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@CarsvO](https://precice.discourse.group/u/CarsvO)\
**Post date:** [October 20, 2020, 12:36pm UTC](https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360/1 "2020-10-20T12:36:30Z")

</div>

Hello!

I am adjusting the CHT tutorial for OpenFOAM and Nutils. I have 2 questions about this.

The first is about OpenFOAM. I am using the buoyantBoussinesqSimpleFoam solver, since i want to solve the heat transfer in a turbulent fluid. (i have neglected the buoyancy term by putting the gravity to 0 and the buoyancy by putting beta to 0). I have tested this with a constant heat flux on the ‘interface’ boundary only in OpenFOAM and compared it to ansys, which validated the case. Now i am trying to run it with preCICE and get the heat flux from Nutils (I am not yet using the solver, but I first want to exchange a constant value from nutils to see if it works), however i get an error i do not know how to solve. It states:

```
-> FOAM Warning : 
    From void adapterInfo(std::string, std::string)
    in file Utilities.C at line 50
    Error (deferred - will exit later) in the preCICE adapter: 
Error in the preCICE adapter: 
Cannot find the Prandtl number in preciceDict/CHT using the name Pr

```

I do state the Prandtl number however in my transportProperties. Do you maybe know what i am doing wrong here? I have left the xml file untouched, since i want to interchange the heat flux.

The second question is about the nutils part.  
The heat flux is computed using:

```
fluxvalues = res.eval(lhs0=lhs0, lhs=lhs, dt=dt)
      writedata = couplingsampleCC.eval('-flux' @ ns, fluxdofs=fluxdofs(fluxvalues))

```

However when you evaluate the residual of the weak form, it should be (close to) 0? I don’t see how this computes the heat flux.

Thank you for your time!

Kind regards,

Cars

---

<div class="post-metadata">

**Author:** ![CarsvO](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@CarsvO](https://precice.discourse.group/u/CarsvO)\
**Post date:** [October 20, 2020, 5:38pm UTC](https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360/2 "2020-10-20T17:38:02Z")

</div>

I think it is easier if i post the files I am using for OpenFOAM. First the normal settings

[fvSolution.txt](https://precice.discourse.group/uploads/short-url/tfTnUG2agoB1Gx3DTqZoosNXcrm.txt) (1.6 KB) [preciceDict.txt](https://precice.discourse.group/uploads/short-url/uHE721SSPrCWoW7uz4lh5Ls2Cs.txt) (426 Bytes) [controlDict.txt](https://precice.discourse.group/uploads/short-url/dYky917M6KaHmXzmwxDOekgQ6ag.txt) (1.3 KB) [fvSchemes.txt](https://precice.discourse.group/uploads/short-url/6OQgTw7j9GUhTY6PUmrr1yRcLRp.txt) (1.5 KB)

[transportProperties.txt](https://precice.discourse.group/uploads/short-url/rz0kVpuZFMrzsdCXi7qb3AkGP50.txt) (1.1 KB) [turbulenceProperties.txt](https://precice.discourse.group/uploads/short-url/xtiHJzAqzw0tIKSV26IoFXkPFUa.txt) (1.1 KB) [g.txt](https://precice.discourse.group/uploads/short-url/4pgePG1HJSjA9IcsycLL2zptHnQ.txt) (933 Bytes)

---

<div class="post-metadata">

**Author:** ![CarsvO](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@CarsvO](https://precice.discourse.group/u/CarsvO)\
**Post date:** [October 20, 2020, 5:38pm UTC](https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360/3 "2020-10-20T17:38:36Z")

</div>

and the 0 folder.

[k.txt](https://precice.discourse.group/uploads/short-url/8OH561s0ThHryVQ3xMSlsfN9czN.txt) (1.5 KB) [nut.txt](https://precice.discourse.group/uploads/short-url/k9ppP0cWcAiihp2oUAIDX3H98Jy.txt) (1.5 KB) [omega.txt](https://precice.discourse.group/uploads/short-url/bEFogIDLFBAfx5PCrzcCnOtcG4E.txt) (1.5 KB) [p.txt](https://precice.discourse.group/uploads/short-url/yvw6CXYDRtvWZRREDksrVVfEB5L.txt) (1.5 KB) [p\_rgh.txt](https://precice.discourse.group/uploads/short-url/eLKdydmu4bSbdUIRM5BHqadnQ2C.txt) (1.4 KB) [T.txt](https://precice.discourse.group/uploads/short-url/3IETthBvAPO8zKFWF2Oyc8IrW5A.txt) (1.4 KB) [U.txt](https://precice.discourse.group/uploads/short-url/gjo9fw68CnpqeYAMldsXKlcnI6u.txt) (1.4 KB) [alphat.txt](https://precice.discourse.group/uploads/short-url/22Ddnn9yzeyWm9qwJqotG2Zfmmq.txt) (1.6 KB) [epsilon.txt](https://precice.discourse.group/uploads/short-url/iV3x9sy4VXLIYisHLYsXN7NYqrj.txt) (1.6 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:** [October 20, 2020, 7:57pm UTC](https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360/4 "2020-10-20T19:57:47Z")

</div>

> [@CarsvO](#):
>
> I am using the buoyantBoussinesqSimpleFoam solver, since i want to solve the heat transfer in a turbulent fluid.

I am not sure if this is a good reason to select this solver, but it is definitely supported. For the future reader: this is an incompressible (with the Boussinesq approximation for density) steady-state solver.

> [@CarsvO](#):
>
> I do state the Prandtl number however in my transportProperties. Do you maybe know what i am doing wrong here?

This is unfortunately a bit ugly, but we currently need to read the Prandtl number to [compute the heat flux](https://github.com/precice/openfoam-adapter/blob/8ae5f061ab26ae059b8cdcf304089306f9ce7227/CHT/KappaEffective.C#L133-L158). As far as I know (please correct me/refer to resources if I am wrong), this solver does not read the Prandtl number from the `transportProperties`, so we read it separately from the `preciceDict`.

I added a point in the documentation (this was previously undocumented, but I don’t remember the reason), please try modifying your `preciceDict`:

```c++
modules (CHT);

interfaces
{
  Interface1
  {
    mesh OpenFOAM-Mesh;
    patches (interface);
    
    readData
    (
      Heat-Flux
    );
    
    writeData
    (
      Temperature
    );
  };
};

CHT
{
    rho [1 -3 0 0 0 0 0] 50; // set your value
    Cp [0 2 -2 -1 0 0 0] 5; // set your value
    Pr 0.71;
};

```

It is a question how you could distinguish between the laminar and turbulent Prandtl, but the turbulent part should be already provided by OpenFOAM in `alphat` (see code I linked to above).

This is something we could improve in the future, but we currently don’t have many users using the Boussinesq solvers, so we lack some experience here.

> [@CarsvO](#):
>
> The second question is about the nutils part.

I would strongly suggest to not handle this question here, but open a separate topic.

---

<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:** [October 21, 2020, 7:06am UTC](https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360/5 "2020-10-21T07:06:02Z")

</div>

Second part handled here: [Compute flux from weak form](https://precice.discourse.group/t/compute-flux-from-weak-form/362)

---

<div class="post-metadata">

**Author:** ![CarsvO](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@CarsvO](https://precice.discourse.group/u/CarsvO)\
**Post date:** [October 21, 2020, 7:57am UTC](https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360/6 "2020-10-21T07:57:52Z")

</div>

> [@Makis](#):
>
> I am not sure if this is a good reason to select this solver, but it is definitely supported. For the future reader: this is an incompressible (with the Boussinesq approximation for density) steady-state solver.

Is a modified simpleFoam also supported then?

I might try that out so i just add another temperature equation? Another option for me would be to modify the simpleFoam solver, however with some parameteres adjusted in the buoyantBoussinesqSimpleFoam, the equations will be the same as simpleFoam with a temperature equation added.

> [@Makis](#):
>
> This is unfortunately a bit ugly, but we currently need to read the Prandtl number to [compute the heat flux](https://github.com/precice/openfoam-adapter/blob/8ae5f061ab26ae059b8cdcf304089306f9ce7227/CHT/KappaEffective.C#L133-L158). As far as I know (please correct me/refer to resources if I am wrong), this solver does not read the Prandtl number from the `transportProperties` , so we read it separately from the `preciceDict` .
> 
> I added a point in the documentation (this was previously undocumented, but I don’t remember the reason), please try modifying your `preciceDict` :

Thank you! I will try this out.

Kind regards,

Cars

---

<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 21, 2020, 8:36am UTC](https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360/7 "2020-10-21T08:36:04Z")

</div>

> [@CarsvO](#):
>
> Is a modified simpleFoam also supported then?
> 
> I might try that out so i just add another temperature equation? Another option for me would be to modify the simpleFoam solver, however with some parameteres adjusted in the buoyantBoussinesqSimpleFoam, the equations will be the same as simpleFoam with a temperature equation added.

Adding temperature to simpleFoam should also be supported if it registers temperature the same way as the standard OpenFOAM solvers, but why not use the full buoyantSimpleFoam? Why do you need the Boussinesq approximation?

---

<div class="post-metadata">

**Author:** ![CarsvO](https://avatars.discourse-cdn.com/v4/letter/c/f08c70/32.png) [@CarsvO](https://precice.discourse.group/u/CarsvO)\
**Post date:** [October 21, 2020, 10:20am UTC](https://precice.discourse.group/t/using-another-solver-to-modify-openfoam-nutils-cht-tutorial/360/8 "2020-10-21T10:20:54Z")

</div>

> [@Makis](#):
>
> Adding temperature to simpleFoam should also be supported if it registers temperature the same way as the standard OpenFOAM solvers, but why not use the full buoyantSimpleFoam? Why do you need the Boussinesq approximation?

Okay, good to know for future other solver uses! In the problem I am facing, the temperature difference/ pressure difference is not very high. Therefore incompressibility is assumed to reduce computation time. It is indeed interesting to check difference in computation time with the coupling, so I will probably do that.

> [@Makis](#):
>
> This is unfortunately a bit ugly, but we currently need to read the Prandtl number to [compute the heat flux](https://github.com/precice/openfoam-adapter/blob/8ae5f061ab26ae059b8cdcf304089306f9ce7227/CHT/KappaEffective.C#L133-L158). As far as I know (please correct me/refer to resources if I am wrong), this solver does not read the Prandtl number from the `transportProperties` , so we read it separately from the `preciceDict` .
> 
> I added a point in the documentation (this was previously undocumented, but I don’t remember the reason), please try modifying your `preciceDict` :

I have implemented it and the coupling worked! Thank you 😃
