This repository provides a PyTorch implementation of MeshGraphNets [1], adapted for stationary-problem. MeshGraphNets was designed for learning time-dependent mesh-based simulations using Graph Neural Networks (GNNs).
Unlike transient problems characterized by a local information propagation over time, stationary problems must directly consider the interactions between distant features. A natural approach for capturing long-range interactions with GNNs is to increase the number of message-passing layers. However, this method is both computationally expensive and prone to oversmoothing [2][3].
The standard MeshGraphNet is modified as follows:
- Edge Augmentation: New edges are added between randomly-selected node pairs, reducing data propagation locality, as explained in [2].
- Rotation/Shift Invariant Node Coordinates: The node coordinates are transformed to a rotation- and shift-invariant coordinate system and included as node attributes, as explained in [2].
- Install the requirements
pip install -r requirements.txt- Edit the config file
config.json. Available parameters:
{
# Training device (cuda/cpu)
"device": "cuda",
# Dataset configuration
"dataset_path": "davide-d/simple_lattice_cell_samples_2d",
"training_groups": [ # Groups used for training
"circles",
"cubic_chiral",
"curved",
"curved_diamond",
"curved_plus",
"diamond",
"square",
"squared_diamond"
],
"extra_groups": [ # Groups for additional evaluation
"hinge",
"cubic_chiral_thick"
],
"train_test_val_split": [0.6, 0.2, 0.2], # Dataset split ratios
# Data processing parameters
"edge_augmentation": 0.2, # Ratio of random edges to add
"simulation_coords": true, # Use rotation/shift-invariant coordinates
# Training parameters
"num_epochs": 5000, # Total training epochs
"loss": "mse", # Loss function (mse/l1)
"batch_size": 1, # Graphs per batch
"initial_lr": 1e-4, # Initial learning rate
"decay_steps": 125, # Steps between LR decay
"decay_rate": 0.1, # LR decay factor
"min_lr": 1e-6, # Minimum learning rate
# Model architecture
"latent_size": 128, # Size of hidden layers
"dropout_rate": 0.005, # Dropout probability
"num_message_passing_steps": 15, # Number of message passing iterations
# Output paths
"log_folder": "run/log", # TensorBoard log directory
"dataset_save_path": "run/cached_dataset.pt",
"checkpoint_save_path": "run/checkpoint.pt",
"checkpoint_freq": 1 # Save checkpoint every N epochs
}- Run training
python src/train.py config.json- Evaluate the results
python src/eval.py \
--dataset-path run/cached_dataset.pt \
--checkpoint-path run/checkpoint.pt \
--device cuda \
--extra-datasets extra_datasets.jsonThe evaluation script accepts these arguments:
- Required:
--dataset-path: Path to the cached dataset file--checkpoint-path: Path to the model checkpoint file
- Optional:
--device: "cuda" or "cpu" (defaults to "cuda" if available)--extra-datasets: JSON file for additional dataset evaluation
Example extra_datasets.json:
[
{
"name": "Out-of-range group",
"path": "davide-d/simple_lattice_cell_samples_2d",
"group": "cubic_chiral_thick"
},
{
"name": "Unseen group",
"path": "davide-d/simple_lattice_cell_samples_2d",
"group": "hinge"
}
]A synthtetic dataset is composed of 2D parametric lattice unit-cells simulated under mechanical deformation.
- Generate geometries through parameter sampling
- Mesh using Gmsh [4]
- Simulate the designs with FEniCS [5] (linear-elastic simulations under fixed boundary conditions)
- Compose the dataset with geometries and simulation results
| Parameter | Sampling Range | Description |
|---|---|---|
thickness |
[0.1, 0.3] | Lattice thickness |
mesh_density_factor |
[3, 4] | Controls mesh density ( mesh characteristic length = thickness / mesh_density_factor) |
curvature |
[0.35, 0.65] | Affects the curvature of the structural elements (when applicable) |
8 groups of exemplary 2D parametric lattice unit cells
| Curved + Plus | Diamond | Square | Square + Diamond |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Additional parameter:amplitude [0.35, 0.65] |
No additional parameters | No additional parameters | No additional parameters |
- Parameter sampling method: Latin Hypercube Sampling (LHS)
- Sample size: 300 data points per group
- Linear elastic uniform material (Young's modulus
E = 1e3, Poisson's ratioν = 0.3) - Lagrange elements (polynomial degree
p = 2) - Fixed boundary conditions (bottom nodes fixed, top nodes with
-0.1displacement in y-direction)
The simulation data is translated into a graph:
- Node type (1-hot encoding: fixed, displaced, free)
- Node coordinates (2D numerical, rotation and shift invariant)
- Cartesian distance between connected nodes (1D numerical)
- Difference between connected nodes (2D numerical)
- Edge type (categorical): augmented or not-augmented edge
The graph edges are augmented by adding new edges between randomly-selected node pairs. The augumentation procedure increases the number of edges by 20%.
- Split each parametric group: 60% training, 20% validation, 20% test
- Compile final training, validation, and test sets by combining the training, validation and tests split of each parametric group, respectively.
- Standardize features based on final training-set statistics (Von-Mises stress, node and edge attributes)
The model follows the MeshGraphNets [1] architecture, consisting of 15 convolutional graph blocks with a latent size of 128, and is enriched by dropout regularization layers placed after the encoding block and between each convolutional block to avoid overfitting.
- Single GPU
- 1000 epochs
- Adam optimizer
- Initial learning rate: 1e-4, exponential decay to 1e-6 in 125 steps
- Batch size:
1 - MSE loss function
A further metric is the mean relative error in the peak (destandardized) von Mises stress
- Mean relative error of peak von Mises stress (mean over all test-set simulations):
8.0%(test set) 58.5%of simulations have an error below5%(test set)72.7%of simulations have an error below10%(test set)88.8%of simulations have an error below20%(test set)
The highest relative error (78.4%) for the peak von Mises stress in the test set is obtained for the following example

The cubic chiral parametric group has been resampled with an out-of-distribution thickness in the interval [0.6, 0.65] out of the original interval [0.1, 0.3] used during training.
- Mean relative error of peak von Mises stress:
36.0%(mean over all simulations on cubic chiral dataset with out-of-distribution thickness)
- Fixed boundary conditions, material properties, and geometry bounding box
- Model learns the FEM discretization error
The model performs poorly on unseen cell group that were not included in the training set. For example a hinge cell was NOT included in the training set
[1] Pfaff, Tobias, et al. "Learning mesh-based simulation with graph networks." arXiv preprint arXiv:2010.03409 (2020).
[2] Gladstone, Rini Jasmine, et al. "Mesh-based GNN surrogates for time-independent PDEs." Scientific reports 14.1 (2024): 3394.
[3] Rusch, T. Konstantin, Michael M. Bronstein, and Siddhartha Mishra. "A survey on oversmoothing in graph neural networks." arXiv preprint arXiv:2303.10993 (2023).
























