@@ -349,8 +349,26 @@ def test_previous_states_with_multiple_flows(self, basic_flow_system_linopy_coor
349349 + 1e-5 ,
350350 )
351351
352- def test_previous_states_with_multiple_flows_2 (self , basic_flow_system_linopy_coords , coords_config ):
353- """Test that flow model constraints are correctly generated."""
352+ @pytest .mark .parametrize (
353+ 'in1_previous_flow_rate, out1_previous_flow_rate, out2_previous_flow_rate, previous_on_hours' ,
354+ [
355+ (None , None , None , 0 ),
356+ (np .array ([0 , 1e-6 , 1e-4 , 5 ]), None , None , 2 ),
357+ (np .array ([0 , 5 , 0 , 5 ]), None , None , 1 ),
358+ (np .array ([0 , 5 , 0 , 0 ]), 3 , 0 , 1 ),
359+ (np .array ([0 , 0 , 2 , 0 , 4 , 5 ]), [3 , 4 , 5 ], None , 4 ),
360+ ],
361+ )
362+ def test_previous_states_with_multiple_flows_parameterized (
363+ self ,
364+ basic_flow_system_linopy_coords ,
365+ coords_config ,
366+ in1_previous_flow_rate ,
367+ out1_previous_flow_rate ,
368+ out2_previous_flow_rate ,
369+ previous_on_hours ,
370+ ):
371+ """Test that flow model constraints are correctly generated with different previous flow rates and constraint factors."""
354372 flow_system , coords_config = basic_flow_system_linopy_coords , coords_config
355373
356374 ub_out2 = np .linspace (1 , 1.5 , 10 ).round (2 )
@@ -360,19 +378,21 @@ def test_previous_states_with_multiple_flows_2(self, basic_flow_system_linopy_co
360378 'Fernwärme' ,
361379 relative_minimum = np .ones (10 ) * 0.1 ,
362380 size = 100 ,
363- previous_flow_rate = np . array ([ 0 , 0 , 1e-6 , 1e-5 , 1e-4 , 3 , 4 ]) ,
381+ previous_flow_rate = in1_previous_flow_rate ,
364382 on_off_parameters = fx .OnOffParameters (consecutive_on_hours_min = 3 ),
365383 ),
366384 ]
367385 outputs = [
368- fx .Flow ('Out1' , 'Gas' , relative_minimum = np .ones (10 ) * 0.2 , size = 200 , previous_flow_rate = [3 , 4 , 5 ]),
386+ fx .Flow (
387+ 'Out1' , 'Gas' , relative_minimum = np .ones (10 ) * 0.2 , size = 200 , previous_flow_rate = out1_previous_flow_rate
388+ ),
369389 fx .Flow (
370390 'Out2' ,
371391 'Gas' ,
372392 relative_minimum = np .ones (10 ) * 0.3 ,
373393 relative_maximum = ub_out2 ,
374394 size = 300 ,
375- previous_flow_rate = 20 ,
395+ previous_flow_rate = out2_previous_flow_rate ,
376396 ),
377397 ]
378398 comp = flixopt .elements .Component (
@@ -387,7 +407,7 @@ def test_previous_states_with_multiple_flows_2(self, basic_flow_system_linopy_co
387407 assert_conequal (
388408 comp .submodel .constraints ['TestComponent|consecutive_on_hours|initial' ],
389409 comp .submodel .variables ['TestComponent|consecutive_on_hours' ].isel (time = 0 )
390- == comp .submodel .variables ['TestComponent|on' ].isel (time = 0 ) * 5 ,
410+ == comp .submodel .variables ['TestComponent|on' ].isel (time = 0 ) * ( previous_on_hours + 1 ) ,
391411 )
392412
393413
0 commit comments