Feasibility of using a custom Python solver (or Neural Network) to replace OpenFOAM in an FSI coupling with CalculiX

Dear preCICE developers and community members,

First of all, I’d like to say thank you for developing and maintaining this powerful open-source coupling library. I am a new user exploring the capabilities of preCICE for a research project, and I am very impressed so far.

I am currently working with the standard fluid-structure interaction (FSI) tutorials, specifically the case of coupling OpenFOAM (for the fluid domain) with CalculiX (for the solid domain). This setup works well and has provided me with a great starting point.

My research objective is to explore alternative approaches for the fluid solver. Specifically, I want to replace the OpenFOAM solver and its corresponding adapter with a custom-built participant written in Python. The CalculiX participant and its adapter would remain unchanged.

I envision two potential scenarios for my Python-based participant:

  1. A simplified, custom Python solver: A script that receives boundary data (e.g., displacements from CalculiX), performs some calculations (e.g., using simplified physics models or surrogate models), and sends back the resulting data (e.g., forces) to CalculiX.
  2. A data-driven Neural Network (NN) solver: A more advanced version where the Python script loads a pre-trained neural network. This NN would take the structural displacements as input and directly predict the fluid forces on the structure, effectively acting as the entire fluid solver.

From an architectural standpoint, does preCICE support such a workflow? In other words, is it feasible to have a “heterogeneous” coupling where one participant is a traditional FEM solver (CalculiX) and the other is a custom Python script (acting as a solver/NN), communicating through the preCICE library?

My assumption is that as long as my Python script correctly implements the preCICE API via the Python bindings to exchange the required data (e.g., Forces and Displacements), preCICE should be able to manage the coupling process seamlessly. I would just need to write a custom Python “adapter” script for my “solver”.

To make it more concrete, I would be very grateful if you could provide some guidance on the following points:

  1. General Feasibility: Is my overall understanding correct? Is coupling a solver like CalculiX with a custom Python script a supported and valid use case for preCICE?
  2. Implementation Strategy: For the Python side, would the recommended approach be to create a single Python script that a) contains the solver/NN logic and b) directly calls the preCICE API functions (e.g., initialize, read_data, write_data, advance, finalize)?
  3. Neural Network Considerations: Are there any specific challenges or best practices I should be aware of when the “solver” is a neural network? For example, related to time stepping, data mapping, or performance?
  4. Relevant Examples: Are you aware of any tutorials, examples, or community projects that demonstrate a similar coupling (i.e., coupling with a pure Python-based participant)? The existing Python examples seem to focus on teaching the API with simple analytical functions, and I’m looking for something closer to a real physics simulation.

Thank you in advance for your time and any insights you can share. This would be a great help for my research.

Best regards

Dear liuyang230125,

I am a master’s student working on the OpenFOAM adapter, for my master’s thesis I am looking into generalized ways to couple neural network based solvers with traditional solvers. If you are interested I can send you a link to my demo case on GitHub later this week. I have not looked into FSI yet, but for my demo case I am trying to create a neural surrogate for the CFD / OpenFOAM participant in a one-way coupling. Regarding bi-directional coupling (e.g., FSI) with a neural network, there are still many open questions (what is the input/output, how to handle BCs, changing geometry etc.). Ultimately I would like to find a standardized approach and create a neural-surrogate adapter.

From the preCICE library perspective (data communication and mapping) there are no obstacles or differences from a traditional solver coupling AFAIK. I would recommend you call the preCICE API using the Python bindings in your custom script. There is an existing adapter called Gym-preCICE for interfacing a neural network with a physics simulation environment for reinforcement learning. You can also look at the source code of the FEniCS-preCICE adapter for a deeper look into the coupling.

If you decide to use preCICE for this purpose, I would be happy to stay in touch and discuss. In a couple of months I will be presenting my results at the preCICE workshop 2025 (September 8-12). In the meantime I am actively working in this topic.

Let’s stay in touch!
Best,
Daniels

1 Like

Dear Daniels,

Thank you so much for your quick and insightful reply. It’s fantastic to hear that you’re working on a very similar topic for your Master’s thesis. The idea of creating a neural surrogate for the OpenFOAM participant is exactly what I was envisioning for the fluid part of my FSI problem.

I would be absolutely delighted to take a look at your demo case. Please do send me the link to your GitHub repository whenever you have a moment. That would be a great help and a valuable reference for me.

I would definitely love to stay in touch and discuss our progress and challenges as we both explore this exciting area. My email is liuyang230125@gmail.com . Please feel free to reach out there as well.

Thank you also for the pointers to Gym-preCICE and the FEniCS adapter; I will certainly look into them.

Looking forward to seeing your work and exchanging ideas. Best of luck with your thesis and your presentation at the preCICE workshop!

Best regards,
liuyang

1 Like