convection equation #426
-
Hi, trying to solve the convection equation with the following code import numpy as np
import pde
from pde import PDE, CartesianGrid, MemoryStorage, ScalarField
nx = 151 # number of spatial discrete points
L = 2.0 # length of the 1D domain
dx = L / (nx - 1) # spatial grid size
nt = 10 # number of time steps
dt = 0.001 # time-step size
x = np.linspace(0.0, L, num=nx)
u0 = np.ones(nx)
mask = np.where(np.logical_and(x >= 0.5, x <= 1.0))
u0[mask] = 2.0
grid = CartesianGrid([[0., 2.]], nx)
field = ScalarField(grid, data=u0)
eq = PDE({"u": "-gradient(u)"})
# solve the equation and store the trajectory
storage = MemoryStorage()
res = eq.solve(field, t_range=5, tracker=storage.tracker(0.1),
dt=dt,
method='scipy',
)
# plot the trajectory as a space-time plot
res.plot() I receive the following error
I tried different solvers but the erro persists. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
The issue is that you define the time-derivative of a scalar field using a vectorial quantity (the gradient of the same field). This is simply incompatible, but unfortunately the error message is difficult to improve because of the automatic parsing of the right hand side. Since you're considering a 1D problem, you should be able to fix the problem using |
Beta Was this translation helpful? Give feedback.
-
Thanks for your help. You are right. I don't know if I have to open another topic or here I can about the result of the code. Applying your suggestion the code works but the result is strange. Even with the |
Beta Was this translation helpful? Give feedback.
-
I moved the issue to a discussion, where it fits better. |
Beta Was this translation helpful? Give feedback.
This is a common issue with advective problems. As far as I know there is no completely general solution, which ensures stability for general advection equations. You might gain some leverage by adjusting the spatial and temporal discretization, though.