How to input this PDE without errors? #45
Unanswered
githubbuhtig10
asked this question in
Q&A
Replies: 1 comment 2 replies
-
I had a look at your problem and think I got it to work by using a different method for implementing the spatial derivative: import functors
from pde import PDE, FieldCollection, PlotTracker, ScalarField, UnitGrid, CartesianGrid
#Desired Boundary Conditions
#bc_x_left = {"derivative": [0, 0]}
#bc_x_right = {"value": [0, 0]}
#bc_y_bottom = {"value": [0, 0]}
#bc_y_top = {"value": [0, 0]}
#bc_x = [bc_x_left, bc_x_right]
#bc_y = [bc_y_bottom, bc_y_top]
#bc = [bc_x, bc_y]
from pde.grids.operators.cartesian import _make_derivative
from pde.grids.cartesian import CartesianGridBase
make_gradient_x = functools.partial(_make_derivative, axis=0)
CartesianGridBase.register_operator('gradient_x', make_gradient_x)
make_gradient_y = functools.partial(_make_derivative, axis=1)
CartesianGridBase.register_operator('gradient_y', make_gradient_y)
# Wanted PDE:
a, b, c = -3, 7, 1
eq = PDE(
{
"u": f"-gradient_x(x * v) + gradient_x(gradient_x(u)) + {c} * {c} * (gradient_y(u) / y + gradient_y(gradient_y(u)))",
"v": f"{a} * u - {b} * {b} * gradient_x(x * u) + gradient_x(gradient_x(v)) + {c} * {c} * (gradient_y(v) / y + gradient_y(gradient_y(v)))",
},
bc="natural"
)
#Wanted Cartesian Grid
grid = CartesianGrid([[0, 1], [0, 1]], [32, 32]) # generate grid
u = ScalarField.random_uniform(grid, 0.9, 1.1, label="Field $u$")
v = ScalarField(grid, 0, label="Field $v$")
state = FieldCollection([u, v])
# Simulating PDE
sol = eq.solve(state, t_range=3)
#Plotting solution
sol.plot()
#Attempts to extract data and plot
#print(sol[1].slice({"x": 0.5}).data[:]) #prints data at x =30 across y at last time
#sol[1].plot()
#sol[1].slice({"x": 0.5}).plot(title='v against y at x = 30') #plots above Note that I actually register 1d-gradient operators for both Cartesian grids. To specify boundary conditions more finely grained, you would need to use the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I wish to solve the following set of 2D coupled PDEs:
du/dt = -d/dx(alpha*v) + d2u/dx2 + c^2(1/y * du/dy + d2u/dy2)
dv/dt = au - b^2 * d/dx(alphau) + d2v/dx2 + c^2(1/y * dv/dy + d2v/dy2)
alpha is a function of x. a, b, and c are constants. 0<=x, y<=1 are the domains of x and y. Boundary conditions are homogeneous Dirichlet for x=1, y=0,1 and homogeneous Neumann for x=0 for both u and v. Initial conditions are u=1 and v=0.
I tried to modify the Brusselator example from the documentation to achieve this but kept facing errors. I have included the code I am trying to implement this with and kept commented out sections which cause errors.
I sometimes get an error saying dimensions don't match when using CartesianGrid rather than UnitGrid, specifically when trying to solve systems of equations.
Another error occurs when I try to change the boundary conditions to anything other than "natural," including manually typing what natural boundary conditions represent. The error states that laplace is not recognised.
The last error occurs when get_x/get_y is used and the message is : Untyped global name 'get_x': Cannot determine Numba type of <class 'function'> .
Any help to get this working would be appreciated.
The code I am trying is below:
Beta Was this translation helpful? Give feedback.
All reactions