Comments (5)
This is certainly possible. The simplest way would be to use the PDE
class,
from pde import PDE
eq = PDE({'P': '(P - P**2) * laplace(P)'})
where I used D(x) = x - x**2
as a concrete example. Alternatively, you may implement your own pde class.
See pde_custom_expression.py
and pde_custom_class.py
in the examples directory for respective implementations.
from py-pde.
I may be missing something, but it seems that you actually used D(P)=P - P**2
rather than D(x) = x - x**2
, meaning the coefficient depends on the variable being solved for and not x (which P is being differentiated with respect to)
from py-pde.
Ohh, I wasn't reading your question carefully enough – sorry about this. The current implementation of the PDE
class does not allow spatially varying coefficients. However, it is not too difficult to achieve this with a custom class:
import pde
class HeterogeneousDiffusionPDE(pde.PDEBase):
def evolution_rate(self, state, t=0):
""" implement the python version of the evolution equation """
assert state.grid.dim == 1 # implementation only works for 1d problems
cell_coords = state.grid.cell_coords[:, 0] # this extracts the x-coordinates of all cells
coeff = (cell_coords - cell_coords**2) # this calculates the pre-factor
return state.laplace('natural') * coeff
grid = pde.CartesianGrid([[0, 1]], 32) # generate grid
state = pde.ScalarField.random_normal(grid, 0.1, 0.9) # generate initial condition
eq = HeterogeneousDiffusionPDE() # define the pde
result = eq.solve(state, t_range=1, dt=1e-4)
result.plot()
A numba-compiled implementation to accelerate the computation can be created similarly. I'll think about extending the PDE
class, but it might be a bit challenging and thus not happen soon. However, pull requests in this direction are welcome!
from py-pde.
I took you suggestion as a challenge and implemented an extended version of the PDE
class that can deal with spatially dependent coefficients. The implementation is not very tested, yet, but it seems to work. I added an example that displays how it works, but it really comes down to just using the spatial coordinates as variables in the expressions.
from py-pde.
Thanks! Looks good
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.