I am trying to solve a PDE of the form
$$\frac{\partial u}{\partial t} = D \frac{\partial^2u}{\partial x^2} + k\ \ \ (1)$$
where only $k$'s first derivative with respect to $x$ is known
$$\frac{\partial k}{\partial x}=-5u\ \ \ \ (2)$$
The boundary conditions are:
$$\frac{\partial u}{\partial x}\left(t,x=0\right)=0\ \ \ \ (3)$$
$$\frac{\partial u}{\partial x}\left(t,x=\left(J-1\right)\Delta x\right)=0\ \ \ \ (4)$$
Using the method of lines, the following discretisation for $u$ is obtained:
$$\frac{\partial u}{\partial t}\left(t,x=0\right)=2D\frac{u^1-u^0}{\Delta x^2}+k^0\ \ \ \ (5)$$
$$\frac{\partial u}{\partial t}\left(t,x=j\Delta x\right)=D\frac{u^{j+1}-2u^j+u^{j-1}}{\Delta x^2}+k^j\ \ \ \ (6)$$
$$\frac{\partial u}{\partial t}\left(t,x=\left(J-1\right)\Delta x\right)=2D\frac{u^{J-2}-u^{J-1}}{\Delta x^2}+k^{J-1}\ \ \ \ (7)$$
Using these 3 equations and scipy.integrate.solve_ivp
allows me to solve the diffusion part of equation (1). However, to get k
, I need to first calculate $\frac{\partial k}{\partial t}$ while I only know $\frac{\partial k}{\partial x}$. How can I do that? I've written the following Python code below to solve $\frac{\partial u}{\partial t}$ but I'm missing the code to calculate $\frac{\partial k}{\partial t}$.
import scipy.integrate as scint
import numpy as np
x = np.linspace(0, 1, 11)
dx = np.diff(x)[0]
D = 10
u0 = np.exp(-5 * x)
k0 = np.zeros(len(x))
t = np.linspace(0, 1, 101)
def get_dydt(_t, y):
""" Return the derivative dy/dt at different points in space """
u, k = np.split(y, 2)
# Calculate du/dt
dudt = np.empty_like(u)
dudt[0] = 2 * (u[1] - u[0])
dudt[1:-1] = np.diff(u, 2)
dudt[-1] = 2 * (u[-2] - u[-1])
dudt = dudt * D / dx ** 2 + k
# Calculate dk/dt
dkdt = None # how can I calculate this?
return np.concatenate([dudt, dkdt])
solver = scint.solve_ivp(get_dydt, [t[0], t[-1]], np.concatenate([u0, k0]), method='Radau')