Coverage for /opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/pysagas/sensitivity/models.py: 61%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-10-30 04:27 +0000

1import numpy as np 

2from pysagas.geometry import Cell 

3 

4 

5def piston_sensitivity(cell: Cell, p_i: int, **kwargs): 

6 """Calculates the pressure-parameter sensitivity using 

7 local piston theory. 

8 

9 Parameters 

10 ---------- 

11 cell : Cell 

12 The cell object. 

13 

14 p_i : int 

15 The index of the parameter to find the sensitivity for. This is used to 

16 index cell.dndp. 

17 """ 

18 M_l = cell.flowstate.M 

19 if M_l < 1.0: 

20 # Subsonic cell, skip 

21 return 0 

22 

23 dPdp = ( 

24 cell.flowstate.rho 

25 * cell.flowstate.a 

26 * np.dot(cell.flowstate.vec, -cell.dndp[:, p_i]) 

27 ) 

28 return dPdp 

29 

30 

31def van_dyke_sensitivity( 

32 cell: Cell, 

33 p_i, 

34 **kwargs, 

35): 

36 """ 

37 Calculates the pressure-parameter sensitivity using 

38 Van Dyke second-order theory. 

39 

40 Parameters 

41 ---------- 

42 cell : Cell 

43 The cell object. 

44 

45 p_i : int 

46 The index of the parameter to find the sensitivity for. This is used to 

47 index cell.dndp. 

48 """ 

49 M_l = cell.flowstate.M 

50 if M_l < 1.0: 

51 # Subsonic cell, skip 

52 return 0 

53 

54 piston = piston_sensitivity(cell=cell, p_i=p_i) 

55 dPdp = piston * M_l / (M_l**2 - 1) ** 0.5 

56 return dPdp 

57 

58 

59def isentropic_sensitivity(cell: Cell, p_i: int, **kwargs): 

60 """Calculates the pressure-parameter sensitivity using 

61 the isentropic flow relation directly.""" 

62 gamma = cell.flowstate.gamma 

63 power = (gamma + 1) / (gamma - 1) 

64 dPdW = (cell.flowstate.P * gamma / cell.flowstate.a) * ( 

65 1 + cell.flowstate.v * (gamma - 1) / (2 * cell.flowstate.a) 

66 ) ** power 

67 dWdn = -cell.flowstate.vec 

68 dndp = cell.dndp[:, p_i] 

69 dPdp = dPdW * np.dot(dWdn, dndp) 

70 return dPdp