-
Notifications
You must be signed in to change notification settings - Fork 1
/
params.py
36 lines (31 loc) · 1.02 KB
/
params.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
import numpy as np
import sys
class Params(object):
def __init__(self, grid):
self.grid = grid
self.t = 0.0
def init_cond(self, type="sine"):
# Some initial conditions
if type == "tophat":
self.grid.u[
np.logical_and(self.grid.x >= 0.333, self.grid.x <= 0.666)
] = 1.0
elif type == "sine":
self.grid.u[:] = 1.0
index = np.logical_and(self.grid.x >= 0.333, self.grid.x <= 0.666)
self.grid.u[index] += 0.5 * np.sin(
2.0 * np.pi * (self.grid.x[index] - 0.333) / 0.333
)
elif type == "rarefaction":
self.grid.u[:] = 1.0
self.grid.u[self.grid.x > 0.5] = 2.0
else:
raise NotImplementedError
def timestep(self, C):
"""
Compute time step according to
CFL number and maximum velocity 'u'
"""
return (
C * self.grid.dx / max(abs(self.grid.u[self.grid.ilo : self.grid.ihi + 1]))
)