Coverage for tests/test_disp_relations.py: 100%

1 from hypothesis import given, settings

2 import numpy as np

3

4 from flexfrac1d.model.model import (

5 DiscreteSpectrum,

6 FreeSurfaceWaves,

7 Ice,

8 Ocean,

9 WavesUnderElasticPlate,

10)

11

12 from .conftest import coupled_ocean_ice, ocean_and_mono_spectrum, spec_mono

13

14

15 def free_surface(wavenumber, depth):

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

17

18

19 def elas_mass_surface(

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

21) -> np.ndarray:

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

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

24 dud = ocean.depth - draft

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

26

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

28

29

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

31# polychromatic DiscreteSpectrum objects are just collections

32# of independent Wave objects

33@given(**ocean_and_mono_spectrum)

34 def test_free_surface(ocean, spectrum, gravity):

35 angfreqs2 = spectrum._ang_freqs_pow2

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

37 x = free_surface(fsw.wavenumbers, ocean.depth)

38 y = angfreqs2 / gravity

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

40

41

42@given(**(coupled_ocean_ice | {"spec": spec_mono()}))

43@settings(max_examples=500)

44 def test_elas_mass_loading(

45 ocean: Ocean, spec: DiscreteSpectrum, ice: Ice, gravity: float

46):

47 assert ocean.density > ice.density

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

49 angfreqs2 = spec._ang_freqs_pow2

50 wui = WavesUnderElasticPlate.from_ocean(ice, ocean, spec, gravity)

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

52 y = angfreqs2 / gravity

53 assert np.allclose(x, y)