# Reaction-advection-diffusion in VoronoiFVM

**URL:** <https://discourse.julialang.org/t/reaction-advection-diffusion-in-voronoifvm/119252>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 10, 2024, 2:41pm UTC](https://discourse.julialang.org/t/reaction-advection-diffusion-in-voronoifvm/119252 "2024-09-10T14:41:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alicanter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alicanter/32/34615_2.png) [@Alicanter](https://discourse.julialang.org/u/Alicanter)\
**Post date:** [September 10, 2024, 2:41pm UTC](https://discourse.julialang.org/t/reaction-advection-diffusion-in-voronoifvm/119252/1 "2024-09-10T14:41:17Z")

</div>

I was trying to use VoronoiFVM.jl and I am not sure I understand how to build a Physics object correctly.  
This is probably because of my lack of knowledge about FVM in general.

I have a PDE in 2D with two species and the following shape:

\begin{aligned} \nabla\_t u &= \nabla\_x (D\_u \nabla\_x u - k\_1 u \nabla\_x v) + (k\_2 (1 - u) - k\_3 + f(v)) u, \\ \nabla\_t v &= D\_v \nabla\_x v + k\_4 u - k\_5 v + k\_6. \end{aligned}

Would it be correct to translate it to this Physics object?

```julia
grid = simplexgrid(collect(0:1/100:1), collect(0:1/100:1))

physics = VoronoiFVM.Physics(
                         ; reaction = function (f, u, node, data)
                             f[1] = (k_2*(1 - u[1]) - k_3 + f(u[2]))*u[1]
                             f[2] = k_4*u[1] - k_5*u[2]
                         end,
                         flux = function (f, u, edge, data)
                             nspecies = 2
                             f[1] = D_u*(u[1,1]-u[1,2]) - k_1*u[1]*(u[2,1]-u[2,2])
                             f[2] = D_v*(u[2,1]-u[2,2])
                         end, source = function (f, node, data)
                             f[1] = 0
                             f[2] = k_6
                         end, storage = function (f, u, node, data)
                             f[1] = u[1]
                             f[2] = u[2]
                         end)

sys = VoronoiFVM.System(grid, physics; unknown_storage = unknown_storage)

enable_species!(sys, 1, [1])
enable_species!(sys, 2, [1])

boundary_neumann!(sys, 1, 1, 1.0)
boundary_neumann!(sys, 1, 2, 0.0)
boundary_neumann!(sys, 2, 1, 1.0)
boundary_neumann!(sys, 2, 2, 0.0)

```

---

<div class="post-metadata">

**Author:** ![j-fu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j-fu/32/11373_2.png) [@j-fu](https://discourse.julialang.org/u/j-fu)\
**Post date:** [September 17, 2024, 6:42pm UTC](https://discourse.julialang.org/t/reaction-advection-diffusion-in-voronoifvm/119252/3 "2024-09-17T18:42:18Z")

</div>

Hi,  
this already looks quite good.

Two things:

- VoronoiFVM assumes that all u-dependent terms are on the left side of the equal sign. So you should reverse the sign in the reaction term.
- For the convective term, you should try some upwinding. The first equation looks similar to a drift-diffusion equation where the drift (convection) term involved a gradient. The best way to discretize this is to use an exponential fitting ansatz. You might consider to look at `classflux` in [160: Unipolar degenerate drift-diffusion · VoronoiFVM.jl](https://j-fu.github.io/VoronoiFVM.jl/stable/module_examples/Example160_UnipolarDriftDiffusion1D/)

---

<div class="post-metadata">

**Author:** ![Alicanter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alicanter/32/34615_2.png) [@Alicanter](https://discourse.julialang.org/u/Alicanter)\
**Post date:** [October 8, 2024, 11:28am UTC](https://discourse.julialang.org/t/reaction-advection-diffusion-in-voronoifvm/119252/4 "2024-10-08T11:28:17Z")

</div>

Sorry for the late answer.

Yes, the reactions have the sign reversed. Thanks for pointing out that.

I’ve tried reading more about FVM, but I do not fully understand how it would be implemented in this case.

From what I see in the example, `classflux!` seems to only be defined and does not appear anywhere else.  
But what I see from that and [103: 1D Convection-diffusion equation · VoronoiFVM.jl](https://j-fu.github.io/VoronoiFVM.jl/stable/module_examples/Example103_ConvectionDiffusion1D/), is that a `bernoulli` function is used. Is that necessary?

I have this, but the advection term seems to not be correct:

```julia
physics = VoronoiFVM.Physics(
                         ; reaction = function (f, u, node, data)
                             f[1] = k_3 - (k_2*(1 - u[1]) - f(u[2]))*u[1]
                             f[2] = k_5*u[2] - k_4*u[1]
                         end,
                         flux = function (f, u, edge, data)
                             nspecies = 2
                             f[1] = D_u*(u[1,1]-u[1,2]) - k_1*u[1]*(u[2,1]-u[2,2])
                             f[2] = D_v*(u[2,1]-u[2,2])
                         end, source = function (f, node, data)
                             f[1] = 0
                             f[2] = k_6
                         end, storage = function (f, u, node, data)
                             f[1] = u[1]
                             f[2] = u[2]
                         end)

```

Is there a way to solve it? I am interested in temporal dynamics.
