This project demonstrates an open-source workflow for simulating and building a physics-informed AI surrogate for a cylindrical pressure vessel under internal pressure.
We replace commercial FEA tools like ANSYS with FEniCS (for physics-based simulation) and combine it with Proper Orthogonal Decomposition (POD) and a Neural Network for rapid prediction of deformation fields.
The pipeline:
- Generate a small 3D hollow cylinder mesh with Gmsh.
- Run FEniCS to solve linear elasticity with varying parameters (Young’s modulus
Eand pressurep). - Build a snapshot matrix from displacement results.
- Apply POD to extract a low-dimensional basis.
- Train a PyTorch NN to map
(E, p)→ POD coefficients. - Reconstruct the displacement field from NN predictions.
- Compare NN results vs. FEniCS results with:
- Error histograms
- 3D scatter plots of spatial error
- ParaView
.xdmfoutput for full visualization.
This example uses a coarse mesh to keep runtimes low (~seconds per simulation), but can be adapted to high-resolution meshes for production.
pressure_vessel_pod_nn.ipynb– Complete runnable Jupyter notebook with explanations.pressure_vessel_pod_nn.py– Script version (same logic, easier CLI execution).requirements.txt– Python dependencies.- (Generated after running the notebook):
vessel.msh,vessel_mesh.xdmf,vessel_facets.xdmf– Mesh files.ground_truth.xdmf– FEniCS displacement field for chosen parameters.nn_prediction.xdmf– Neural network predicted displacement field.error_field.xdmf– Absolute displacement error magnitude field.
Install everything with:
pip install -r requirements.txtRequirements:
fenics==2019.1.0– Physics-based finite element solver.gmsh– Mesh generation.meshio– Mesh format conversion.torch– Neural network training.numpy,scikit-learn,matplotlib– Data handling and visualization.
jupyter notebook pressure_vessel_pod_nn.ipynbRun all cells to:
- Generate mesh
- Solve PDE for multiple
(E, p)combinations - Perform POD
- Train NN
- Output ParaView-ready results
python pressure_vessel_pod_nn.pyThis will execute the same pipeline without interactive plots.
Three .xdmf files are saved for ParaView:
- Ground Truth:
ground_truth.xdmf - NN Prediction:
nn_prediction.xdmf - Error Field:
error_field.xdmf
To view:
- Open
.xdmffile in ParaView and click Apply. - Use "Surface" or "Warp By Vector" to view displacements.
- Color by displacement magnitude or error magnitude.
- Compare ground truth vs NN visually.
- This is a demo mesh with coarse resolution for fast runs.
Replacelcin the mesh generation step for finer accuracy. - Extensible to nonlinear materials, thermal loading, or dynamic simulations.
- The POD+NN framework can be swapped for other reduced-order models (e.g., GP regression).
This project is licensed under the MIT License - see the LICENSE file for details.
