-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrid.py
More file actions
55 lines (37 loc) · 1.63 KB
/
Copy pathgrid.py
File metadata and controls
55 lines (37 loc) · 1.63 KB
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
import numpy as np
import sys
class Grid1d(object):
def __init__(self, nx, ng, xmin=0.0, xmax=1.0, bc="periodic"):
self.nx = nx
self.ng = ng # = number of ghost cells = order + 1
self.xmin = xmin
self.xmax = xmax
self.bc = bc
# python is zero-based. Make easy intergers to know where the
# real data lives
self.ilo = ng # where the 'real' data starts (outside of ghost cell region)
self.ihi = ng + nx - 1 # where the 'real' data ends
# physical coords -- cell-centered, left and right edges
self.dx = (xmax - xmin) / (nx)
self.x = xmin + (np.arange(nx + 2 * ng) - ng + 0.5) * self.dx
# Actual number of points in state variable / grid = nx + 2* ng
# Since you have `ng` ghost cells on each side of domain
# storage for the solution
self.u = np.zeros((nx + 2 * ng), dtype=np.float64)
def scratch_array(self):
""" return a scratch array dimensioned for our grid """
return np.zeros((self.nx + 2 * self.ng), dtype=np.float64)
def fill_BCs(self):
""" fill all ghostcells as periodic """
if self.bc == "periodic":
# left boundary
self.u[0 : self.ilo] = self.u[self.ihi - self.ng + 1 : self.ihi + 1]
# right boundary
self.u[self.ihi + 1 :] = self.u[self.ilo : self.ilo + self.ng]
elif self.bc == "outflow":
# left boundary
self.u[0 : self.ilo] = self.u[self.ilo]
# right boundary
self.u[self.ihi + 1 :] = self.u[self.ihi]
else:
raise NotImplementedError