I am looking for a general purpose library which can solve a 2D or 3D linear elliptic PDE on a rectangular domain with mixed/Robin boundary conditions. I am a C programmer, so I would prefer a C library, but fortran is ok too since its easy to call fortran code from C. So far I have found only 1 option: MUDPACK. This is a fortran library which uses Multigrid and handles 2D and 3D elliptic PDEs.

Just wondering if there are other options out there? Unfortunately for me, many PDE libraries are written in C++ which likely cannot be interfaced with C easily.

  • $\begingroup$ If you are not looking at large-scale problems, then why not implement it yourself? Since the domains are simple, I don't think it is much of an effort. You can use a third-party library, for example, PETSc, for matrix algebra. I have a Fortran code for 2D and 3D Poisson equation and elasticity using the FEM, if you want to have a look. github.com/chennachaos/PFEMFort You can update it to incorporate Robin/Mixed BCs. $\endgroup$ – Chenna K Nov 5 '20 at 21:42
  • 1
    $\begingroup$ Discretizing the equation, implementing the BCs, and doing multigrid seems like reinventing the wheel. I would like to just specify my equation coefficients and let a nice library handle the rest. $\endgroup$ – vibe Nov 5 '20 at 21:47
  • $\begingroup$ FEniCS does the job. $\endgroup$ – Spencer Bryngelson Nov 5 '20 at 23:55
  • $\begingroup$ You can write it fairly easily in MATLAB, and then generate C code out of it: mathworks.com/products/matlab-coder.html $\endgroup$ – Maxim Umansky Nov 6 '20 at 1:28
  • $\begingroup$ @Spencer: but FEniCS is written in C++. Can it be called easily from a pure C program? $\endgroup$ – vibe Nov 6 '20 at 6:07

Most of the widely used finite element libraries are written in C++. If all you really care for -- and if all you will ever care for -- is solving an elliptic PDE on a rectangle, then it's probably not a large amount of work (a few 100 lines) to just write the finite element part yourself and use PETSc for the linear algebra.

But, if you think you might ever want to do something more complicated, it's probably worth using one of the established bigger packages. It's not difficult to call C++ from C: You write your your finite element solver in C++, and in one of your C++ file you have a function of the kind

extern "C" int run_fem_solver (/*possibly arguments*/) {
   ...put C++ code here that runs the fem solver...

This function is compiled by the C++ compiler, and so can call all of the C++ FEM machinery. But because it's marked extern "C", you can call it from the C part of your application.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.