# Transforming a 1D cartesian variable-coefficient diffusion code into a 1D adially symmetric one

So I have a code that I use which solves a 1D variable coefficient diffusion problem in cartesian coordinates:

$\frac{\partial u}{\partial t}=\frac{\partial}{\partial x}\left(D(x)\frac{\partial u}{\partial x}\right)$.

It solves the equation implicitly using a backward euler discretization. it works fine, but I want to convert it into a spherically symmetric code. The problem is that I can't find information on how to do this for variable coefficients. I would appreciate if someone shows me the specific modifications I need to make.

Also, how much different those the solution for this equation looks in a 1D cartesian slab vs a 1D spherically symmetric radial slab? If they look about the same then maybe I shouldn't do the modifications. Thanks!

More generally, the equation you are solving is $$\frac{\partial u}{\partial t} = \nabla \cdot \left( D(x) \nabla u \right) \quad ,$$ where the first nabla operator represents the divergence operator, and the second represents the gradient operator. Your equation is the special case for a one-dimensional cartesian coordinate system.

From a practical point of view, if you want to move into a cylindrical or spherical coordinate system all you have to do is to apply the respective definitions of the nabla operators. For example, you can find them on Wikipedia:

If you take axial and azimuthal symmetry into consideration, you can derive a similar equation in $r$ that includes metric terms, i.e.: $$\frac{\partial u}{\partial t} = \frac{1}{r} \frac{\partial}{\partial r} \left( D(r) r \frac{\partial u}{\partial r} \right) \quad ,$$ As you can see, it does not really matter in this approach whether your diffusion coefficient is constant or not.

I am not sure whether telling you the final equation was already spoiling too much. But I am sure that you know how to do the implementation from here on. ;-)