Neper edit page


Neper is an open source software package for polycrystal generation and meshing developed by Romain Query. It can be obtained from, where also the documentation is located.

This module provides an comfortable interface to neper. It is used to simulate microstructures with certain parameters and load them back into MTEX for analysis and further investigation with the various tools provided by MTEX.

In order to do this, a slicing of the 3-dimensional tesselation is necessary after the simulation. The obtained 2-dimensional tesselation is processed as an object from the class grain2d.

Setting-up the neper instance

If you do not want to make any further adjustments to the default values, this step could be done very easily. In this case please skip to chapter "Simulating a microstructure with Neper"

job = neperInstance
job = 
  neperInstance with properties:

            id: 1
      cubeSize: [1 1 1]
        morpho: 'graingrowth'
       iterMax: 1000
    fileName2d: '2dslice'
    fileName3d: 'allgrains'
      filePath: '/tmp/'
     newfolder: 1

File options: By default your neper will work under the temporary folder of your matlab (matlab command tempdir). If you want to do your tesselations elsewhere or your tesselations are already located under another path, you can change it:

% for example
% job.filePath = 'C:\Users\user\Documents\work\MtexWork\neper';
% or
 job.filePath = [mtexDataPath filesep 'Neeper'];

By default a new folder, named neper will be created for the tesselation data. If you do not want to create a new folder you can switch it of by setting newfolder to false.

job.newfolder = false;

If newfolder is true (default) the slicing module also works in the subfolder neper, if it exists.

By deafult the 3d tesselation data will be named "allgrains" with the endings .tess and .ori and the 2d slices will be named "2dslice" with the ending .tess and .ori . You can change the file names in variables fileName3d and fileName2d.

job.fileName3d = 'my100grains';
job.fileName2d = 'my100GrSlice';

Tesselation options

The grains will be generated in cubic domain. By default the domain has the edge length 1 in each direction. To change the size of the domain, store a row vector with 3 entries (x,y,z) in the variable cubeSize.

job.cubeSize = [4 4 2];

Neper uses an id to identify the tesselation. This interger value "is used as seed of the random number generator to compute the (initial) seed positions" ( By default the tesselation id is always 1. = 529;

Neper allows to specify the morphological properties of the cells. See for more information. By default graingrowth is used, that is an alias for:

job.morpho = 'diameq:lognormal(1,0.35),1-sphericity:lognormal(0.145,0.03)';

Simulating a microstructure with Neper

The tesselation is executed by the command simulateGrains. There are two option to call it.

  1. by an ODF and the number of grains
  2. by a list of orientations. In this case the length of the list determines the number of grains.
cs = crystalSymmetry('432');
ori = orientation.rand(cs);
odf = unimodalODF(ori);



To get slices of your tesselation, that you can process with MTEX, the command getSlice is used, wich returns a set of grains (grain2d). It is called by giving the normal vector [a,b,c] of the plane and either a point that lies in the plane or the "d" of the plane equation. Please consider that the slicing must align with the size of the domain/cube (see Tesselation options - cubeSize)

% the normals of the slices
N = [vector3d(0,0,1),vector3d(1,-1,0),vector3d(2,2,4)];

% make all slices passing through this point

grains001 = job.getSlice(N(1),A,'silent');
grains1_10= job.getSlice(N(2),A,'silent');
grains224 = job.getSlice(N(3),A,'silent');
hold on
hold on

% set camera
how2plot = plottingConvention;
how2plot.outOfScreen = vector3d(-10,-5,2)
how2plot.east = vector3d(1,-2,0)
Warning: still can not concatenate grains on different slices 
Warning: still can not concatenate grains on different slices 
how2plot = plottingConvention
  outOfScreen: (-10,-5,2)                
  north      : (-0.32956,0.83522,0.44023)
  east       : (3,-3,8)                  
how2plot = plottingConvention
  outOfScreen: (-10,-5,2)
  north      : (2,1,12)  
  east       : (1,-2,0)