Coverage for pySDC/implementations/problem_classes/boussinesq_helpers/buildBoussinesq2DMatrix.py: 0%

34 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-16 14:51 +0000

1import numpy as np 

2import scipy.sparse as sp 

3 

4from pySDC.implementations.problem_classes.boussinesq_helpers.build2DFDMatrix import ( 

5 get2DMatrix, 

6 getBCHorizontal, 

7 get2DUpwindMatrix, 

8) 

9 

10 

11def getBoussinesq2DUpwindMatrix(N, dx, u_adv, order): 

12 Dx = get2DUpwindMatrix(N, dx, order) 

13 

14 # Note: In the equations it is u_t + u_adv* D_x u = ... so in order to comply with the form u_t = M u, 

15 # add a minus sign in front of u_adv 

16 

17 Zero = np.zeros((N[0] * N[1], N[0] * N[1])) 

18 M1 = sp.hstack((-u_adv * Dx, Zero, Zero, Zero), format="csr") 

19 M2 = sp.hstack((Zero, -u_adv * Dx, Zero, Zero), format="csr") 

20 M3 = sp.hstack((Zero, Zero, -u_adv * Dx, Zero), format="csr") 

21 M4 = sp.hstack((Zero, Zero, Zero, -u_adv * Dx), format="csr") 

22 M = sp.vstack((M1, M2, M3, M4), format="csr") 

23 

24 return sp.csc_matrix(M) 

25 

26 

27def getBoussinesq2DMatrix(N, h, bc_hor, bc_ver, c_s, Nfreq, order): 

28 Dx_u, Dz_u = get2DMatrix(N, h, bc_hor[0], bc_ver[0], order) 

29 Dx_w, Dz_w = get2DMatrix(N, h, bc_hor[1], bc_ver[1], order) 

30 # Dx_b, Dz_b = get2DMatrix(N, h, bc_hor[2], bc_ver[2], order) 

31 Dx_p, Dz_p = get2DMatrix(N, h, bc_hor[3], bc_ver[3], order) 

32 

33 # Id_N = sp.eye(N[0] * N[1]) 

34 

35 Zero = np.zeros((N[0] * N[1], N[0] * N[1])) 

36 Id_w = sp.eye(N[0] * N[1]) 

37 

38 # Note: Bring all terms to right hand side, therefore a couple of minus signs 

39 # are needed 

40 

41 M1 = sp.hstack((Zero, Zero, Zero, -Dx_p), format="csr") 

42 M2 = sp.hstack((Zero, Zero, Id_w, -Dz_p), format="csr") 

43 M3 = sp.hstack((Zero, -(Nfreq**2) * Id_w, Zero, Zero), format="csr") 

44 M4 = sp.hstack((-(c_s**2) * Dx_u, -(c_s**2) * Dz_w, Zero, Zero), format="csr") 

45 M = sp.vstack((M1, M2, M3, M4), format="csr") 

46 

47 Id = sp.eye(4 * N[0] * N[1]) 

48 

49 return sp.csc_matrix(Id), sp.csc_matrix(M) 

50 

51 

52def getBoussinesqBCHorizontal(value, N, dx, bc_hor): 

53 bu_left, bu_right = getBCHorizontal(value[0], N, dx, bc_hor[0]) 

54 bw_left, bw_right = getBCHorizontal(value[1], N, dx, bc_hor[1]) 

55 # bb_left, bb_right = getBCHorizontal(value[2], N, dx, bc_hor[2]) 

56 bp_left, bp_right = getBCHorizontal(value[3], N, dx, bc_hor[3]) 

57 

58 b_left = np.concatenate((bp_left, bp_left, bu_left + bw_left)) 

59 b_right = np.concatenate((bp_right, bp_right, bu_right + bw_right)) 

60 return b_left, b_right 

61 

62 

63def getBoussinesqBCVertical(): 

64 return 0.0