Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FEniCS"

Line 1: Line 1:
 
== Introduction and Installation ==  
 
== Introduction and Installation ==  
  
[http://fenicsproject.org/ FEniCS] is a package of powerful tools used for mesh generation and solving problems. Dolfin is a core component of FEniCS and serves as an interface and solver. The package is available for download [http://fenicsproject.org/download/ here].
+
[http://fenicsproject.org/ 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 [http://fenicsproject.org/download/ here].
There are several 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 (on Linux): eigen3, swig, and boost are all required. Info on this process is available [http://fenicsproject.org/download/installation_from_source.html here]. Finally, there is an option to install from an install script provided at the bottom of the download page. If problems arise when trying to install the mshr package (running Linux Fedora 22), just edit the hashdist profile (the fenics.yaml file) and take out that package. 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:
+
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 [http://fenicsproject.org/download/installation_from_source.html 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:
 +
 
 
<code>source fenics.custom</code>
 
<code>source fenics.custom</code>
  
on the command line. ** NOTE: only tested on Linux Fedora 22 **
+
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:
  
Running Dolfin commands involves creating a script or program in python/c++ that calls on the Dolfin libraries and running it. From the command line, a user can run python commands:
 
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
>>> from dolfin import *
 
>>> from dolfin import *
Line 13: Line 16:
 
...
 
...
 
>>> plot(mesh)
 
>>> 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()
 
>>> interactive()
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
  
 
==File type specifications ==  
 
==File type specifications ==  
Line 46: Line 54:
  
 
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:
 
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:
 
+
<syntaxhighlight lang="python">
 
mesh = UnitSquareMesh(10,10)
 
mesh = UnitSquareMesh(10,10)
 
+
</syntaxhighlight>
 
Creates a new 10 by 10 unit square mesh. There are also vectors and matrices with which to do physical problems and computations.  
 
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. For example,
 +
<syntaxhighlight lang="python">
 +
r = Rectangle(dolfin.Point(0,0), dolfin.Point(1,1))
 +
</syntaxhighlight>
 +
defines a rectangle in 2D space. To create more complex shapes, use geometry subtraction:
 +
<syntaxhighlight lang="python">
 +
shape = Circle(dolfin.Point(.5, .5), 3) - r
 +
</syntaxhighlight>
 +
More information on Mshr is available [https://bitbucket.org/fenics-project/mshr here].
  
 
==Inputs/Outputs==  
 
==Inputs/Outputs==  
Line 68: Line 86:
 
| .m || GNUOctave and MATLAB format  
 
| .m || GNUOctave and MATLAB format  
 
|-  
 
|-  
| .tec || TecPlot format *
+
| .tec || TecPlot format  
 
|-
 
|-
 
| .msh/.res || GiD format  
 
| .msh/.res || GiD format  
 
|}
 
|}
  
* Indicates that the format may no longer be supported  
+
* 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.  
+
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
 +
* Note- It is left to be determined if an ICE Geometry can be exported to a readable geometry format for FEniCS to read in and generate a mesh from. The API from Mshr seems to only accept the CSG format, although there does not seem an easy way to read in a geometry file.  
  
 
== Editor Features ==
 
== Editor Features ==
  
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 ]  
+
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 http://fenicsproject.org/about/features.html#features], FEniCS serves to do the following:
  
 
* Automated solution of variational problems
 
* Automated solution of variational problems
Line 91: Line 110:
 
== Ease of Use ==  
 
== 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 [http://fenicsproject.org/download/installation_using_hashdist.html#installation-using-hashdist installing FEniCS using Hashdist] for more information.  
+
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 [http://fenicsproject.org/download/installation_using_hashdist.html#installation-using-hashdist 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 [http://fenicsproject.org/documentation/dolfin/dev/python/demo/ 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.
 
- Only tested on Linux Fedora 22.

Revision as of 10:23, 31 May 2016

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:

source fenics.custom

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.

Attributes

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. 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.

Inputs/Outputs

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:

Extention Format/Visualization Software
.pvd VTK format, Paraview and MayaVi
.dx Open DX format
.m GNUOctave and MATLAB format
.tec TecPlot format
.msh/.res GiD 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

  • Note- It is left to be determined if an ICE Geometry can be exported to a readable geometry format for FEniCS to read in and generate a mesh from. The API from Mshr seems to only accept the CSG format, although there does not seem an easy way to read in a geometry file.

Editor Features

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.

Back to the top