def volume_int_convergence(): ''' convergence test for volume int flux ''' N_LGL = np.arange(15).astype(float) + 3 L1_norm_option_3 = np.zeros([15]) L1_norm_option_1 = np.zeros([15]) for i in range(0, 15): test_waveEqn.change_parameters(i + 3, 16, i + 4) vol_int_analytical = np.zeros([params.N_Elements, params.N_LGL]) for j in range (params.N_Elements): for k in range (params.N_LGL): vol_int_analytical[j][k] = (analytical_volume_integral\ (af.transpose(params.element_array[j]), k)) vol_int_analytical = af.transpose(af.np_to_af_array\ (vol_int_analytical)) L1_norm_option_3[i] = af.mean(af.abs(vol_int_analytical\ - wave_equation.volume_integral_flux(params.u_init, 0))) for i in range(0, 15): test_waveEqn.change_parameters(i + 3, 16, i + 3) vol_int_analytical = np.zeros([params.N_Elements, params.N_LGL]) for j in range (params.N_Elements): for k in range (params.N_LGL): vol_int_analytical[j][k] = analytical_volume_integral(\ af.transpose(params.element_array[j]), k) vol_int_analytical = af.transpose(af.np_to_af_array(vol_int_analytical)) L1_norm_option_1[i] = af.mean(af.abs(vol_int_analytical\ - wave_equation.volume_integral_flux(params.u_init, 0))) normalization = 0.0023187 / (3 ** (-3)) print(L1_norm_option_1, L1_norm_option_3) plt.loglog(N_LGL, L1_norm_option_1, marker='o', label='L1 norm option 1') plt.loglog(N_LGL, L1_norm_option_3, marker='o', label='L1 norm option 3') plt.loglog(N_LGL, normalization * N_LGL **(-N_LGL), color='black', linestyle='--', label='$N_{LGL}^{-N_{LGL}}$') plt.title('L1 norm of volume integral term') plt.xlabel('LGL points') plt.ylabel('L1 norm') plt.legend(loc='best') plt.show()
def test_volume_integral_flux(): ''' A test function to check the volume_integral_flux function in wave_equation module by analytically calculated Gauss-Lobatto quadrature. Reference --------- The link to the sage worksheet where the calculations were caried out is given below. `https://goo.gl/5Mub8M` ''' threshold = 4e-9 params.c = 1 change_parameters(8, 10, 11, 'gaussian') referenceFluxIntegral = af.transpose(af.interop.np_to_af_array(np.array ([ [-0.002016634876668093, -0.000588597708116113, -0.0013016773719126333,\ -0.002368387579324652, -0.003620502047659841, -0.004320197094090966, -0.003445512010153811, 0.0176615086879261],\ [-0.018969769374, -0.00431252844519,-0.00882630935977,-0.0144355176966,\ -0.019612124119, -0.0209837936827, -0.0154359890788, 0.102576031756], \ [-0.108222418798, -0.0179274222595, -0.0337807018822, -0.0492589052599,\ -0.0588472807471, -0.0557970236273, -0.0374764132459, 0.361310165819],\ [-0.374448714304, -0.0399576371245, -0.0683852285846, -0.0869229749357,\ -0.0884322503841, -0.0714664112839, -0.0422339853622, 0.771847201979], \ [-0.785754362849, -0.0396035640187, -0.0579313769517, -0.0569022801117,\ -0.0392041960688, -0.0172295769141, -0.00337464521455, 1.00000000213],\ [-1.00000000213, 0.00337464521455, 0.0172295769141, 0.0392041960688,\ 0.0569022801117, 0.0579313769517, 0.0396035640187, 0.785754362849],\ [-0.771847201979, 0.0422339853622, 0.0714664112839, 0.0884322503841, \ 0.0869229749357, 0.0683852285846, 0.0399576371245, 0.374448714304],\ [-0.361310165819, 0.0374764132459, 0.0557970236273, 0.0588472807471,\ 0.0492589052599, 0.0337807018822, 0.0179274222595, 0.108222418798], \ [-0.102576031756, 0.0154359890788, 0.0209837936827, 0.019612124119, \ 0.0144355176966, 0.00882630935977, 0.00431252844519, 0.018969769374],\ [-0.0176615086879, 0.00344551201015 ,0.00432019709409, 0.00362050204766,\ 0.00236838757932, 0.00130167737191, 0.000588597708116, 0.00201663487667]\ ]))) numerical_flux = wave_equation.volume_integral_flux(params.u[:, :, 0]) assert (af.mean(af.abs(numerical_flux - referenceFluxIntegral)) < threshold)
def test_b_vector(): ''' A test function to check the b vector obtained analytically and compare it with the one returned by b_vector function in wave_equation module. ''' threshold = 1e-13 params.c = 1 change_parameters(8, 10, 8, 'gaussian') u_n_A_matrix = af.blas.matmul(wave_equation.A_matrix(),\ params.u[:, :, 0]) volume_integral_flux = wave_equation.volume_integral_flux(params.u[:, :, 0]) surface_term = test_surface_term() b_vector_analytical = u_n_A_matrix + (volume_integral_flux -\ (surface_term)) * params.delta_t b_vector_array = wave_equation.b_vector(params.u[:, :, 0]) assert (b_vector_analytical - b_vector_array) < threshold