Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Byte-compiled / optimized / DLL files
__pycache__/
sim.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since sim.json is part of the repository, I would not include it in the .gitignore. there is a potential that sim.json would be changed in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sim.json changes each time I run the test cases, because of the randomness assigned to them - I'll rewrite the test case so it doesn't change each time

*.py[cod]
*$py.class

Expand Down
8 changes: 3 additions & 5 deletions pygridsim/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions pygridsim/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions pygridsim/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
44 changes: 31 additions & 13 deletions tests/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ 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"))

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"]))
Expand All @@ -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"]))
Expand All @@ -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"]))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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()