@@ -27,13 +27,23 @@ def __init__(self):
2727 self .num_transformers = 0
2828 self .num_pv = 0
2929 self .num_generators = 0
30+ self .nickname_to_name = {}
3031 altdss .ClearAll ()
3132 altdss ('new circuit.MyCircuit' )
3233
34+ def _check_naming (self , name ):
35+ if name in self .nickname_to_name :
36+ raise NameError ("Provided name already assigned to a node" )
37+ if name .startswith ("load" ) or name .startswith (
38+ "generator" ) or name == "source" or name .startswith ("pv" ):
39+ raise NameError (
40+ "Cannot name nodes of the format 'component + __', ambiguity with internal names" )
41+
3342 def add_load_nodes (self ,
3443 load_type : str = "house" ,
3544 params : dict [str , int ] = None ,
36- num : int = 1 ):
45+ num : int = 1 ,
46+ names : list [str ] = None ):
3747 """Adds Load Node(s) to circuit.
3848
3949 Allows the user to add num load nodes,
@@ -47,14 +57,24 @@ def add_load_nodes(self,
4757 Load parameters for these manual additions. Defaults to empty dictionary.
4858 num (int, optional):
4959 The number of loads to create with these parameters. Defaults to 1.
60+ names (list(str), optional):
61+ Up to num names to assign as shortcuts to the loads
5062
5163 Returns:
5264 list[OpenDSS object]:
5365 A list of OpenDSS objects representing the load nodes created.
5466 """
5567 params = params or dict ()
68+ names = names or list ()
69+ if len (names ) > num :
70+ raise ValueError ("Specified more names of loads than number of nodes" )
71+
5672 load_nodes = []
57- for _ in range (num ):
73+ for i in range (num ):
74+ if (len (names ) > i ):
75+ self ._check_naming (names [i ])
76+ self .nickname_to_name [names [i ]] = "load" + str (self .num_loads )
77+
5878 _make_load_node (params , load_type , self .num_loads )
5979 self .num_loads += 1
6080
@@ -106,12 +126,19 @@ def add_PVSystems(self, load_nodes: list[str],
106126
107127 PV_nodes = []
108128 for load in load_nodes :
129+ if (load in self .nickname_to_name ):
130+ self .nickname_to_name [load ]
131+
109132 PV_nodes .append (_make_pv (load , params , num_panels , self .num_pv ))
110133 self .num_pv += 1
111134
112135 return PV_nodes
113136
114- def add_generators (self , num : int = 1 , gen_type : str = "small" , params : dict [str , int ] = None ):
137+ def add_generators (self ,
138+ num : int = 1 ,
139+ gen_type : str = "small" ,
140+ params : dict [str , int ] = None ,
141+ names : list [str ] = None ):
115142 """Adds generator(s) to the system.
116143
117144 Args:
@@ -121,14 +148,24 @@ def add_generators(self, num: int = 1, gen_type: str = "small", params: dict[str
121148 The type of generator (one of "small", "large", "industrial"). Defaults to "small".
122149 params (dict[str, int], optional):
123150 A dictionary of parameters to configure the generator. Defaults to None.
151+ names (list(str), optional):
152+ Up to num names to assign as shortcuts to the generators
124153
125154 Returns:
126155 list[DSS objects]:
127156 A list of OpenDSS objects representing the generators created.
128157 """
129158 params = params or dict ()
159+ names = names or list ()
160+ if len (names ) > num :
161+ raise ValueError ("Specified more names of generators than number of nodes" )
162+
130163 generators = []
131- for _ in range (num ):
164+ for i in range (num ):
165+ if (len (names ) > i ):
166+ self ._check_naming (names [i ])
167+ self .nickname_to_name [names [i ]] = "generator" + str (self .num_generators )
168+
132169 generators .append (_make_generator (params , gen_type , count = self .num_generators ))
133170 self .num_generators += 1
134171
@@ -159,6 +196,13 @@ def add_lines(self,
159196 """
160197 params = params or dict ()
161198 for src , dst in connections :
199+ if (src in self .nickname_to_name ):
200+ src = self .nickname_to_name [src ]
201+ if (dst in self .nickname_to_name ):
202+ dst = self .nickname_to_name [dst ]
203+ if (src == dst ):
204+ raise ValueError ("Tried to make a line between equivalent src and dst" )
205+
162206 _make_line (src , dst , line_type , self .num_lines , params , transformer )
163207 self .num_lines += 1
164208
0 commit comments