diff --git a/.gitignore b/.gitignore index d25d75e..a2a94b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Byte-compiled / optimized / DLL files __pycache__/ +sim.json *.py[cod] *$py.class diff --git a/pygridsim/core.py b/pygridsim/core.py index 7444482..780d393 100644 --- a/pygridsim/core.py +++ b/pygridsim/core.py @@ -81,10 +81,8 @@ 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. @@ -113,7 +111,7 @@ def add_PVSystem(self, 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 eb807e9..9af1219 100644 --- a/pygridsim/defaults.py +++ b/pygridsim/defaults.py @@ -23,9 +23,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 6fadf35..050a38d 100644 --- a/pygridsim/lines.py +++ b/pygridsim/lines.py @@ -41,9 +41,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/tests/test_circuit.py b/tests/test_circuit.py index 8460d5f..f67c00a 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")) @@ -99,7 +99,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"])) @@ -108,7 +108,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"])) @@ -117,10 +117,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.update_source(source_type="turbine") - circuit.add_generator(num=4, gen_type="large") + 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_generators(num=4, gen_type="large") circuit.add_lines([("source", "load0"), ("generator0", "load0"), ("generator5", "source")]) circuit.solve() print(circuit.results(["Voltages", "Losses"])) @@ -148,10 +148,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 @@ -210,9 +210,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): """ @@ -243,3 +243,21 @@ def test_104_non_int_parameters(self): circuit = PyGridSim() 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()