Sample codes

These are codes that demonstrate basic methods in computational mechanics.

Note to prospective students: These sample codes are simple implementations of basic methods. Any students interested in experimenting with these codes or expanding their capabilities are exactly the type of students that are a good fit for this research group.

2D finite element code in Python

This code demonstrates a simple 2D plane strain finite element code in Python using both numpy and matplotlib. The global stiffness matrix is stored in full format (i.e. not sparse). Interested students can try to convert to a sparse format via scipy.sparse.

download code
 

Matlab code for quadtree mesh with hanging nodes

This code demonstrates static condensation degrees of freedom to enforce compatibility in a mesh with hanging nodes. A simple patch test demonstrates that compatibility is enforced.

download code
 

Matlab code for 1D bridging domain method

MAE 598 Student Project: David Chao, spring 2012

This code demonstrates the bridging domain method in 1D with both consistent Lagrange multiplier constraints and diagonalized constraint equations. The diagonalized version damps some of the high frequency energy at the coupling interface.

download code
 

Matlab xfem example

This code demonstrates a strong discontinuity within a total Lagrangian explicit extended finite element formulation. In the simulation, a velocity boundary condition is applied to a bimaterial strip, where there is no cohesive interaction between the two materials.

download code

Mesh generators for MATLAB

Simple codes for creating meshes in MATLAB.

2D uniform mesh generator

This MATLAB function generates a 2D finite element mesh in MATLAB. You can generate a plot with commands like
m = uniform_mesh(5, 6, 5.0, 5.0);
p.vertices = m.x';
p.faces = m.connectivity';
p.facecolor = 'w';
patch(p)

download code

2D plate with hole mesh generator

This MATLAB function generates a 2D finite element mesh in MATLAB. You can generate a plot with the command:
m = hole_mesh(nh, L, r), where

  • 2*nh is the number of elements along an edge
  • L is the length of the plate
  • r is the radius of the hole
  • download code