def updata_analytical_solution(): """ updates the analytical solution """ x = np.linspace(pde_settings.x_min, pde_settings.x_max, 200) u_ana_id = get_solver_id() f0 = pde_functions.parse(initial_condition.value) u_x[0] = pde_settings.analytical_solutions[u_ana_id](f0, x)
def updata_analytical_solution(): """ updates the analytical solution """ x = np.linspace(pde_settings.x_min, pde_settings.x_max, 200) u_ana_id = get_solver_id() f0 = pde_functions.parse(initial_condition.value) u_x = pde_settings.analytical_solutions[u_ana_id](f0, x) ana_sol.data = dict({'u_x':u_x})
def update_mesh(h, k): """ called if the numerical discretization mesh changed. i.e. if temporal or spatial meshwidth changes. The whole problem is recomputed and each timestep is saved to the mesh_data. Finally the currently active timestep is plotted. :param h: spatial meshwidth :param k: temporal meshwidth """ solver_id = get_solver_id() pde_specs.data = dict(h=[h], k=[k], solver_id=[solver_id]) solver = pde_settings.solvers[solver_id] # spatial discretization x0 = pde_settings.x_min x1 = pde_settings.x_max x = np.arange(x0, x1+h, h) # get initial condition f0 = pde_functions.parse(initial_condition.value) u = f0(x) # this enforces neumann BC: u'(t=0)=0 u_old = np.array(u) # number of timesteps n_temporal = int(round(pde_settings.t_max / k, 0)) + 1 # setup datastructure for saving each timestep mesh_dict = dict(x=x) for i in range(n_temporal): # iterate over all timesteps key = 'u' + str(i) mesh_dict[key] = u.tolist() # save result to dict u_new = solver(u_old, u, k, h) # propagate in time u_old = u u = u_new mesh_data.data = mesh_dict t = time_slider.value update_plot(k, t)
def update_mesh(h, k): """ called if the numerical discretization mesh changed. i.e. if temporal or spatial meshwidth changes. The whole problem is recomputed and each timestep is saved to the mesh_data. Finally the currently active timestep is plotted. :param h: spatial meshwidth :param k: temporal meshwidth """ solver_id = get_solver_id() pde_specs.data = dict(h=[h], k=[k], solver_id=[solver_id]) solver = pde_settings.solvers[solver_id] # spatial discretization x0 = pde_settings.x_min x1 = pde_settings.x_max x = np.arange(x0, x1 + h, h) # get initial condition f0 = pde_functions.parse(initial_condition.value) u = f0(x) # this enforces neumann BC: u'(t=0)=0 u_old = np.array(u) # number of timesteps n_temporal = int(round(pde_settings.t_max / k, 0)) + 1 # setup datastructure for saving each timestep mesh_dict = dict(x=x) for i in range(n_temporal): # iterate over all timesteps key = 'u' + str(i) mesh_dict[key] = u.tolist() # save result to dict u_new = solver(u_old, u, k, h) # propagate in time u_old = u u = u_new mesh_data.data = mesh_dict t = time_slider.value update_plot(k, t)