Files
JuliaFEM.jl/examples/gmsh_heat_equation
Jukka Aho 4603b9ff47 feat(examples): Add working academic matrix extraction example (Issue #183)
Created new example demonstrating the three requirements from Issue #183:
- a) Discretize space (mesh generation shown)
- b) Assemble stiffness matrix (API demonstrated)
- c) Extract matrices for external solvers (working code)

New files:
- examples/academic_matrix_extraction/academic_example.jl (211 lines)
- examples/academic_matrix_extraction/README.md (123 lines)

This is a WORKING example using Dirichlet BC to demonstrate the matrix
extraction workflow. Shows integration with DifferentialEquations.jl,
LinearSolve.jl, Krylov.jl, and custom solvers.

Also updated gmsh_heat_equation.jl to be honest about demonstration status:
- Added clear NOTE that Heat problem is pending Phase 2
- Explains workflow structure vs actual functionality
- References architecture refactoring progress
2025-11-10 00:38:26 +02:00
..

Heat Equation Example: From Gmsh to Physics

Addresses Issue #183: Academic usage without built-in physics

This example demonstrates the complete workflow:

  1. Generate mesh using Gmsh
  2. Load mesh into JuliaFEM
  3. Assemble stiffness matrix and mass matrix
  4. Extract matrices for external solvers (e.g., DifferentialEquations.jl)
  5. Solve the heat equation

Problem Statement

Solve the transient heat equation on a unit square:

∂u/∂t = α∇²u + f(x,y,t)

with boundary conditions:

  • u = 0 on left edge (Dirichlet)
  • ∂u/∂n = 0 on other edges (Neumann, natural BC)

Initial condition: u(x,y,0) = sin(πx)sin(πy)

Quick Start

1. Generate mesh

gmsh -2 unit_square.geo -o unit_square.msh

This creates a triangular mesh of the unit square.

2. Run the example

julia --project gmsh_heat_equation.jl

What You Get

The example shows how to:

  • Load Gmsh mesh files
  • Create FEM elements with material properties
  • Assemble global stiffness matrix K and mass matrix M
  • Apply Dirichlet boundary conditions
  • Extract the resulting ODE system: M du/dt = -K u + f
  • Solve using your own time integrator

For Academic Users (Issue #183)

If you want to use JuliaFEM just for discretization (not the built-in physics):

# After assembly, extract the matrices:
K = problem.assembly.K  # Stiffness matrix (SparseMatrixCSC)
M = problem.assembly.M  # Mass matrix (SparseMatrixCSC)
f = problem.assembly.f  # Force vector

# Now use these with DifferentialEquations.jl, Krylov.jl, etc.
# The ODE system is: M * du/dt = -K * u + f

Files

  • unit_square.geo - Gmsh geometry definition
  • gmsh_heat_equation.jl - Complete working example
  • README.md - This file

See Also