Skip to content

Commit 3511973

Browse files
committed
change source enum, add config file for cleaner code and string inputs
1 parent 88fbb11 commit 3511973

15 files changed

+181
-65
lines changed
1.73 KB
Binary file not shown.
-1013 Bytes
Binary file not shown.
-613 Bytes
Binary file not shown.
-749 Bytes
Binary file not shown.
201 Bytes
Binary file not shown.
796 Bytes
Binary file not shown.

pygridsim/configs.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from pygridsim.enums import *
2+
from pygridsim.defaults import *
3+
4+
LOAD_CONFIGURATIONS = {
5+
LoadType.HOUSE: {
6+
"kV": HOUSE_KV,
7+
"kW": HOUSE_KW,
8+
"kvar": HOUSE_KVAR
9+
},
10+
LoadType.COMMERCIAL: {
11+
"kV": COMMERCIAL_KV,
12+
"kW": COMMERCIAL_KW,
13+
"kvar": COMMERCIAL_KVAR
14+
},
15+
LoadType.INDUSTRIAL: {
16+
"kV": INDUSTRIAL_KV,
17+
"kW": INDUSTRIAL_KW,
18+
"kvar": INDUSTRIAL_KVAR
19+
}
20+
}
21+
22+
SOURCE_CONFIGURATIONS = {
23+
SourceType.TURBINE: {
24+
"kV": TURBINE_BASE_KV
25+
},
26+
SourceType.POWER_PLANT: {
27+
"kV": POWER_PLANT_KV
28+
},
29+
SourceType.LV_SUBSTATION: {
30+
"kV": LV_SUBSTATION_BASE_KV
31+
},
32+
SourceType.MV_SUBSTATION: {
33+
"kV": MV_SUBSTATION_BASE_KV
34+
},
35+
SourceType.HV_SUBSTATION: {
36+
"kV": HV_SUBSTATION_BASE_KV
37+
},
38+
SourceType.SHV_SUBSTATION: {
39+
"kV": SHV_SUBSTATION_BASE_KV
40+
},
41+
}
42+
43+
LINE_CONFIGURATIONS = {
44+
LineType.LV_LINE: {
45+
"length": LV_LINE_LENGTH
46+
},
47+
LineType.MV_LINE: {
48+
"length": MV_LINE_LENGTH
49+
},
50+
LineType.HV_LINE: {
51+
"length": HV_LINE_LENGTH
52+
}
53+
}
54+
55+
GENERATOR_CONFIGURATIONS = {
56+
GeneratorType.SMALL: {
57+
"kV": SMALL_GEN_KV,
58+
"kW": SMALL_GEN_KW,
59+
},
60+
GeneratorType.LARGE: {
61+
"kV": LARGE_GEN_KV,
62+
"kW": LARGE_GEN_KW,
63+
},
64+
GeneratorType.INDUSTRIAL: {
65+
"kV": INDUSTRIAL_GEN_KV,
66+
"kW": INDUSTRIAL_GEN_KW,
67+
}
68+
}

pygridsim/core.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pygridsim.parameters import *
66
from pygridsim.results import query_solution, export_results
77
from pygridsim.lines import make_line
8-
from pygridsim.transformers import make_transformer
98
from pygridsim.enums import LineType, SourceType, LoadType, GeneratorType
109

1110
"""Main module."""
@@ -23,12 +22,13 @@ def __init__(self):
2322
altdss.ClearAll()
2423
altdss('new circuit.MyCircuit')
2524

