forked from sogno-platform/dpsim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added IEEE39 simulation notebooks in sp and pf domain
Signed-off-by: martin.moraga <[email protected]>
- Loading branch information
1 parent
9892913
commit 5edabc8
Showing
2 changed files
with
851 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# IEEE39 - Validation against PF" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import subprocess, sys, os\n", | ||
"import urllib.request\n", | ||
"\n", | ||
"dpsim_root_dir = subprocess.Popen(['git', 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE).communicate()[0].rstrip().decode('utf-8')\n", | ||
"sys.path.insert(0, os.path.join(dpsim_root_dir, 'python/src/dpsim/'))\n", | ||
"sys.path.insert(0, os.path.join(dpsim_root_dir, 'build'))\n", | ||
"\n", | ||
"import matpower\n", | ||
"import dpsimpy\n", | ||
"from villas.dataprocessing.readtools import *\n", | ||
"from villas.dataprocessing.timeseries import *\n", | ||
"import urllib.request\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Get simulation data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"if not os.path.exists('ieee39-data'):\n", | ||
" os.mkdir('ieee39-data')\n", | ||
"\n", | ||
"file_names = [\"20140528T0800Z_XX_YYY_DY_.xml\", \"20140528T0800Z_XX_YYY_SSH_.xml\", \"20140528T0800Z_XX_YYY_SV_.xml\", \"20140528T0800Z_XX_YYY_TP_.xml\", \"20140528T0800Z_YYY_EQ_.xml\"]\n", | ||
"for file_name in file_names:\n", | ||
" url_dynamic = 'https://raw.githubusercontent.com/martinmoraga/dpsim_data/main/IEEE39/CIM/' + file_name\n", | ||
" local_file = './ieee39-data/' + file_name\n", | ||
" urllib.request.urlretrieve(url_dynamic, local_file)\n", | ||
" \n", | ||
"path_to_files = []\n", | ||
"for item in file_names: path_to_files.append('./ieee39-data/' + item)" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### PF Simulation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sim_name_pf = \"IEEE39\"\n", | ||
"\n", | ||
"dpsimpy.Logger.set_log_dir('logs/' + sim_name_pf)\n", | ||
"reader = dpsimpy.CIMReader(sim_name_pf, dpsimpy.LogLevel.debug, dpsimpy.LogLevel.debug)\n", | ||
"system_pf = reader.loadCIM(60, path_to_files, dpsimpy.Domain.SP, dpsimpy.PhaseType.Single, dpsimpy.GeneratorType.PVNode)\n", | ||
"gen_ref = system_pf.component(\"G 02\")\n", | ||
"gen_ref.modify_power_flow_bus_type(dpsimpy.PowerflowBusType.VD)\n", | ||
"\n", | ||
"logger = dpsimpy.Logger(sim_name_pf)\n", | ||
"for node in system_pf.nodes:\n", | ||
" logger.log_attribute(node.name() + '.V', 'v', node)\n", | ||
" logger.log_attribute(node.name() + '.S', 's', node)\n", | ||
" \n", | ||
"sim = dpsimpy.Simulation(sim_name_pf, dpsimpy.LogLevel.debug)\n", | ||
"sim.set_system(system_pf)\n", | ||
"sim.set_time_step(0.1)\n", | ||
"sim.set_final_time(0.1)\n", | ||
"sim.set_domain(dpsimpy.Domain.SP)\n", | ||
"sim.set_solver(dpsimpy.Solver.NRP)\n", | ||
"sim.do_init_from_nodes_and_terminals(True)\n", | ||
"\n", | ||
"sim.add_logger(logger)\n", | ||
"sim.run()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Read pf results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dpsim_result_file = 'logs/' + sim_name_pf + '/' + sim_name_pf + '.csv'\n", | ||
"ts_dpsim_pf = read_timeseries_csv(dpsim_result_file)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### DPsim Results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dpsim_results = pd.DataFrame(columns=['Bus', 'Vmag [kV]', 'Va [°]', 'P [MW]', 'Q [MVAr]'])\n", | ||
"w_mw = 1e-6\n", | ||
"v_kV = 1e-3\n", | ||
"for i in range (39):\n", | ||
" node_name = f\"Bus {i+1:02d}\"\n", | ||
" dpsim_results.loc[i] = (\n", | ||
" [node_name] \n", | ||
" + [np.round(np.absolute(ts_dpsim_pf[node_name + '.V'].values[-1] * v_kV), 4)]\n", | ||
" + [np.round(np.angle(ts_dpsim_pf[node_name + '.V'].values[-1]) * 180/np.pi , 4)] \n", | ||
" + [np.round(np.real(ts_dpsim_pf[node_name + '.S'].values[-1] * w_mw), 4)] \n", | ||
" + [np.round(np.imag(ts_dpsim_pf[node_name + '.S'].values[-1] * w_mw), 4)])\n", | ||
"\n", | ||
"dpsim_results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### DigSilent Results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"res = reader.get_powerflow_results()\n", | ||
"pf_results = pd.DataFrame(columns=['Bus', 'Vmag [kV]', 'Va [°]', 'P [MW]', 'Q [MVAr]'])\n", | ||
"w_mw = 1e-6\n", | ||
"v_kV = 1\n", | ||
"for node_name, data in res.items():\n", | ||
" loc = int(node_name[4:]) - 1\n", | ||
" pf_results.loc[loc] = (\n", | ||
" [node_name] \n", | ||
" + [round(data[0] * v_kV, 4)]\n", | ||
" + [round(data[1], 4)] \n", | ||
" + [round(data[2], 4)] \n", | ||
" + [round(data[3], 4)])\n", | ||
"\n", | ||
"pf_results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"difference_vmag = pf_results['Vmag [kV]'] - dpsim_results['Vmag [kV]']\n", | ||
"difference_vangle = pf_results['Va [°]'] - dpsim_results['Va [°]']\n", | ||
"\n", | ||
"#base power = 100MW\n", | ||
"difference_p = (pf_results['P [MW]'] - dpsim_results['P [MW]'])\n", | ||
"difference_q = (pf_results['Q [MVAr]'] - dpsim_results['Q [MVAr]'])\n", | ||
"difference = {\"Bus\": pf_results['Bus'], \"Vmag [kV]\": difference_vmag, \"Va [°]\": difference_vangle, \"P [MW]\": difference_p, \"Q [MVAr]\": difference_q}\n", | ||
"difference = pd.DataFrame(difference)\n", | ||
"\n", | ||
"difference\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"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.9.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.