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

28 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.dynamics import ( 

32 SphericalDynamicsModelComponent, 

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() -> SphericalDynamicsModelComponent: 

41 return SphericalDynamicsModelComponent( 

42 disp=Quantity(0.00002), 

43 fib_deform=Quantity(0.000054), 

44 pressure=Quantity(10000.0), 

45 pressure_external=Quantity(123.4), 

46 vel=Quantity(1.1), 

47 radius=Quantity(0.03), 

48 vol_mass=Quantity(1000), 

49 thickness=Quantity(0.01), 

50 damping_coef=Quantity(70.0), 

51 series_stiffness=Quantity(1e8), 

52 hyperelastic_cst=Quantity(np.array([638.4135, 2.3724, 99.12522, 5.5326])), 

53 time=Time(0.0), 

54 ) 

55 

56 

57@pytest.fixture 

58def state(ref_block: SphericalDynamicsModelComponent): 

59 state = State() 

60 state["disp"] = ref_block.disp 

61 state["fib_deform"] = ref_block.fib_deform 

62 state["pressure"] = ref_block.pressure 

63 state["pressure_external"] = ref_block.pressure_external 

64 state["vel"] = ref_block.vel 

65 return state 

66 

67 

68@pytest.fixture 

69def magnitudes(): 

70 return np.array([0.013, 0.4, 1e5, 151.2, 1.1]) 

71 

72 

73class TestSphericalDynamicsModelComponent: 

74 def test_check_gradient_small_disp_diff(self, ref_block, state, magnitudes): 

75 assert gradient_test_from_model(ref_block, state, magnitudes) 

76 

77 def test_check_gradient_big_disp_diff(self, ref_block, state, magnitudes): 

78 magnitudes[0] = 1e-6 

79 assert gradient_test_from_model(ref_block, state, magnitudes)