Coverage for tests/test_diagnosis.py: 0%
36 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-09-11 16:23 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-09-11 16:23 +0200
1import typing
3import numpy as np
4import pytest
6from swiift.model import frac_handlers
7from swiift.model.model import WavesUnderFloe
8from tests.helpers import growth_params_bool, make_growth_params, setup_wuf, wave_params
10strain_handlers = (
11 frac_handlers.BinaryStrainFracture,
12 frac_handlers.MultipleStrainFracture,
13)
14resolutions = 0.21, 0.03, 1, 1.14, 5
15coefs_nd = 1, 2, 4, 6
18@typing.overload
19def boiler_plate(
20 growth_params_bool: typing.Literal[True],
21 resolution: float,
22 wave_params: tuple[np.ndarray, np.ndarray],
23 fracture_handler: frac_handlers.BinaryFracture,
24) -> tuple[frac_handlers._FractureDiag, WavesUnderFloe, tuple]: ...
27@typing.overload
28def boiler_plate(
29 growth_params_bool: None,
30 resolution: float,
31 wave_params: tuple[np.ndarray, np.ndarray],
32 fracture_handler: frac_handlers.BinaryFracture,
33) -> tuple[frac_handlers._FractureDiag, WavesUnderFloe, None]: ...
36@typing.overload
37def boiler_plate(
38 growth_params_bool: typing.Literal[True],
39 resolution: float,
40 wave_params: tuple[np.ndarray, np.ndarray],
41 fracture_handler: frac_handlers._StrainFracture,
42) -> tuple[frac_handlers._StrainDiag, WavesUnderFloe, tuple]: ...
45@typing.overload
46def boiler_plate(
47 growth_params_bool: None,
48 resolution: float,
49 wave_params: tuple[np.ndarray, np.ndarray],
50 fracture_handler: frac_handlers._StrainFracture,
51) -> tuple[frac_handlers._StrainDiag, WavesUnderFloe, None]: ...
54def boiler_plate(growth_params_bool, resolution, wave_params, fracture_handler):
55 growth_params = make_growth_params(growth_params_bool, wave_params)
56 wuf = setup_wuf(wave_params)
57 diag = fracture_handler.diagnose(wuf, resolution, growth_params)
58 return diag, wuf, growth_params
61@pytest.mark.slow
62@pytest.mark.parametrize("coef_nd", coefs_nd)
63@pytest.mark.parametrize("wave_params", wave_params)
64@pytest.mark.parametrize("growth_params_bool", growth_params_bool)
65@pytest.mark.parametrize("resolution", resolutions)
66def test_energy(coef_nd, wave_params, growth_params_bool, resolution):
67 diag, wuf, growth_params = boiler_plate(
68 growth_params_bool,
69 resolution,
70 wave_params,
71 frac_handlers.BinaryFracture(coef_nd),
72 )
73 # for energy diagnostics, the bounds of the plate are excluded, so x[0] := Delta x
74 assert diag.x[0] <= resolution
75 assert diag.energy.shape == (diag.x.size, 2)
76 assert hasattr(diag, "initial_energy") and diag.initial_energy == wuf.energy(
77 growth_params
78 )
79 assert (
80 hasattr(diag, "frac_energy_rate")
81 and diag.frac_energy_rate == wuf.wui.ice.frac_energy_rate
82 )
85@pytest.mark.parametrize("handler", strain_handlers)
86@pytest.mark.parametrize("coef_nd", coefs_nd)
87@pytest.mark.parametrize("wave_params", wave_params)
88@pytest.mark.parametrize("growth_params_bool", growth_params_bool)
89@pytest.mark.parametrize("resolution", resolutions)
90def test_strain(handler, coef_nd, wave_params, growth_params_bool, resolution):
91 diag, wuf, _ = boiler_plate(
92 growth_params_bool,
93 resolution,
94 wave_params,
95 handler(coef_nd),
96 )
97 # for strain diagnostics, the bounds of the plate are included, so x[1] := Delta x
98 assert diag.x[1] <= resolution
99 assert diag.strain.shape == diag.x.shape
100 assert hasattr(diag, "peaks")
101 assert (
102 hasattr(diag, "strain_extrema")
103 and diag.peaks.shape == diag.strain_extrema.shape
104 )