Giter VIP home page Giter VIP logo

Comments (3)

david-zwicker avatar david-zwicker commented on August 25, 2024

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.

engsbk avatar engsbk commented on August 25, 2024

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.

david-zwicker avatar david-zwicker commented on August 25, 2024

The Laplace operator of a scalar field returns a scalar field, so you cannot take any components.

from py-pde.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.