Skip to content

About

M1 CSMI individual semester project on the finite element method in Python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

M1 CSMI Finite Element Method Project in Python

Implement a two-dimensional finite element solver for the Poisson equation with Dirichlet boundary conditions. You will read Gmsh meshes, integrate functions on triangular elements, assemble and solve a sparse system, and export fields for ParaView. This is an individual semester project for the M1 Project course.

The project brief explains the mathematics and scientific tasks. The proposed rubric describes the software deliverables and milestones. Record and disclose AI use according to the project instructions in your individual journal.

Run the Starter Examples

You need Git and uv. The repository selects Python 3.12. NumPy and SciPy are declared in pyproject.toml and resolved versions are recorded in uv.lock.

Use GitHub’s Use this template button or clone the individual repository assigned by your instructors. Run these commands at the repository root.

uv sync --locked
uv run --locked python examples/example_evaluator.py
uv run --locked python examples/example_assembly.py

The first example prints f(1.2, 2.2) = 0.29296494. The second solves a small illustrative system. It prints solution = [1. 2. 3. 4.] and a residual close to zero.

When developing the solver, use Python callables for the source function and the boundary value. A CLI can select a named test case or read parameters from a configuration file.

Scientific Work

  1. Read the supplied Gmsh 2.2 ASCII meshes and map node identifiers to array indices. Use the physical boundary segments to compute the perimeter and identify Dirichlet nodes. The four-triangle square has five nodes, area 1, and perimeter 4.

  2. Evaluate a field at mesh nodes and export it in VTK format. Compare the small case to the reference export in ParaView. Implement and validate the triangular quadrature rules in the brief.

  3. Assemble the P1 stiffness matrix and load vector, impose Dirichlet conditions, and solve the sparse system. For the four-triangle square with a unit source and zero boundary values, the discrete solution at the centre is 1/12. Check the boundary values and the residual. Then use the refined and perforated meshes for the experiments in the brief.

Use NumPy arrays for coordinates and element calculations and SciPy’s sparse matrices and solvers for linear algebra. Implement the mesh reader for the supplied format, quadrature, finite element assembly and application of boundary conditions in your own code. Gmsh and ParaView are useful for generating new meshes and inspecting results. The supplied cases run without either tool installed.

Software Deliverables

The starter supplies the scientific brief, meshes, a reference VTK file, two illustrative Python scripts and a locked dependency environment. You will develop the solver and its command line interface, and set up packaging, automated tests, GitHub Actions and Docker.

  • GitHub. Track the work with issues, branches and pull requests. Use PRs for self-review, verification results and instructor feedback.

  • Package. Organize the code in a src/ package, add a build backend and a CLI entry point to pyproject.toml, and keep uv.lock current. Build an installable wheel with uv build and test the installed CLI in a clean environment.

  • Tests and CI. Add a development dependency on pytest and write numerical unit tests and at least one end-to-end test. Use GitHub Actions on pushes and pull requests to install the locked dependencies, run the tests, build the wheel and retain the PDFs as artifacts. Record a regression the workflow detected and how you fixed it.

  • Docker. Write a Dockerfile that uses the locked dependencies. Build it in CI and run a small mesh case with input and output mounts. Identify the delivered image by tag or digest and provide reproduction commands.

  • Documentation. Replace the startup instructions in this README with the exact package, CLI, test and Docker commands for your project. Describe the architecture, supported inputs, expected output and tolerances.

The course’s Python packaging, CI and Docker workshop uses a separate application to show the workflow.

Brief, Report and Presentation

Use the shared CSMI LaTeX style to build the brief and the report.

latexmk -pdf project.tex report.tex

The PDFs are written to output/pdf/. In VS Code, open the source file and use LaTeX Workshop to build and view it. See the style and installation guide. Submit the report and presentation sources with the corresponding PDFs produced in CI.

Source and Licence

Adapted from the original finite element project template. The code, brief and starter materials are provided under the MIT licence.

About

M1 CSMI individual semester project on the finite element method in Python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages