Skip to content

Commit 50dd804

Browse files
authored
Merge pull request #6 from DAI-Lab/misc-corrections
Miscellaneous Corrections
2 parents 205b4b4 + 4b80a84 commit 50dd804

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Byte-compiled / optimized / DLL files
22
__pycache__/
3+
sim.json
34
*.py[cod]
45
*$py.class
56

pygridsim/core.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ def update_source(self, source_type: str = "turbine", params: dict[str, int] = N
8181
params = params or dict()
8282
return _make_source_node(params, source_type)
8383

84-
def add_PVSystem(self,
85-
load_nodes: list[str],
86-
params: dict[str, int] = None,
87-
num_panels: int = 1):
84+
def add_PVSystems(self, load_nodes: list[str],
85+
params: dict[str, int] = None, num_panels: int = 1):
8886
"""Adds a photovoltaic (PV) system to the specified load nodes.
8987
9088
Adds PV system with num_panels to each of the listed load nodes.
@@ -113,7 +111,7 @@ def add_PVSystem(self,
113111

114112
return PV_nodes
115113

116-
def add_generator(self, num: int = 1, gen_type: str = "small", params: dict[str, int] = None):
114+
def add_generators(self, num: int = 1, gen_type: str = "small", params: dict[str, int] = None):
117115
"""Adds generator(s) to the system.
118116
119117
Args:

pygridsim/defaults.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
COMMERCIAL_KW = [10, 50]
2424
COMMERCIAL_KVAR = [5, 10]
2525

26-
INDUSTRIAL_KV = [.24, .48]
27-
INDUSTRIAL_KW = [30, 100]
28-
INDUSTRIAL_KVAR = [20, 25]
26+
INDUSTRIAL_KV = [4.16, 34.5]
27+
INDUSTRIAL_KW = [200, 10000]
28+
INDUSTRIAL_KVAR = [150, 480]
2929

3030
"""
3131
Source Nodes (including other form of sources, like PVSystem)

pygridsim/lines.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def _make_line(src, dst, line_type, count, params={}, transformer=True):
4141
transformer.Windings = defaults.NUM_WINDINGS
4242
transformer.XHL = _get_param(params, "XHL", defaults.XHL)
4343
transformer.Buses = [src, dst]
44-
transformer.Conns = _get_param(params, "Conns",
45-
[defaults.PRIMARY_CONN, defaults.SECONDARY_CONN])
46-
44+
transformer.Conns = [defaults.PRIMARY_CONN, defaults.SECONDARY_CONN]
4745
transformer.kVs = [_get_kv(src), _get_kv(dst)]
4846

4947
transformer.end_edit()

tests/test_circuit.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ def test_006_update_multiple_source(self):
8989

9090
def test_007_export(self):
9191
circuit = PyGridSim()
92-
circuit.update_source()
93-
circuit.add_load_nodes()
94-
circuit.add_lines([("source", "load0")])
92+
circuit.update_source(params={"kV": 10})
93+
circuit.add_load_nodes(params={"kV": 5, "kW": 10, "kvar": 2})
94+
circuit.add_lines([("source", "load0")], params={"length": 2})
9595
circuit.solve()
9696
print(circuit.results(["Voltages", "Losses"], export_path="sim.json"))
9797

9898
def test_008_PVsystem(self):
9999
circuit = PyGridSim()
100100
circuit.update_source()
101101
circuit.add_load_nodes(num=2)
102-
circuit.add_PVSystem(load_nodes=["load0", "load1"], num_panels=5)
102+
circuit.add_PVSystems(load_nodes=["load0", "load1"], num_panels=5)
103103
circuit.add_lines([("source", "load0")])
104104
circuit.solve()
105105
print(circuit.results(["Voltages", "Losses"]))
@@ -108,7 +108,7 @@ def test_009_generator(self):
108108
circuit = PyGridSim()
109109
circuit.update_source()
110110
circuit.add_load_nodes()
111-
circuit.add_generator(num=3, gen_type="small")
111+
circuit.add_generators(num=3, gen_type="small")
112112
circuit.add_lines([("source", "load0"), ("generator0", "load0")])
113113
circuit.solve()
114114
print(circuit.results(["Voltages", "Losses"]))
@@ -117,10 +117,10 @@ def test_010_many_sources(self):
117117
circuit = PyGridSim()
118118
circuit.update_source(source_type="powerplant")
119119
circuit.add_load_nodes(num=3)
120-
circuit.add_PVSystem(load_nodes=["load1", "load2"], num_panels=10)
121-
circuit.add_generator(num=3, gen_type="small")
122-
circuit.update_source(source_type="turbine")
123-
circuit.add_generator(num=4, gen_type="large")
120+
circuit.add_PVSystems(load_nodes=["load1", "load2"], num_panels=10)
121+
circuit.add_generators(num=3, gen_type="small")
122+
circuit.update_source(source_type="turbine") # change to a turbine source midway
123+
circuit.add_generators(num=4, gen_type="large")
124124
circuit.add_lines([("source", "load0"), ("generator0", "load0"), ("generator5", "source")])
125125
circuit.solve()
126126
print(circuit.results(["Voltages", "Losses"]))
@@ -148,10 +148,10 @@ def test_011_configs(self):
148148

149149
# GENERATOR CONFIG
150150
# works, because not case sensitive
151-
circuit.add_generator(num=3, gen_type="SMALl")
151+
circuit.add_generators(num=3, gen_type="SMALl")
152152
# don't want linetype input, just string
153153
with self.assertRaises(Exception):
154-
circuit.add_generator(num=3, gen_type=GeneratorType.SMALL)
154+
circuit.add_generators(num=3, gen_type=GeneratorType.SMALL)
155155

156156
# SOURCE CONFIG
157157
# works, because not case sensitive
@@ -210,9 +210,9 @@ def test_101_bad_parameter(self):
210210
# add load nodes so we can test pv system erroring
211211
circuit.add_load_nodes(num=2, params={"kV": 10, "kW": 20, "kvar": 1})
212212
with self.assertRaises(KeyError):
213-
circuit.add_generator(num=4, params={"badParam": 100})
213+
circuit.add_generators(num=4, params={"badParam": 100})
214214
with self.assertRaises(KeyError):
215-
circuit.add_PVSystem(load_nodes=["load0"], params={"badParam": 100}, num_panels=4)
215+
circuit.add_PVSystems(load_nodes=["load0"], params={"badParam": 100}, num_panels=4)
216216

217217
def test_102_negative_inputs(self):
218218
"""
@@ -243,3 +243,21 @@ def test_104_non_int_parameters(self):
243243
circuit = PyGridSim()
244244
with self.assertRaises(TypeError):
245245
circuit.add_load_nodes(params={"kV": "stringInput"})
246+
247+
def test_105_alt_source_parameters(self):
248+
circuit = PyGridSim()
249+
circuit.add_load_nodes(num=5)
250+
circuit.add_generators(params={"kV": 50, "kW": 100})
251+
circuit.add_PVSystems(load_nodes=["load0", "load1"], num_panels=5, params={"kV": 0.1})
252+
circuit.solve()
253+
print(circuit.results(["Voltages", "Losses"]))
254+
circuit.clear()
255+
256+
def test_106_transformer_parameters(self):
257+
circuit = PyGridSim()
258+
circuit.add_load_nodes(num=5)
259+
circuit.update_source()
260+
circuit.add_lines([("source", "load0")], params={"length": 20, "XHL": 5})
261+
circuit.solve()
262+
print(circuit.results(["Voltages", "Losses"]))
263+
circuit.clear()

0 commit comments

Comments
 (0)