Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from sogno-platform/version-for-git-without-cov…
Browse files Browse the repository at this point in the history
…ee-powerflow

Voltage control strategy using Dual Ascent method working. Powerflow used as class in covee. Adressing issue:
#1
  • Loading branch information
edoardo-dedin authored Jun 21, 2022
2 parents 227c1c1 + 28fcaf3 commit 4b1a3ca
Show file tree
Hide file tree
Showing 51 changed files with 2,383 additions and 953 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ csv_files/*.csv
*.vscode/
*.ipynb_checkpoints/
csv_files/results/
plots/
csv_files/plots/
powerflow/powerflow
pv_centralized/covee
venv_ext
covee
*.csv
*.eps
*.png

489 changes: 489 additions & 0 deletions Control_MPC_main.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ RUN apt-get update -y \
&& apt install python3-pip -y \
&& apt-get install python3-venv -y \
&& apt-get install sudo -y

COPY ../conf.json tmp/
82 changes: 82 additions & 0 deletions Flex_sim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import numpy as np
import csv
import os
import coloredlogs, logging, threading
from submodules.dmu.dmu import dmu
from submodules.dmu.httpSrv import httpSrv
from submodules.dmu.mqttClient import mqttClient
import time
import sys
import requests
import json
import csv

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")

if bool(os.getenv('MQTT_ENABLED')):
mqtt_url = str(os.getenv('MQTTURL'))
mqtt_port = int(os.getenv('MQTTPORT'))
mqtt_user = str(os.getenv('MQTTUSER'))
mqtt_password = str(os.getenv('MQTTPASS'))
else:
mqtt_url = "mqtt"
mqtt_port = 1883
mqtt_password = ""
mqtt_user = ""

############################ Start the Server #######################################################

''' Initialize objects '''
dmuObj = dmu()

''' Start mqtt client '''
mqttObj = mqttClient(mqtt_url, dmuObj, mqtt_port, mqtt_user, mqtt_password)

time.sleep(2.0)
#######################################################################################################

flex_offer = {"variables": [],"flex_output": {}}
flex_request_dict = {}

# Receive flexibility_request
dmuObj.addElm("flex_values", {})
mqttObj.attachSubscriber("/edgeflex/goflex/flex_request","json","flex_values")

# Send flexibility_output
dmuObj.addElm("flex_input", {})
mqttObj.attachPublisher("/edgeflex/goflex/flex_result","json","flex_input")

while True:
flex_request = dmuObj.getDataSubset("flex_values")
if flex_request:
flex_output = {}
print(flex_request)
for i in flex_request["variables"]:
if flex_request["flex_dict"][i]:
logging.info("flexibility request " + str(i) + " = " + str(flex_request["flex_dict"][i]))
logging.info(" ")
time.sleep(2)
###################### PREPARE THE ANSWER ###########
vector_node_name = [7,9,10]
vector_position = []
for i in range(len(flex_request["active_nodes"])):
if any(flex_request["active_nodes"][i]+1 == t for t in vector_node_name):
vector_position.append(flex_request["active_nodes"].index(flex_request["active_nodes"][i]))
predictions = [1]
flex_output = {"variable":["active_power", "reactive_power"],
"active_power": {"vector_position":vector_position,"prediction": predictions,"flex_value": {"pred_"+str(predictions[j]):[list(np.round(np.random.rand(1)*abs(flex_request["flex_dict"]["active_power"]["pred_"+str(predictions[j])]["node_"+str(i)]), 2))[0] for i in vector_node_name ] for j in range(len(predictions))} },
"reactive_power": {"vector_position":vector_position,"prediction": predictions,"flex_value": {"pred_"+str(predictions[j]):[list(np.round(np.random.rand(1)*abs(flex_request["flex_dict"]["reactive_power"]["pred_"+str(predictions[j])]["node_"+str(i)]), 2))[0] for i in vector_node_name ] for j in range(len(predictions))} }
}
print(flex_output)
dmuObj.setDataSubset(flex_output,"flex_input")
time.sleep(0.5)
break

File renamed without changes.
167 changes: 0 additions & 167 deletions cases/LV_SOGNO.py

This file was deleted.

7 changes: 6 additions & 1 deletion cases/LV_SOGNO_virtual_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

from numpy import array

def LV_SOGNO_virtual_nodes():
class case_():

def __init__(self):
pass

def case(self):

ppc = {"version": '2'}

Expand Down
40 changes: 22 additions & 18 deletions cases/case14.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Copyright (c) 1996-2015 PSERC. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

"""Power flow data for IEEE 14 bus test case.
"""

from numpy import array
import numpy as np

class case_():

def case14():
def __init__(self):
pass

def case(self):

ppc = {"version": '2'}

Expand All @@ -21,7 +23,7 @@ def case14():

ppc["VMAX"] = VMAX
ppc["VMIN"] = VMIN

baseKV = 1
## bus data
# bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin
ppc["bus"] = array([
Expand All @@ -46,9 +48,19 @@ def case14():
# Qc1min, Qc1max, Qc2min, Qc2max, ramp_agc, ramp_10, ramp_30, ramp_q, apf
ppc["gen"] = array([
[1, 0, 0, 200, -200, 1, 1, 1, 200, -200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[2, 0, 0, 0.03, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[3, 0, 0, 0.2, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[8, 0, 0, 0.2, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[2, 0, 0, 0.0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[3, 0, 0, 0.0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[4, 0, 0, 0., 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[5, 0, 0, 0.0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[6, 0, 0, 0.0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[7, 0, 0, 0., 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[8, 0, 0, 0.0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[9, 0, 0, 0.0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[10, 0, 0, 0., 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[11, 0, 0, 0., 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[12, 0, 0, 0.0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[13, 0, 0, 0.0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[14, 0, 0, 0., 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],

])

Expand All @@ -70,15 +82,7 @@ def case14():
[13, 14, 0.0019424682, 0.0009254892, 1.28748775575886E-007, 100, 100, 100, 0, 0, 1, -360, 360]
])

##----- OPF Data -----##
## generator cost data
# 1 startup shutdown n x1 y1 ... xn yn
# 2 startup shutdown n c(n-1) ... c0
ppc["gencost"] = array([
[2, 0, 0, 3, 0.0430293, 20, 0],
[2, 0, 0, 3, 0.25, 20, 0],
[2, 0, 0, 3, 0.01, 40, 0],
[2, 0, 0, 3, 0.01, 40, 0]
ppc["gencost"] = np.vstack([[2, 0, 0, 3, 0.01, 40, 0] for i in range(np.shape(ppc["gen"])[0])
])

return ppc
Loading

0 comments on commit 4b1a3ca

Please sign in to comment.