def rk3(phi, exact_phi, temp_phi, deri, Hhat, dt): temp_phi.assign(phi) #compute u1, stored in var_list bdry_values = bdry.get_bdry_values(exact_phi) hdw.get_deri(deri[0], phi, bdry_values, 0, "+") hdw.get_deri(deri[1], phi, bdry_values, 0, "-") u1_form = phi - dt*Hhat project(u1_form, phi.function_space(), function=phi) #compute u2, stored in var_list bdry_values = bdry.get_bdry_values(exact_phi) hdw.get_deri(deri[0], phi, bdry_values, 0, "+") hdw.get_deri(deri[1], phi, bdry_values, 0, "-") u2_form = 3.0/4.0*temp_phi + 1.0/4.0*phi - 1.0/4.0*dt*Hhat project(u2_form, phi.function_space(), function=phi) #compute final u, stored in var_list bdry_values = bdry.get_bdry_values(exact_phi) hdw.get_deri(deri[0], phi, bdry_values, 0, "+") hdw.get_deri(deri[1], phi, bdry_values, 0, "-") final_form = 1.0/3.0*temp_phi + 2.0/3.0*phi - 2.0/3.0*dt*Hhat project(final_form, phi.function_space(), function=phi)
def rk3(var_list, exact_characteristic_field_values, temp_var_list, deri_list, form_packs, func_packs, dt): auxi_list = func_packs[1] rhs_forms = form_packs[-1] rhs_list = func_packs[-1] #compute u1, stored in var_list for idx in range(len(form_packs) - 1): hdw.project_functions(form_packs[idx], func_packs[idx]) bdry_values = bdry.get_bdry_values(var_list, auxi_list, exact_characteristic_field_values) for idx in range(len(var_list)): hdw.get_deri(deri_list[idx][0], var_list[idx], bdry_values[idx], 0, "+") hdw.get_deri(deri_list[idx][1], var_list[idx], bdry_values[idx], 0, "-") hdw.project_functions(rhs_forms, rhs_list) u1_forms = [ temp_var_list[idx] + dt * rhs_list[idx] for idx in range(len(var_list)) ] hdw.project_functions(u1_forms, var_list) #compute u2, stored in var_list for idx in range(len(form_packs) - 1): hdw.project_functions(form_packs[idx], func_packs[idx]) bdry_values = bdry.get_bdry_values(var_list, auxi_list, exact_characteristic_field_values) for idx in range(len(var_list)): hdw.get_deri(deri_list[idx][0], var_list[idx], bdry_values[idx], 0, "+") hdw.get_deri(deri_list[idx][1], var_list[idx], bdry_values[idx], 0, "-") hdw.project_functions(rhs_forms, rhs_list) u2_forms = [ 3.0 / 4.0 * temp_var_list[idx] + 1.0 / 4.0 * var_list[idx] + 1.0 / 4.0 * dt * rhs_list[idx] for idx in range(len(var_list)) ] hdw.project_functions(u2_forms, var_list) #compute final u, stored in var_list for idx in range(len(form_packs) - 1): hdw.project_functions(form_packs[idx], func_packs[idx]) bdry_values = bdry.get_bdry_values(var_list, auxi_list, exact_characteristic_field_values) for idx in range(len(var_list)): hdw.get_deri(deri_list[idx][0], var_list[idx], bdry_values[idx], 0, "+") hdw.get_deri(deri_list[idx][1], var_list[idx], bdry_values[idx], 0, "-") hdw.project_functions(rhs_forms, rhs_list) final_forms = [ 1.0 / 3.0 * temp_var_list[idx] + 2.0 / 3.0 * var_list[idx] + 2.0 / 3.0 * dt * rhs_list[idx] for idx in range(len(var_list)) ] hdw.project_functions(final_forms, var_list)
def rk2(var_list, exact_characteristic_field_values, temp_var_list, deri_list, form_packs, func_packs, dt): auxi_list = func_packs[1] rhs_forms = form_packs[-1] rhs_list = func_packs[-1] for dummy in range(2): for idx in range(len(form_packs) - 1): hdw.project_functions(form_packs[idx], func_packs[idx]) bdry_values = bdry.get_bdry_values(var_list, auxi_list, exact_characteristic_field_values) for idx in range(len(var_list)): hdw.get_deri(deri_list[idx][0], var_list[idx], bdry_values[idx], 0, "+") hdw.get_deri(deri_list[idx][1], var_list[idx], bdry_values[idx], 0, "-") hdw.project_functions(rhs_forms, rhs_list) dt_forms = [ var_list[idx] + dt * rhs_list[idx] for idx in range(len(var_list)) ] hdw.project_functions(dt_forms, var_list) final_forms = [ 0.5 * (temp_var_list[idx] + var_list[idx]) for idx in range(len(var_list)) ] hdw.project_functions(final_forms, var_list)
def rk2(phi, exact_phi, temp_phi, deri, Hhat, dt): temp_phi.assign(phi) for dummy in range(2): bdry_values = bdry.get_bdry_values(exact_phi) hdw.get_deri(deri[0], phi, bdry_values, 0, "+") hdw.get_deri(deri[1], phi, bdry_values, 0, "-") dt_form = phi - dt*Hhat project(dt_form, phi.function_space(), function=phi) final_form = 0.5*(temp_phi + phi) project(final_form, phi.function_space(), function=phi)