thank you for this question.
1. One (distributed cell-based) solution would be to iteratively let each cell communicate to its neighbors what the shortest distance to medium has been for itself and to let it add its own cell diameter. Boundary cells know that their distance to medium is zero (this would also be reset to zero when one voxel of medium forms inside your cluster). This communication can be achieved with the following lines inside your CellType. Property "L" for each cell then reports the distance in voxels from the cell's center of mass to the nearest medium voxel. There is an empirically determined factor of 1.28 to get each cell diameter from the volume of a realistic cell shape, you may adjust that factor to your cell shapes:
<Property symbol="medium_contact" tags="new" value="0.0"/>
<NeighborhoodReporter name="medium_contact" tags="new">
<Input noflux-cell-medium="false" scaling="cell" value="cell.type ==
celltype.medium.id"/>
<Output symbol-ref="medium_contact" mapping="maximum"/>
</NeighborhoodReporter>
<Property symbol="L" value="0.0"/>
<NeighborhoodReporter time-step="1.0" name="propagate distance">
<Input scaling="cell" value="L"/>
<Output symbol-ref="LTmp" mapping="minimum"/>
</NeighborhoodReporter>
<Property symbol="LTmp" value="1000000"/>
<System time-step="1.0" solver="Euler [O(1)]">
<Rule symbol-ref="L">
<Expression>if(medium_contact==1,sqrt(cell.volume/pi),LTmp+1.28*sqrt(4*cell.volume/pi))</Expression>
</Rule>
</System>
so you may download and run that model and plot L in another Gnuplotter. This solution is not elegant but it runs fast!
Just because it is related and now also elegant: a counter of how many cells are between each cell and the nearest medium has been used along the same idea in this model:
https://identifiers.org/morpheus/M9147It gets visualized in the top-left panel of Video 2.
2. An alternative solution (computationally more expensive!!!) could use a morphogen gradient as global field that starts from a fixed level ("c.target") at each medium voxel and then diffuses and decays where cells are.
This has also been used in the above liver model:
https://identifiers.org/morpheus/M9147 where the morphogen was called "Chemoattractant" with symbol "c". Each cell can measure its (spatially averaged) value of c ("c.cell") and calculate its distance from medium based on the quasi steady-state profile with decay length = sqrt(D/k) where D is the morphogen diffusivity and k the decay rate. You get
distance = sqrt(D/k) * ln (c.target / c.cell)
Best,
Lutz