Coverage for tests / tests_library / tests_model_components / test_active_law.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-09 16:40 +0100

1# SPDX-FileCopyrightText: Copyright INRIA 

2# 

3# SPDX-License-Identifier: LGPL-3.0-only 

4# 

5# Copyright INRIA 

6# 

7# This file is part of PhysioBlocks, a library mostly developed by the 

8# [Ananke project-team](https://team.inria.fr/ananke) at INRIA. 

9# 

10# Authors: 

11# - Colin Drieu 

12# - Dominique Chapelle 

13# - François Kimmig 

14# - Philippe Moireau 

15# 

16# PhysioBlocks is free software: you can redistribute it and/or modify it under the 

17# terms of the GNU Lesser General Public License as published by the Free Software 

18# Foundation, version 3 of the License. 

19# 

20# PhysioBlocks is distributed in the hope that it will be useful, but WITHOUT ANY 

21# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 

22# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 

23# 

24# You should have received a copy of the GNU Lesser General Public License along with 

25# PhysioBlocks. If not, see <https://www.gnu.org/licenses/>. 

26 

27import numpy as np 

28import pytest 

29 

30from physioblocks.computing.quantities import Quantity 

31from physioblocks.library.model_components.active_law import ( 

32 ActiveLawMacroscopicHuxleyTwoMoment, 

33) 

34from physioblocks.simulation.state import State 

35from physioblocks.simulation.time_manager import Time 

36from physioblocks.utils.gradient_test_utils import gradient_test_from_model 

37 

38 

39@pytest.fixture 

40def ref_block() -> ActiveLawMacroscopicHuxleyTwoMoment: 

41 return ActiveLawMacroscopicHuxleyTwoMoment( 

42 fib_deform=Quantity(0.1), 

43 active_tension_discr=Quantity(np.sqrt(10.0) * 2.5), 

44 active_stiffness=Quantity(10.0), 

45 active_energy_sqrt=Quantity(2.5), 

46 starling_abscissas=Quantity( 

47 np.array( 

48 [ 

49 -0.1668, 

50 -0.0073, 

51 0.0534, 

52 0.0969, 

53 0.1326, 

54 0.2016, 

55 0.4663, 

56 0.9187, 

57 1.1762, 

58 ] 

59 ) 

60 ), 

61 starling_ordinates=Quantity( 

62 np.array([0.0, 0.5614, 0.7748, 0.8933, 0.9618, 1.0, 1.0, 0.1075, 0.0]) 

63 ), 

64 activation=Quantity(35.0), 

65 destruction_rate=Quantity(10.0), 

66 crossbridge_stiffness=Quantity(100000.0), 

67 contractility=Quantity(50000.0), 

68 time=Time(0.0), 

69 ) 

70 

71 

72class TestActiveLawMacroscopicHuxleyTwoMoment: 

73 def test_check_gradient(self, ref_block: ActiveLawMacroscopicHuxleyTwoMoment): 

74 state = State() 

75 state["fib_deform"] = ref_block.fib_deform 

76 state["active_stiffness"] = ref_block.active_stiffness 

77 state["active_energy_sqrt"] = ref_block.active_energy_sqrt 

78 state["active_tension_discr"] = ref_block.active_tension_discr 

79 

80 ref_block.time.update(0.001) 

81 magnitudes = np.array([0.14, 10.4, 2.48, 12.3]) 

82 

83 assert gradient_test_from_model( 

84 ref_block, 

85 state, 

86 magnitudes, 

87 )