diff --git a/examples/Notebooks/Circuits/VS_SW_RL1.ipynb b/examples/Notebooks/Circuits/VS_SW_RL1.ipynb index 2c0e555e7..54b5b41a2 100644 --- a/examples/Notebooks/Circuits/VS_SW_RL1.ipynb +++ b/examples/Notebooks/Circuits/VS_SW_RL1.ipynb @@ -23,7 +23,7 @@ "import numpy as np\n", "import dpsimpy\n", "\n", - "# %matplotlib widget" + "#%matplotlib widget" ] }, { @@ -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", @@ -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()" ] @@ -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", @@ -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", @@ -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()" ] @@ -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", @@ -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", @@ -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()" ] @@ -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", @@ -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()" ] @@ -381,7 +389,6 @@ { "cell_type": "markdown", "metadata": { - "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ @@ -456,7 +463,6 @@ { "cell_type": "markdown", "metadata": { - "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ @@ -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))" ] } ],