From 5c96c00810d5ae4911ea87067a8ed5363b9ab0e0 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Sun, 24 Mar 2024 17:47:50 +0100 Subject: [PATCH] Add results of DPsim-Matlab co-simulation to the Notebook Signed-off-by: pipeacosta --- examples/Notebooks/cosim-villas-socket.ipynb | 3205 +++++++++++++++++- 1 file changed, 3188 insertions(+), 17 deletions(-) diff --git a/examples/Notebooks/cosim-villas-socket.ipynb b/examples/Notebooks/cosim-villas-socket.ipynb index 7a46ee30dd..e84150b4d0 100644 --- a/examples/Notebooks/cosim-villas-socket.ipynb +++ b/examples/Notebooks/cosim-villas-socket.ipynb @@ -34,7 +34,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -93,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -109,9 +109,171 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Warning: some nodes with margin (3.20,3.20) touch - falling back to straight line edges\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "topology\n", + "\n", + "\n", + "\n", + "gnd\n", + "\n", + "\n", + "\n", + "\n", + "gnd\n", + "\n", + "\n", + "\n", + "n1\n", + "\n", + "\n", + "\n", + "\n", + "n1\n", + "(5.00 V > 0.00°)\n", + "\n", + "\n", + "\n", + "n2\n", + "\n", + "\n", + "\n", + "\n", + "n2\n", + "(2.00 V > 0.00°)\n", + "\n", + "\n", + "\n", + "r_1\n", + "\n", + "\n", + "r_1\n", + "EMT::Ph1::Resistor\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "r_1--gnd\n", + "\n", + "\n", + "\n", + "\n", + "r_1--n1\n", + "\n", + "\n", + "\n", + "\n", + "r_line\n", + "\n", + "\n", + "r_line\n", + "EMT::Ph1::Resistor\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "r_line--n1\n", + "\n", + "\n", + "\n", + "\n", + "r_line--n2\n", + "\n", + "\n", + "\n", + "\n", + "c_1\n", + "\n", + "\n", + "c_1\n", + "EMT::Ph1::Capacitor\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "c_1--gnd\n", + "\n", + "\n", + "\n", + "\n", + "c_1--n1\n", + "\n", + "\n", + "\n", + "\n", + "c_2\n", + "\n", + "\n", + "c_2\n", + "EMT::Ph1::Capacitor\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "c_2--gnd\n", + "\n", + "\n", + "\n", + "\n", + "c_2--n2\n", + "\n", + "\n", + "\n", + "\n", + "r_load\n", + "\n", + "\n", + "r_load\n", + "EMT::Ph1::Resistor\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "r_load--gnd\n", + "\n", + "\n", + "\n", + "\n", + "r_load--n2\n", + "\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "sys" ] @@ -125,9 +287,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "[07:52:58.353939 EMTCosim info] Initialize simulation: EMTCosim\n", + "[07:52:58.354170 MnaSolverFactory info] creating KLUAdapter solver implementation\n", + "[07:52:58.354817 EMTCosim info] Scheduling tasks.\n", + "[07:52:58.355182 EMTCosim info] Scheduling done.\n", + "[07:52:58.355185 EMTCosim info] Opening interfaces.\n", + "[07:52:58.355188 EMTCosim info] Start synchronization with remotes on interfaces\n", + "[07:52:58.355190 EMTCosim info] Synchronized simulation start with remotes\n", + "[07:52:58.355193 EMTCosim info] Start simulation: EMTCosim\n", + "[07:52:58.355200 EMTCosim info] Time step: 1.000000e-06\n", + "[07:52:58.355204 EMTCosim info] Final time: 1.000000e+00\n", + "[07:53:08.913325 EMTCosim info] Simulation calculation time: 10.558085\n", + "[07:53:08.980948 EMTCosim info] Simulation finished.\n" + ] + } + ], "source": [ "time_step = 1e-6\n", "final_time = 1.0\n", @@ -156,7 +337,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -168,8 +349,8 @@ "\n", "i=0\n", "for H in H_v:\n", - " subprocess.run([\"python3\", \"examples/Python/Attributes/emt-cosim-attributes_polynomial.py\", \"-t\", str(time_step), \"-e\", \"1\", \"-H\", str(H), \"-p\", \"EMTCosimAttributes_zoh_\" + H_v_legends[i]], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n", - " subprocess.run([\"python3\", \"examples/Python/Attributes/emt-cosim-attributes_polynomial.py\", \"-t\", str(time_step), \"-e\", \"1\", \"-H\", str(H), \"-i\", \"linear\", \"-p\", \"EMTCosimAttributes_linear_\" + H_v_legends[i]], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n", + " subprocess.run([\"python3\", \"../Python/Attributes/emt-cosim-attributes_polynomial.py\", \"-t\", str(time_step), \"-e\", \"1\", \"-H\", str(H), \"-p\", \"EMTCosimAttributes_zoh_\" + H_v_legends[i]], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n", + " subprocess.run([\"python3\", \"../Python/Attributes/emt-cosim-attributes_polynomial.py\", \"-t\", str(time_step), \"-e\", \"1\", \"-H\", str(H), \"-i\", \"linear\", \"-p\", \"EMTCosimAttributes_linear_\" + H_v_legends[i]], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n", " i+=1\n", "\n", "# TODO: Verify why the villas co-simulation does not log outputs correctly using Popen\n", @@ -185,9 +366,2028 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "column number: 2\n", + "results length: 1000000\n", + "real column names: ['v1', 'v2']\n", + "complex column names: []\n", + "column number: 4\n", + "results length: 1000000\n", + "real column names: ['i', 'ir', 'v1', 'v2']\n", + "complex column names: []\n", + "column number: 4\n", + "results length: 1000000\n", + "real column names: ['i', 'ir', 'v1', 'v2']\n", + "complex column names: []\n", + "column number: 4\n", + "results length: 1000000\n", + "real column names: ['i', 'ir', 'v1', 'v2']\n", + "complex column names: []\n", + "column number: 4\n", + "results length: 1000000\n", + "real column names: ['i', 'ir', 'v1', 'v2']\n", + "complex column names: []\n", + "column number: 4\n", + "results length: 1000000\n", + "real column names: ['i', 'ir', 'v1', 'v2']\n", + "complex column names: []\n", + "column number: 4\n", + "results length: 1000000\n", + "real column names: ['i', 'ir', 'v1', 'v2']\n", + "complex column names: []\n", + "column number: 5\n", + "results length: 1000\n", + "real column names: ['i', 'ir', 'v1', 'v2_S1']\n", + "complex column names: ['V_ref']\n" + ] + }, + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " 2024-03-19T07:53:14.334819\n", + " image/svg+xml\n", + " \n", + " \n", + " Matplotlib v3.8.0, https://matplotlib.org/\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n" + ], + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "%matplotlib inline\n", "%config InlineBackend.figure_format = 'svg'\n", @@ -221,6 +2421,13 @@ "# results_villas1 = rt.read_timeseries_dpsim('../../logs/EMTCosimVILLAS1/EMTCosimVILLAS1.csv')\n", "# results_villas2 = rt.read_timeseries_dpsim('../../logs/EMTCosimVILLAS2/EMTCosimVILLAS2.csv')\n", "\n", + "# Get logs from the co-simulation with Matlab\n", + "results_matlab = rt.read_timeseries_dpsim('logs/EMTCosimUDP1/EMTCosimUDP1.csv')\n", + "\n", + "results_emt_matlab = []\n", + "for series in results_matlab:\n", + " results_emt_matlab.append(results_matlab[series])\n", + "\n", "results_emt_attributes_zoh = {}\n", "\n", "for k, results_att_list in results_attributes_zoh.items():\n", @@ -254,6 +2461,9 @@ "# pt.plot_timeseries('Co-simulation results', results_emt_villas_1[4], '--')\n", "# pt.plot_timeseries('Co-simulation results', results_emt_villas_2[2], '--')\n", "\n", + "pt.plot_timeseries('Co-simulation results', results_emt_matlab[3], '-.')\n", + "pt.plot_timeseries('Co-simulation results', results_emt_matlab[4], '-.')\n", + "\n", "plt.grid()\n", "plt.show()" ] @@ -267,9 +2477,951 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " 2024-03-19T07:53:14.804341\n", + " image/svg+xml\n", + " \n", + " \n", + " Matplotlib v3.8.0, https://matplotlib.org/\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n" + ], + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "global_error_zoh = []\n", "global_error_linear = []\n", @@ -317,9 +3469,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[I] Initialize simulation: EMTCosim\n", + "[I] Scheduling tasks.\n", + "[I] Scheduling done.\n", + "[I] Opening interfaces.\n", + "[I] Start synchronization with remotes on interfaces\n", + "[I] Synchronized simulation start with remotes\n", + "[I] Start simulation: EMTCosim\n", + "[I] Time step: 1.000000e-06\n", + "[I] Final time: 1.000000e+00\n", + "[I] Simulation calculation time: 10.558085\n", + "[I] Simulation finished.\n" + ] + } + ], "source": [ "!cat logs/EMTCosim.log" ] @@ -335,7 +3505,8 @@ "hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a" }, "kernelspec": { - "display_name": "Python 3.9.7 64-bit", + "display_name": "Python 3 (ipykernel)", + "language": "python", "name": "python3" }, "language_info": {