Coverage for test/unit/elements/aggregation/test_underfloorheating.py: 99%

82 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-12 17:09 +0000

1import math 

2import unittest 

3 

4import numpy as np 

5 

6import bim2sim.elements.aggregation.hvac_aggregations 

7from bim2sim.elements import aggregation 

8from bim2sim.elements import hvac_elements as hvac 

9from bim2sim.elements.graphs.hvac_graph import HvacGraph 

10from bim2sim.elements.mapping.units import ureg 

11from test.unit.elements.helper import SetupHelperHVAC 

12 

13 

14class UFHHelper(SetupHelperHVAC): 

15 

16 def get_setup_ufh1(self): 

17 """ 

18 Simple underfloorheating 

19 """ 

20 flags = {} 

21 

22 x_dimension = 5 * ureg.meter 

23 y_dimension = 4 * ureg.meter 

24 spacing = 0.19 * ureg.meter 

25 with self.flag_manager(flags): 

26 # elements generator 

27 ny_pipes = math.floor(y_dimension / spacing) 

28 y_pipes = [self.element_generator( 

29 hvac.Pipe, length=y_dimension / ny_pipes, diameter=15) for 

30 i in range(ny_pipes)] 

31 x_pipes = [self.element_generator( 

32 hvac.Pipe, length=x_dimension, diameter=15) for 

33 i in range(ny_pipes + 1)] 

34 # connect 

35 ufh_strand = self.connect_ufh(x_pipes, y_pipes, x_dimension, spacing) 

36 

37 # full system 

38 gen_circuit = [ 

39 *ufh_strand 

40 ] 

41 flags['connect'] = [ufh_strand[0], ufh_strand[-1]] 

42 graph = HvacGraph(gen_circuit) 

43 return graph, flags 

44 

45 @classmethod 

46 def connect_ufh(cls, x_pipes, y_pipes, x_dimension, spacing): 

47 """ 

48 Function to connect an UFH taking into account the number of pipes 

49 laid in x and y, the pipes spacing and the room dimension in x 

50 Args: 

51 x_pipes: UFH Pipes laid parallel to x-axis 

52 y_pipes: UFH Pipes laid parallel to y-axis 

53 x_dimension: Dimension of the room parallel to x-axis 

54 spacing: spacing of the UFH parallel to y-axis 

55 

56 Returns: 

57 ufh_strand: resultant connected ufh strand 

58 

59 """ 

60 position = np.array([0.0, 0.0, 0.0]) 

61 n = 0 

62 for item in x_pipes: 

63 item.position = position.copy() 

64 port_position = position.copy() 

65 if n % 2: 

66 port_position[0] += x_dimension.m / 2 

67 item.ports[0].position = port_position.copy() 

68 port_position[0] -= x_dimension.m 

69 item.ports[1].position = port_position.copy() 

70 else: 

71 port_position[0] -= x_dimension.m / 2 

72 item.ports[0].position = port_position.copy() 

73 port_position[0] += x_dimension.m 

74 item.ports[1].position = port_position.copy() 

75 position[1] += spacing.m 

76 n += 1 

77 position = np.array([x_dimension.m / 2, spacing.m / 2, 0.0]) 

78 n = 0 

79 for item in y_pipes: 

80 port_position = position.copy() 

81 item.position = position.copy() 

82 port_position[1] -= spacing.m / 2 

83 item.ports[0].position = port_position.copy() 

84 port_position[1] += spacing.m 

85 item.ports[1].position = port_position.copy() 

86 position[1] += spacing.m 

87 if n % 2: 

88 position[0] += x_dimension.m 

89 else: 

90 position[0] -= x_dimension.m 

91 n += 1 

92 ufh_strand = [None] * (len(x_pipes) + len(y_pipes)) 

93 ufh_strand[::2] = x_pipes 

94 ufh_strand[1::2] = y_pipes 

95 cls.connect_strait(ufh_strand) 

96 return ufh_strand 

97 

98 

99class TestUnderfloorHeating(unittest.TestCase): 

100 

101 helper = None 

102 

103 @classmethod 

104 def setUpClass(cls): 

105 cls.helper = UFHHelper() 

106 

107 def tearDown(self) -> None: 

108 self.helper.reset() 

109 

110 def test_simple_ufh(self): 

111 """ Test aggregation of underfloor heating no. 1.""" 

112 graph, flags = self.helper.get_setup_ufh1() 

113 ele = graph.elements 

114 

115 matches, meta = bim2sim.elements.aggregation.hvac_aggregations.UnderfloorHeating.find_matches(graph) 

116 self.assertEqual(1, len(matches)) 

117 agg = bim2sim.elements.aggregation.hvac_aggregations.UnderfloorHeating(graph, matches[0], **meta[0]) 

118 

119 exp_length = sum([e.length for e in ele]) 

120 self.assertAlmostEqual(exp_length, agg.length) 

121 self.assertAlmostEqual(20 * ureg.meter ** 2, agg.heating_area, 0) 

122 self.assertAlmostEqual(15 * ureg.millimeter, agg.diameter, 0) 

123 self.assertAlmostEqual(.2 * ureg.meter, agg.y_spacing, 1) 

124 self.assertAlmostEqual(.24 * ureg.meter, agg.x_spacing, 2) 

125 

126 

127if __name__ == '__main__': 

128 unittest.main()