## Mean exit time for diffusion on irregular domains

This dataset is comprised of MATLAB codes to support Matthew J Simpson *et al* 2021 *New J. Phys.* **23** 043030 https://doi.org/10.1088/1367-2630/abe60d.

Abstract: Many problems in physics, biology, and economics depend upon the duration of time required fora diffusing particle to cross a boundary. As such, calculations of the distribution of first passagetime, and in particular the mean first passage time, is an active area of research relevant to manydisciplines. Exact results for the mean first passage time for diffusion on simple geometries, such aslines, discs and spheres, are well-known. In contrast, computational methods are often used tostudy the first passage time for diffusion on more realistic geometries where closed-form solutionsof the governing elliptic boundary value problem are not available. Here, we develop aperturbation solution to calculate the mean first passage time on irregular domains formed byperturbing the boundary of a disc or an ellipse. Classical perturbation expansion solutions are thenconstructed using the exact solutions availableon a disc and an ellipse. We apply the perturbationsolutions to compute the mean first exit time on twonaturally-occurring irregular domains: a mapof Tasmania, an island state of Australia, and a map of Taiwan. Comparing the perturbationsolutions with numerical solutions of the elliptic boundary value problem on these irregulardomains confirms that we obtain a very accurate solution with a few terms in the series only. MATLAB software to implement all calculations is available at https://github.com/ProfMJSimpson/Exit_time.

These MATLAB codes require GMSH 4.7.1 to generate unstructured meshes for the finite volume and random walk calculations. The software can be downloaded at https://gmsh.info/.

The MATLAB codes also include ellipse fitting tools from Szpak, Z.L., Chojnacki, W. & van den Hengel, A. Guaranteed Ellipse Fitting with a Confidence Region and an Uncertainty Measure for Centre, Axes, and Orientation. *J Math Imaging Vis* **52, **173–199 (2015). https://doi.org/10.1007/s10851-014-0536-x.

The main MATLAB scripts are:

- unperturbed_disc_main.m for the unperturbed disc problem;
- unperturbed_ellipse_main.m for the unperturbed ellipse problem;
- perturbed_disc_main.m for the perturbed disc problem;
- perturbed_ellipse_main.m for the perturbed ellipse problem;
- tasmania_analysis.m for the Tasmania case study;
- taiwan_main.m for the Taiwan case study.

Some notes for each figure:

- To produce Figure 1, run unperturbed_disc_main.m Lines 1 through 64.
- To produce Figure 2, run unperturbed_ellipse_main.m Lines 1 through 64.
- To produce Figure 3, run perturbed_disc_main.m Lines 1 through 78,
- To produce Figure 4, run perturbed_ellipse_main.m Lines 1 through 82.
- To produce Figure 6, run tasmania_analysis.m Lines 1 through 214.
- To produce Figure 7, run taiwan_analysis.m Lines 1 through 192.
- To produce Figure 8, run perturbed_disc_main.m Lines 1 through 29, Line 37, Lines 80 through 136.
- To produce Figure 9, run perturbed_ellipse_main.m Lines 1 through 42, Lines 84 through 123.

About inpoly2:

- In perturbed_ellipse_walk_2.m, the inpoly2 function from Engwirda (2020) [https://github.com/dengwirda/inpoly] with a slight modification to prevent errors in the case of a single remaining walk. This modification is given in the documentation of perturbed_ellipse_walk_2.m.