Skip to main content

Introduction

Presented here is a PyTorch implementation of mesh graph networks (MGNs) for predicting von Mises stress fields in 2D structural components with arbitrary hole geometries.

This repository accompanies the paper:

Kunz, J. & Choudhary, K. (2026). "Mesh Graph Neural Network Framework for Accelerating Finite Element Simulation for Arbitrary Geometries." [Journal TBD].

Key Features

  • Geometry-agnostic: Generalizes to unseen hole shapes without retraining
  • Translation/rotation invariant: Uses relative edge features and node-type embeddings rather than absolute coordinates
  • Clean, high-level API: Go from geometry to trained surrogate model with simplicity
  • Fast inference: Sub-second predictions compared to minutes for FEM

Overview schematic

Installation

# Install FEniCS for Colab
!wget "https://fem-on-colab.github.io/releases/fenics-install-release-real.sh" -O "/tmp/fenics-install.sh" && bash "/tmp/fenics-install.sh"
!apt-get install -y libglu1-mesa -q

# Install meshgraphnet
!pip install meshgraphnet -q

Local (conda)

# FEniCS must be installed via conda
conda install -c conda-forge fenics

# Then install meshgraphnet
pip install meshgraphnet

Package Structure

meshgraphnet/
├── mesh_object/            # Geometry loading & meshing (STEP -> Dolfin)
├── fem_object/             # FEM problem setup, solving, and visualization
│   ├── material.py         # Linear-elastic material properties
│   ├── load_types.py       # VolumeLoad, SurfaceLoad, EdgeLoad, PointLoad
│   ├── load_collection.py  # Housing for various load types
│   ├── fixed_boundary.py   # FEM boundary condition (only fixed is currently supported)
│   └── fem_object.py       # Main FEMObject class
├── ml_object/              # ML training & evaluation on FEM results
│   ├── ml_object.py        # MLObject wrapper (sklearn + GNN)
│   ├── gnn.py              # Graph Neural Network (GNN)
│   ├── mgn.py              # Mesh Graph Network (MGN); main result
│   ├── basic_gcn.py        # Basic graph convolution network (GCN)
│   └── relative_gcn.py     # GCN that uses differences
├── units/                  # Unit system management (Pint-based)
│   └── unit_system.py      # UnitSystem, Units presets
└── common_utils/           # Shared formatting helpers

Key Classes

MeshObject

Represents a mesh. Loads a geometry file (e.g. STEP), runs Gmsh auto-meshing, and produces a Dolfin mesh ready for FEniCS. Usage snippet (see examples folder for more):

mesh = MeshObject("bracket.step", mesh_size=5, units=Units.SI_MM)
mesh.summary()      # prints statistics: vertices, cells, extents
mesh.visualize()    # matplotlib plot of the mesh

FEMObject

Represents a finite element method (FEM) simulation object. Combines a mesh, loads, boundary conditions, and material into a complete linear-elastic FEM problem. Solves with FEniCS and exposes results as NumPy arrays. Usage snippet (see examples folder for more):

fem = FEMObject(
    mesh=mesh,
    loads=loads,
    boundaries=[FixedBoundary("left")],
    material=Material.steel(),
    name="Cantilever bracket"
)

fem.visualize_setup()       # preview loads & BCs
fem.solve()                 # run FEniCS solver
fem.plot_displacement()     # displacement field
fem.plot_stress()           # von Mises stress
fem.save_results("out.csv") # export nodal results

MLObject

Represents a machine learning (ML) model object. Trains sklearn or GNN surrogate models on FEM result CSV data, with built-in cross-validation, feature analysis, and visualization. Usage snippet (see examples folder for more):

ml = MLObject(
    data="fem_results.csv",
    features=["x (m)", "y (m)"],
    objectives=["von_mises (GPa)"],
)

ml.summary()
ml.analyze_features(plot=True)
ml.train(model=GradientBoostingRegressor())
ml.evaluate_on_unseen_data()
ml.plot_predictions()

GNN/MGN

Represents either a graph neural network (GNN) model or a mesh graph network (MGN) model that uses node-level regression on FEMObjects.

  • GNN: standard GCN operating on (X, y) feature matrices with an explicit edge CSV
  • MGN: geometry-agnostic model inspired by Pfaff et al. 2021. Uses relative edge features and learned node-type embeddings (such as hole or fixed) so it can generalize across different geometries. Usage snippet (see examples folder for more):
mgn = MGN(hidden_channels=64, num_layers=20, global_features=["load"], epochs=5000)

ml = MLObject(
    train_fem=train_fems,   # list of solved FEMObjects
    test_fem=test_fem,
    objectives=["von_mises"],
)
ml.train(model=mgn, model_name="MGN")
mgn.save("model.pt")

# Load and reuse later:
mgn = MGN.load("model.pt")

Dependencies

Library Purpose
fenics / dolfin FEM solver
gmsh Auto-meshing from STEP/geometry files
meshio Mesh format conversion
pint Unit arithmetic and conversion
torch / torch_geometric Graph neural networks
scikit-learn Classical ML models
numpy, pandas Numerics and data handling
matplotlib Visualization

See also requirements.txt.

Correspondence

License

Apache License 2.0

Metadata

Release files for meshgraphnet 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for meshgraphnet 0.1.3
File Size Uploaded Provenance Actions
meshgraphnet-0.1.3.tar.gz 61.2 kB Without provenance Details for meshgraphnet-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for meshgraphnet 0.1.3
File Interpreter ABI Platform Actions
meshgraphnet-0.1.3-py3-none-any.whl Python 3 none any Details for meshgraphnet-0.1.3-py3-none-any.whl

Total release size: 128.5 kB

Release files / meshgraphnet-0.1.3.tar.gz

Download URL meshgraphnet-0.1.3.tar.gz
Size 61.2 kB
Tags Source
SHA-256 checksum
How to use checksums
21061f0ed1dba054d65ca8eeb63e36834dc5a73412608ba62cee8be7d1658b47
BLAKE2b-256 checksum
How to use checksums
f208e4300d9eaa9806031dbe7a9144a715caafa267c4a0bc3ceb505ccf270d72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / meshgraphnet-0.1.3-py3-none-any.whl

Download URL meshgraphnet-0.1.3-py3-none-any.whl
Size 67.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15956ca01ac69ed9938eab69299462575e2c9019a34e747cd0b77d654fdbab64
BLAKE2b-256 checksum
How to use checksums
e22b266436ca334baa79f6be6dfff8e2295ec18dce1ce60fb8fab22d3bc6675d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for meshgraphnet 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page