10
$\begingroup$

Basically, FEM seems to be a problem that is pretty much "solved". There are numerous powerful frameworks existing, like Trilinos, PETSc, FEniCS, Libmesh or MOOSE.

One thing they have in common: They are extremely "heavy-weight". First, the installation normally is super painful. Second, their interface/API is thick and heavy - you have to translate your whole idea into the thinking of the respective library. That also means, interoperability and extendability for special requirements or existing code is difficult.

Other projects like (random examples) Boost, LibIGL, Aztec (linear solver), Eigen or CGAL demonstrate that it's absolutely possible to write powerful libraries that seamlessly integrate into C++ or Python code, with a very lean and clean interface, without need of installation of a super heavy framework.

Is there a really lightweight package for FEM? I'm not looking for the easy, automagic solver - I'm looking for a library that offers powerful functions while maintaining a lean interface, interoperability with common datastructures (C++ STL for example) and lightweight installation (header only for example).

$\endgroup$
11
  • 1
    $\begingroup$ Are you asking about FEM libraries or FEM applications? $\endgroup$
    – nicoguaro
    Commented Oct 17, 2016 at 13:12
  • 2
    $\begingroup$ "offers powerful functions while maintaining a lean interface", isn't this bit contradictory. I use Fenics and deal.ii and its not difficult to install or even to use. Fenics comes with binaries which you can easily install. deal.II has many installation options like via Linuxbrew, Homebrew, Candi, etc. I would recommend choosing one and learning it well. It will payoff well once you cross the initial learning curve. I use Fenics for small problems, quickly testing some idea and also for some teaching. For bigger problems, parallel computing, I prefer deal.II. Both have good documentation. $\endgroup$
    – cfdlab
    Commented Oct 17, 2016 at 14:16
  • 2
    $\begingroup$ @PraveenChandrashekar: Powerful functions and lean interface is absolutely NOT contradictory. Have a look into libigl, boost or Numpy for example. Yes, Fenics seems easy to use, but it would be cumbersome to integrate for example in an existing application. Imagine you have a little game where you need to integrate a real time FEM code (just as an example). $\endgroup$
    – Michael
    Commented Oct 17, 2016 at 17:17
  • 2
    $\begingroup$ I agree with @PraveenChandrashekar but beyond that, I believe the question, as posed, is unanswerable. At a minimum, you need to provide an example of a PDE you want to solve with FEM and what functionality you want a "lightweight" library to provide to help you do that. $\endgroup$ Commented Oct 17, 2016 at 18:28
  • 1
    $\begingroup$ A simple one that comes to my mind is SfePy, I download it and it is 7 MB. I also checked Hermes, and it is 10 MB, I have not tried it though (but I have tried Agros 2D). There are more options here: en.wikipedia.org/wiki/List_of_finite_element_software_packages $\endgroup$
    – nicoguaro
    Commented Oct 17, 2016 at 18:39

3 Answers 3

10
$\begingroup$

I've been developing a lightweight finite element library in Python 2.7 harnessing the power of NumPy arrays and SciPy sparse matrices. The general idea is that given a mesh and a finite element, you have more-or-less one-to-one correspondence between the bilinear form and a (sparse) matrix. The user can then use the resulting matrix as he or she sees fit.

Let me present a canonical example where we solve the Poisson equation in a unit square with an unit loading.

from spfem.mesh import MeshTri
from spfem.asm import AssemblerElement
from spfem.element import ElementTriP1
from spfem.utils import direct

# Create a triangular mesh. By default, the unit square is meshed.
m=MeshTri()

# Refine the mesh six times by splitting each triangle into four
# subtriangles repeatedly.
m.refine(6)

# Combine the mesh and a type of finite element to create
# an assembler. By default, an affine mapping is used.
a=AssemblerElement(m,ElementTriP1())

# Assemble the bilinear and linear forms. The former outputs
# a SciPy csr_matrix and the latter outputs linear NumPy array.
A=a.iasm(lambda du,dv: du[0]*dv[0]+du[1]*dv[1])
b=a.iasm(lambda v: 1.0*v)

# Solve the linear system in interior nodes using
# a direct solution method provided by SciPy.
x=direct(A,b,I=m.interior_nodes())

# Visualize the solution using Matplotlib.
m.plot3(x)
m.show()

Other comments:

  • My goal is to write rigorous convergence unit tests checking e.g. that theoretical convergence rates in the respective norms are obtained. Tests are run automatically on each change.
  • Implementing new elements is quite easy.

You can find the project in GitHub.

Python 3 version of the code can be found here.

$\endgroup$
4
$\begingroup$

I think you have some confusion. PETSc is not in the same league as Fenics, Libmesh, Moose etc. In fact, all of these (heavyweight) packages use PETSc for linear algebra.

IMHO PETSc is as lightweight as you can get. It just requires C/Fortran compilers and Python (used only for configuration) and you can build the library in under 5 minutes on your laptop. Also, the most complicated part of a FE code is parallel assembly and solve and PETSc takes care of both. The rest (e.g., element level calculations) is rather straightforward.

Trillinos, OTOH is much more than a linear algebra framework, e.g., Aztec (linear solver) which you mention is part of it. In some ways Aztec in Trillinos can be compared to PETSc.

$\endgroup$
1
  • 1
    $\begingroup$ What exactly do you mean by "parallel assembly" in that case? Just the communication of the matrix/vector elements, or is there more? I read the manual semi-thorougly, but I did not find much about the assembly (besides of communication in the linear solver) (Manual: mcs.anl.gov/petsc/petsc-current/docs/manual.pdf ) $\endgroup$
    – Michael
    Commented Nov 8, 2016 at 12:45
4
$\begingroup$

I can recommend nutils.

nutils meets at least a few your "light-weight" requirements.

  • it is pure python and easy to install since it only depends on standard Python libraries numpy, scipy, and matplotlib
  • and, thus, it is well suited for interoperations. At least the developers claim that

"Exposed objects are of native python type or allow for easy conversion to leverage third party tools."

$\endgroup$
1
  • $\begingroup$ This is a very interesting project! I was not aware of it and the goals seem to be quite similar to that of mine. They surely have some nice demo videos... $\endgroup$
    – knl
    Commented Oct 19, 2016 at 12:15

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.