@@ -39,7 +39,7 @@ def solver_FECS(I, U0, v, L, dt, C, T, user_action=None):
3939
4040
4141def solver (I , U0 , v , L , dt , C , T , user_action = None ,
42- scheme = 'FE' , periodic_bc = False ):
42+ scheme = 'FE' , periodic_bc = True ):
4343 Nt = int (round (T / np .float64 (dt )))
4444 t = np .linspace (0 , Nt * dt , Nt + 1 ) # Mesh points in time
4545 dx = v * dt / C
@@ -53,8 +53,17 @@ def solver(I, U0, v, L, dt, C, T, user_action=None,
5353 print ('dt=%g, dx=%g, Nx=%d, C=%g' % (dt , dx , Nx , C ))
5454
5555 integral = np .zeros (Nt + 1 )
56-
56+
57+ # class Left(SubDomain):
58+ # name = 'left'
59+ # def define(self, dimensions):
60+ # x = dimensions[0]
61+ # return {x: ('left', Nx-1)}
62+
63+ # left = Left()
5764 grid = Grid (shape = (Nx + 1 ,), extent = (L ,), dtype = np .float64 )
65+
66+ # grid = Grid(shape=(Nx+1,), extent=(L,), dtype=np.float64, subdomains=(left))
5867 t_s = grid .time_dim
5968
6069 def u (to = 1 , so = 1 ):
@@ -66,23 +75,23 @@ def u(to=1, so=1):
6675 pde = u .dtr + v * u .dxc
6776
6877 pbc = [Eq (u [t_s + 1 , 0 ], u [t_s , 0 ] - 0.5 * C * (u [t_s , 1 ] - u [t_s , Nx ]))]
69- pbc += [Eq (u [t_s , Nx ], u [t_s , 0 ])]
78+ pbc += [Eq (u [t_s + 1 , Nx ], u [t_s + 1 , 0 ])]
7079
7180 elif scheme == 'LF' :
72- # Use UP scheme for first timestep
81+ # Use UP scheme for the first timestep
7382 u = u (to = 2 , so = 2 )
7483 pde0 = u .dtr (fd_order = 1 ) + v * u .dxl (fd_order = 1 )
7584
7685 stencil0 = solve (pde0 , u .forward )
7786 eq0 = Eq (u .forward , stencil0 ).subs (t_s , 0 )
78-
87+
7988 pbc0 = [Eq (u [t_s , 0 ], u [t_s , Nx ]).subs (t_s , 0 )]
8089
8190 # Now continue with LF scheme
8291 pde = u .dtc + v * u .dxc
8392
8493 pbc = [Eq (u [t_s + 1 , 0 ], u [t_s - 1 , 0 ] - C * (u [t_s , 1 ] - u [t_s , Nx - 1 ]))]
85- pbc += [Eq (u [t_s , Nx ], u [t_s , 0 ])]
94+ pbc += [Eq (u [t_s + 1 , Nx ], u [t_s + 1 , 0 ])]
8695
8796 elif scheme == 'UP' :
8897 u = u ()
@@ -93,16 +102,20 @@ def u(to=1, so=1):
93102 elif scheme == 'LW' :
94103 u = u (so = 2 )
95104 pde = u .dtr + v * u .dxc - 0.5 * dt * v ** 2 * u .dx2
105+ print (pde )
96106
97107 pbc = [Eq (u [t_s + 1 , 0 ], u [t_s , 0 ] - 0.5 * C * (u [t_s , 1 ] - u [t_s , Nx - 1 ]) + \
98- 0.5 * C * (u [t_s , 1 ] - 2 * u [t_s , 0 ] + u [t_s , Nx - 1 ]))]
99- pbc += [Eq (u [t_s , Nx ], u [t_s , 0 ])]
108+ 0.5 * C ** 2 * (u [t_s , 1 ] - 2 * u [t_s , 0 ] + u [t_s , Nx - 1 ]))]
109+ pbc += [Eq (u [t_s + 1 , Nx ], u [t_s + 1 , 0 ])]
100110
101111 else :
102112 raise ValueError ('scheme="%s" not implemented' % scheme )
103113
104114 stencil = solve (pde , u .forward )
115+ # eq = Eq(u.forward, stencil, subdomain=grid.subdomains['left'])
105116 eq = Eq (u .forward , stencil )
117+ print (eq )
118+ print (v )
106119
107120 bc_init = [Eq (u [t_s + 1 , 0 ], U0 ).subs (t_s , 0 )]
108121
@@ -118,14 +131,15 @@ def u(to=1, so=1):
118131 bc = [Eq (u [t_s + 1 , 0 ], U0 )]
119132
120133 if scheme == 'LF' :
121- op = Operator ((pbc0 if periodic_bc else []) + [eq0 ] + bc_init + (pbc if periodic_bc else []) + [eq ] + (bc if not periodic_bc else []))
134+ op = Operator ((pbc0 if periodic_bc else []) + [eq0 ] + (bc_init if not periodic_bc else []) \
135+ + (pbc if periodic_bc else []) + [eq ] + (bc if not periodic_bc else []))
122136 else :
123137 op = Operator (bc_init + (pbc if periodic_bc else []) + [eq ] + (bc if not periodic_bc else []))
124138
125- print (op .arguments (dt = dt ))
139+ print (op .arguments (dt = dt , x_m = 1 , x_M = Nx - 1 ))
126140 print (op .ccode )
127141
128- op .apply (dt = dt )
142+ op .apply (dt = dt , x_m = 1 , x_M = Nx if scheme == 'UP' else Nx - 1 )
129143
130144 for n in range (1 , Nt + 1 ):
131145 # Compute the integral under the curve
@@ -137,6 +151,7 @@ def u(to=1, so=1):
137151 print ('I:' , integral [n ])
138152 return integral
139153
154+
140155def run_FECS (case ):
141156 """Special function for the FECS case."""
142157 if case == 'gaussian' :
0 commit comments