Question about how to coupling new variables

Thanks for such amazing codes. I am a beginner and have some questions about preCICE. Specifically, I would like to create a new variable (let’s name it G). G is calculated by the velocity from my solver and OpenFOAM. For instance, read and write G_mysolver and G_OF. I am confused about how could I realize this. It seems like what I could do in the present solver is read and write velocity. My current idea is read velocity from two solvers and calculate Q in codes of preCICE-OF adapter? Does this correct or there is a better method to realize this?

Many thanks


Does this G take part in the actual coupling?

Your description sounds like this calculation could be done in a post-processing step after the simulation finished.


Thanks. For instance, let’s set G_OF=u_OF-u_solver and G_solver=u_solver-u_OF. G will be added as a source term in the NS equation. I think what I could do is create a new variable repo to store u_ and couple them. Then calculate G in solver rather than in PreCICE.

Hi @rwwww,

we actually have some documentation on adding new variables to the OpenFOAM adapter: Extend the OpenFOAM adapter | preCICE - The Coupling Library

To add a new variable to a custom OpenFOAM solver (independent of coupling), you can typically add it to your createFields.H file of the solver. If you register it to the objects’ registry, then you can modify the OpenFOAM adapter to read/write to that.

Unfortunately, you do need to modify the adapter at the moment to do that. We don’t yet support specifying arbitrary fields in the configuration to couple them, but it’s in our long-term plans.

Note that, the current documentation only covers surface-coupled fields. It you want to couple a new field in the complete domain, let me know. We will have some documentation and examples on that soon.

Thanks for detailed solution.

1 Like

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