CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Coupling to external code using MPI calls from within a solver (https://www.cfd-online.com/Forums/openfoam-programming-development/195116-coupling-external-code-using-mpi-calls-within-solver.html)

Regis_ October 31, 2017 10:50

Coupling to external code using MPI calls from within a solver
 
Hi everyone. I'm trying to couple OpenFOAM to an external code but I'm having trouble where exactly to start. My main issue is how to make MPI calls from within a solver

So here's what I'm trying to achieve:
1. An external code will request velocities at certain positions and send forces to be added to the momentum equations (at slightly different positions, also passed to OpenFOAM)
2. OpenFOAM would add the forces to the flowfield and get the velocities requested and send back.
3. Loop. The external code gets the velocities, does its thing, and return external forces to be added and array of new locations of the velocities needed.

So ideally I need this to occur at every timestep, say, after we have runTime.write() within a solver. I do have the source code of the external application but can't modify substantially. The exchange of information needs to be done by means of MPI function calls, like mpi_send() and mpi_recv().

I've been looking into the UPstream class which directly includes mpi.h and have known functions (to me) like MPI_Comm_rank. I was also able to play around how the master process communicates with its slave, but all within a decomposed case. I'm interested in learning the syntax I need to use the 'call' and 'receive' MPI functions because these need to be "connected" to the external code. I would also need to implement the "handshake" between both codes, and I'm not sure if this should be done within the solver (before the main loop) or somewhere else.

I've been looking around and going through the code but I'm still stuck. If anyone have any tips or anything, I'd love to hear. I'm also interested in the big picture of how to make such coupling work, if my approach is not a good one.


All times are GMT -4. The time now is 00:23.