Comments (3)
You had multiple typos in your code (e.g., getx
vs get_x
), but the error message stems from the fact that user_funcs
expects a dictionary, not a list.
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)
from py-pde.
Thank you for the prompt reply!
Just double checking on 2 things:
"u": f"{nu} * (laplace(u)+laplace(u)) - u * (get_x(gradient(u))+get_y(gradient(u)))"
Is this equivalent to:
du_t = nu * (du_xx+du_yy) - u *(du_x + du_y)
why can't I use get x
and get y
on laplace (u)? Can you please explain how laplace(u)
work ?
When I use the following code, I get an error:
NameError: name 'laplace' is not defined
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)
from py-pde.
The Laplace operator of a scalar field returns a scalar field, so you cannot take any components.
from py-pde.
Related Issues (20)
- Custom PDE HOT 1
- 3-dimensional Laplace matrix not implemented HOT 1
- Add plotting routine to combine multiple fields HOT 1
- Allow more flexible expressions in `ExpressionBC`
- Allow user functions in expressions for boundary conditions
- Enable boundary conditions ONLY on one side of the geometry/domain/grid
- Falls back to basic python backend if user-supplied function cannot be compiled using numba. HOT 5
- Add `py-modelrunner` as a dependency HOT 2
- Separate geometry from grid definition HOT 1
- Allow choosing color maps in `field.plot(kind="rgb")`
- Question about 3d PDE simulation
- Allow scalars that are evolved alongside fields
- Allow storing instantaneous fields alongside dynamic fields
- Defining boundary conditions through bc_ops for 'n' coupled pde's HOT 9
- Add tracker that directly writes all data to video HOT 3
- Error : PDE with time dependent boundary conditions HOT 2
- Extract result from last successful timestep when simulation fails to converge
- PlotTracker doesn't show up on Jupyter notebook. HOT 1
- Add automatic MPI decomposition
- Allow using Cartesian coordinates in `from_expression` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py-pde.