Many resources including but not limited to 1, 2, 3, 4, 5, 6, 7** discuss various forms of diffusion and heat equations under different conditions. However, the following specific formulation with a spatially variable source and inhomogeneous flux BCs was not studied in them:
$$\frac{\partial c}{\partial t}=\frac{\partial}{\partial x}J=\frac{\partial}{\partial x}(k(\frac{\partial c}{\partial x} +S)) \quad \text{or} \quad c_t=k c_{xx}+k S_x$$ $$J(-L/2,t)=J_{-} \\ J(+L/2,t)=J_{+} \\ c(x,0)=c_0$$
where $-L/2\leq x \leq L/2$ and $S(x)$ is spatially variable.
I'm looking for a nice closed form or an (infinite series-based) analytic expression -- if possible. I have done some work by using the technique of Laplace transformations but could not get it done fully. Any help on the rest of my work is highly appreciated.
Here is my attempt:
- Transform inhomogeneous BCs to homogeneous BCs
Introducing $u$ and $v$ such that $c = u + v$ and $u$ satisfies the non-homogeneous BCs, yields:
\begin{align*} x = -L/2: & \quad u_x = (J_-/k) - S_- \\ x = +L/2: & \quad u_x = (J_+/k) - S_+ \end{align*}
where the subscripts for $J$ and $S$ indicate evaluation at the corresponding endpoint. An easy function $u$ is $u(x) = A x^2 + B x$, where $A=\frac{(J_+-J_-)-(S_+-S_-) k}{2kL}$ and $B=\frac{(J_++J_-)-(S_++S_-) k}{2k}$.
Now, the problem for $v$ is homogeneous and given by ($-L/2 < x < L/2$):
$$ v_t = kv_{xx} + Q(x) $$ $$v_x(-L/2,t) = v_x(+L/2,t) = 0 \\ v(x,0) = c_0 - u(x)$$
where the source term is $Q(x) = k (u_x + S)_x$ which is also known.
Thanks to superposition, the problem has now homogeneous BCs but contains a nonzero, in general, source term. I found the solution for the problem with $Q = 0$ and $0<x<L$ (rather that $-L/2<x<L/2$) which is as follows (I verified it with 5):
$$v=2\sum_{n=1}^{n=\infty}e^{-k\alpha_n^2t}\frac{\beta_n \cos(\alpha_n x)}{\alpha_n^2L/2}\int_{0}^{L}f(x)[\beta_n \cos(\alpha_n x)]dx+\frac{1}{L}\int_{0}^{L}f(x)dx$$
where $\beta_n=\alpha_n \cos(\alpha_n L/2)$ and $\alpha_n=\frac{(2n+1)\pi}{L}$. Also $f(x)=c_0-u(x)$.
- Extending the solution to where there is $Q(x)$
I was not able to convert the intervl from $0<x<L$ to $-L/2<x<L/2$ properly and expand the obtained solution to the original problem with a spatially variable source (i.e. $Q(x)$). A sanity check is also greatly appreciate as there might be some errors in my work.
** Essentially the question asked in 7 is even a more general form of the current question. While I learned a lot from the discussion done in 7, the questions remained unanswered (in a complete way). The main and intersting complication in 7 was the varying diffusion coefficient rather than what is focused in current question. Special thanks to dmoreno for providing fruitful discussions.
So, you have to solve $$v_{t}-kv_{xx}=Q(x)$$ With $$v_{x}(L/2, t)=v_{x}(-L/2, t)=0$$ $$v(x, 0)=f(x)$$ Let us expand the solution in terms of the von-Neumann functions $$v(x, t)=\sum_{n\in\mathbb{Z}}v_{n}(t)\cos\Big(\frac{(2{n}+1)\pi{x}}{L}\Big)$$ Then $$\sum_{n\in\mathbb{Z}}\Big(\partial_{t}+\frac{k((2{n}+1)\pi)^{2}}{L^{2}}\Big)v_{n}(t)\cos\Big(\frac{(2{n}+1)\pi{x}}{L}\Big)=Q(x)$$ Then multiply by $$\cos\Big(\frac{(2{m}+1)\pi{x}}{L}\Big)$$ and integrate on $[-L/2, L/2]$ to give $$\Big(\partial_{t}+\frac{k((2{m}+1)\pi)^{2}}{L^{2}}\Big)v_{m}(t)=\frac{1}{L}\int_{-L/2}^{L/2}Q(x)\cos\Big(\frac{(2{m}+1)\pi{x}}{L}\Big)dx$$ The solution is found by the integrating factor technique $$v_{m}(t)=c_{m}\exp\Big(-\frac{k((2{m}+1)\pi)^{2}t}{L^{2}}\Big)+\frac{L}{k((2{m}+1)\pi)^{2}}\int_{-L/2}^{L/2}Q(x)\cos\Big(\frac{(2{m}+1)\pi{x}}{L}\Big)dx$$ And the constants $c_{m}$ is found from the condition $$v_{m}(0)=\frac{1}{L}\int_{-L/2}^{L/2}f(x)\cos\Big(\frac{(2{m}+1)\pi{x}}{L}\Big)dx$$