From 668d91eb403ce208e30ed38c3ed6e90043c1f90e Mon Sep 17 00:00:00 2001 From: Angela Zhao Date: Wed, 9 Apr 2025 14:06:42 -0400 Subject: [PATCH 1/4] misc fixes --- pygridsim/core.py | 4 ++-- pygridsim/defaults.py | 6 +++--- pygridsim/lines.py | 3 +-- pygridsim/parameters.py | 2 +- sim.json | 10 ++++++++++ tests/test_circuit.py | 36 +++++++++++++++++++++++++++--------- 6 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 sim.json diff --git a/pygridsim/core.py b/pygridsim/core.py index ca6a488..418aa60 100644 --- a/pygridsim/core.py +++ b/pygridsim/core.py @@ -71,7 +71,7 @@ def update_source(self, source_type: str = "turbine", params: dict[str, int] = N params = params or dict() return _make_source_node(params, source_type) - def add_PVSystem(self, load_nodes: list[str], params: dict[str, int] = None, num_panels: int = 1): + def add_PVSystems(self, load_nodes: list[str], params: dict[str, int] = None, num_panels: int = 1): """Adds a photovoltaic (PV) system to the specified load nodes. Adds PV system with num_panels to each of the listed load nodes. Can be customized with parameters. @@ -99,7 +99,7 @@ def add_PVSystem(self, load_nodes: list[str], params: dict[str, int] = None, num return PV_nodes - def add_generator(self, num: int = 1, gen_type: str = "small", params: dict[str, int] = None): + def add_generators(self, num: int = 1, gen_type: str = "small", params: dict[str, int] = None): """Adds generator(s) to the system. Args: diff --git a/pygridsim/defaults.py b/pygridsim/defaults.py index 7a67a33..0f75b05 100644 --- a/pygridsim/defaults.py +++ b/pygridsim/defaults.py @@ -22,9 +22,9 @@ COMMERCIAL_KW = [10, 50] COMMERCIAL_KVAR = [5, 10] -INDUSTRIAL_KV = [.24, .48] -INDUSTRIAL_KW = [30, 100] -INDUSTRIAL_KVAR = [20, 25] +INDUSTRIAL_KV = [4.16, 34.5] +INDUSTRIAL_KW = [200, 10000] +INDUSTRIAL_KVAR = [150, 480] """ Source Nodes (including other form of sources, like PVSystem) diff --git a/pygridsim/lines.py b/pygridsim/lines.py index f7ac3a8..88e1d10 100644 --- a/pygridsim/lines.py +++ b/pygridsim/lines.py @@ -38,8 +38,7 @@ def _make_line(src, dst, line_type, count, params = {}, transformer = True): transformer.Windings = defaults.NUM_WINDINGS transformer.XHL = _get_param(params, "XHL", defaults.XHL) transformer.Buses = [src, dst] - transformer.Conns = _get_param(params, "Conns", [defaults.PRIMARY_CONN, defaults.SECONDARY_CONN]) - + transformer.Conns = [defaults.PRIMARY_CONN, defaults.SECONDARY_CONN] transformer.kVs = [_get_kv(src), _get_kv(dst)] transformer.end_edit() diff --git a/pygridsim/parameters.py b/pygridsim/parameters.py index 0904af3..c65e291 100644 --- a/pygridsim/parameters.py +++ b/pygridsim/parameters.py @@ -88,4 +88,4 @@ def _make_generator(params, gen_type, count): generator.Phases = _get_param(params, "phases", defaults.PHASES) for attr in ["kV", "kW"]: gen_type_param = GENERATOR_CONFIGURATIONS[gen_type_obj][attr] - setattr(generator, attr, _get_param(params, attr, _random_param(gen_type_param))) \ No newline at end of file + setattr(generator, attr, _get_param(params, attr, _random_param(gen_type_param))) diff --git a/sim.json b/sim.json new file mode 100644 index 0000000..52ca397 --- /dev/null +++ b/sim.json @@ -0,0 +1,10 @@ +{ + "Voltages": { + "source": 1086.5694813600999, + "load0": 187.13447522128487 + }, + "Losses": { + "Active Power Loss": 62520.07562712451, + "Reactive Power Loss": 129976.52141894132 + } +} \ No newline at end of file diff --git a/tests/test_circuit.py b/tests/test_circuit.py index fa27276..9d17a1d 100644 --- a/tests/test_circuit.py +++ b/tests/test_circuit.py @@ -100,7 +100,7 @@ def test_008_PVsystem(self): circuit = PyGridSim() circuit.update_source() circuit.add_load_nodes(num=2) - circuit.add_PVSystem(load_nodes=["load0", "load1"], num_panels=5) + circuit.add_PVSystems(load_nodes=["load0", "load1"], num_panels=5) circuit.add_lines([("source", "load0")]) circuit.solve() print(circuit.results(["Voltages", "Losses"])) @@ -109,7 +109,7 @@ def test_009_generator(self): circuit = PyGridSim() circuit.update_source() circuit.add_load_nodes() - circuit.add_generator(num=3, gen_type="small") + circuit.add_generators(num=3, gen_type="small") circuit.add_lines([("source", "load0"), ("generator0", "load0")]) circuit.solve() print(circuit.results(["Voltages", "Losses"])) @@ -118,10 +118,10 @@ def test_010_many_sources(self): circuit = PyGridSim() circuit.update_source(source_type="powerplant") circuit.add_load_nodes(num=3) - circuit.add_PVSystem(load_nodes=["load1", "load2"], num_panels=10) - circuit.add_generator(num=3, gen_type="small") + circuit.add_PVSystems(load_nodes=["load1", "load2"], num_panels=10) + circuit.add_generators(num=3, gen_type="small") circuit.update_source(source_type="turbine") # change to a turbine source midway - circuit.add_generator(num=4, gen_type="large") + circuit.add_generators(num=4, gen_type="large") circuit.add_lines([("source", "load0"), ("generator0", "load0"), ("generator5", "source")]) circuit.solve() print(circuit.results(["Voltages", "Losses"])) @@ -149,10 +149,10 @@ def test_011_configs(self): # GENERATOR CONFIG # works, because not case sensitive - circuit.add_generator(num=3, gen_type="SMALl") + circuit.add_generators(num=3, gen_type="SMALl") # don't want linetype input, just string with self.assertRaises(Exception): - circuit.add_generator(num=3, gen_type=GeneratorType.SMALL) + circuit.add_generators(num=3, gen_type=GeneratorType.SMALL) # SOURCE CONFIG # works, because not case sensitive @@ -211,9 +211,9 @@ def test_101_bad_parameter(self): # add load nodes so we can test pv system erroring circuit.add_load_nodes(num=2, params={"kV": 10, "kW": 20, "kvar":1}) with self.assertRaises(KeyError): - circuit.add_generator(num=4, params={"badParam": 100}) + circuit.add_generators(num=4, params={"badParam": 100}) with self.assertRaises(KeyError): - circuit.add_PVSystem(load_nodes=["load0"], params={"badParam": 100}, num_panels=4) + circuit.add_PVSystems(load_nodes=["load0"], params={"badParam": 100}, num_panels=4) def test_102_negative_inputs(self): """ @@ -245,6 +245,24 @@ def test_104_non_int_parameters(self): with self.assertRaises(TypeError): circuit.add_load_nodes(params={"kV": "stringInput"}) + def test_105_alt_source_parameters(self): + circuit = PyGridSim() + circuit.add_load_nodes(num=5) + circuit.add_generators(params={"kV": 50, "kW": 100}) + circuit.add_PVSystems(load_nodes=["load0", "load1"], num_panels=5, params={"kV": 0.1}) + circuit.solve() + print(circuit.results(["Voltages", "Losses"])) + circuit.clear() + + def test_106_transformer_parameters(self): + circuit = PyGridSim() + circuit.add_load_nodes(num=5) + circuit.update_source() + circuit.add_lines([("source", "load0")], params={"length": 20, "XHL": 5}) + circuit.solve() + print(circuit.results(["Voltages", "Losses"])) + circuit.clear() + class TestLargeCircuit(unittest.TestCase): """ From 532c98fb2f6916f1cdc4e640a02a71895d3e6284 Mon Sep 17 00:00:00 2001 From: Angela Zhao Date: Wed, 9 Apr 2025 14:07:27 -0400 Subject: [PATCH 2/4] remove unnecssary file --- sim.json | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 sim.json diff --git a/sim.json b/sim.json deleted file mode 100644 index 52ca397..0000000 --- a/sim.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Voltages": { - "source": 1086.5694813600999, - "load0": 187.13447522128487 - }, - "Losses": { - "Active Power Loss": 62520.07562712451, - "Reactive Power Loss": 129976.52141894132 - } -} \ No newline at end of file From fcbc3e9e8273a38708fc2e14a15c549c6be6dc1b Mon Sep 17 00:00:00 2001 From: Angela Zhao Date: Thu, 10 Apr 2025 10:23:56 -0400 Subject: [PATCH 3/4] make export test non customized so sim.json doesn't continue to change each test run --- tests/test_circuit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_circuit.py b/tests/test_circuit.py index 1224963..b70bd22 100644 --- a/tests/test_circuit.py +++ b/tests/test_circuit.py @@ -89,9 +89,9 @@ def test_006_update_multiple_source(self): def test_007_export(self): circuit = PyGridSim() - circuit.update_source() - circuit.add_load_nodes() - circuit.add_lines([("source", "load0")]) + circuit.update_source(params={"kV": 10}) + circuit.add_load_nodes(params={"kV": 5, "kW": 10, "kvar": 2}) + circuit.add_lines([("source", "load0")], params={"length": 2}) circuit.solve() print(circuit.results(["Voltages", "Losses"], export_path="sim.json")) From 4b80a845ad0bdae312518d325843b68fddb04ff0 Mon Sep 17 00:00:00 2001 From: Angela Zhao Date: Thu, 10 Apr 2025 10:24:36 -0400 Subject: [PATCH 4/4] remove extraneous test class --- tests/test_circuit.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/test_circuit.py b/tests/test_circuit.py index b70bd22..f67c00a 100644 --- a/tests/test_circuit.py +++ b/tests/test_circuit.py @@ -261,16 +261,3 @@ def test_106_transformer_parameters(self): circuit.solve() print(circuit.results(["Voltages", "Losses"])) circuit.clear() - - -class TestLargeCircuit(unittest.TestCase): - """ - Test very large circuit (i.e. to the size of a neighborhood) - """ - - def setUp(self): - """Set up test fixtures, if any.""" - print("\nTest", self._testMethodName) - - def tearDown(self): - """Tear down test fixtures, if any."""