setMTEXpref('generatingHelpMode',true); % Avoid some artefact (fix issue #5)
mtexdata small
[grains, ebsd('indexed').grainId]=calcGrains(ebsd('indexed'));
ebsd(grains(grains.grainSize<3))=[];	% Remove small grains
ebsd = EBSD  
 Phase  Orientations     Mineral         Color  Symmetry  Crystal reference frame
     0    1197 (32%)  notIndexed                                                 
     1    1952 (52%)  Forsterite  LightSkyBlue       mmm                         
     2    290 (7.8%)   Enstatite  DarkSeaGreen       mmm                         
     3    282 (7.6%)    Diopside     Goldenrod     12/m1        X||a*, Y||b, Z||c
 Properties: bands, bc, bs, error, mad, x, y
 Scan unit : um

Basic use

The geometry described by the object G can be meshed using the Gmsh software as follows:


Open mesh file

The above command results in a 1 element thick mesh, consisting in linear wedge elements (6-node 3D elements. The element size is (roughly) equal to the EBSD resolution.

Constant element size

The default element size can be set as follows:


The resulting mesh cannot be (easily) displayed in MATLAB. Thus, the following illustrates the geometry when opening the mesh file with Gmsh:

Open mesh file

The unit here is the same as the EBSD map (ususally µm).

Size gradient

Let $s(\mathbf{x})$ be the local element size at coordinates $\mathbf{x}$. The element size can be set as an increasing distance from the grains boundary such that:



If one wants to mesh with element size equal to 50 at grain boundaries and a slope of k=0.5:


Open mesh file

Element size Depending on the curvature of grain boundaries

The local curvature of grain boundaries can be used to set the element size. For instance, the following command use 5 nodes to describe a full circle:


Open mesh file

Element type

The default element type for meshing is linear wedge. It can be changed to hexahedron (or brick element).


Open mesh file

Note: In this case, the mesh will be hex-dominated. Indeed, the resulting mesh may still contain some wedge elements. To avoid it, use 'HexOnly' option instead.

Tetrahedron can also be used:


Open mesh file

If you wants to work in 2D only, use triangular ('Tri') or quandrangular ('Quad') elements instead:


Open mesh file


Open mesh file

Again, 'Quad' results in quad-dominated mesh. For pure Quad mesh (no triangle), use 'QuadOnly'.

Element order

The default element order is 1 (linear elements). It can be changed with the ElementOrder option. E.g.:


Open mesh file

Periodic mesh

Periodic conditions can be used on X or/and Y direction for meshing. It consists in ensuring that nodes at opposite borders are at the same coordinates. This is usually requested for periodic conditions in FEM in order to take into account the medium surrounding the RoI.


Open mesh file


Open mesh file

Dump the geometry in an ASCII file

The geometry can be exported into a Gmsh-readable (and somehow human-readable) format using the following command:


Open geo file

Go back to documentation index