def _dh(h): lo, hi = h.limits() dh = Array(lo, hi - 1) for i in range(lo, hi): dh.set(i, h.get(i + 1) - h.get(i)) return dh
def new_h(self, h_0): n_cells = h_0.shape[0] n_ghost = self._n_ghost h = Array(1 - n_ghost, n_cells + n_ghost) for i in range(n_cells): h.set(i + 1, h_0[i]) return h
def _phi(self, theta): phi = Array.empty_like(theta) lo, hi = theta.limits() for i in range(lo, hi + 1): theta_mid = theta.get(i) r = (1 + theta_mid) / 2 phi.set(i, max(0, min(r, 2, 2 * theta_mid))) return phi
def _flux_lim(self, s, dh, dt, dx): theta = self._theta(dh, s) phi = self._phi(theta) lo, hi = phi.limits() lim_flux = Array.empty_like(phi) for i in range(lo, hi + 1): lim_wave = dh.get(i) * phi.get(i) abs_s = abs(s.get(i)) lim_flux.set(i, 0.5 * abs_s * (1 - dt / dx * abs_s) * lim_wave) return lim_flux
def _theta(self, dh, s): lo, hi = dh.limits() theta = Array(lo + 1, hi - 1) for i in range(lo + 1, hi): dh_mid = dh.get(i) if dh_mid == 0: theta.set(i, 0) continue dh_left = dh.get(i - 1) dh_right = dh.get(i + 1) s_mid = s.get(i) if s_mid > 0: theta.set(i, dh_left / dh_mid) elif s_mid < 0: theta.set(i, dh_right / dh_mid) return theta
def new_s(self, h): lo, hi = h.limits() s = Array(lo, hi - 1) return s
def new_f_x(self, h): lo, hi = h.limits() return Array(lo + self._n_ghost, hi - self._n_ghost)