A. Ghaffarizadeh, S.H. Friedman, and P. Macklin. BioFVM: an efficient, parallelized diffusive transport solver for 3-D biological simulations. Bioinformatics, 2015.
DOI: 10.1093/bioinformatics/btv730 (free; open access)
Design philosophy and main capabilities
Solving for many diffusing substrates
Combining simple but tailored solvers
Optimizing the diffusion solver for large 3-D domains
By using constant diffusion and decay coefficients, we were able to write very fast solvers for Cartesian meshes. We use the locally one-dimensional (LOD) method--a specialized form of operator splitting--to break the 3-D diffusion problem into a series of 1-D diffusion problems. For each (y,z) in our mesh, we have a 1-D diffusion problem along x. This yields a tridiagonal linear system which we can solve efficiently with the Thomas algorithm. Moreover, because the forward-sweep steps only depend upon the coefficient matrix (which is unchanging over time), we can pre-compute and store the results in memory for all the x-diffusion problems. In fact, the structure of the matrix allows us to pre-compute part of the back-substitution steps as well. Same for y- and z-diffusion. This gives a big speedup.
Next, we can use all those CPU cores to speed up our work. While the back-substitution steps of the Thomas algorithm can't be easily parallelized (it's a serial operation), we can solve many x-diffusion problems at the same time, using independent copies (instances) of the Thomas solver. So, we break up all the x-diffusion problems up across a big OpenMP loop, and repeat for y- and z-diffusion.
Lastly, we used overloaded +=, axpy and similar operations on the vector of substrates, to avoid unnecessary (and very expensive) memory allocation and copy operations wherever we could. This was a really fun code to write!
The work seems to have payed off: we have found that solving on 1 million voxel meshes (about 8 mm3 at 20 μm resolution) is easy even for laptops.
Simulating many cells
We tailored the solver to allow both lattice- and off-lattice cell sources and sinks. Desktop workstations should have no trouble with 1,000,000 cells secreting and uptaking a few substrates.Simplifying the non-science
Similarly, we stuck to a very simple mesh data structure so we wouldn't have to maintain compatibility with general mesh libraries (which can tend to favor feature sets and generality over performance and simplicity). Rather than use general-purpose ODE solvers (with yet more library dependencies, and more work for maintaining compatibility), we wrote simple solvers tailored specifically to our equations.
The upshot of this is that you don't have to do anything fancy to replicate results with BioFVM. Just grab a copy of the source, drop it into your project directory, include it in your project (e.g., your makefile), and you're good to go.
All the juicy details
- The full details of the numerical algorithm, including information on our optimizations.
- Convergence tests: For several examples, we showed:
- First-order convergence in time (with respect to Δt), and stability
- Second-order convergence in space (with respect to Δx)
- Accuracy tests: For each convergence test, we looked at how small Δt has to be to ensure 5% relative accuracy at Δx = 20 μm resolution. For oxygen-like problems with cell-based sources and sinks, Δt = 0.01 min will do the trick. This is about 15 times larger than the stability-restricted time step for explicit methods.
- Performance tests:
- Computational cost (wall time to simulate a fixed problem on a fixed domain size with fixed time/spatial resolution) increases linearly with the number of substrates. 5-10 substrates are very feasible on desktop workstations.
- Computational cost increases linearly with the number of voxels
- Computational cost increases linearly in the number of cell-based source/sinks
What's next?
- As MultiCellDS (multicellular data standard) matures, we will implement read/write support for <microenvironment> data in digital snapshots.
- We have a few ideas to improve the speed of the cell-based sources and sinks. In particular, switching to a higher-order accurate solver may allow larger time step sizes, so long as the method is still stable. For the specific form of the sources/sinks, the trapezoid rule could work well here.
- I'd like to allow a spatially-varying diffusion coefficient. We could probably do this (at very great memory cost) by writing separate Thomas solvers for each strip in x, y, and z, or by giving up the pre-computation part of the optimization. I'm still mulling this one over.
- I'd also like to implement non-Cartesian meshes. The data structure isn't a big deal, but we lose the LOD optimization and Thomas solvers. In this case, we'd either use explicit methods (very slow!), use an iterative matrix solver (trickier to parallelize nicely, except in matrix-vector multiplication operations), or start with quasi-steady problems that let us use Gauss-Seidel iterative type methods, like this old paper.
- Since advective flow (particularly interstitial flow) is so important for many problems, I'd like to add an advective solver. This will require some sort of upwinding to maintain stability.
- At some point, we'd like to port this to GPUs. However, I don't currently have time / resources to maintain a separate CUDA or OpenCL branch. (Perhaps this will be an excuse to learn Julia on GPUs.)
