Wiki
Clone wikimshr / Tutorial
mshr tutorial
The tutorial is currently being prepared. It is not complete yet.
Prerequisites
This tutorial uses Python interface mshr. C++ users should be able to use the tutorial as well, as the APIs are identical (in fact the API reference manual which is supposed to be common to both langauges is generated from the C++ interface).
If you are not familiar with Python programming, try to follow the tutorial anyway. The syntax is easy to learn. The official Python tutorial is here: https://docs.python.org/tutorial/.
This guide assumes you have succesfully installed mshr. To verify this, run the following command from the command line prompt
$ python -c "import mshr"
If the error message contains something like ImportError: No module named dolfin
, then you need to check the installation of the other FEniCS components, and Dolfin (FEniCS's main interface) in particular.
Introduction
mshr generates meshes in 2D and 3D for Dolfin. The meshes are generated from CSG, ie. boolean combinations of geometric primitives or triangulated surfaces loaded form files. The two can also be combined.
mshr works in 2D and 3D with similar APIs.
Creating and loading models
CSG geometries
Geometries are defined by combining geometric primitives through the boolean operation intersection
, union
and difference
. Here is a small 2D example
#!python from mshr import * import dolfin domain = Rectangle(dolfin.Point(0., 0.), dolfin.Point(1., 1.)) - Circle(dolfin.Point(0.0, 0.0), .35)
The geometry consists of a box with a circle subtracted. The -
represents the boolean difference.
TODO: Insert plot of geometry
The geometries can be arbitrally complex and you can use all python constructs to build of your geometry.
This example is the intersection of a box and sphere, with lots of holes subtracted
TODO: Insert example
Loading models from file
Generating meshes from the models
3D models can be loaded from files. mshr currently support the formats off
, stl
and vtp
. Files are loaded through the class Surface3D
Updated