26-
def add_load_nodes(self, params = {}, load_type: LoadType = LoadType.HOUSE, num = 1):
25+
def add_load_nodes(self, params = {}, load_type: str = "house", num = 1):
2726
"""
2827
When the user wants to manually add nodes, or make nodes with varying parameters.
2928
3029
Args:
3130
params: load parameters for these manual additions
31+
load_type: input as string, representing one of the load types
3232
lines: which nodes these new loads are connected to
3333
num (optional): number of loads to create with these parameters
3434
Return:
@@ -40,13 +40,13 @@ def add_load_nodes(self, params = {}, load_type: LoadType = LoadType.HOUSE, num
4040
self.num_loads += 1
4141
return load_nodes
4242

43-
def update_source(self, params = {}, source_type: SourceType = SourceType.TURBINE):
43+
def update_source(self, params = {}, source_type: str = "turbine"):
4444
"""
4545
Adds a main voltage source if it doesn't exist, otherwise edits it
4646
4747
Args:
4848
params: load parameters for these manual additions
49-
lines: which nodes these new sources are connected to
49+
source_type: source type as a string
5050
num (optional): number of sources to create with these parameters (removed for now)
5151
(removed) num_in_batch: how many to batch together directly (so they can't be connected to lines separately, etc.
5252
most common use case is if a house has 20 solar panels it's more useful to group them together)
@@ -92,13 +92,13 @@ def add_generator(self, num, params = {}, gen_type: GeneratorType = GeneratorTyp
9292
return generators
9393

9494

95-
def add_lines(self, connections, line_type: LineType = LineType.LV_LINE, params = {}, transformer = True):
95+
def add_lines(self, connections, line_type: str = "lv", params = {}, transformer = True):
9696
"""
9797
Specify all lines that the user wants to add. If redundant lines, doesn't add anything
9898
9999
Args:
100100
connections: a list of new connections to add. Each item of the list follows the form (source1, load1)
101-
TODO: allow the input to also contain optional parameters
101+
line_type: a string representing linetype if user wants to use preset parameters
102102
"""
103103
for src, dst in connections:
104104
make_line(src, dst, line_type, self.num_lines, params, transformer)

pygridsim/defaults.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
"""
22
Set any defaults (i.e. default source voltage, default node load etc.)
3-
Will start with things like HOUSE_KV to define typical load of a house (perhaps with some variance)
4-
5-
Source:
6-
Define default values for a few types of objects.
7-
In a neighborhood the main ones are
8-
solar panels, wind turbines
9-
10-
Load:
11-
Define for a typical house, using statistics
12-
https://forum.allaboutcircuits.com/threads/what-is-the-actual-household-voltage-110-115-120-220-240.3320/
13-
https://www.eia.gov/energyexplained/use-of-energy/electricity-use-in-homes.php?utm_source=chatgpt.com
14-
15-
In the second iteration
16-
- implement the typical LoadShape in the house
17-
- some randomness to cover the standard distribution of houses, not all the averages
18-
19-
For now, many of them are listed as tuples - lower end, higher end.
20-
TODO: make generate function that does Math.rand for in the range (later: improve distribution to be non-uniform)
213
"""
224
from altdss import altdss
235
from altdss import Connection
@@ -48,11 +30,15 @@
4830
"""
4931
Source Nodes (including other form of sources, like PVSystem)
5032
"""
51-
52-
TURBINE_BASE_KV = [3000,4000]
53-
SOLAR_PANEL_BASE_KV = [0.2, 0.4] # per solar panel
5433
IMPEDANCE = 0.0001
34+
TURBINE_BASE_KV = [1,3]
35+
POWER_PLANT_KV = [10, 20]
36+
LV_SUBSTATION_BASE_KV = [0.2, 0.4]
37+
MV_SUBSTATION_BASE_KV = [6, 35]
38+
HV_SUBSTATION_BASE_KV = [66, 500]
39+
SHV_SUBSTATION_BASE_KV = [500, 1000]
5540

41+
SOLAR_PANEL_BASE_KV = [0.2, 0.4] # per solar panel
5642
"""
5743
Generator default values (small, large, industrial)
5844
"""

pygridsim/enums.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33

44
# todo: update to have a name so that users can query from name
55
class SourceType(Enum):
6-
TURBINE = defaults.TURBINE_BASE_KV
7-
SOLAR_PANEL = defaults.SOLAR_PANEL_BASE_KV
6+
TURBINE = "turbine"
7+
POWER_PLANT = "powerplant"
8+
LV_SUBSTATION = "lvsub"
9+
MV_SUBSTATION = "mvsub"
10+
HV_SUBSTATION = "hvsub"
11+
SHV_SUBSTATION = "shvsub"
812

913
class LineType(Enum):
10-
LV_LINE = defaults.LV_LINE_LENGTH
11-
MV_LINE = defaults.MV_LINE_LENGTH
12-
HV_LINE = defaults.HV_LINE_LENGTH
14+
LV_LINE = "lv"
15+
MV_LINE = "mv"
16+
HV_LINE = "hv"
1317

1418
class LoadType(Enum):
15-
HOUSE = {"kV": defaults.HOUSE_KV, "kW": defaults.HOUSE_KW, "kvar": defaults.HOUSE_KVAR}
16-
COMMERCIAL = {"kV": defaults.COMMERCIAL_KV, "kW": defaults.COMMERCIAL_KW, "kvar": defaults.COMMERCIAL_KVAR}
17-
INDUSTRIAL = {"kV": defaults.INDUSTRIAL_KV, "kW": defaults.INDUSTRIAL_KW, "kvar": defaults.INDUSTRIAL_KVAR}
19+
HOUSE = "house"
20+
COMMERCIAL = "commercial"
21+
INDUSTRIAL = "industrial"
1822

1923
class GeneratorType(Enum):
20-
SMALL = {"kV": defaults.SMALL_GEN_KV, "kW": defaults.SMALL_GEN_KW}
21-
LARGE = {"kV": defaults.LARGE_GEN_KV, "kW": defaults.LARGE_GEN_KW}
22-
INDUSTRIAL = {"kV": defaults.INDUSTRIAL_GEN_KV, "kW": defaults.INDUSTRIAL_GEN_KW}
24+
SMALL = "small"
25+
LARGE = "large"
26+
INDUSTRIAL = "industrial"

0 commit comments

Comments
 (0)