FEniCS Support in ICE
Note: This page is supported by the Eclipse ICE project's Geometry and Meshing initiative. This page is in no way affiliated or supported by the FEniCS project.
Introduction and Installation
FEniCS is a package of powerful tools used for solving partial differential equations and linear algebra problems. Dolfin is a core component of FEniCS and serves as an interface and solver, while a component called Mshr serves as a 2D and 3D mesh generator from Constructive Solid Geometry (CSG) format. The package is available for download here. There are three ways to install FEniCS- Docker images, Ubuntu packages, and from the source code itself. If installing from source, you will need Python 2.7, git, a c and c++ compiler, a fortran compiler, and OpenGL development files. If compiling from source (not using the install script), then there are several dependencies and optional packages to install: eigen3, swig, and boost are all required, while there are around a dozen other optional packages. Info on this process is available here. Finally, there is an option to install from an install script provided at the bottom of the download page. Finally, before running any Dolfin commands, several environment variables need to be declared. The fenics.custom file will add the variables to your running instance with the command:
on the command line.
- NOTE: installation only tested on Linux Fedora 22
Running Fenics commands involves creating a script or program in python/c++ that calls on the Dolfin or Mshr libraries and running it. From the command line, a user can run python commands:
>>> from dolfin import * >>> mesh = UnitSquareMesh(10,10) ... >>> plot(mesh) >>> from mshr import * >>> geom = Rectangle(Point(0,0),Point(1,1)) - Circle(Point(.5,.5), .35) >>> plot(generate_mesh(geom, 20, 'cgal')) >>> interactive()
File type specifications
Dolfin uses the native Dolfin XML mesh format. It specifies vertices and then either triangles or tetrahedrons. An example of the formatting is shown here:
<?xml version="1.0?> <dolfin xmlns:dolfin="http://fenicsproject.org"> <mesh celltype="triangle" dim="2"> <vertices size="###"> <vertex index="0" x="##" y="##" z="##" /> <vertex index="1" x="##" y="##" z="##" /> <vertex index="2" x="##" y="##" z="##" /> ... <vertex index="###" x="##" y="##" z="##" /> </vertices> <cells size="###"> <triangle index="0" v0="#" v1="#" v2="#"> <triangle index="1" v0="#" v1="#" v2="#"> <triangle index="2" v0="#" v1="#" v2="#"> ... <triangle index="###" v0="#" v1="#" v2="#"> </cells> </mesh> </dolfin>
Or use celltype ="tetrahedron" dim="3" for three dimensional meshes.
Meshes have vertices and each is defined by triangles or quadrilaterals. Faces are defined by the vertices being specified in counter-clockwise order. Objects are usually defined as meshes, with some basic one, two, and three dimensional square meshes being available to generate. For example:
mesh = UnitSquareMesh(10,10)
Creates a new 10 by 10 unit square mesh. There are also vectors and matrices with which to do physical problems and computations.
The Mshr library is used to create CSG geometries and generate meshes from them, using either CGal or Tetgen for the back end meshing algorithms. For example,
r = Rectangle(dolfin.Point(0,0), dolfin.Point(1,1))
defines a rectangle in 2D space. To create more complex shapes, use geometry subtraction:
shape = Circle(dolfin.Point(.5, .5), 3) - r
More information on Mshr is available here.
Dolfin works with it's own native Dolfin XML format, but can convert both .mesh and .gmsh formats using its own converter. It would not be theoretically difficult to make a XML conversion tool between ICE's native format and Dolfin's XML format.
Dolfin is a able to visualize meshes using VTK, but it can also export to several mesh formats, shown here:
|.pvd||VTK format, Paraview and MayaVi|
|.dx||Open DX format|
|.m||GNUOctave and MATLAB format|
- The TecPlot format may no longer be supported
It is thus possible to export an ICE native mesh to Dolfin for computation and then export a VTK file back to ICE for visualization using Paraview
Using Mshr, .stl, .off, and .vtp geometry files can be read in using Surface3D("filename").
Dolfin and FEniCS do not provide a simple GUI or graphical interface, as the FEniCS project is not intended as a pure mesh editor. Rather, the tools serve as a collection of libraries and an interface for performing meshing functions and solving physical systems. From http://fenicsproject.org/about/features.html#features, FEniCS serves to do the following:
- Automated solution of variational problems
- Automated error control and adaptivity
- An extensive library of finite elements
- High performance linear algebra
- Computational meshes
- Postprocessing using VTK
- Python and C++ support
Ease of Use
FEniCS is quick and easy to use from the command line with Python, and can be powerful with extensive and well-documented libraries. However difficulties can arise when installing from source or using the default Hashdist installation profile. Look into installing FEniCS using Hashdist for more information. There are some demo examples provided with the FEniCS installation, but not much documentation on the process from turning geometries into meshes. A list of the currently supported demos can be found here. In all, the install scripts work well, the interface has adequate documentation, and there is good support for interfacing with ICE, with some file conversions in between. - Only tested on Linux Fedora 22.