Commit 5e7d263a authored by Markus Mirz's avatar Markus Mirz
Browse files

python: add shmem villas cigre-mv example


Signed-off-by: Markus Mirz's avatarMarkus Mirz <mmirz@eonerc.rwth-aachen.de>
parent 9c9918b7
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CIGRE MV Powerflow with Profiles Test"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Run simulation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import urllib.request\n",
"import glob\n",
"\n",
"import dpsimpy"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"name = 'CIGRE-MV-Profiles'\n",
"files = glob.glob('../../../build/_deps/cim-data-src/CIGRE_MV/NEPLAN/CIGRE_MV_no_tapchanger_With_LoadFlow_Results/*.xml')\n",
"print(files)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"reader = dpsimpy.CIMReader(name)\n",
"system = reader.loadCIM(50, files, dpsimpy.Domain.SP, dpsimpy.PhaseType.Single)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"csv_files = glob.glob('../../../build/_deps/profile-data-src/CIGRE_MV_NoTap/load_profiles/')[0]\n",
"print(csv_files)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"assignList = { }\n",
"assignList['LOAD-H-1'] = 'Load_H_1'\n",
"assignList['LOAD-H-3'] = 'Load_H_3'\n",
"assignList['LOAD-H-4'] = 'Load_H_4'\n",
"assignList['LOAD-H-5'] = 'Load_H_5'\n",
"assignList['LOAD-H-6'] = 'Load_H_6'\n",
"assignList['LOAD-H-8'] = 'Load_H_8'\n",
"assignList['LOAD-H-10'] = 'Load_H_10'\n",
"assignList['LOAD-H-11'] = 'Load_H_11'\n",
"assignList['LOAD-H-12'] = 'Load_H_12'\n",
"assignList['LOAD-H-14'] = 'Load_H_14'\n",
"assignList['LOAD-I-1'] = 'Load_I_1'\n",
"assignList['LOAD-I-3'] = 'Load_I_3'\n",
"assignList['LOAD-I-7'] = 'Load_I_7'\n",
"assignList['LOAD-I-9'] = 'Load_I_9'\n",
"assignList['LOAD-I-10'] = 'Load_I_10'\n",
"assignList['LOAD-I-12'] = 'Load_I_12'\n",
"assignList['LOAD-I-13'] = 'Load_I_13'\n",
"assignList['LOAD-I-14'] = 'Load_I_14'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"csvreader = dpsimpy.CSVReader(name, csv_files, assignList, dpsimpy.LogLevel.info)\n",
"csvreader.assignLoadProfile(system, 0, 1, 300, dpsimpy.CSVReaderMode.MANUAL, dpsimpy.CSVReaderFormat.SECONDS)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"system"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim = dpsimpy.Simulation(name)\n",
"sim.set_system(system)\n",
"sim.set_domain(dpsimpy.Domain.SP)\n",
"sim.set_solver(dpsimpy.Solver.NRP)\n",
"sim.set_time_step(1)\n",
"sim.set_final_time(300)\n",
"\n",
"logger = dpsimpy.Logger(name)\n",
"sim.add_logger(logger)\n",
"\n",
"intf = dpsimpy.InterfaceShmem()\n",
"sim.add_interface(intf)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"obj_list = system.list_idobjects()\n",
"node_list = {k: v for k, v in obj_list.items() if v == 'SimNode<std::complex<double> >'}\n",
"node_list"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for i in range(14):\n",
" sim.export_attr('N'+str(i), 'v', i, dpsimpy.AttrModifier.mag)\n",
" sim.export_attr('N'+str(i), 'v', i+1, dpsimpy.AttrModifier.phase)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for node in system.nodes:\n",
" logger.log_attribute(node.name()+'.V', 'v', node)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim.run()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.7"
},
"tests": {
"skip": true
}
},
"nbformat": 4,
"nbformat_minor": 4
}
import os
import urllib.request
import glob
import dpsimpy
name = 'CIGRE-MV-Profiles'
files = glob.glob('build/_deps/cim-data-src/CIGRE_MV/NEPLAN/CIGRE_MV_no_tapchanger_With_LoadFlow_Results/*.xml')
print(files)
reader = dpsimpy.CIMReader(name)
system = reader.loadCIM(50, files, dpsimpy.Domain.SP, dpsimpy.PhaseType.Single)
csv_files = glob.glob('build/_deps/profile-data-src/CIGRE_MV_NoTap/load_profiles/')[0]
print(csv_files)
assignList = { }
assignList['LOAD-H-1'] = 'Load_H_1'
assignList['LOAD-H-3'] = 'Load_H_3'
assignList['LOAD-H-4'] = 'Load_H_4'
assignList['LOAD-H-5'] = 'Load_H_5'
assignList['LOAD-H-6'] = 'Load_H_6'
assignList['LOAD-H-8'] = 'Load_H_8'
assignList['LOAD-H-10'] = 'Load_H_10'
assignList['LOAD-H-11'] = 'Load_H_11'
assignList['LOAD-H-12'] = 'Load_H_12'
assignList['LOAD-H-14'] = 'Load_H_14'
assignList['LOAD-I-1'] = 'Load_I_1'
assignList['LOAD-I-3'] = 'Load_I_3'
assignList['LOAD-I-7'] = 'Load_I_7'
assignList['LOAD-I-9'] = 'Load_I_9'
assignList['LOAD-I-10'] = 'Load_I_10'
assignList['LOAD-I-12'] = 'Load_I_12'
assignList['LOAD-I-13'] = 'Load_I_13'
assignList['LOAD-I-14'] = 'Load_I_14'
csvreader = dpsimpy.CSVReader(name, csv_files, assignList, dpsimpy.LogLevel.info)
csvreader.assignLoadProfile(system, 0, 1, 300, dpsimpy.CSVReaderMode.MANUAL, dpsimpy.CSVReaderFormat.SECONDS)
sim = dpsimpy.RealTimeSimulation(name)
sim.set_system(system)
sim.set_domain(dpsimpy.Domain.SP)
sim.set_solver(dpsimpy.Solver.NRP)
sim.set_time_step(1)
sim.set_final_time(30)
logger = dpsimpy.Logger(name)
sim.add_logger(logger)
intf = dpsimpy.InterfaceShmem()
sim.add_interface(intf)
obj_list = system.list_idobjects()
node_list = {k: v for k, v in obj_list.items() if v == 'SimNode<std::complex<double> >'}
print(node_list)
for i in range(15):
objname = 'N'+str(i)
sim.export_attr(objname, 'v', (i*2), dpsimpy.AttrModifier.mag)
sim.export_attr(objname, 'v', (i*2)+1, dpsimpy.AttrModifier.phase)
print(objname)
for node in system.nodes:
logger.log_attribute(node.name()+'.V', 'v', node)
sim.run(2)
\ No newline at end of file
#build/Examples/Cxx/Shmem_CIGRE_MV_PowerFlowTest_LoadProfiles
#villas-node Configs/shmem_CIGRE_MV_PF/Shmem_CIGRE_MV.conf
import asyncio
import time
......@@ -10,8 +7,8 @@ async def run(cmd):
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)
time.sleep(30)
proc.kill()
#time.sleep(30)
#proc.kill()
stdout, stderr = await proc.communicate()
print(f'[{cmd!r} exited with {proc.returncode}]')
......@@ -26,7 +23,9 @@ async def main():
run('villas-node villas-node.conf'),
run('sleep 1; echo "hello"'))
villas_conf = """
def write_villas_conf():
villas_conf = """
nodes = {
broker1 = {
type = "mqtt"
......@@ -46,7 +45,7 @@ villas_conf = """
type = "shmem"
in = {
name = "/dpsim1-villas", # Name of shared memory segment for sending side
name = "/dpsim-villas", # Name of shared memory segment for sending side
hooks = (
{
......@@ -59,7 +58,7 @@ villas_conf = """
}
},
out = {
name = "/villas-dpsim1" # Name of shared memory segment for receiving side
name = "/villas-dpsim" # Name of shared memory segment for receiving side
}
}
}
......@@ -78,8 +77,14 @@ villas_conf = """
}
)"""
with open("villas-node.conf", "w") as text_file:
with open("villas-node.conf", "w") as text_file:
text_file.write("%s" % villas_conf)
write_villas_conf()
#asyncio.run(main())
#asyncio.run(run('villas-node villas-node.conf'))
import os
os.system('villas-node villas-node.conf')
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment