def test_config_option(self): """ Test single and multiple config_option passed to `andes.run`. """ path = andes.get_case("5bus/pjm5bus.json") self.assertRaises(ValueError, andes.load, path, config_option={"TDS = 1"}) self.assertRaises(ValueError, andes.load, path, config_option={"System.TDS.any = 1"}) self.assertRaises(ValueError, andes.load, path, config_option={"TDS.tf == 1"}) ss = andes.load(path, config_option={"PQ.pq2z = 0"}, default_config=True) self.assertEqual(ss.PQ.config.pq2z, 0) ss = andes.load(path, config_option={"PQ.pq2z=0"}, default_config=True) self.assertEqual(ss.PQ.config.pq2z, 0) ss = andes.load(path, config_option=["PQ.pq2z=0", "TDS.tf = 1"], default_config=True) self.assertEqual(ss.PQ.config.pq2z, 0) self.assertEqual(ss.TDS.config.tf, 1)
def test_save_load_ss(self): """ Test loading a snapshot and continuing the simulation """ # --- save a snapshot --- ss = andes.run(andes.get_case("kundur/kundur_full.xlsx"), no_output=True, default_config=True, # remove if outside tests ) ss.TDS.config.tf = 2.0 ss.TDS.run() path = save_ss('kundur_full_2s.pkl', ss) # --- load a snapshot --- ss = load_ss(path) # set a new simulation end time ss.TDS.config.tf = 3.0 ss.TDS.run() np.testing.assert_almost_equal(ss.GENROU.omega.v, np.array([1.00549119, 1.00529052, 1.00426882, 1.0039297])) os.remove(path)
class TestTDSResume(unittest.TestCase): def test_tds_resume(self): case = andes.get_case('kundur/kundur_full.xlsx') ss = andes.run(case, routine='tds', tf=0.1, no_output=True, default_config=True) ss.TDS.config.tf = 0.5 ss.TDS.run() self.assertEqual(ss.exit_code, 0.0) # check if time stamps are correctly stored self.assertIn(0.1, ss.dae.ts._ys) self.assertIn(0.5, ss.dae.ts._ys) # check if values are correctly stored self.assertTrue(len(ss.dae.ts._ys[0.1]) > 0) self.assertTrue(len(ss.dae.ts._ys[0.5]) > 0) # check if `get_data` works data1 = ss.dae.ts.get_data((ss.GENROU.omega, ss.GENROU.v)) data2 = ss.dae.ts.get_data((ss.GENROU.omega, ss.GENROU.v), a=[2]) nt = len(ss.dae.ts.t) self.assertEqual(data1.shape[1], 8) self.assertEqual(data1.shape[0], nt) self.assertEqual(data2.shape[1], 2) self.assertEqual(data2.shape[0], nt)
def setUp(self): self.ss = andes.run( andes.get_case("ieee14/ieee14_pvd1.xlsx"), default_config=True, no_output=True, ) self.ss.config.warn_limits = 0 self.ss.config.warn_abnormal = 0
def test_relative_path(self): ss = andes.run( 'ieee14.raw', input_path=andes.get_case('ieee14/', check=False), no_output=True, default_config=True, ) self.assertNotEqual(ss, None)
def test_backref_ieee14(self): ss = andes.load(andes.get_case("ieee14/ieee14_gentrip.xlsx")) self.assertSequenceEqual(ss.Area.Bus.v[0], [1, 2, 3, 4, 5]) self.assertSequenceEqual(ss.Area.Bus.v[1], [6, 7, 8, 9, 10, 11, 12, 13, 14]) self.assertSequenceEqual(ss.StaticGen.SynGen.v[0], ['GENROU_2']) self.assertSequenceEqual(ss.SynGen.TurbineGov.v[0], ['TGOV1_1'])
def test_addfile_path(self): ieee14 = andes.get_case("ieee14/ieee14.raw") path, case = os.path.split(ieee14) andes.load('ieee14.raw', addfile='ieee14.dyr', input_path=path) andes.run('ieee14.raw', addfile='ieee14.dyr', input_path=path, no_output=True)
class TestTDSResume(unittest.TestCase): def test_tds_resume(self): case = andes.get_case('kundur/kundur_full.xlsx') ss = andes.run(case, routine='tds', tf=0.1, no_output=True, default_config=True) ss.TDS.config.tf = 0.5 ss.TDS.run() self.assertEqual(ss.exit_code, 0.0)
def test_PLBVFU1(self): """ Test PLVBFU1 model. """ ss = andes.run( andes.get_case("ieee14/ieee14_plbvfu1.xlsx"), default_config=True, no_output=True, ) ss.TDS.config.tf = 3.0 ss.TDS.run() self.assertEqual(ss.exit_code, 0)
def test_output_xyname(self): """ Test x_name and y_name for Output """ ss = andes.load(andes.get_case("5bus/pjm5bus.json"), no_output=True, setup=False, default_config=True) ss.add("Output", {"model": "GENCLS", "varname": "omega"}) ss.add("Output", {"model": "GENCLS", "varname": "delta", "dev": 2}) ss.add("Output", {"model": "Bus"}) ss.setup() ss.PFlow.run() ss.TDS.config.tf = 0.1 ss.TDS.run() ss.TDS.load_plotter() nt = len(ss.dae.ts.t) nx = 5 ny = 10 self.assertEqual(len(ss.dae.x_name_output), nx) self.assertEqual(len(ss.dae.y_name_output), ny) self.assertEqual(ss.dae.ts.x.shape[1], nx) self.assertEqual(ss.dae.ts.y.shape[1], ny) np.testing.assert_array_equal(ss.Output.xidx, [1, 4, 5, 6, 7]) np.testing.assert_array_equal(ss.Output.yidx, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) # test loaded data by plot self.assertEqual(ss.TDS.plt._data.shape, (nt, nx + ny + 1)) np.testing.assert_array_equal( ss.TDS.plt._process_yidx(ss.GENCLS.omega, a=None), [2, 3, 4, 5]) np.testing.assert_array_equal( ss.TDS.plt._process_yidx(ss.GENCLS.delta, a=None), [1]) np.testing.assert_array_equal( ss.TDS.plt._process_yidx(ss.TG2.pout, a=None), [])
def setUp(self) -> None: self.kundur = 'kundur/' self.matpower = 'matpower/' self.ieee14 = andes.get_case("ieee14/ieee14.raw")
def setUp(self): self.ss = andes.run( andes.get_case("ieee14/ieee14_linetrip.xlsx"), no_output=True, default_config=True, )
def setUp(self): self.ss = andes.run( andes.get_case("kundur/kundur_full.json"), default_config=True, no_output=True, )