Mesh (MATLAB Class)

Mesh is a MATLAB class for finite element methods:

  • Easy to use
  • Works for 1D, 2D, 3D simplices
  • Automatic facet generation from given mesh for interior/boundary
  • Automatic generation of affine information of given mesh

Create an Mesh Object

You can create a Mesh object by

mesh = Mesh(v4e, x); % 1D line mesh / v4e: 2 x nrE
mesh = Mesh(v4e, x, y); % 2D triangular mesh / v4e: 3 x nrE
mesh = Mesh(v4e, x, y, z); % 3D tetrahedral mesh / v4e: 4 x nrE

where v4e(:,i) contains vertex index for each element.

Or, you can get uniform mesh by

% 1D uniform mesh in (0,1) with 10 elements.
mesh = line2linemesh(0,1,10);
% 2D uniform mesh in (0,1)x(0,2) with 10 x 20 (x2) elements.
mesh = rect2rectmesh(0,1,0,2,10,20);
% 3D uniform mesh in (0,1)x(0,2)x(0,3) with 10 x 20 x 30 (x6) elements
mesh = cube2cubemesh(0,1,0,2,0,3,10,20,30);

Display Mesh

To show the mesh, you can use show() method.

mesh.show(); % default configuration
mesh.show('FaceColor', 'r'); % change face color
mesh.show(ax, __); % specify target axes

where the optional arguments are from plot for 1D and patch for 2D and 3D

1D Line Mesh
2D Triangular Mesh
3D Tetrahedral Mesh

Facet Information

When a Mesh object is created, facet information can be obtained, where

  • v4f is the vertex index for each facet
  • x4f is the x-coordinate for each facet (or y, z)
  • nx4f is the facet normal for each facet (or y, z)
  • J4f is the Jacobian for each facet
  • e4f is the neighboring elements' index for each facet
  • ef4f is the neighboring elements' local facet index for each facet
  • fmask and fmask_neg are the local facet vertex index of an element (positive / negative)

All information about facets can be obtained seperately for interior/boundary facets
by changing f to f0 or fb.

If you want to access to the first neighboring element to 10th facet, you can use

mesh.e4f(1,10); % gives the first neighboring element of 10th facet
mesh.ef4f(1,10); % gives the positive element's which facet is 10th facet.

In other words,

mesh.v4f(:,10) == mesh.v4e(mesh.fmask(:,mesh.ef4f(1,10)), mesh.e4f(1,10))

Or, for negative element (the second neighboring element)

mesh.v4f(:,10) == mesh.v4e(mesh.fmask_neg(:,mesh.ef4f(2,10)), mesh.e4f(2,10))

Note that e4fb and ef4fb are 1 x nrfb vectors since there is only one neighboring element.

mesh = rect2trimesh(); % get uniform triangular mesh
figure;
mesh.show(); % display mesh
hold on;
plot(mesh.x4fb, mesh.y4fb, 'r', 'linewidth', 2); % plot boundary edges
plot(mesh.x4f0, mesh.y4f0, 'b', 'linewidth', 1.5); % plot interior edges
2d triangular mesh with boundary edges and interior edges

Affine Information

In finite element assembly, affine information of physical triangles is often used.

One can access to the affine information by

% dX/dR
mesh.xr, mesh.xs, mesh.xm
mesh.yr, mesh.ys, mesh.ym
mesh.zr, mesh.zs, mesh.zm

% Jacobial
mesh.J

% dR/dX
mesh.rx, mesh.ry, mesh.rz
mesh.sx, mesh.sy, mesh.sz
mesh.mx, mesh.my, mesh.mz

Here, each property is 1 x nrE vector.

Chemical Kinetics (MATLAB Class)

Reaction is a MATLAB class for chemical kinetics:

  • Supports various order reactions, forward and reversible reactions
  • User-friedly name-based reaction definitions
  • Large model can be imported with custom data file
  • Automatic generation of ODEs
  • Examine system with human readable form: reaction equations, and ODEs