Skip to content
xwpkenPublic

About

Finite Element Analysis in MATLAB

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FEMAT

Finite Element Analysis in MATLAB

GitHub stars GitHub forks GitHub license

FEMAT is a compact finite-element library for two- and three-dimensional small-strain and finite-strain analysis. Its API is namespaced under femat, and custom material and element formulations can be supplied from an external project without copying source files.

Features

  • QUAD4, TRI3, HEX8, and TET4 elements
  • Small-strain and total-Lagrangian finite-strain analysis
  • Isotropic linear elasticity, Saint Venant-Kirchhoff, and Neo-Hookean models
  • User-defined materials through model.material.evaluate
  • User-defined analysis routines through model.analysis
  • Application-defined nodal fields and element variables

Installation

git clone https://github.com/xwpken/femat.git
cd femat

In MATLAB, run:

setup

setup.m resolves the repository location from its own path, so it can also be called from an external project.

API

[elements, nodes] = femat.mesh.rectangle(2, 1, 40, 20);
model = femat.model(elements, nodes);

model.material = femat.material.linearelastic("plane_strain", 1, 0.3);
model.analysis = @femat.analysis.small_strain;

left = find(abs(nodes(:,1)) < 1e-12);
model.fixedDofs = reshape([2*left-1, 2*left]', [], 1);
model.force = sparse(2*size(nodes,1), 1);

state.u = zeros(model.nDof, 1);
solution = femat.solve(model, state);

Custom analysis routine

An external project can provide its own element formulation:

model.analysis = @my_analysis;

with the interface:

function [Ke, internalForce] = my_analysis( ...
    model, state, vars)

The analysis evaluates all elements in one batch. Ke has size nEleDof-by-nEleDof-by-nElement, and internalForce has size nEleDof-by-nElement. state and vars are forwarded unchanged.

Custom material

Materials implement stress and tangent evaluation, with energy as an optional third output:

[stress, tangent, energy] = material.evaluate( ...
    kinematics, fields, vars)

The analysis routine defines the kinematic and stress measures. Built-in finite-strain analysis uses second Piola-Kirchhoff stress and the corresponding material tangent.

Application variables

The vars struct carries application-specific data required by an analysis or material. femat.solve passes it to model.analysis, which may use it directly or forward it to model.material.evaluate.

vars.elementParameters = ...;
vars.analysisParameters = ...;
solution = femat.solve(model, state, options, vars);

function [elementK, elementForce] = my_analysis(model, state, vars)
elementParameters = vars.elementParameters;
analysisParameters = vars.analysisParameters;

% Compute the batched element response using the supplied variables.
[elementK, elementForce] = ...;
end

Nodal-field interpolation

Application-defined nodal fields can be interpolated at one quadrature-point index for all elements at once:

fields = femat.element.interpolate(model, state.fields, iQuad);

A nodal field has model.nNode rows. The interpolated value has model.nElement rows and follows the same element ordering as model.elements.

Tests

The tests cover solving and assembly, custom analyses, material responses, field interpolation, input validation, and VTK output.

setup
results = runtests("tests");
assertSuccess(results)

Examples

Finite-strain torsion


A Neo-Hookean square bar twisted through 360 degrees using displacement control.

The torsion example uses a 36 x 8 x 8 HEX8 mesh, a Neo-Hookean material, and displacement control through 360 degrees. The final solution is compared with JAX-FEM.

setup
cd examples/torsion
example

Topology optimization


Three-dimensional cantilever optimized under a distributed downward load on the lower free edge.

The example uses a 60 x 20 x 4 HEX8 mesh, a volume fraction of 0.3, penal = 3, and rmin = 1.5.

setup
cd examples/top3d
example

Citation

@software{xu2026femat,
  author = {Weipeng Xu},
  title = {FEMAT: Finite Element Analysis in MATLAB},
  url = {https://github.com/xwpken/femat},
  year = {2026},
}

About

Finite Element Analysis in MATLAB

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages