Coverage for tests/test_disp_relations.py: 0%

1 from hypothesis import given, settings

2 import numpy as np

3

4 from swiift.api.utils import (

5 compute_elastic_mass_loading_wavenumbers,

6 compute_free_surface_wavenumbers,

7)

8 from swiift.model.model import (

9 DiscreteSpectrum,

10 FloatingIce,

11 FreeSurfaceWaves,

12 Ice,

13 Ocean,

14 WavesUnderElasticPlate,

15)

16 from tests.model_strategies import coupled_ocean_ice, ocean_and_mono_spectrum, spec_mono

17

18

19 def _free_surface(wavenumber, depth):

20 # RHS of alpha = k*tanh(kH), avec alpha := omega**2 / g

21 return wavenumber * np.tanh(wavenumber * depth)

22

23

24 def elas_mass_surface(

25 wavenumbers: np.ndarray, ice: Ice, ocean: Ocean, gravity: float

26) -> np.ndarray:

27 l4 = ice.flex_rigidity / (ocean.density * gravity)

28 draft = ice.density / ocean.density * ice.thickness

29 dud = ocean.depth - draft

30 k_tanh_kdud = wavenumbers * np.tanh(wavenumbers * dud)

31

32 return (l4 * wavenumbers**4 + 1) / (1 + draft * k_tanh_kdud) * k_tanh_kdud

33

34

35# Use a monochromatic spectrum, which sould not be limiting as

36# polychromatic DiscreteSpectrum objects are just collections

37# of independent Wave objects

38@given(**ocean_and_mono_spectrum)

39 def test_free_surface(ocean, spectrum, gravity):

40 angfreqs2 = spectrum._ang_freqs_pow2

41 fsw = FreeSurfaceWaves.from_ocean(ocean, spectrum, gravity)

42 x = _free_surface(fsw.wavenumbers, ocean.depth)

43 y = angfreqs2 / gravity

44 assert np.allclose(x * ocean.depth, y * ocean.depth)

45

46

47@given(**ocean_and_mono_spectrum)

48 def test_free_surface_utils(ocean: Ocean, spectrum: DiscreteSpectrum, gravity: float):

49 wavenumbers = compute_free_surface_wavenumbers(ocean, spectrum, gravity)

50 x = _free_surface(wavenumbers, ocean.depth)

51 y = spectrum._ang_freqs_pow2 / gravity

52 assert np.allclose(x * ocean.depth, y * ocean.depth)

53

54

55@given(**(coupled_ocean_ice | {"spectrum": spec_mono()}))

56@settings(max_examples=500)

57 def test_elas_mass_loading(

58 ocean: Ocean, spectrum: DiscreteSpectrum, ice: Ice, gravity: float

59):

60 assert ocean.density > ice.density

61 assert ocean.depth - ice.density / ocean.density * ice.thickness > 0

62 angfreqs2 = spectrum._ang_freqs_pow2

63 wui = WavesUnderElasticPlate.from_ocean(ice, ocean, spectrum, gravity)

64 x = elas_mass_surface(wui.wavenumbers, ice, ocean, gravity)

65 y = angfreqs2 / gravity

66 assert np.allclose(x, y)

67

68

69@given(**(coupled_ocean_ice | {"spectrum": spec_mono()}))

70 def test_elas_mass_loading_utils(

71 ocean: Ocean, spectrum: DiscreteSpectrum, ice: Ice, gravity: float

72):

73 assert ocean.density > ice.density

74 assert ocean.depth - ice.density / ocean.density * ice.thickness > 0

75 floating_ice = FloatingIce.from_ice_ocean(ice, ocean, gravity)

76 wavenumbers = compute_elastic_mass_loading_wavenumbers(

77 floating_ice, spectrum, gravity

78 )

79 x = elas_mass_surface(wavenumbers, ice, ocean, gravity)

80 y = spectrum._ang_freqs_pow2 / gravity

81 assert np.allclose(x, y)