Questions on coupling OpenFOAM with Micro Manager

Hello everybody,

I have started using the Micro Manager to couple an OpenFOAM-based micro scale simulation to an OpenFOAM-based macro scale simulation as a continuum-continuum coupling approach and have run into some issues/questions.

The first question, maybe a bit trivial, but am I correct in understanding that the entire code for the micro simulation would have to be restructured and made out to be object oriented? I am confused because my understanding was that preCICE would be non-invasive.

Next, are you aware of any open source minimal working examples of simulations using the Micro Manager, in which the micro simulation is based on Openfoam, which you could share? In particular, I would be interested how I would have to change the Make/files and Make/options files to allow for a compilation with OpenFOAM. So far my attempts at this meant including the flags from the following compilation command (from Prepare micro simulation | preCICE - The Coupling Library)

c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) micro_cpp_dummy.cpp -o micro_dummy$(python3-config --extension-suffix)

in the Make/{options,files} file of my OpenFOAM code, as shown in the attachment. micro_cpp_dummy.cpp would include a MicroSimulation class that implements the micro simulation requirements for Micro Manager. However, running wmake, I get the following error: g++: error: Make/linux64GccDPInt32Opt/micro_cpp_dummy.o: No such file or directory (Note: I didn’t upload the rest of my code, because I think I have a mistake with what I am including in the Make/{options,files} files, however, if needed I could write a minimal example that reproduces the error)

I would be happy if anybody could help me with my questions and issue. Thanks in advance. All the best,
Dennis

files.txt (76 Bytes)
options.txt (127 Bytes)

Hi @dennis

You are right in your understanding that the micro simulation needs to be restructured into an object-oriented style library. This restriction comes from the Micro Manager and not from preCICE. The Micro Manager needs to control the micro simulations, and it only do that when the micro simulation code has a certain class name and member variables in that class.

Although we have coupled an OpenFOAM-based micro simulation, we have coupled micro simulations which are written in C++. Essentially we rely on pybind11 to expose a class written in C++ to a Python-style calling. We do this because the Micro Manager is written in Python, and needs a compiled library which it can call. For your case, it would make sense to get some understanding of how pybind11 works. I have never worked with OpenFOAM, but we can find a solution where you will be able to control a micro simulation. I will ask other users who have written C++ based micro simulations to reply here.

Hi @IshaanDesai alright thanks for your advice, I will check it out :slight_smile:

1 Like

If anyone runs into similar issues, I found this solids4foam repository to be a great starting point: GitHub - solids4foam/pybind11foam: This repository contains an easy to use C++ header class for executing Python code directly from OpenFOAM applications. More information can be found at http://pythonpal4foam.github.io.

1 Like

Hi @dennis
I also only scratched the surface of OpenFOAM a few years ago and don’t know much about it or wmake. Maybe using wmake for the python importable class can be avoided: In a mechanics project I’m currently working on with the Micro Manager it was enough to have a separate CMakeLists.txt file for the pybind11 module with the following lines (in addition to making sure pybind11 is found) and link it to the shared library used.

pybind11_add_module(PyOpFOAM micro.hpp micro.cpp)
target_link_libraries(PyOpFOAM PRIVATE library_to_link)

where the microsimulation is set up in the way the Micro Manager requires in micro.cpp and library_to_link, which potentially are the compiled OpenFOAM libraries.
The OpenFOAM case probably requires some more directories to be added for the OpenFOAM libraries. I’m not sure this is at all for the OpenFOAM case.

4 Likes

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