diff --git a/pygridsim/configs.py b/pygridsim/configs.py index cc8bd3e..b31ae52 100644 --- a/pygridsim/configs.py +++ b/pygridsim/configs.py @@ -66,3 +66,10 @@ "kW": defaults.INDUSTRIAL_GEN_KW, } } + +NAME_TO_CONFIG = { + "load": LOAD_CONFIGURATIONS, + "source": SOURCE_CONFIGURATIONS, + "generator": GENERATOR_CONFIGURATIONS, + "line": LINE_CONFIGURATIONS +} diff --git a/pygridsim/core.py b/pygridsim/core.py index c85798f..e507fe6 100644 --- a/pygridsim/core.py +++ b/pygridsim/core.py @@ -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 @@ -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') @@ -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): @@ -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 diff --git a/sim.json b/sim.json new file mode 100644 index 0000000..ed80665 --- /dev/null +++ b/sim.json @@ -0,0 +1,10 @@ +{ + "Voltages": { + "source": 1912.250959225854, + "load0": 164.87512862167387 + }, + "Losses": { + "Active Power Loss": 181552.68984510849, + "Reactive Power Loss": 377394.0863595363 + } +} \ No newline at end of file diff --git a/tests/test_circuit.py b/tests/test_circuit.py index cbd313e..1542d38 100644 --- a/tests/test_circuit.py +++ b/tests/test_circuit.py @@ -274,3 +274,25 @@ def test_106_transformer_parameters(self): circuit.solve() print(circuit.results(["Voltages", "Losses"])) circuit.clear() + + +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")