2
$\begingroup$

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.

$\endgroup$
5
  • $\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
    Commented Nov 5, 2020 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
    Commented Nov 5, 2020 at 21:47
  • $\begingroup$ FEniCS does the job. $\endgroup$
    – user20857
    Commented Nov 5, 2020 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$ Commented Nov 6, 2020 at 1:28
  • $\begingroup$ @Spencer: but FEniCS is written in C++. Can it be called easily from a pure C program? $\endgroup$
    – vibe
    Commented Nov 6, 2020 at 6:07

1 Answer 1

4
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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