Coverage for pySDC/implementations/problem_classes/acoustic_helpers/buildWave1DMatrix.py: 100%
24 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-17 13:41 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-17 13:41 +0000
1import numpy as np
2import scipy.sparse as sp
4from pySDC.helpers.problem_helper import get_finite_difference_matrix
6wave_order = 6
9def getFDMatrix(N, dx, order, stencil_type, bc):
10 """
11 First derivative matrix. Only homogeneous boundary conditions are supported, so the
12 right hand side contribution returned by the helper has to vanish.
13 """
14 A, b = get_finite_difference_matrix(
15 derivative=1, order=order, stencil_type=stencil_type, dx=dx, size=N, dim=1, bc=bc
16 )
17 assert np.linalg.norm(b) == 0.0, 'Inhomogeneous boundary conditions are not supported here'
18 return sp.csc_matrix(A)
21def getWave1DMatrix(N, dx, bc_left, bc_right):
22 Id = sp.eye(2 * N)
24 D_u = getFDMatrix(N, dx, wave_order, 'center', (bc_left[0], bc_right[0]))
25 D_p = getFDMatrix(N, dx, wave_order, 'center', (bc_left[1], bc_right[1]))
26 Zero = np.zeros((N, N))
27 M1 = sp.hstack((Zero, D_p), format="csc")
28 M2 = sp.hstack((D_u, Zero), format="csc")
29 M = sp.vstack((M1, M2), format="csc")
30 return sp.csc_matrix(Id), sp.csc_matrix(M)
33def getWave1DAdvectionMatrix(N, dx, order):
34 Dx = getFDMatrix(N, dx, order, 'upwind', 'periodic')
35 Zero = np.zeros((N, N))
36 M1 = sp.hstack((Dx, Zero), format="csc")
37 M2 = sp.hstack((Zero, Dx), format="csc")
38 M = sp.vstack((M1, M2), format="csc")
39 return sp.csc_matrix(M)