Coverage for src/swiift/lib/att.py: 81%

21 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-09-11 16:23 +0200

1"""Attenuation parameterisations.""" 

2 

3import enum 

4import typing 

5 

6import attrs 

7import numpy as np 

8 

9 

10def no_attenuation(): 

11 """No attenuation. 

12 

13 Waves propagate indifinitely, as if the ice cover is perfectly elastic and 

14 the fluid perfectly inviscid. 

15 

16 Returns 

17 ------- 

18 typing.Literal[0] 

19 Amplitude attenuation, in m^-1 

20 

21 Notes 

22 ----- 

23 The attenuation is defined as: 

24 

25 .. math:: 

26 

27 \alpha_j = 0 \forall j. 

28 

29 """ 

30 return 0 

31 

32 

33def parameterisation_01(thickness: float, wavenumbers: np.ndarray) -> np.ndarray: 

34 """Parameterised attenuation for individual wave modes. 

35 

36 Parameters 

37 ---------- 

38 thickness : float 

39 Ice thickness, in m 

40 wavenumbers : np.ndarray 

41 Propagating wavenumbers, in rad m^-1 

42 

43 Returns 

44 ------- 

45 np.ndarray 

46 Amplitude attenuation, in m^-1 

47 

48 Notes 

49 ----- 

50 The attenuation is defined as: 

51 

52 .. math:: 

53 

54 \alpha_j = \frac{1}{4} {k_j}^2 h. 

55 

56 """ 

57 return wavenumbers**2 * thickness / 4 

58 

59 

60def parameterisation_yu2022( 

61 thickness: float, gravity: float, angular_frequencies: np.ndarray 

62) -> np.ndarray: 

63 r"""Parameterised attenuation for individual wave modes. 

64 

65 This parameterisation is issued from Yu et al. (2022) [1]_. 

66 

67 .. versionadded:: 0.16.0 

68 

69 Parameters 

70 ---------- 

71 thickness : float 

72 Ice thickness, in m. 

73 gravity : float 

74 Acceleration of gravity, in m s**-2. 

75 angular_frequencies : np.ndarray 

76 Angular frequencies, in rad s**-1. 

77 

78 Returns 

79 ------- 

80 np.ndarray 

81 Amplitude attenuation rates, in m**-1. 

82 

83 Notes 

84 ----- 

85 The attenuation is defined as: 

86 

87 .. math:: 

88 

89 \alpha_j h = 0.108 {(\omega\sqrt{\frac{h}{g}})}^4.46 

90 

91 where the prefactor and exponents were obtained by a best fit to 

92 available data [1]_. 

93 

94 References 

95 ---------- 

96 .. [1] Yu, J., W. E. Rogers, and D. W. Wang (2022). A new method for 

97 parameterization of wave dissipation by sea ice. Cold Regions Science and 

98 Technology 199, p. 103582. 

99 DOI: https://doi.org/10.1016/j.coldregions.2022.103582. 

100 

101 """ 

102 prefactor, exponent = 0.108, 4.46 

103 return ( 

104 prefactor 

105 * angular_frequencies**exponent 

106 * thickness ** (exponent / 2 - 1) 

107 / gravity ** (exponent / 2) 

108 ) 

109 

110 

111class AttenuationParameterisation(enum.Enum): 

112 NO = 0 

113 PARAM_01 = 1 

114 PARAM_YU_2022 = 20 

115 

116 

117@attrs.frozen 

118class AttenuationSpecification: 

119 function: typing.Callable 

120 args: str | None = None 

121 kwargs: dict[str, typing.Any] = attrs.field(factory=dict) 

122 

123 

124Attenuation: typing.TypeAlias = AttenuationParameterisation | AttenuationSpecification