2D Burger's Equation #76
Replies: 3 comments
-
You had multiple typos in your code (e.g., Here is a revised version of your code that might do what you want: from math import sqrt,pi
import pde
from pde import WavePDE, CartesianGrid, ScalarField, MemoryStorage, FieldCollection, PDE, plot_kymograph, PlotTracker, plot_magnitudes, FileStorage
import matplotlib.pyplot as plt
#Set the Geometry
#Generate grid
grid = CartesianGrid( [[-1, 1],[-1,1]] , 256 )
#Initial condition
p=2
q=1
state = ScalarField.from_expression(grid, f"sin({p}*pi*x)*sin({q}*pi*y)" )
#Boundary condition
#specified within eq call
nu =0.01/pi
eq = PDE(
{
"u": f"{nu} * (laplace(u)+laplace(u)) - u * (get_x(gradient(u))+get_y(gradient(u)))"
}, user_funcs={"get_x": lambda arr: arr[0], "get_y": lambda arr: arr[1]},
bc={"value": 0}
)
# store intermediate information of the simulation
storage = FileStorage("2D_burger_data.npz")
# solve the pde
result = eq.solve(state, t_range = 0.99, tracker=storage.tracker(0.01))
pde.movie(storage, filename="2D_burger_movie.mov")
# plot the resulting field
result.plot()
# visualize the result in a space-time plot
plot_kymograph(storage)
# slice data
data=state
smoothed = data.smooth() # Gaussian smoothing to get rid of the noise
sliced = smoothed.slice({"y": 0})
# create two plots of the field and the modifications
fig, axes = plt.subplots(nrows=1, ncols=2)
data.plot(ax=axes[0], title="Original field")
sliced.plot(ax=axes[1], title="Slice of smoothed field at $y=1$")
plt.subplots_adjust(hspace=1.5) |
Beta Was this translation helpful? Give feedback.
-
Thank you for the prompt reply!
why can't I use When I use the following code, I get an error:
How can I fix that? from math import sqrt,pi
import pde
from pde import WavePDE, CartesianGrid, ScalarField, MemoryStorage, FieldCollection, PDE, plot_kymograph, PlotTracker, plot_magnitudes, FileStorage
import matplotlib.pyplot as plt
#Set the Geometry
#Generate grid
grid = pde.CartesianGrid( [[-1, 1],[-1,1]] , 256 )
#Initial condition
p=2
q=1
state = ScalarField.from_expression(grid,f"sin({p}*pi*x)*sin({q}*pi*y)",label="Field $u$")
#Boundary condition
#specified within eq call
eq = PDE(
{
"u": f"-u * get_x(gradient(u)) + (0.01/pi) * get_x(laplace(u))"
}, user_funcs={"get_x": lambda arr: arr[0]},
bc=[{"value": 0}]
)
# store intermediate information of the simulation
storage = FileStorage("2D_burger_data.npz")
# solve the pde
result = eq.solve(state, t_range = 0.99, tracker=storage.tracker(0.01))
pde.movie(storage, filename="2D_burger_movie.mov")
# plot the resulting field
result.plot()
# visualize the result in a space-time plot
plot_kymograph(storage)
# slice data
data=state
smoothed = data.smooth() # Gaussian smoothing to get rid of the noise
sliced = smoothed.slice({"y": 0})
# create two plots of the field and the modifications
fig, axes = plt.subplots(nrows=1, ncols=2)
data.plot(ax=axes[0], title="Original field")
sliced.plot(ax=axes[1], title="Slice of smoothed field at $y=1$")
plt.subplots_adjust(hspace=1.5) |
Beta Was this translation helpful? Give feedback.
-
The Laplace operator of a scalar field returns a scalar field, so you cannot take any components. |
Beta Was this translation helpful? Give feedback.
-
Thank you for all your efforts! I'm trying to solve the 2D burger's equation. I ran into this error:
What is the right way to define and solve the equation?
Here's my reference:
In my case v is just a constant :0.01/pi.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions