# How to discretize a PDE with a Moving Boundary? (a.k.a Stefan Problem, a.k.a Variable Boundary)

**URL:** <https://discourse.julialang.org/t/how-to-discretize-a-pde-with-a-moving-boundary-a-k-a-stefan-problem-a-k-a-variable-boundary/123687>\
**Category:** General Usage\
**Tags:** question, discretization, pde, methodoflines\
**Created:** [December 11, 2024, 5:06am UTC](https://discourse.julialang.org/t/how-to-discretize-a-pde-with-a-moving-boundary-a-k-a-stefan-problem-a-k-a-variable-boundary/123687 "2024-12-11T05:06:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jax\_Xu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jax_xu/32/213903_2.png) [@Jax\_Xu](https://discourse.julialang.org/u/Jax_Xu)\
**Post date:** [December 11, 2024, 5:06am UTC](https://discourse.julialang.org/t/how-to-discretize-a-pde-with-a-moving-boundary-a-k-a-stefan-problem-a-k-a-variable-boundary/123687/1 "2024-12-11T05:06:07Z")

</div>

Hi Community! I need your expertise 😭! I am solving a 1D diffusion equation with a moving boundary. The physical background is the reaction of gas with a solid particle, where the gas diffuses through the product layer but cannot penetrate the dense core so that surface reaction happens. The dense core will be gradually consumed and shrink. In combustion science, this classical model is named shrinking core model.  
I tried to explain this model clearly with a diagram and my equations, as shown in the supplementary material. What is tricky here, for me, is the left boundary of the domain – it changes with time. I checked the previous topics in our Julia community, and they do not really help.

My codes are also attached for your perusal, which is problematic (I know~). Feel free to share your ideas!

> using MethodOfLines, OrdinaryDiffEq, Plots, DifferentialEquations, Symbolics, Latexify, DomainSets, ModelingToolkit
> 
> r0 = 0.01; K = 2e-4; De = 6e-6; mol\_rho = 109500  
> Nx=30  
> order=2
> 
> C=20; k=0.08; x\_inf=1 #bulk concentration; reaciton rate const; molar fraction of bulk  
> @parameters r, t  
> @variables u(…)  
> @variables r\_c(…)
> 
> Dr = Differential(r)  
> Drr = Differential(r)^2  
> Dt = Differential(t)
> 
> eqs=[Dt(u(r,t)) ~ De\*Drr(u(r,t)),  
> Dt(r\_c(t)) ~ (-k)_C_u(r\_c(t),t)/mol\_rho]
> 
> bcs=[Dr(u(r\_c(t),t)) ~ -k_u(r\_c(t),t)/r\_c(t),  
> De_Dr(u(r0,t)) ~ -K\*(u(r0,t)-u\_inf/r0),  
> u(r,0) ~ 0.0, r\_c(0) ~ r0]
> 
> domains = [r ∈ Interval(0, r0), t ∈ Interval(0.0, 30.0)]
> 
> @named scmsys = PDESystem(eqs,bcs,domains,[r,t], [u(r,t), r\_c(t)])
> 
> discretization = MOLFiniteDifference([r =\> Nx], t)
> 
> @time prob = discretize(scmsys, discretization)

I think the domain should be [0, r\_0] or [r\_c, r\_0]. The former domain discretizes the whole area, and returns zero values to u(r,t) when r\<r\_c. The latter is a dynamic discretization which I have no idea how to achieve that. Or could this be an interface problem ([0, r\_0] + [r\_c, r\_0])?

Similar cases were found in a Mathematica community [here](https://mathematica.stackexchange.com/questions/114967/how-to-use-ndsolve-with-moving-boundary-conditions) and [there](https://mathematica.stackexchange.com/questions/58596/pde-with-stefan-conditions-a-k-a-variable-boundary/58622#58622). I am trying to understand but really struggling.

Supplementary figures

 ![Screenshot 2024-12-11 125908](https://global.discourse-cdn.com/julialang/original/3X/b/0/b0e8e6fb6be7f7046bcb54151394fb360d0dc831.png)  
 ![Screenshot 2024-12-11 130131](https://global.discourse-cdn.com/julialang/original/3X/a/9/a9a130c2ff99ba94e3f54fa3075343068801b8b8.png)

(Note: the diffusion equation is altered for simplification, which is inaccurate in fact but does not influence the solution of this topic.)

---

<div class="post-metadata">

**Author:** ![vettert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vettert/32/30599_2.png) [@vettert](https://discourse.julialang.org/u/vettert)\
**Post date:** [December 11, 2024, 5:18am UTC](https://discourse.julialang.org/t/how-to-discretize-a-pde-with-a-moving-boundary-a-k-a-stefan-problem-a-k-a-variable-boundary/123687/2 "2024-12-11T05:18:21Z")

</div>

I worked extensively with a PhD student on a similar problem in a different context (spray drying; it’s an evaporating (=shrinking) droplet in which particles precipitate at some point).

Our solution is here: [A mechanistic model to predict droplet drying history and particle shell formation in multicomponent systems - ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0009250920302451)  
(In case you don’t have access, pm me; I am sure I can find the preprint somewhere!).

The problem can essentially be solved by changing the coordinate system into one with a fixed boundary; this introduces a virtual reaction term instead of the moving boundary. The problem than becomes a standard one for which many solution approaches work. 🙂

If you read the paper, skip the part about particle formation; it’s unimportant in your context.

---

<div class="post-metadata">

**Author:** ![Jax\_Xu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jax_xu/32/213903_2.png) [@Jax\_Xu](https://discourse.julialang.org/u/Jax_Xu)\
**Post date:** [December 11, 2024, 5:31am UTC](https://discourse.julialang.org/t/how-to-discretize-a-pde-with-a-moving-boundary-a-k-a-stefan-problem-a-k-a-variable-boundary/123687/3 "2024-12-11T05:31:00Z")

</div>

Thanks, Thomas! Such a good paper! I am reading already 😁!

---

<div class="post-metadata">

**Author:** ![Jax\_Xu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jax_xu/32/213903_2.png) [@Jax\_Xu](https://discourse.julialang.org/u/Jax_Xu)\
**Post date:** [December 13, 2024, 8:45am UTC](https://discourse.julialang.org/t/how-to-discretize-a-pde-with-a-moving-boundary-a-k-a-stefan-problem-a-k-a-variable-boundary/123687/4 "2024-12-13T08:45:56Z")

</div>

Hi Vettert! Thank you for your sharing! I have successfully discretised the moving boundary by normalising the moving domain into a relatively fixed domain and solve the PDE! It took me some time to understand the Eq.(21) of your paper, which is the transfer of time differentiation. Therefore, I checked your citation ([here](https://www.tandfonline.com/doi/full/10.1080/07373930600558912), for anyone may find this topic helpful), which gave more details.

Again, I am amazed by how smart human can be, especially scientists! 😁 ☺Thank you!

(the original publication came up with the normalisation to deal with the moving boundary might be referred to [Crank, John. “Free and moving boundary problems.” (No Title) (1984).](https://cir.nii.ac.jp/crid/1130282273146244992))

---

<div class="post-metadata">

**Author:** ![Anish\_Kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anish_kumar/32/202471_2.png) [@Anish\_Kumar](https://discourse.julialang.org/u/Anish_Kumar)\
**Post date:** [August 18, 2025, 4:11pm UTC](https://discourse.julialang.org/t/how-to-discretize-a-pde-with-a-moving-boundary-a-k-a-stefan-problem-a-k-a-variable-boundary/123687/5 "2025-08-18T16:11:04Z")

</div>

Hi Jax,

Do you happen to have that model uploaded anywhere? I am also working something similar and could be useful for me.

Anish

---

<div class="post-metadata">

**Author:** ![Jax\_Xu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jax_xu/32/213903_2.png) [@Jax\_Xu](https://discourse.julialang.org/u/Jax_Xu)\
**Post date:** [August 21, 2025, 2:45am UTC](https://discourse.julialang.org/t/how-to-discretize-a-pde-with-a-moving-boundary-a-k-a-stefan-problem-a-k-a-variable-boundary/123687/6 "2025-08-21T02:45:20Z")

</div>

Hi Anish,

Not really. We have to develop the model by ourselves. And I think this modelling field is not very active in recent decades, since more scholars joined the army of Ansys or Comsol.

---

<div class="post-metadata">

**Author:** ![Anish\_Kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anish_kumar/32/202471_2.png) [@Anish\_Kumar](https://discourse.julialang.org/u/Anish_Kumar)\
**Post date:** [August 26, 2025, 9:12am UTC](https://discourse.julialang.org/t/how-to-discretize-a-pde-with-a-moving-boundary-a-k-a-stefan-problem-a-k-a-variable-boundary/123687/7 "2025-08-26T09:12:30Z")

</div>

Haha yes thats true. Thanks for the question and the discussion above. This is exactly what I was looking for too!

Anish
