A C++ expression system for partial differential equations enables generic simulations of biological hydrodynamics

Abhinav Kumar Singh, Pietro Incardona, Ivo F. SbalzariniThe European Physical Journal E 2021

Abstract

We present a user-friendly and intuitive C++ expression system to implement numerical simulations of continuum biological hydrodynamics. The expression system allows writing simulation programs in near-mathematical notation and makes codes more readable, more compact, and less error-prone. It also cleanly separates the implementation of the partial differential equation model from the implementation of the numerical methods used to discretize it. This allows changing either of them with minimal changes to the source code. The presented expression system is implemented in the high-performance computing platform OpenFPM, supporting simulations that transparently parallelize on multi-processor computer systems. We demonstrate that our expression system makes it easier to write scalable codes for simulating biological hydrodynamics in space and time. We showcase the present framework in numerical simulations of active polar fluids, as well as in classic simulations of fluid dynamics from the incompressible Navier-Stokes equations to Stokes flow in a ball. The presented expression system accelerates scalable simulations of spatio-temporal models that encode the physics and material properties of tissues in order to algorithmically study morphogenesis.

Introduction

In scientific computing, a significant challenge arises from the tight coupling between mathematical models—expressed as partial differential equations (PDEs)—and the numerical methods used to solve them. Traditionally, implementing a new physical term or switching discretization schemes (e.g., from finite differences to mesh-free methods) requires extensive rewriting of the codebase. This "hard-coding" approach is error-prone, difficult to maintain, and creates a high barrier to entry for researchers in biology and physics who may not be expert software engineers.

This work addresses these challenges by introducing a "separation of concerns." By decoupling the physical model from the numerical solver, scientists can define the physics of a system independently of the underlying computational implementation.

Methods and Implementation

The core of this framework is a C++ template expression system integrated into OpenFPM, an open-source high-performance computing (HPC) platform. The system utilizes operator overloading to construct compile-time expression trees. For instance, a mathematical expression like $\partial_x P + \partial_y P$ is represented as a tree structure that the compiler optimizes into efficient machine code, ensuring no "abstraction penalty" compared to low-level, hand-written C++.

The expression system uses C++ template metaprogramming to map mathematical operators to an expression tree for efficient computation.

OpenFPM manages complex tasks such as memory allocation, domain decomposition, and inter-processor communication (MPI/GPU) transparently. A key feature is the support for Discretization-Corrected Particle Strength Exchange (DC-PSE), a mesh-free method ideal for simulations involving complex or deforming geometries, such as moving cells or tissues.

Results and Validation

The system's primary advantage is its compactness and flexibility. An incompressible Navier-Stokes solver with pressure correction was implemented in only 156 lines of code. Remarkably, switching from a mesh-free DC-PSE solver to a standard finite-difference solver required changing only 21 lines of code.

To validate the framework, we utilized several benchmark problems:

  • Lid-Driven Cavity Flow: A standard test for incompressible Navier-Stokes solvers.
  • Active Polar Fluids: Testing the nonlinear coupling of polarity and velocity fields in biological matter.
  • Analytical Stokes Flow: Verifying accuracy in 3D non-Cartesian geometries.
Validation of the DC-PSE method against finite differences (FD) and established literature data (Ghia et al.) for the lid-driven cavity benchmark.

Numerical results demonstrated second-order convergence, confirming mathematical integrity. Furthermore, the system showed high parallel efficiency, maintaining 87% efficiency when scaling to 24 CPU cores on an Intel Xeon processor.

Conclusion and Future Work

While the use of complex C++ templates increases compile times, the benefits in code readability, maintainability, and development speed are substantial. Future developments will focus on extending the system to support Smoothed Particle Hydrodynamics (SPH) and simulations on curved manifolds, such as the surfaces of growing embryos, further bridging the gap between mathematical theory and large-scale biological simulation.

Summary updated

BibTeX
@article{singh2021c,
  author = {Abhinav Kumar Singh and Pietro Incardona and Ivo F. Sbalzarini},
  title = {{A C++ expression system for partial differential equations enables generic simulations of biological hydrodynamics}},
  journal = {The European Physical Journal E},
  year = {2021},
  doi = {10.1140/epje/s10189-021-00121-x},
}
Figure