@@ -315,32 +315,43 @@ def test_simulate_inputs(self):
315315 model_file .write_text ("""
316316model M_input
317317 Real x(start=0, fixed=true);
318- input Real u;
318+ input Real u1;
319+ input Real u2;
319320 output Real y;
320321equation
321- der(x) = u ;
322+ der(x) = u1 + u2 ;
322323 y = x;
323324end M_input;
324325""" )
325326 mod = OMPython .ModelicaSystem (model_file .as_posix (), "M_input" , raiseerrors = True )
326327
327328 mod .setSimulationOptions ("stopTime=1.0" )
328329
330+ # integrate zero (no setInputs call) - it should default to None -> 0
331+ assert mod .getInputs () == {
332+ "u1" : None ,
333+ "u2" : None ,
334+ }
335+ mod .simulate ()
336+ y = mod .getSolutions ("y" )[0 ]
337+ assert np .isclose (y [- 1 ], 0.0 )
338+
329339 # integrate a constant
330- mod .setInputs ("u =2.5" )
340+ mod .setInputs ("u1 =2.5" )
331341 assert mod .getInputs () == {
332- "u " : [
342+ "u1 " : [
333343 (0.0 , 2.5 ),
334344 (1.0 , 2.5 ),
335345 ],
346+ "u2" : None ,
336347 }
337348 mod .simulate ()
338349 y = mod .getSolutions ("y" )[0 ]
339350 assert np .isclose (y [- 1 ], 2.5 )
340351
341352 # now let's integrate the sum of two ramps
342- mod .setInputs ("u =[(0.0, 0.0), (0.5, 2), (1.0, 0)]" )
343- assert mod .getInputs ("u " ) == [[
353+ mod .setInputs ("u1 =[(0.0, 0.0), (0.5, 2), (1.0, 0)]" )
354+ assert mod .getInputs ("u1 " ) == [[
344355 (0.0 , 0.0 ),
345356 (0.5 , 2.0 ),
346357 (1.0 , 0.0 ),
@@ -349,6 +360,26 @@ def test_simulate_inputs(self):
349360 y = mod .getSolutions ("y" )[0 ]
350361 assert np .isclose (y [- 1 ], 1.0 )
351362
363+ # let's try some edge cases
364+ mod .setInputs ("u1=[(-0.5, 0.0), (1.0, 1)]" )
365+ # unmatched startTime
366+ with self .assertRaises (OMPython .ModelicaSystemError ):
367+ mod .simulate ()
368+ # unmatched stopTime
369+ mod .setInputs ("u1=[(0.0, 0.0), (0.5, 1)]" )
370+ with self .assertRaises (OMPython .ModelicaSystemError ):
371+ mod .simulate ()
372+
373+ # Let's use both inputs, but each one with different number of of
374+ # samples. This has an effect when generating the csv file.
375+ mod .setInputs ([
376+ "u1=[(0.0, 0), (1.0, 1)]" ,
377+ "u2=[(0.0, 0), (0.25, 0.5), (0.5, 1.0), (1.0, 0)]" ,
378+ ])
379+ mod .simulate ()
380+ y = mod .getSolutions ("y" )[0 ]
381+ assert np .isclose (y [- 1 ], 1.0 )
382+
352383
353384if __name__ == '__main__' :
354385 unittest .main ()
0 commit comments