Skip to content

Commit 668d91e

Browse files
committed
misc fixes
1 parent 7fd76bd commit 668d91e

File tree

6 files changed

+44
-17
lines changed

6 files changed

+44
-17
lines changed

pygridsim/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def update_source(self, source_type: str = "turbine", params: dict[str, int] = N
7171
params = params or dict()
7272
return _make_source_node(params, source_type)
7373

74-
def add_PVSystem(self, load_nodes: list[str], params: dict[str, int] = None, num_panels: int = 1):
74+
def add_PVSystems(self, load_nodes: list[str], params: dict[str, int] = None, num_panels: int = 1):
7575
"""Adds a photovoltaic (PV) system to the specified load nodes.
7676
7777
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
9999

100100
return PV_nodes
101101

102-
def add_generator(self, num: int = 1, gen_type: str = "small", params: dict[str, int] = None):
102+
def add_generators(self, num: int = 1, gen_type: str = "small", params: dict[str, int] = None):
103103
"""Adds generator(s) to the system.
104104
105105
Args:

pygridsim/defaults.py

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

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

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

pygridsim/lines.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def _make_line(src, dst, line_type, count, params = {}, transformer = True):
3838
transformer.Windings = defaults.NUM_WINDINGS
3939
transformer.XHL = _get_param(params, "XHL", defaults.XHL)
4040
transformer.Buses = [src, dst]
41-
transformer.Conns = _get_param(params, "Conns", [defaults.PRIMARY_CONN, defaults.SECONDARY_CONN])
42-
41+
transformer.Conns = [defaults.PRIMARY_CONN, defaults.SECONDARY_CONN]
4342
transformer.kVs = [_get_kv(src), _get_kv(dst)]
4443

4544
transformer.end_edit()

pygridsim/parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,4 @@ def _make_generator(params, gen_type, count):
8888
generator.Phases = _get_param(params, "phases", defaults.PHASES)
8989
for attr in ["kV", "kW"]:
9090
gen_type_param = GENERATOR_CONFIGURATIONS[gen_type_obj][attr]
91-
setattr(generator, attr, _get_param(params, attr, _random_param(gen_type_param)))
91+
setattr(generator, attr, _get_param(params, attr, _random_param(gen_type_param)))

sim.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Voltages": {
3+
"source": 1086.5694813600999,
4+
"load0": 187.13447522128487
5+
},
6+
"Losses": {
7+
"Active Power Loss": 62520.07562712451,
8+
"Reactive Power Loss": 129976.52141894132
9+
}
10+
}

tests/test_circuit.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_008_PVsystem(self):
100100
circuit = PyGridSim()
101101
circuit.update_source()
102102
circuit.add_load_nodes(num=2)
103-
circuit.add_PVSystem(load_nodes=["load0", "load1"], num_panels=5)
103+
circuit.add_PVSystems(load_nodes=["load0", "load1"], num_panels=5)
104104
circuit.add_lines([("source", "load0")])
105105
circuit.solve()
106106
print(circuit.results(["Voltages", "Losses"]))
@@ -109,7 +109,7 @@ def test_009_generator(self):
109109
circuit = PyGridSim()
110110
circuit.update_source()
111111
circuit.add_load_nodes()
112-
circuit.add_generator(num=3, gen_type="small")
112+
circuit.add_generators(num=3, gen_type="small")
113113
circuit.add_lines([("source", "load0"), ("generator0", "load0")])
114114
circuit.solve()
115115
print(circuit.results(["Voltages", "Losses"]))
@@ -118,10 +118,10 @@ def test_010_many_sources(self):
118118
circuit = PyGridSim()
119119
circuit.update_source(source_type="powerplant")
120120
circuit.add_load_nodes(num=3)
121-
circuit.add_PVSystem(load_nodes=["load1", "load2"], num_panels=10)
122-
circuit.add_generator(num=3, gen_type="small")
121+
circuit.add_PVSystems(load_nodes=["load1", "load2"], num_panels=10)
122+
circuit.add_generators(num=3, gen_type="small")
123123
circuit.update_source(source_type="turbine") # change to a turbine source midway
124-
circuit.add_generator(num=4, gen_type="large")
124+
circuit.add_generators(num=4, gen_type="large")
125125
circuit.add_lines([("source", "load0"), ("generator0", "load0"), ("generator5", "source")])
126126
circuit.solve()
127127
print(circuit.results(["Voltages", "Losses"]))
@@ -149,10 +149,10 @@ def test_011_configs(self):
149149

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

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

218218
def test_102_negative_inputs(self):
219219
"""
@@ -245,6 +245,24 @@ def test_104_non_int_parameters(self):
245245
with self.assertRaises(TypeError):
246246
circuit.add_load_nodes(params={"kV": "stringInput"})
247247

248+
def test_105_alt_source_parameters(self):
249+
circuit = PyGridSim()
250+
circuit.add_load_nodes(num=5)
251+
circuit.add_generators(params={"kV": 50, "kW": 100})
252+
circuit.add_PVSystems(load_nodes=["load0", "load1"], num_panels=5, params={"kV": 0.1})
253+
circuit.solve()
254+
print(circuit.results(["Voltages", "Losses"]))
255+
circuit.clear()
256+
257+
def test_106_transformer_parameters(self):
258+
circuit = PyGridSim()
259+
circuit.add_load_nodes(num=5)
260+
circuit.update_source()
261+
circuit.add_lines([("source", "load0")], params={"length": 20, "XHL": 5})
262+
circuit.solve()
263+
print(circuit.results(["Voltages", "Losses"]))
264+
circuit.clear()
265+
248266

249267
class TestLargeCircuit(unittest.TestCase):
250268
"""

0 commit comments

Comments
 (0)