Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 additions & 0 deletions pygridsim/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@
"kW": defaults.INDUSTRIAL_GEN_KW,
}
}

NAME_TO_CONFIG = {
"load": LOAD_CONFIGURATIONS,
"source": SOURCE_CONFIGURATIONS,
"generator": GENERATOR_CONFIGURATIONS,
"line": LINE_CONFIGURATIONS
}
54 changes: 43 additions & 11 deletions pygridsim/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from altdss import altdss

from pygridsim.configs import NAME_TO_CONFIG
from pygridsim.lines import _make_line
from pygridsim.parameters import _make_generator, _make_load_node, _make_pv, _make_source_node
from pygridsim.results import _export_results, _query_solution
Expand All @@ -16,17 +17,16 @@ def __init__(self):
Stores numbers of circuit components to ensure unique naming of repeat circuit components.

Attributes:
num_loads (int): Number of loads in circuit so far.
num_lines (int): Number of lines in circuit so far.
num_transformers (int): Number of transformers in circuit so far.
num_pv (int): Number of PV systems in circuit so far.
num_generators (int): Number generators in circuit so far.
num_generators (int): Number of generators created so far.
num_lines (int): Number of lines created so far.
num_loads (int): Number of load nodes created so far.
num_pv (int): Number of PVSystems create so far.
"""
self.num_loads = 0
self.num_generators = 0
self.num_lines = 0
self.num_transformers = 0
self.num_loads = 0
self.num_pv = 0
self.num_generators = 0

altdss.ClearAll()
altdss('new circuit.MyCircuit')

Expand All @@ -52,6 +52,7 @@ def add_load_nodes(self,
list[OpenDSS object]:
A list of OpenDSS objects representing the load nodes created.
"""

params = params or dict()
load_nodes = []
for _ in range(num):
Expand Down Expand Up @@ -206,6 +207,37 @@ def clear(self):
None
"""
altdss.ClearAll()
self.num_loads = 0
self.num_lines = 0
self.num_transformers = 0

def get_types(self, component: str, show_ranges: bool = False):
"""Provides list of all supported Load Types

Args:
component (str):
Which component to get, one of (one of "load", "source", "pv", "line")
show_ranges (bool, optional):
Whether to show all configuration ranges in output.

Returns:
list:
A list containing all load types, if show_ranges False.
A list of tuples showing all load types and configurations, if show_ranges True.
"""
component_simplified = component.lower().replace(" ", "")
if (component_simplified[-1] == "s"):
component_simplified = component_simplified[:-1]
configuration = {}
if component_simplified in NAME_TO_CONFIG:
configuration = NAME_TO_CONFIG[component_simplified]
else:
raise KeyError(
f"Invalid component input: expect one of {[name for name in NAME_TO_CONFIG]}")

if not show_ranges:
return [component_type.value for component_type in configuration]

component_types = []
for component_type in configuration:
config_dict = configuration[component_type]
component_types.append((component_type.value, config_dict))

return component_types
10 changes: 10 additions & 0 deletions sim.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Voltages": {
"source": 1912.250959225854,
"load0": 164.87512862167387
},
"Losses": {
"Active Power Loss": 181552.68984510849,
"Reactive Power Loss": 377394.0863595363
}
}
22 changes: 22 additions & 0 deletions tests/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,25 @@ def test_104_non_int_parameters(self):
circuit = PyGridSim()
with self.assertRaises(TypeError):
circuit.add_load_nodes(params={"kV": "stringInput"})


class TestTypeQueryFunctions(unittest.TestCase):

def setUp(self):
"""Set up test fixtures, if any."""
print("\nTest", self._testMethodName)

def tearDown(self):
"""Tear down test fixtures, if any."""

def test_200_type_queries(self):
circuit = PyGridSim()
# should still work if plural, capitalized, spaces
for component in ["load ", "sources", "Line", "GENERATOR"]:
print(circuit.get_types(component))
print(circuit.get_types(component, show_ranges=True))

def test_200_invalid_type_quer(self):
circuit = PyGridSim()
with self.assertRaises(KeyError):
circuit.get_types("bad_component_name")