def get_weno_grid(self, dx, dt, T): left_boundary = self.x_low - dx * 0.5 right_boundary = self.x_high + dx * 0.5 ncells = int((self.x_high - self.x_low) / dx + 1.) # need to be very small num_t = int(T/dt + 1.) w = Weno3(left_boundary, right_boundary, ncells, self.flux, self.flux_deriv, self.max_flux_deriv, dx = dx, dt = dt, num_t = num_t + 100) x_center = w.get_x_center() u0 = self.init_condition(x_center, self.args.initial_t) w.integrate(u0, T) solutions = w.u_grid[:num_t,:] return solutions
def get_weno_grid(init_condition, dx=0.02, dt=0.004, T=0.8, x_low=-1, x_high=1, boundary='periodic', eta=0, forcing=None, ncells=None, num_t=None, flux_name='u2'): """ dx: grid size. e.g. 0.02 dt: time step size. e.g. 0.004 T: evolve time. e.g. 1 x_low: if the grid is in the range [-1,1], then x_low = -1. x_high: if the grid is in the range [-1,1], then x_low = 1. init_condition: a function that computes the initial values of u. e.g. the init func above. return: a grid of size num_t x num_x where num_t = T/dt + 1 num_x = (x_high - x_low) / dx + 1 """ left_boundary = x_low - dx * 0.5 right_boundary = x_high + dx * 0.5 if ncells is None: ncells = int((x_high - x_low) / dx + 1.) # need to be very small if num_t is None: num_t = int(T / dt + 1.) w = Weno3(left_boundary, right_boundary, ncells, lambda x: flux(val=x, flux=flux_name), lambda x: flux_deriv(val=x, flux=flux_name), lambda a, b: max_flux_deriv(a=a, b=b, flux=flux_name), dx=dx, dt=dt, num_t=num_t + 100, boundary=boundary, eta=eta, forcing=forcing) x_center = w.get_x_center() u0 = init_condition(x_center) w.integrate(u0, T, num_t=num_t) solutions = w.u_grid[:num_t, :] return solutions
def evolve(x_center, t, u0): dx = x_center[1] - x_center[0] cfl = 0.2 left_boundary = x_center[0] - dx * 0.5 right_boundary = x_center[-1] + dx * 0.5 ncells = len(x_center) w = Weno3(left_boundary, right_boundary, ncells, flux, flux_deriv, max_flux_deriv, dx=dx, dt=dx * cfl, cfl_number=cfl, record=False) return w.integrate(u0, t)
def evolve(x_center, u0, t, animation=0): dx = x_center[1] - x_center[0] cfl = 0.2 left_boundary = x_center[0] - dx * 0.5 right_boundary = x_center[-1] + dx * 0.5 ncells = len(x_center) dt = dx * cfl evolve_num = int(t / dt) w = Weno3(left_boundary, right_boundary, ncells, flux, flux_deriv, max_flux_deriv, dx=dx, dt=dx * cfl, cfl_number=cfl) w.integrate(u0, t) solutions = w.u_grid[:evolve_num + 1, :] if animation: return solutions else: return solutions[-1]