Coverage for tests / tests_library / tests_blocks / test_valves.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.blocks.valves import ValveRLBlock 

32from physioblocks.simulation.state import State 

33from physioblocks.simulation.time_manager import Time 

34from physioblocks.utils.gradient_test_utils import gradient_test_from_model 

35 

36 

37@pytest.fixture 

38def ref_block() -> ValveRLBlock: 

39 block = ValveRLBlock( 

40 flux=Quantity(0.0011), 

41 pressure_1=Quantity(5002), 

42 pressure_2=Quantity(5003), 

43 conductance=Quantity(1.1e-6), 

44 backward_conductance=Quantity(1.2e-15), 

45 inductance=Quantity(3.1e3), 

46 scheme_ts_flux=Quantity(0.15), 

47 time=Time(0.0), 

48 ) 

49 block.time.update(0.001) 

50 

51 return block 

52 

53 

54@pytest.fixture 

55def state(ref_block: ValveRLBlock): 

56 state = State() 

57 state["pressure_1"] = ref_block.pressure_1 

58 state["pressure_2"] = ref_block.pressure_2 

59 state["flux"] = ref_block.flux 

60 return state 

61 

62 

63@pytest.fixture 

64def magnitudes(): 

65 return np.array([1e5, 1e5, 1e-3]) 

66 

67 

68class TestValveRLBlock: 

69 def test_check_gradient(self, ref_block: ValveRLBlock, state: State, magnitudes): 

70 assert gradient_test_from_model(ref_block, state, magnitudes) 

71 

72 def test_check_gradient_flux_neg(self, ref_block: ValveRLBlock, state, magnitudes): 

73 ref_block.flux.initialize(-0.0011) 

74 assert gradient_test_from_model(ref_block, state, magnitudes)