-
Notifications
You must be signed in to change notification settings - Fork 0
/
fokker_planck_class.py
71 lines (54 loc) · 2.94 KB
/
fokker_planck_class.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pde
neumann_bc = "auto_periodic_neumann"
final_bc = neumann_bc
class KuramotoSivashinskyPDE(pde.PDEBase):
def __init__(self, diffusivity=1, bc=final_bc, bc_laplace=final_bc):
""" initialize the class with a diffusivity and boundary conditions
for the actual field and its second derivative """
self.diffusivity = diffusivity
self.bc = bc
self.bc_laplace = bc_laplace
def evolution_rate(self, probability, t=0):
""" numpy implementation of the evolution equation """
probability_lapacian = probability.laplace(bc=self.bc)
probability_gradient = probability.gradient(bc=final_bc)
probability_divergence = probability.divergence(bc=final_bc)
return (- probability_lapacian.laplace(bc=self.bc_laplace)
- probability_lapacian
- 0.5 * self.diffusivity * (probability_gradient @ probability_gradient))
def _make_pde_fp_numba(self, probability, diffusion, drift):
""" the numba-accelerated evolution equation """
# make attributes locally available
diffusivity = self.diffusivity
div_term = probability @ drift
lapl_term = probability @ diffusion
# create operators
# laplace_u = probability.grid.make_operator("laplace", bc=self.bc)
# gradient_u = probability.grid.make_operator("gradient", bc=self.bc)
# divergence_u = probability.grid.make_operator("divergence", bc=self.bc)
# laplace2_u = probability.grid.make_operator("laplace", bc=self.bc_laplace)
# dot = pde.VectorField(probability.grid).make_dot_operator()
div = div_term.grid.make_operator("divergence", bc=self.bc)
lapl = lapl_term.grid.make_operator("laplace", bc=self.bc)
# d_dx = probability.grid.make_operator("d_dx", bc=self.bc)
# d_dy = probability.grid.make_operator("d_dx", bc=self.bc)
# d_dz = probability.grid.make_operator("d_dx", bc=self.bc)
# d_d2x = probability.grid.make_operator("d_d2x", bc=self.bc)
# d_d2y = probability.grid.make_operator("d_d2x", bc=self.bc)
# d_d2z = probability.grid.make_operator("d_d2x", bc=self.bc)
# @pde.tools.numba.jit
# def pde_fp(probability_data, t=0):
# """ compiled helper function evaluating right hand side """
# probability_lapacian = laplace_u(probability_data)
# probability_grad = gradient_u(probability_data)
# return (- laplace2_u(probability_lapacian)
# - probability_lapacian
# - diffusivity / 2 * dot(probability_grad, probability_grad))
# return pde_fp
@pde.tools.numba.jit
def pde_fp(probability_data, t=0):
""" compiled helper function evaluating right hand side """
div_applied = div(div_term)
lapl_applied = lapl(lapl_term)
return (-div_applied + lapl_applied)
return pde_fp