Skip to content

Commit

Permalink
Rename and improve plotting of co-simulation Notebook
Browse files Browse the repository at this point in the history
Signed-off-by: pipeacosta <pipeacosta@gmail.com>
  • Loading branch information
pipeacosta committed Jul 1, 2024
1 parent df8002b commit accc8d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@
"import subprocess\n",
"import numpy as np\n",
"\n",
"H_v = np.array([1e-4, 2e-4, 4e-4])\n",
"H_v_legends = ['1e-4', '2e-4', '4e-4']\n",
"H_v = np.array([1e-4, 2e-4, 4e-4, 0.001, 0.003, 0.01])\n",
"H_v_legends = ['1e-4', '2e-4', '4e-4', '1e-3', '3e-3', '1e-2']\n",
"\n",
"i=0\n",
"for H in H_v:\n",
Expand Down Expand Up @@ -236,7 +236,6 @@
"import villas.dataprocessing.plottools as pt\n",
"import villas.dataprocessing.readtools as rt\n",
"import villas.dataprocessing.timeseries as ts\n",
"%matplotlib widget\n",
"\n",
"results = rt.read_timeseries_dpsim('logs/EMTCosim.csv')\n",
"\n",
Expand Down Expand Up @@ -365,18 +364,18 @@
" v_zoh = np.array([ts_1_zoh.values[::m], ts_2_zoh.values[::m]])\n",
" v_linear = np.array([ts_1_linear.values[::m], ts_2_linear.values[::m]])\n",
" \n",
" gloal_error_zoh_t = np.mean(np.linalg.norm(v_a - v_zoh, axis=0))\n",
" gloal_error_zoh_t = np.max(np.linalg.norm(v_a - v_zoh, axis=0))\n",
" \n",
" global_error_zoh.append(gloal_error_zoh_t)\n",
" global_error_linear.append(np.mean(np.linalg.norm(v_a - v_linear, axis=0)))\n",
" global_error_linear.append(np.max(np.linalg.norm(v_a - v_linear, axis=0)))\n",
" \n",
"plt.figure()\n",
"plt.plot(np.log10(H_v), np.log10(global_error_zoh), 'b', label='ZOH')\n",
"plt.plot(np.log10(H_v), np.log10(global_error_zoh), 'bo')\n",
"plt.plot(np.log10(H_v), np.log10(np.multiply(H_v, 10**0.85)), 'k', label=r'$\\mathcal{O}(H)$')\n",
"plt.plot(np.log10(H_v), np.log10(np.multiply(H_v, 10*0.012)), 'k', label=r'$\\mathcal{O}(H)$')\n",
"plt.plot(np.log10(H_v), np.log10(global_error_linear), 'r', label='Linear')\n",
"plt.plot(np.log10(H_v), np.log10(global_error_linear), 'ro')\n",
"plt.plot(np.log10(H_v), np.log10(np.multiply(H_v**2, 10**2.9)), '--k', label=r'$\\mathcal{O}(H^2)$')\n",
"plt.plot(np.log10(H_v), np.log10(np.multiply(H_v**2, 10**1.5)), '--k', label=r'$\\mathcal{O}(H^2)$')\n",
"plt.xlabel('')\n",
"# TODO: Fix log scale\n",
"# plt.xscale(\"log\")\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ def set_dpsim2(t_s, t_f, vs_cond, logger_prefix):

# We have to assume the trajectory of y_2 extending its initial value, since we have no prior information
# y_1_m_prev = np.tile(y_1_0, m)

# This one as computed in Matlab
y_1_m_prev = np.array([30.108, y_1_0])
y_1_m_prev = np.array([complex(0, 0), y_1_0])

for i in range(0, N):
y_1_prev = y_1_m_prev[-1]
Expand Down

0 comments on commit accc8d1

Please sign in to comment.