Пример #1
0
def test_convective_flux_1D_zero_velocity():
    '''
	This tests the convective flux for a 1D case but with zero vel
	'''
    physics = euler.Euler1D()

    ns = physics.NUM_STATE_VARS

    P = 101325.
    rho = 1.1
    gamma = 1.4
    rhoE = P / (gamma - 1.)

    Uq = np.zeros([1, 1, ns])

    irho, irhou, irhoE = physics.get_state_indices()

    Uq[:, :, irho] = rho
    Uq[:, :, irhou] = 0.
    Uq[:, :, irhoE] = rhoE

    Fref = np.zeros([1, 1, ns, 1])
    Fref[:, :, irho, 0] = 0.
    Fref[:, :, irhou, 0] = P
    Fref[:, :, irhoE, 0] = 0.

    physics.set_physical_params()
    F, (u2c, rhoc, pc) = physics.get_conv_flux_interior(Uq)

    np.testing.assert_allclose(rhoc, rho, rtol, atol)
    np.testing.assert_allclose(u2c, 0., rtol, atol)
    np.testing.assert_allclose(pc, P, rtol, atol)
    np.testing.assert_allclose(F, Fref, rtol, atol)
Пример #2
0
def test_conv_eigenvectors_multiplied_is_identity():
    '''
	This tests the convective eigenvectors in euler and ensures
	that when dotted together they are identity
	'''
    physics = euler.Euler1D()
    ns = physics.NUM_STATE_VARS
    irho, irhou, irhoE = physics.get_state_indices()
    physics.set_physical_params()
    U_bar = np.zeros([1, 1, ns])

    P = 101325.
    rho = 1.1
    u = 2.5
    gamma = 1.4
    rhoE = P / (gamma - 1.) + 0.5 * rho * u * u

    U_bar[:, :, irho] = rho
    U_bar[:, :, irhou] = rho * u
    U_bar[:, :, irhoE] = rhoE

    right_eigen, left_eigen = physics.get_conv_eigenvectors(U_bar)
    ldotr = np.einsum('elij,eljk->elik', left_eigen, right_eigen)

    expected = np.zeros_like(left_eigen)
    expected[:, :] = np.identity(left_eigen.shape[-1])

    np.testing.assert_allclose(ldotr, expected, rtol, atol)
Пример #3
0
def test_convective_flux_1D():
    '''
	This tests the convective flux for a 1D case.
	'''
    physics = euler.Euler1D()

    ns = physics.NUM_STATE_VARS

    P = 101325.
    rho = 1.1
    u = 2.5
    gamma = 1.4
    rhoE = P / (gamma - 1.) + 0.5 * rho * u * u

    Uq = np.zeros([1, 1, ns])

    irho, irhou, irhoE = physics.get_state_indices()

    Uq[:, :, irho] = rho
    Uq[:, :, irhou] = rho * u
    Uq[:, :, irhoE] = rhoE

    Fref = np.zeros([1, 1, ns, 1])
    Fref[:, :, irho, 0] = rho * u
    Fref[:, :, irhou, 0] = rho * u * u + P
    Fref[:, :, irhoE, 0] = (rhoE + P) * u

    physics.set_physical_params()
    F, (u2c, rhoc, pc) = physics.get_conv_flux_interior(Uq)

    np.testing.assert_allclose(rhoc, rho, rtol, atol)
    np.testing.assert_allclose(u2c, u * u, rtol, atol)
    np.testing.assert_allclose(pc, P, rtol, atol)
    np.testing.assert_allclose(F, Fref, rtol, atol)
Пример #4
0
def test_numerical_flux_1D_conservation(conv_num_flux_type):
	'''
	This test ensures that the 1D numerical flux functions are 
	conservative, i.e. 
	F_numerical(uL, uR, n) = -F_numerical(uR, uL, -n)
	'''
	physics = euler.Euler1D()
	physics.set_conv_num_flux(conv_num_flux_type)
	physics.set_physical_params()

	UqL = np.zeros([1, 1, physics.NUM_STATE_VARS])
	UqR = UqL.copy()

	irho, irhou, irhoE = physics.get_state_indices()

	# Left state
	P = 101325.
	rho = 1.1
	u = 2.5
	gamma = physics.gamma
	rhoE = P / (gamma - 1.) + 0.5 * rho * u * u

	UqL[:, :, irho] = rho
	UqL[:, :, irhou] = rho * u
	UqL[:, :, irhoE] = rhoE

	# Right state
	P = 101325*2.
	rho = 0.7
	u = -3.5
	rhoE = P / (gamma - 1.) + 0.5 * rho * u * u

	UqR[:, :, irho] = rho
	UqR[:, :, irhou] = rho * u
	UqR[:, :, irhoE] = rhoE

	# Normals
	normals = np.zeros([1, 1, 1])
	normals[:, :, 0] = 0.5

	# Compute numerical flux
	Fnum = physics.conv_flux_fcn.compute_flux(physics, UqL, UqR, normals)

	# Compute numerical flux, but switch left and right states and negate 
	# normals
	F_expected = physics.conv_flux_fcn.compute_flux(physics, UqR, UqL, 
			-normals)

	np.testing.assert_allclose(Fnum, -F_expected, rtol, atol)
Пример #5
0
def create_solver_object():
    '''
	This function creates a solver object that stores the positivity-
	preserving limiter object needed for the tests here.
	'''
    mesh = mesh_common.mesh_1D(num_elems=1, xmin=0., xmax=1.)

    mesh_tools.make_periodic_translational(mesh, x1="x1", x2="x2")

    params = general.set_solver_params(SolutionOrder=1,
                                       SolutionBasis="LagrangeSeg",
                                       ApplyLimiters=["PositivityPreserving"])

    physics = euler.Euler1D()
    physics.set_conv_num_flux("Roe")
    physics.set_physical_params()
    U = np.array([1., 0., 1.])
    physics.set_IC(IC_type="Uniform", state=U)

    solver = DG.DG(params, physics, mesh)

    return solver
Пример #6
0
def test_numerical_flux_1D_consistency(conv_num_flux_type):
	'''
	This test ensures that the 1D numerical flux functions are 
	consistent, .e. F_numerical(u, u, n) = F(u) dot n
	'''
	physics = euler.Euler1D()
	physics.set_conv_num_flux(conv_num_flux_type)
	physics.set_physical_params()

	UqL = np.zeros([1, 1, physics.NUM_STATE_VARS])

	# Fill state
	P = 101325.
	rho = 1.1
	u = 2.5
	gamma = physics.gamma
	rhoE = P / (gamma - 1.) + 0.5 * rho * u * u

	irho, irhou, irhoE = physics.get_state_indices()

	UqL[:, :, irho] = rho
	UqL[:, :, irhou] = rho * u
	UqL[:, :, irhoE] = rhoE

	UqR = UqL.copy()

	# Normals
	normals = np.zeros([1, 1, 1])
	normals[:, :, 0] = 0.5

	# Compute numerical flux
	Fnum = physics.conv_flux_fcn.compute_flux(physics, UqL, UqR, normals)

	# Physical flux projected in normal direction
	F_expected, _ = physics.get_conv_flux_projected(UqL, normals)

	np.testing.assert_allclose(Fnum, F_expected, rtol, atol)