def test_legendre_spacetime_massmatrix(order): ''' This test compares the analytical solution of the space-time MM to the computed one. ''' basis = basis_defs.LegendreQuad(order) mesh = mesh_common.mesh_1D(num_elems=1, xmin=-1., xmax=1.) # Set quadrature basis.set_elem_quadrature_type("GaussLegendre") basis.set_face_quadrature_type("GaussLegendre") MM = basis_st_tools.get_elem_mass_matrix_ader(mesh, basis, order, -1) ''' Reference: Dumbser, M., Enaux, C., and Toro, E. JCP 2008 Vol. 227, Issue 8, Pgs: 3971 - 4001 Appendix B ''' # Multiply by 4.0 caused by reference element shift [0, 1] -> [-1, 1] if order == 1: expected = 4.0 * np.array([[1., 0., 0., 0.], [0., 1. / 3., 0., 0.], [0., 0., 1. / 3., 0], [0., 0., 0., 1. / 9.] ]) elif order == 2: expected = 4.0 * np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 1. / 3., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 1. / 5., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 1. / 3., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1. / 9., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 1. / 15., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 1. / 5, 0., 0.], [0., 0., 0., 0., 0., 0., 0., 1. / 15., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 1. / 25.]]) # Assert np.testing.assert_allclose(MM, expected, rtol, atol)
def set_basis(order, basis_name): ''' Sets the basis class given the basis_name string argument Inputs: ------- order: solution order basis_name: name of the basis function we wish to instantiate as a class Outputs: -------- basis: instantiated basis class Raise: ------ If the basis class is not defined, returns a NotImplementedError ''' if BasisType[basis_name] == BasisType.LagrangeSeg: basis = basis_defs.LagrangeSeg(order) elif BasisType[basis_name] == BasisType.LegendreSeg: basis = basis_defs.LegendreSeg(order) elif BasisType[basis_name] == BasisType.LagrangeQuad: basis = basis_defs.LagrangeQuad(order) elif BasisType[basis_name] == BasisType.LegendreQuad: basis = basis_defs.LegendreQuad(order) elif BasisType[basis_name] == BasisType.LagrangeTri: basis = basis_defs.LagrangeTri(order) elif BasisType[basis_name] == BasisType.HierarchicH1Tri: basis = basis_defs.HierarchicH1Tri(order) else: raise NotImplementedError return basis
def set_basis_spacetime(mesh, order, basis_name): ''' Sets the space-time basis class given the basis_name string argument Inputs: ------- order: solution order basis_name: name of the spatial basis function used to determine the space-time basis function we wish to instantiate as a class Outputs: -------- basis_st: instantiated space-time basis class Raise: ------ If the basis class is not defined returns a NotImplementedError ''' if BasisType[basis_name] == BasisType.LagrangeSeg: basis_st = basis_defs.LagrangeQuad(order) elif BasisType[basis_name] == BasisType.LegendreSeg: basis_st = basis_defs.LegendreQuad(order) elif BasisType[basis_name] == BasisType.LagrangeQuad: basis_st = basis_defs.LagrangeHex(order) elif BasisType[basis_name] == BasisType.LagrangeTri: basis_st = basis_defs.LagrangePrism(order) else: raise NotImplementedError return basis_st
def test_legendre_spacetime_stiffnessmatrix_spacedir_phys(dt, order): ''' This test compares the analytical solution of the space-time stiffness matrix in space to the computed one. ''' basis = basis_defs.LegendreSeg(order) basis_st = basis_defs.LegendreQuad(order) mesh = mesh_common.mesh_1D(num_elems=1, xmin=0., xmax=1.) # Set quadrature basis.set_elem_quadrature_type("GaussLegendre") basis.set_face_quadrature_type("GaussLegendre") basis_st.set_elem_quadrature_type("GaussLegendre") basis_st.set_face_quadrature_type("GaussLegendre") mesh.gbasis.set_elem_quadrature_type("GaussLegendre") mesh.gbasis.set_face_quadrature_type("GaussLegendre") # Get stiffness matrix in space SMS = basis_st_tools.get_stiffness_matrix_ader(mesh, basis, basis_st, order, dt, elem_ID=0, grad_dir=0, physical_space=True) ''' Reference: Dumbser, M., Enaux, C., and Toro, E. JCP 2008 Vol. 227, Issue 8, Pgs: 3971 - 4001 Appendix B Note: We multiply by 4 here because (unlike Dumbser's paper), we multiply by the inverse jacobian to account for non-ideal meshes See the Quail documentation (Section for ADER-DG: space-time predictor step where the K matrices are defined) ''' if order == 1: expected = 4.0 * np.array([[0., 2., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 2. / 3.], [0., 0., 0., 0.]]) elif order == 2: expected = 4.0 * np.array([[0., 2., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 2., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 2. / 3., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 2. / 3., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 2. / 5., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 2. / 5.], [0., 0., 0., 0., 0., 0., 0., 0., 0.]]) # Assert np.testing.assert_allclose(SMS.transpose(), expected, rtol, atol)
def test_legendre_spacetime_stiffnessmatrix_timedir(dt, order): ''' This test compares the analytical solution of the space-time stiffness matrix in time to the computed one. ''' basis = basis_defs.LegendreSeg(order) basis_st = basis_defs.LegendreQuad(order) mesh = mesh_common.mesh_1D(num_elems=1, xmin=-1., xmax=1.) # Set quadrature basis.set_elem_quadrature_type("GaussLegendre") basis.set_face_quadrature_type("GaussLegendre") basis_st.set_elem_quadrature_type("GaussLegendre") basis_st.set_face_quadrature_type("GaussLegendre") mesh.gbasis.set_elem_quadrature_type("GaussLegendre") mesh.gbasis.set_face_quadrature_type("GaussLegendre") # Get stiffness matrix in time SMT = basis_st_tools.get_stiffness_matrix_ader(mesh, basis, basis_st, order, dt, elem_ID=0, grad_dir=-1, physical_space=False) ''' Reference: Dumbser, M., Enaux, C., and Toro, E. JCP 2008 Vol. 227, Issue 8, Pgs: 3971 - 4001 Appendix B ''' # Multiply by 2.0 caused by reference element shift [0, 1] -> [-1, 1] if order == 1: expected = 2.0 * np.array([[0., 0., 0., 0.], [0., 0., 0., 0.], [2., 0., 0., 0.], [0., 2. / 3., 0., 0.]]) elif order == 2: expected = 2.0 * np.array([[0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0.], [2., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 2. / 3., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 2. / 5., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 2., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 2. / 3., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 2. / 5., 0., 0., 0.]]) # Assert np.testing.assert_allclose(SMT, expected, rtol, atol)
def test_legendre_spacetime_massmatrix(order): ''' This test makes sure that the already tested mass matrix yields the corrected inverse mass matrix with the diagonal inverted. ''' basis = basis_defs.LegendreQuad(order) mesh = mesh_common.mesh_1D(num_elems=1, xmin=-1., xmax=1.) # Set quadrature basis.set_elem_quadrature_type("GaussLegendre") basis.set_face_quadrature_type("GaussLegendre") MM = basis_st_tools.get_elem_mass_matrix_ader(mesh, basis, order, -1) iMM = basis_st_tools.get_elem_inv_mass_matrix_ader(mesh, basis, order, -1) np.testing.assert_allclose(np.diagonal(iMM), 1. / np.diagonal(MM), rtol, atol)
def test_temporal_flux_ader_tnp1(order): ''' This test compares the analytical solution of the space-time temporal flux evaluated at t^{n+1} to the computed one. ''' basis_st = basis_defs.LegendreQuad(order) mesh = mesh_common.mesh_1D(num_elems=1, xmin=-1., xmax=1.) # Set quadrature basis_st.set_elem_quadrature_type("GaussLegendre") basis_st.set_face_quadrature_type("GaussLegendre") mesh.gbasis.set_elem_quadrature_type("GaussLegendre") mesh.gbasis.set_face_quadrature_type("GaussLegendre") # Get flux matrices in time FTL = basis_st_tools.get_temporal_flux_ader(mesh, basis_st, basis_st, order, physical_space=False) ''' Reference: Dumbser, M., Enaux, C., and Toro, E. JCP 2008 Vol. 227, Issue 8, Pgs: 3971 - 4001 Appendix B ''' # Multiply by 2.0 caused by reference element shift [0, 1] -> [-1, 1] if order == 1: expected = 2.0 * np.array([[1., 0., 1., 0.], [ 0., 1. / 3., 0., 1. / 3. ], [1., 0., 1., 0], [0., 1. / 3., 0., 1. / 3.]]) elif order == 2: expected = 2.0 * np.array( [[1., 0., 0., 1., 0., 0., 1., 0., 0.], [0., 1. / 3., 0., 0., 1. / 3., 0., 0., 1. / 3., 0.], [0., 0., 1. / 5., 0., 0., 1. / 5., 0., 0., 1. / 5.], [1., 0., 0., 1., 0., 0., 1., 0., 0.], [0., 1. / 3., 0., 0., 1. / 3., 0., 0., 1. / 3., 0.], [0., 0., 1. / 5., 0., 0., 1. / 5., 0., 0., 1. / 5.], [1., 0., 0., 1., 0., 0., 1., 0., 0.], [0., 1. / 3., 0., 0., 1. / 3., 0., 0., 1. / 3., 0.], [0., 0., 1. / 5., 0., 0., 1. / 5., 0., 0., 1. / 5.]]) # Assert np.testing.assert_allclose(FTL, expected, rtol, atol)
def test_legendre_spacetime_massmatrix_phys(order): ''' This test compares the analytical solution of the space-time MM to the computed one, but uses a physics element that spans [0.0, 0.5] ''' basis = basis_defs.LegendreQuad(order) mesh = mesh_common.mesh_1D(num_elems=1, xmin=0., xmax=0.5) # Set quadrature basis.set_elem_quadrature_type("GaussLegendre") basis.set_face_quadrature_type("GaussLegendre") MM = basis_st_tools.get_elem_mass_matrix_ader(mesh, basis, order, 0, physical_space=True) ''' Reference: Dumbser, M., Enaux, C., and Toro, E. JCP 2008 Vol. 227, Issue 8, Pgs: 3971 - 4001 Appendix B ''' if order == 1: expected = np.array([[1., 0., 0., 0.], [0., 1. / 3., 0., 0.], [0., 0., 1. / 3., 0], [0., 0., 0., 1. / 9.]]) elif order == 2: expected = np.array([[1., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 1. / 3., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 1. / 5., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 1. / 3., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 1. / 9., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 1. / 15., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 1. / 5, 0., 0.], [0., 0., 0., 0., 0., 0., 0., 1. / 15., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 1. / 25.]]) # Assert np.testing.assert_allclose(MM, expected, rtol, atol)