Skip to content

Commit

Permalink
Adjust switch test notebook
Browse files Browse the repository at this point in the history
- increase simulation time to 2 seconds
- add another switch event to close switch at 1.5 seconds
- fix vs parameters by removing frequency for dp and sp domains
- add assertions to check Ph1::EMT against Ph3::EMT, Ph1::EMT against dp and dp against sp

Signed-off-by: Marvin Tollnitsch <marvin.tollnitsch@rwth-aachen.de>
  • Loading branch information
MarvinTollnitschRWTH authored and m-mirz committed Aug 15, 2024
1 parent 6e79a62 commit 64b5021
Showing 1 changed file with 101 additions and 18 deletions.
119 changes: 101 additions & 18 deletions examples/Notebooks/Circuits/VS_SW_RL1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"import numpy as np\n",
"import dpsimpy\n",
"\n",
"# %matplotlib widget"
"#%matplotlib widget"
]
},
{
Expand Down Expand Up @@ -108,7 +108,7 @@
"outputs": [],
"source": [
"time_step = 0.00001\n",
"final_time = 1\n",
"final_time = 2\n",
"sim_name = 'EMT_1Ph_VS_SW_RL1'\n",
"dpsimpy.Logger.set_log_dir('logs/' + sim_name)\n",
"\n",
Expand Down Expand Up @@ -155,8 +155,10 @@
"sim.set_final_time(final_time)\n",
"sim.add_logger(logger)\n",
"\n",
"event_sw = dpsimpy.event.SwitchEvent(0.5, sw, False)\n",
"sim.add_event(event_sw)\n",
"event_sw1 = dpsimpy.event.SwitchEvent(0.5, sw, False)\n",
"event_sw2 = dpsimpy.event.SwitchEvent(1.5, sw, True)\n",
"sim.add_event(event_sw1)\n",
"sim.add_event(event_sw2)\n",
"\n",
"sim.run()"
]
Expand All @@ -177,7 +179,7 @@
"outputs": [],
"source": [
"time_step = 0.00001\n",
"final_time = 1\n",
"final_time = 2\n",
"sim_name = 'DP_1Ph_VS_SW_RL1'\n",
"dpsimpy.Logger.set_log_dir(\"logs/\" + sim_name)\n",
"\n",
Expand All @@ -197,7 +199,7 @@
"\n",
"# Components\n",
"vs = dpsimpy.dp.ph1.VoltageSource('vs')\n",
"vs.set_parameters(V_ref=complex(10,0), f_src=50)\n",
"vs.set_parameters(V_ref=complex(10,0))\n",
"res = dpsimpy.dp.ph1.Resistor('r1')\n",
"res.set_parameters(resistance)\n",
"ind = dpsimpy.dp.ph1.Inductor('l1')\n",
Expand Down Expand Up @@ -226,8 +228,10 @@
"sim.set_final_time(final_time)\n",
"sim.add_logger(logger)\n",
"\n",
"event_sw = dpsimpy.event.SwitchEvent(0.5, sw, False)\n",
"sim.add_event(event_sw)\n",
"event_sw1 = dpsimpy.event.SwitchEvent(0.5, sw, False)\n",
"event_sw2 = dpsimpy.event.SwitchEvent(1.5, sw, True)\n",
"sim.add_event(event_sw1)\n",
"sim.add_event(event_sw2)\n",
"\n",
"sim.run()"
]
Expand All @@ -248,7 +252,7 @@
"outputs": [],
"source": [
"time_step = 0.00001\n",
"final_time = 1\n",
"final_time = 2\n",
"sim_name = 'SP_1Ph_VS_SW_RL1'\n",
"dpsimpy.Logger.set_log_dir(\"logs/\" + sim_name)\n",
"\n",
Expand All @@ -268,7 +272,7 @@
"\n",
"# Components\n",
"vs = dpsimpy.sp.ph1.VoltageSource('vs')\n",
"vs.set_parameters(V_ref=complex(10,0), f_src=50)\n",
"vs.set_parameters(V_ref=complex(10,0))\n",
"res = dpsimpy.sp.ph1.Resistor('r1')\n",
"res.set_parameters(resistance)\n",
"ind = dpsimpy.sp.ph1.Inductor('l1')\n",
Expand Down Expand Up @@ -297,8 +301,10 @@
"sim.set_final_time(final_time)\n",
"sim.add_logger(logger)\n",
"\n",
"event_sw = dpsimpy.event.SwitchEvent(0.5, sw, False)\n",
"sim.add_event(event_sw)\n",
"event_sw1 = dpsimpy.event.SwitchEvent(0.5, sw, False)\n",
"event_sw2 = dpsimpy.event.SwitchEvent(1.5, sw, True)\n",
"sim.add_event(event_sw1)\n",
"sim.add_event(event_sw2)\n",
"\n",
"sim.run()"
]
Expand All @@ -317,7 +323,7 @@
"outputs": [],
"source": [
"time_step = 0.00001\n",
"final_time = 1\n",
"final_time = 2\n",
"sim_name = 'EMT_3Ph_VS_SW_RL1'\n",
"dpsimpy.Logger.set_log_dir('logs/' + sim_name)\n",
"\n",
Expand Down Expand Up @@ -365,8 +371,10 @@
"sim.set_final_time(final_time)\n",
"sim.add_logger(logger)\n",
"\n",
"event_sw = dpsimpy.event.SwitchEvent3Ph(0.5, sw, False)\n",
"sim.add_event(event_sw)\n",
"event_sw1 = dpsimpy.event.SwitchEvent3Ph(0.5, sw, False)\n",
"event_sw2 = dpsimpy.event.SwitchEvent3Ph(1.5, sw, True)\n",
"sim.add_event(event_sw1)\n",
"sim.add_event(event_sw2)\n",
"\n",
"sim.run()"
]
Expand All @@ -381,7 +389,6 @@
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
Expand Down Expand Up @@ -456,7 +463,6 @@
{
"cell_type": "markdown",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
Expand Down Expand Up @@ -547,7 +553,84 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Assertions"
"# Assertions: Compare current through all components"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#1 s ≙ 100'000 steps\n",
"#0.025 s ≙ 2500 steps\n",
"#0.001 s ≙ 100 steps\n",
"\n",
"\n",
"#EMT::Ph1 vs EMT::Ph3 assertions\n",
"\n",
"tolerance = 1e-6\n",
"\n",
"#simulation start: Check between 0.025s and 0.03s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[2500:3000] - ts_dpsim_emt_3ph['r1.i_intf_0'].values[2500:3000]) < tolerance))\n",
"#before open switch: Check between 0.47 and 0.495s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[47000:49500] - ts_dpsim_emt_3ph['r1.i_intf_0'].values[47000:49500]) < tolerance))\n",
"#after open switch: Check between 0.525s and 0.53s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[52500:53000] - ts_dpsim_emt_3ph['r1.i_intf_0'].values[52500:53000]) < tolerance))\n",
"#before close switch: Check between 1.47 and 1.495s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[147000:149500] - ts_dpsim_emt_3ph['r1.i_intf_0'].values[147000:149500]) < tolerance))\n",
"#after close switch: Check between 1.525s and 1.505s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[152500:153000] - ts_dpsim_emt_3ph['r1.i_intf_0'].values[152500:153000]) < tolerance))\n",
"#simulation end: Check between 1.995s and 2s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[199500:200000] - ts_dpsim_emt_3ph['r1.i_intf_0'].values[199500:200000]) < tolerance))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#EMT::Ph1 vs DP\n",
"\n",
"tolerance = 1e-5\n",
"\n",
"#simulation start: Check between 0.025s and 0.03s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[2500:3000] - ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[2500:3000]) < tolerance))\n",
"#before open switch: Check between 0.47 and 0.495s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[47000:49500] - ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[47000:49500]) < tolerance))\n",
"#after open switch: Check between 0.525s and 0.53s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[52500:53000] - ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[52500:53000]) < tolerance))\n",
"#before close switch: Check between 1.47 and 1.495s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[147000:149500] - ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[147000:149500]) < tolerance))\n",
"#after close switch: Check between 1.525s and 1.505s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[152500:153000] - ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[152500:153000]) < tolerance))\n",
"#simulation end: Check between 1.995s and 2s\n",
"assert(np.all(abs(ts_dpsim_emt_1ph['r1.i_intf'].values[199500:200000] - ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[199500:200000]) < tolerance))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#SP vs DP\n",
"\n",
"tolerance = 0.00125\n",
"\n",
"#simulation start: Check between 0.025s and 0.03s\n",
"assert(np.all(abs(ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[2500:3000] - ts_dpsim_sp_1ph_shift['r1.i_intf_shift'].values[2500:3000]) < tolerance))\n",
"#before open switch: Check between 0.47 and 0.495s\n",
"assert(np.all(abs(ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[47000:49500] - ts_dpsim_sp_1ph_shift['r1.i_intf_shift'].values[47000:49500]) < tolerance))\n",
"#after open switch: Check between 0.525s and 0.53s\n",
"assert(np.all(abs(ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[52500:53000] - ts_dpsim_sp_1ph_shift['r1.i_intf_shift'].values[52500:53000]) < tolerance))\n",
"#before close switch: Check between 1.47 and 1.495s\n",
"assert(np.all(abs(ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[147000:149500] - ts_dpsim_sp_1ph_shift['r1.i_intf_shift'].values[147000:149500]) < tolerance))\n",
"#after close switch: Check between 1.525s and 1.505s\n",
"assert(np.all(abs(ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[152500:153000] - ts_dpsim_sp_1ph_shift['r1.i_intf_shift'].values[152500:153000]) < tolerance))\n",
"#simulation end: Check between 1.995s and 2s\n",
"assert(np.all(abs(ts_dpsim_dp_1ph_shift['r1.i_intf_shift'].values[199500:200000] - ts_dpsim_sp_1ph_shift['r1.i_intf_shift'].values[199500:200000]) < tolerance))"
]
}
],
Expand Down

0 comments on commit 64b5021

Please sign in to comment.