11# -*- coding: utf-8 -*-
22from altdss import altdss
33
4+ from pygridsim .configs import LOAD_CONFIGURATIONS
5+ from pygridsim .enums import LoadType
46from pygridsim .lines import _make_line
57from pygridsim .parameters import _make_generator , _make_load_node , _make_pv , _make_source_node
68from pygridsim .results import _export_results , _query_solution
@@ -16,17 +18,12 @@ def __init__(self):
1618 Stores numbers of circuit components to ensure unique naming of repeat circuit components.
1719
1820 Attributes:
19- num_loads (int): Number of loads in circuit so far.
20- num_lines (int): Number of lines in circuit so far.
21- num_transformers (int): Number of transformers in circuit so far.
22- num_pv (int): Number of PV systems in circuit so far.
23- num_generators (int): Number generators in circuit so far.
21+ counts (dict[str, int]): Map of each type to the number seen of that type so far
2422 """
25- self .num_loads = 0
26- self .num_lines = 0
27- self .num_transformers = 0
28- self .num_pv = 0
29- self .num_generators = 0
23+ self .counts = {}
24+ for count_type in ["loads" , "lines" , "transformers" , "pv" , "generators" ]:
25+ self .counts [count_type ] = 0
26+
3027 altdss .ClearAll ()
3128 altdss ('new circuit.MyCircuit' )
3229
@@ -52,11 +49,12 @@ def add_load_nodes(self,
5249 list[OpenDSS object]:
5350 A list of OpenDSS objects representing the load nodes created.
5451 """
52+
5553 params = params or dict ()
5654 load_nodes = []
5755 for _ in range (num ):
58- _make_load_node (params , load_type , self .num_loads )
59- self .num_loads += 1
56+ _make_load_node (params , load_type , self .counts [ "loads" ] )
57+ self .counts [ "loads" ] += 1
6058
6159 return load_nodes
6260
@@ -108,8 +106,8 @@ def add_PVSystem(self,
108106
109107 PV_nodes = []
110108 for load in load_nodes :
111- PV_nodes .append (_make_pv (load , params , num_panels , self .num_pv ))
112- self .num_pv += 1
109+ PV_nodes .append (_make_pv (load , params , num_panels , self .counts [ "pv" ] ))
110+ self .counts [ "pv" ] += 1
113111
114112 return PV_nodes
115113
@@ -131,8 +129,8 @@ def add_generator(self, num: int = 1, gen_type: str = "small", params: dict[str,
131129 params = params or dict ()
132130 generators = []
133131 for _ in range (num ):
134- generators .append (_make_generator (params , gen_type , count = self .num_generators ))
135- self .num_generators += 1
132+ generators .append (_make_generator (params , gen_type , count = self .counts [ "generators" ] ))
133+ self .counts [ "generators" ] += 1
136134
137135 return generators
138136
@@ -161,8 +159,8 @@ def add_lines(self,
161159 """
162160 params = params or dict ()
163161 for src , dst in connections :
164- _make_line (src , dst , line_type , self .num_lines , params , transformer )
165- self .num_lines += 1
162+ _make_line (src , dst , line_type , self .counts [ "lines" ] , params , transformer )
163+ self .counts [ "lines" ] += 1
166164
167165 def solve (self ):
168166 """Solves the OpenDSS circuit.
@@ -206,6 +204,27 @@ def clear(self):
206204 None
207205 """
208206 altdss .ClearAll ()
209- self .num_loads = 0
210- self .num_lines = 0
211- self .num_transformers = 0
207+ for key in self .counts :
208+ self .counts [key ] = 0
209+
210+ def get_load_types (self , show_ranges : bool = False ):
211+ """Provides list of all supported Load Types
212+
213+ Args:
214+ show_ranges (bool, optional):
215+ Whether to show all configuration ranges in output.
216+
217+ Returns:
218+ list:
219+ A list containing all load types, if show_ranges False.
220+ A list of tuples showing all load types and configurations, if show_ranges True.
221+ """
222+ if not show_ranges :
223+ return [load_type .value for load_type in LoadType ]
224+
225+ load_types = []
226+ for load_type in LoadType :
227+ config_dict = LOAD_CONFIGURATIONS [load_type ]
228+ load_types .append ((load_type .value , config_dict ))
229+
230+ return load_types
0 commit comments