Interface Freefem++ with C++

Hello users,

I have an object-oriented code written in C++ and I would like to call FreeFem to solve a FE problem. So, how can I interface FreeFem with C++ ? I know it’s possible with Python. Is it also possible with C++ ? If so, can I have an example ?

Thanks !

Lily

1 Like

Hi @Lily,

Generally speaking, you cannot call FF as an API in your programs, neither in C++ nor Python. But, if you mean you want to call it as an external program, it can be done in C++ with a system call. This sort of offline linking is always possible, in which you call FF executable to solve a problem and write the solution the disk (you wait for it), and then, you collect the answer in your own code.

Another solution, which of course requires more effort and some architectural changes to your code, is the other way around. I mean you can call your C++ codes in FF as external functions (and not an external executable binary). It’s possible to build C++ codes as dynamics libraries and load them inside FF as a sort of plugin. FF comes with a script called ff-c++ that makes this process easier. You can find a couple of examples for various types of functions in FF website and examples.

1 Like

Hello @mojtaba.barzegari,
Thank you ! It works fine with a system call in C++

Thanks for the nice illustration!

I guess you could also used the FF exec() function to invoke your
own arbitary code and communicate throught files or pipes.
For initial testing anyway the fileio gives you debug information when things go wrong.

The interface between ff and the graphics in ffglut is kind of interesting and maybe
something to extend. Maybe a decade or so ago I was trying to do
something similar, making a freestanding program that accepts signals or
in this cases meshes or graphical datq from arbitrary sources via a pipe
or maybe a TCP or UDP connection. I came up with a primitive version now
that kind of interfaces with FF and my own code ( called “datascope”)
that may make a good plugin at some point but right now I just have
ff dump meshes and dofs into files I later read. This “interface” works with
other code too.