Issue with Boundary Conditions in 1D Diffusion PDE Example #576
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Your code runs into the classical von Neumann instability. To avoid this, it is better to use an adaptive time stepper by replacing the central line that solves the PDE by |
Beta Was this translation helpful? Give feedback.
-
Hi @david-zwicker, I am still working on replicating Matlab code using the py-pde package, but have encountered another problem. This problem focusses on the Schnakenberg model which involves 2 chemical species X and Y which undergo the following reactions: The 2 PDE of the reaction diffusion system are given by: We now look for the concentration of X and Y along a line which we can model as an uni-dimensional problem, stretching between We take the system to be isolated: no molecules enter of exit the system. We then need Neumann's conditions applied at both ends of the line. `import numpy as np Define the spatial and temporal domainx_min, x_max = 0, 1 Create a Cartesian gridgrid = CartesianGrid([[x_min, x_max]], [nx]) Define initial conditionsu0 = ScalarField(grid, 0) Define the boundary conditionsboundary_conditions = "neumann" Model parametersa = 0.2 Define the PDEseq = PDE({ Create storage to save the solutionstorage = MemoryStorage() Solve the PDEresult = eq.solve(state, t_range=t_max, adaptive=True, tracker=storage.tracker(interval=0.1)) Extract data from storage for plottingtimes = np.linspace(0, t_max, len(storage)) Convert the stored data into a format suitable for plottingsolution_u = data_u.reshape((len(storage), nx)) Create a 2D meshgrid for plottingX, T = np.meshgrid(grid.axes_coords[0], times) Plot the solutionfig, axs = plt.subplots(2, 1, figsize=(10, 8)) Plot ucax1 = axs[0].imshow(solution_u, aspect='auto', origin='lower', cmap='jet', extent=[x_min, x_max, t_min, t_max]) Plot vcax2 = axs[1].imshow(solution_v, aspect='auto', origin='lower', cmap='jet', extent=[x_min, x_max, t_min, t_max]) plt.tight_layout() While the matlab code looks like this: Both the solutions for u and v are different from Matlab. U appears constant in space x, while this is not the case in Matlab, and v has a slightly different pattern with higher values. Do you have any idea what could be causing this problem? Thank you very much! |
Beta Was this translation helpful? Give feedback.
Your code runs into the classical von Neumann instability. To avoid this, it is better to use an adaptive time stepper by replacing the central line that solves the PDE by
result = eq.solve(field, t_range=t_max, adaptive=True, tracker=storage.tracker(interval=0.001))