22from altdss import altdss
33from altdss import AltDSS , Transformer , Vsource , Load , LoadModel , LoadShape
44from dss .enums import LineUnits , SolveModes
5- from parameters import make_load_node , make_source_node
6- from queries import query_solution
7- from lines import make_line
8- from transformers import make_transformer
9- from enums import LineType , SourceType , LoadType
5+ from pygridsim . parameters import make_load_node , make_source_node
6+ from pygridsim . results import query_solution
7+ from pygridsim . lines import make_line
8+ from pygridsim . transformers import make_transformer
9+ from pygridsim . enums import LineType , SourceType , LoadType
1010
1111"""Main module."""
1212
@@ -16,43 +16,50 @@ def __init__(self):
1616 Initialize OpenDSS/AltDSS engine. Creates an Empty Circuit
1717 """
1818 self .num_loads = 0
19+ self .num_sources = 0
1920 self .num_lines = 0
2021 self .num_transformers = 0
21- altdss ('new circuit.IEEE13Nodeckt' )
22+ altdss .ClearAll ()
23+ #altdss('new circuit.IEEE13Nodeckt')
24+ altdss ('new circuit.MyCircuit' )
2225
23- def add_load_nodes (self , load_params = {}, load_type : LoadType = LoadType .HOUSE , num = 1 ):
26+ def add_load_nodes (self , params = {}, load_type : LoadType = LoadType .HOUSE , num = 1 ):
2427 """
2528 When the user wants to manually add nodes, or make nodes with varying parameters.
2629
2730 Args:
28- load_params : load parameters for these manual additions
31+ params : load parameters for these manual additions
2932 lines: which nodes these new loads are connected to
3033 num (optional): number of loads to create with these parameters
3134 Return:
3235 List of load_nodes
3336 """
3437 load_nodes = []
3538 for i in range (num ):
36- make_load_node (load_params , load_type , self .num_loads )
39+ make_load_node (params , load_type , self .num_loads )
3740 self .num_loads += 1
3841 return load_nodes
3942
40- def add_source_nodes (self , source_params = {}, source_type : SourceType = SourceType .TURBINE , num_in_batch = 1 ):
43+ def add_source_nodes (self , params = {}, source_type : SourceType = SourceType .TURBINE , num_in_batch = 1 , num = 1 ):
4144 """
4245 When the user wants to manually add nodes, or make nodes with varying parameters.
4346
4447 Args:
45- source_params : load parameters for these manual additions
48+ params : load parameters for these manual additions
4649 lines: which nodes these new sources are connected to
4750 num (optional): number of sources to create with these parameters (removed for now)
4851 num_in_batch: how many to batch together directly (so they can't be connected to lines separately, etc.
4952 most common use case is if a house has 20 solar panels it's more useful to group them together)
5053 Return:
5154 List of source_nodes
5255 """
53- return make_source_node (source_params , source_type , num_in_batch = num_in_batch )
56+ source_nodes = []
57+ for i in range (num ):
58+ make_source_node (params , source_type , count = self .num_sources , num_in_batch = num_in_batch )
59+ self .num_sources += 1
60+ return source_nodes
5461
55- def add_lines (self , connections , line_type : LineType = LineType .LV_LINE , params = {}):
62+ def add_lines (self , connections , line_type : LineType = LineType .LV_LINE , params = {}, transformer = True ):
5663 """
5764 Specify all lines that the user wants to add. If redundant lines, doesn't add anything
5865
@@ -61,7 +68,7 @@ def add_lines(self, connections, line_type: LineType = LineType.LV_LINE, params
6168 TODO: allow the input to also contain optional parameters
6269 """
6370 for src , dst in connections :
64- make_line (src , dst , line_type , self .num_lines , params )
71+ make_line (src , dst , line_type , self .num_lines , params , transformer )
6572 self .num_lines += 1
6673
6774 def add_transformers (self , connections , params = {}):
@@ -70,6 +77,7 @@ def add_transformers(self, connections, params = {}):
7077
7178 Args:
7279 connections: a list of new transformers to add (where to add them), with these params
80+ TODO: remove
7381 """
7482 for src , dst in connections :
7583 make_transformer (src , dst , self .num_transformers , params )
@@ -118,6 +126,8 @@ def view_source_node(self):
118126 def solve (self ):
119127 """
120128 Initialize "solve" mode in AltDSS, then allowing the user to query various results on the circuit
129+
130+ TODO: error handling here
121131 """
122132 altdss .Solution .Solve ()
123133
@@ -132,27 +142,15 @@ def results(self, queries):
132142 for query in queries :
133143 results [query ] = query_solution (query )
134144 return results
135-
136- def remove_load_nodes (self , indices ):
137- """
138- All load nodes are defined by indices, so remove the ones in list of indices.
139-
140- Args:
141- indices: indices corresponding to nodes to remove (i.e. [1,3] removes the 1st and 3rd load nodes)
142- """
143-
144- def remove_source_nodes (self , indices ):
145- """
146- All source nodes are defined by indices, so remove the ones in list of indices
147145
148- Args:
149- indices: indices corresponding to nodes to remove
146+ def clear (self ):
150147 """
148+ Must call after we are done using the circuit, or will cause re-creation errors.
151149
152- def remove_lines (self , connections ):
150+ We only work with one circuit at a time, can only have one PyGridSim object at a time.
151+ TODO: maybe this isn't necessary because it's done in the beginning
153152 """
154- Remove all the connections (and any corresponding transformers) specified.
155-
156- Args:
157- connections: a list of connections to remove
158- """
153+ altdss .ClearAll ()
154+ self .num_loads = 0
155+ self .num_lines = 0
156+ self .num_transformers = 0
0 commit comments