-
Notifications
You must be signed in to change notification settings - Fork 0
/
covee_main.py
115 lines (93 loc) · 5.33 KB
/
covee_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import numpy as np
import os
import coloredlogs, logging, threading
import time
import json
from importlib import import_module
from alive_progress import alive_bar
from pypower.api import *
from pypower.ext2int import ext2int
import covee.control_strategies.utils as utils
from covee.powerflow.runPF_class import runPF_class
from covee.csv_files.save_results import save_results
'''
coloredlogs.install(level='DEBUG',
fmt='%(asctime)s %(levelname)-8s %(name)s[%(process)d] %(message)s',
field_styles=dict(
asctime=dict(color='green'),
hostname=dict(color='magenta'),
levelname=dict(color='white', bold=True),
programname=dict(color='cyan'),
name=dict(color='blue')))
'''
logging.info("Program Start")
# Read json file and set Control Strategy and Case
# =====================================================================================================
with open("./examples/conf.json", "r") as f:
conf_dict = json.load(f)
module_obj = utils.select(conf_dict)
Quadratic_Control = module_obj.select_control()
case = module_obj.select_case()
# =====================================================================================================
'''
#########################################################################################################
##################################### INITIALIZE ########################################################
#########################################################################################################
'''
# Get the grid data infos
# =====================================================================================================
additional = utils.additional()
conf_dict = additional.convert_index(conf_dict)
active_nodes = conf_dict["CONTROL_DATA"]["active_nodes"] # number of active DGs
active_ESS = conf_dict["CONTROL_DATA"]["active_ESS"] # number of active ESSs
logging.info("active_nodes"+str(active_nodes))
ppc_obj = case.case_()
ppc = ppc_obj.case()
ppc = ext2int(ppc) # convert to continuous indexing starting from 0
BUS_TYPE = 1
[grid_data,reactive_power,active_power,active_power_ESS] = additional.system_info(ppc,BUS_TYPE, active_nodes, active_ESS)
# Initialize the control
# =====================================================================================================
control = Quadratic_Control.Quadratic_Control(grid_data, active_nodes ,active_ESS, conf_dict["CONTROL_DATA"])
[R,X,output] = control.initialize_control()
save_obj = save_results(voltage_list = [], iterations = [], conf_dict = conf_dict)
# Initialize the powerflow
# =====================================================================================================
run_PF = runPF_class(active_nodes, active_ESS, grid_data["full_nodes"], grid_data["total_control_nodes"])
profiles = run_PF.read_profiles(conf_dict, grid_data)
active_power_dict = {}
reactive_power_dict = {}
active_power_ESS_dict = {}
'''
#########################################################################################################
############################################ RUN ########################################################
#########################################################################################################
'''
with alive_bar(int(len(profiles["gen_profile"]))) as bar: # declare your expected total
for iter in range(int(len(profiles["gen_profile"]))):
################################# Run the PowerFlow #####################################
#########################################################################################
[v_tot,v_gen,p,c,p_load,v_pv,v_ess] = run_PF.run_Power_Flow(ppc,output["DG"]["active_power"],output["DG"]["reactive_power"],output["ESS"]["active_power"],profiles["gen_profile"][iter],profiles["load_profile"][iter])
###################### Calculate the control output #####################################
#########################################################################################
output = control.control_(profiles["gen_profile"][iter][active_nodes], output, R, X, v_gen, v_ess, VMIN=conf_dict["CONTROL_DATA"]["VMIN"], VMAX=conf_dict["CONTROL_DATA"]["VMAX"], iter=iter)
# update the dictionaries
#########################################################################################
[reactive_power_dict, active_power_dict, active_power_ESS_dict] = additional.update_dict(output, reactive_power_dict, active_power_dict, active_power_ESS_dict)
save_obj.save_list(output, v_tot, iter)
print("voltage ", v_tot)
print("pv_input ", profiles["gen_profile"][iter][active_nodes])
print("reactive_power_dict ", reactive_power_dict)
bar()
# Save the data in csv files
# =====================================================================================================
save_obj.save_csv()
# Plot function
# =====================================================================================================
save_obj.Plot("voltage", {"VMAX" : conf_dict["CONTROL_DATA"]["VMAX"],
"VMIN" : conf_dict["CONTROL_DATA"]["VMIN"]})
for i in conf_dict["CONTROL_DATA"]["control_variables"]["DG"]:
save_obj.Plot(i+'_DG', None)
for i in conf_dict["CONTROL_DATA"]["control_variables"]["ESS"]:
save_obj.Plot(i+"_ESS", None)
logging.info('simulation finished')