Coverage for tests/test_fracture_handlers.py: 100%

1 import numpy as np

2 import pathlib

3 import pytest

4

5

6 from flexfrac1d.model.model import Ice, Ocean, DiscreteSpectrum, Floe, Domain

7 import flexfrac1d.model.frac_handlers as fh

8

9 PATH_BIN_EGY = pathlib.Path("tests/target/fracture")

10

11

12 def make_wuf(array, growth_params):

13 (

14 frac_toughness,

15 strain_threshold,

16 thickness,

17 youngs_modulus,

18 depth,

19 gravity,

20 amplitude,

21 frequency,

22 length,

23 left_edge,

24 phase,

25 ) = array

26

27 ice = Ice(

28 frac_toughness=frac_toughness,

29 strain_threshold=strain_threshold,

30 thickness=thickness,

31 youngs_modulus=youngs_modulus,

32 )

33 ocean = Ocean(depth=depth)

34 spectrum = DiscreteSpectrum(

35 amplitudes=amplitude, frequencies=frequency, phases=phase

36 )

37 domain = Domain.from_discrete(gravity, spectrum, ocean, growth_params)

38 floe = Floe(left_edge=left_edge, length=length, ice=ice)

39 domain.add_floes(floe)

40 return domain.subdomains[0]

41

42

43@pytest.mark.slow

44 def test_binary_energy_no_growth():

45 growth_params = None

46 an_sol = True

47 binary_handler = fh.BinaryFracture()

48 target = np.loadtxt(PATH_BIN_EGY.joinpath("binary_fracture.ssv"))

49

50 for row in target:

51 wuf = make_wuf(row[:-1], growth_params)

52 xf = binary_handler.search(wuf, growth_params, an_sol, None)

53 if xf is not None:

54 assert np.allclose(row[-1] - xf, 0)

55 else:

56 assert np.isnan(row[-1])

57

58

59 def test_binary_strain_no_growth():

60 growth_params = None

61 an_sol = True

62 binary_handler = fh.BinaryStrainFracture()

63 target = np.loadtxt(PATH_BIN_EGY.joinpath("binary_strain_fracture.ssv"))

64

65 for row in target:

66 wuf = make_wuf(row[:-1], growth_params)

67 xf = binary_handler.search(wuf, growth_params, an_sol, None)

68 if xf is not None:

69 assert np.allclose(row[-1] - xf, 0)

70 else:

71 assert np.isnan(row[-1])