Torch-DPhys: A Torch-Native, MOOSE-Compatible Framework for Differentiable Physics Simulation and Hybrid Machine Learning Integration
Organizations: Department of Nuclear Engineering, Texas A&M University
Abstract
We present Torch-DPhys, a Torch-native framework implemented in PyTorch for differentiable physics simulation and hybrid physics-machine learning. It implements selected thermal-hydraulic modeling concepts and discretizations from MOOSE's Thermal Hydraulics Module and the System Analysis Module (SAM), with a preliminary extension to continuum mechanics. Native tensor residuals support CPU and GPU execution, compilation of selected numerical kernels, and sparse direct linear solves. Sensitivities are obtained by differentiating executed numerical operations or through discrete adjoints of converged residual equations. Verification combines analytical solutions, reference-code comparisons, and derivative checks. Demonstrations cover plane-strain elasticity, one- and two-loop thermal-hydraulic transients, and an axisymmetric molten-salt fast reactor. For the reactor, comparison with SAM-Lite gives a maximum normalized field discrepancy of 1.13 x 10^-5 over 200 adaptive time steps, demonstrating agreement between the tested discrete implementations. Selected transient sensitivities are assessed using tangent-linear calculations and finite differences on fixed time schedules. Two applications illustrate the framework's connection between simulation and optimization. A residual-adjoint parameter-identification calculation recovers nominal pump head and heating power with relative errors below 0.06% from noiseless synthetic MOOSE observations. A separate three-loop plant demonstration uses solver-in-the-loop training of a predictive controller by differentiating trajectory-level objectives through the thermal-hydraulic simulation. These examples illustrate a foundation for gradient-based inference, control, and coupled physics-machine learning models in nuclear engineering.
Figures & tables
| Quantity | Configuration |
|---|---|
| Fluid properties | Constant kg/m 3 , J/(kg K), and Pa s. Molecular conductivity varies linearly from 0.9952 at 800 K to 1.0288 W/(m K) at 1200 K. |
| Mixing length | 0.07 m for m, decreasing linearly to 0.018 m at m, and 0.018 m beyond. Turbulent Prandtl number . |
| Inlet | Recorded normalized Nek5000 velocity profile, multiplied by m/s and the coarse-boundary flux correction 1.02705297222. Radial velocity is zero and temperature is 900 K. |
| Outlet, walls and axis | Outlet pressure 161 kPa. Walls are no-slip and adiabatic. The symmetry axis has zero radial velocity and zero normal gradients of axial velocity and temperature. |
| Initial fields | Both velocity components m/s, pressure 110 kPa and temperature 900 K, subject to the prescribed boundary values. |
| Body force and heating | Gravity is m/s 2 in the mesh axial direction. The fixed volumetric heat source is given by Eq. ( 5 ). |
| Field | Unit | Maximum absolute difference | Step |
|---|---|---|---|
| Temperature | K | 31 | |
| Axial velocity | m/s | 3 | |
| Radial velocity | m/s | 3 | |
| Pressure | Pa | 4 |
| Item | Setting |
|---|---|
| Workload | 200 adaptive forward steps to s at baseline tolerances (266 Newton iterations), followed by a 200-step discrete residual adjoint. |
| Hardware and precision | Intel Core Ultra 7 265K CPU, NVIDIA RTX 2000 Ada GPU (16 GB), float64 arithmetic under Windows Subsystem for Linux 2 (WSL2). |
| Software stack | Python 3.12.3, PyTorch 2.13.0+cu129, Triton 3.7.1, CUDA 12.9, cuDSS 0.8.0.10, NumPy 2.1.2, SciPy 1.16.1, Intel oneAPI Math Kernel Library (MKL) 2024.2. |
| Thread and rank settings | Torch-DPhys: 4, 8, or 16 Torch/OpenMP/MKL threads (with MKL_CBWR=AUTO,STRICT and 1 OpenBLAS thread). SAM-Lite: 1 rank with 1 or 4 MOOSE threads, or 4, 8, and 16 MPI ranks with 1 thread per rank. |
| Measurement protocol | Medians and min–max ranges over three warm repetitions for Torch-DPhys; single runs for cold compilation and SAM-Lite. Forward timings measure Transient.execute() (Torch-DPhys) and cumulative PicardSolve (SAM-Lite). |
| Observation source / Initial guess | Initial (m) | Initial (W) | L-BFGS-B updates | Recovered (m, W) |
|---|---|---|---|---|
| Same solver / Start A | 0.06615 | 1300 | 8 | (0.094500, 2000.00) |
| Same solver / Start B | 0.12285 | 2700 | 7 | (0.094500, 2000.00) |
| MOOSE / Start A | 0.06615 | 1300 | 8 | (0.094516, 1998.87) |
| Differentiation route | Backward time (s) | Peak allocation (MiB) |
|---|---|---|
| Converged-residual discrete adjoint | 26.9 [26.1, 27.0] | 24.7 |
| Unrolled Newton AD (with step recomputation) | 268 [263, 274] | 201.0 |
Appendix figures & tables7 assets
Supplementary material from the paper’s appendix.
Appendix
| Observations | Parameter | Adjoint derivative | |||
|---|---|---|---|---|---|
| Same solver | Pump head | ||||
| Same solver | Heating power | ||||
| MOOSE | Pump head | ||||
| MOOSE | Heating power |
| Quantity | Change ( s minus s) | Context |
|---|---|---|
| Mean outlet temperature | K | |
| Mean inlet pressure | kPa | of the inlet–outlet pressure drop |
| Outlet mass flow from velocity field | kg/s | Global mass-flux imbalance rises from to |
| Maximum core temperature | K |
| Quantity | Comparison scope | Maximum discrepancy |
|---|---|---|
| Jacobian assembly | Tested states within each execution mode | Bitwise identical |
| Forward states | Eager trajectories (Eq. ( 8 )) | |
| Adjoint gradients | Evaluated on common dense trajectories | |
| Adjoint gradients | Sparse forward trajectory vs. dense reference |
| Trajectory window / schedule | Max. discrepancy | FD counts | Reference change |
|---|---|---|---|
| 1 step, backward Euler | 11/3 | ||
| 3 steps, backward Euler + BDF2 | 11/3 | ||
| 10 steps, with step-9 retry | 11/3 | ||
| 10 steps, baseline schedule | 3/0 | ||
| 40 steps, baseline schedule | 3/0 |
| Evaluated quantity | Maximum normalized discrepancy |
|---|---|
| Assembled residual vector | |
| Residual vector–Jacobian product (VJP) | |
| Element-Jacobian blocks | |
| Dense LU factors and linear-system solutions | Bitwise identical |
| Adjoint gradient (40-step window) | |
| Adjoint gradient (10-step retry window) |
Differentiable Physics
Differentiable physics makes physical simulators usable for gradient-based learning, parameter estimation, design, and control.
See all 64 papers