SymPhas 2.0: C++17 Simulation Framework
- SymPhas 2.0 is a C++17 simulation framework designed for scalable phase-field and reaction-diffusion models with compile-time symbolic differentiation.
- It leverages a symbolic algebra engine to automatically compute functional derivatives and generate high-order finite-difference stencils at compile time.
- The framework employs MPI, OpenMP, and CUDA backends to enable large-scale simulations with significant speedups on 2D and 3D grids.
SymPhas 2.0 is a C++17-based simulation framework designed for efficient, scalable implementation of phase-field and reaction-diffusion models. Building on the original SymPhas architecture, version 2.0 employs a compile-time symbolic algebra engine to represent all mathematical objects and operations as C++ template types, enabling zero-overhead manipulation of models at the level of free-energy functionals or partial differential equation (PDE) operators. Major advancements include automatic compile-time evaluation of functional derivatives, support for directional and mixed derivatives, compile-time symbolic summation, and arbitrary-order finite-difference stencil generation. CPU (MPI + OpenMP) and GPU (CUDA) backends permit simulations on systems as large as (2D) and (3D), with observed speedups up to compared to earlier CPU-only implementations (Silber et al., 13 Nov 2025).
1. Symbolic Model Specification and Framework Architecture
SymPhas 2.0's architecture is centered around a symbolic-algebra kernel, a modular finite-difference solver backend, and a model-abstraction layer. All mathematical expressions, including fields, operators, and free-energy densities, are encoded as C++ template type trees. Expression transformation—such as simplification, tensor contraction, and derivative computation—is performed exclusively at compile time, which eliminates runtime evaluation overhead.
The model-abstraction layer enables specification of phase-field and reaction-diffusion systems directly from their free-energy functionals or PDE forms. For phase-field models:
users can declare the model with a single macro, e.g.,
1 |
FREE_ENERGY((DynamicsType), INT(freeEnergyExpr)) |
which instantiates the integrand, performs symbolic functional differentiation, and incorporates the result into the dynamical evolution (conserved or non-conserved). Reaction-diffusion systems can be similarly constructed from PDEs or (where available) energy-like functionals (Silber et al., 13 Nov 2025).
2. Compile-Time Symbolic Differentiation
SymPhas 2.0 provides compile-time evaluation of variational (functional) derivatives, essential for deriving kinetic equations from a specified free-energy functional. Given
the functional derivative
is encoded in the type SymbolicFunctionalDerivative, and template-recursive expansion computes all relevant terms during compilation. Directional derivatives and mixed higher-order derivatives are supported via types such as OpOperatorDirectionalDerivative<n,i> and OpOperatorMixedDerivative, which allow for arbitrary-order differentiation along specific spatial directions, all resolved at compile time. Symbolic summations (e.g., ) are expanded statically using the SymbolicSum construct, yielding efficient code for tensor-valued and multi-field systems (Silber et al., 13 Nov 2025).
3. Automated Derivation of High-Order Finite-Difference Stencils
All finite-difference stencils in SymPhas 2.0 are derived symbolically at compile time. For a derivative of order and accuracy , the framework constructs the associated interpolation polynomial and solves a linear Vandermonde system—leveraging symmetry, parity, and compile-time evaluation via constexpr—to determine optimal stencil coefficients. The computed stencil is instantiated as a type Stencil<Offsets...,Coeffs...>.
Representative examples include:
- Second-order central difference :
- Fourth-order central difference :
- Second-order Laplacian in 2D:
All stencils are available for arbitrary derivative orders, spatial dimensions, and accuracy, completely eliminating manual implementation (Silber et al., 13 Nov 2025).
4. Parallelization and GPU Acceleration
SymPhas 2.0 is parallelized for modern high-performance computing architectures, supporting distributed-memory decomposition via MPI, shared-memory threading (OpenMP), and GPU offload (CUDA):
- MPI/CPU Backends: The computational domain is divided into sub-domains, each assigned to an MPI rank. Halo exchanges for stencil operations use non-blocking calls (
MPI_Isend/Irecv), followed by OpenMP-parallelized stencil calculation on interior points. Global reductions (e.g., for monitoring free energy) employMPI_Allreduce. - CUDA/GPU Backend: Symbolic expression trees are mirrored as CUDA-device types, and a templated kernel
LaunchKernel<ExprTree,HaloWidth, ...>is instantiated by the compiler. Data is laid out in struct-of-arrays (SoA) format to maximize memory coalescing and bandwidth. All temporary buffers remain in GPU memory for the simulation duration; only diagnostics are transferred asynchronously to CPU memory. CUDA streams and events overlap kernel execution and I/O, mitigating data-transfer bottlenecks (Silber et al., 13 Nov 2025).
5. Performance Benchmarks
SymPhas 2.0 provides substantial acceleration for large-scale phase-field and reaction-diffusion simulations. Benchmarks include models such as Allen–Cahn (Model A), Cahn–Hilliard (Model B), coupled scalar systems (Model C), and hybrid scalar+vector fields (Model H), operating in double precision.
- Maximum tested grid sizes: (2D), (3D)
- CPU platforms: Intel i7-9700, AMD Ryzen 7 5800, i7-1195G7 laptops
- GPU platforms: NVIDIA RTX 2070 Super, RTX 3080, GTX 1650, H100 SXM
Observed results include speedups up to for 3D double-precision runs on the H100 GPU compared to SymPhas 1.0 on a multi-threaded CPU. For small grid sizes, fixed overheads (kernel launch and device synchronization) dominate, but with large problem sizes, scaling approaches when compute throughput saturates. Sudden jumps in time-to-solution are observed when problem sizes exceed the L2/shared cache capacity of the GPU (Silber et al., 13 Nov 2025).
6. Practical Usage and Model Prototyping
Model definition and simulation in SymPhas 2.0 are accomplished with concise C++ code. The framework provides macros for declaring order parameters, defining free-energy functionals, and specifying dynamic types (conserved, non-conserved):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <SymPhas/SymPhas.hpp> using namespace symphas; #define phi op(1) MODEL(MA_FE, (SCALAR), FREE_ENERGY((NONCONSERVED), INT( LANDAU_FE(phi, c(1), c(2)) ) ) ) int main(int argc, char** argv) { symphas::initialize(&argc, &argv); Config cfg("modelA.cfg"); auto sim = make_simulator<MA_FE,Device::CUDA2D>(cfg, {1024,1024}); sim.run(1000); sim.write("phi_final.vtk"); symphas::finalize(); return 0; } |
This example implements the Landau free-energy model (“Model A”) entirely on a 2D grid using GPU acceleration. The user's involvement is restricted to supplying symbolic expressions for the free energy and runtime parameters; all kernel optimization and parallelization is automatic (Silber et al., 13 Nov 2025).
7. Context and Evolution from SymPhas 1.0
The original SymPhas system provided a modular C/C++ template metaprogramming approach to phase-field and reaction-diffusion simulation, supporting model specification via symbolic expressions, compile-time transformation, and integration with user-defined solvers. Its numerics included forward Euler and semi-implicit Fourier spectral schemes with OpenMP-based parallelism (Silber et al., 2021). SymPhas 2.0 extends this paradigm to distributed-memory platforms (MPI), generalizes symbolic algebra to cover tensor-valued quantities and higher-order operations, and introduces GPU-optimized pipelines. A plausible implication is that this trajectory enables broad applicability to emerging large-scale, multi-physics simulations while preserving the high abstraction and performance guarantees of the template metaprogramming approach.
For further reference, see (Silber et al., 13 Nov 2025) and (Silber et al., 2021) for detailed descriptions and benchmarks.
Sponsored by Paperpile, the PDF & BibTeX manager trusted by top AI labs.
Get 30 days free