diff --git a/exercises/03_ResistiveCompanion/CS_R1L1.ipynb b/exercises/03_ResistiveCompanion/CS_R1L1.ipynb index 6685f2f15d2be00497dde5c494bbcec39c4a326c..db7af77605d4cb129dafc1d95ebba798b62befa6 100644 --- a/exercises/03_ResistiveCompanion/CS_R1L1.ipynb +++ b/exercises/03_ResistiveCompanion/CS_R1L1.ipynb @@ -40,24 +40,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 9, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "3f7630bf6b614af193bf35ddada960d8", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "interactive(children=(SelectionSlider(description='time_step', layout=Layout(height='80px', width='50%'), optiā¦" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "import numpy as np\n", "import ipywidgets as widget\n", @@ -69,22 +54,7 @@ "L1 = 1e-3\n", "I_src= 1\n", "\n", - "G1 = 1/R1\n", - "\n", - "#Slider function to print the selected values and return them the the widget object\n", - "def slider_fun(time_step, total_time):\n", - " print('\\n \\n \\n' + 'Simulation time step is set to: ' + str(time_step) + ' seconds')\n", - " print('Total simulation time: ' + str(total_time) + ' seconds')\n", - " return time_step, total_time\n", - "\n", - "\n", - "#Values range for the simulation steps\n", - "values=[round(i*10**-7, 7) for i in range(101)]\n", - "\n", - "slider= widget.interactive(slider_fun, time_step=widget.SelectionSlider(options=[(\"%g\"%i,i) for i in values], layout=widget.Layout(width='50%', height='80px')), \n", - " total_time=widget.FloatSlider(min=0.0, max=1, step=0.001, layout=widget.Layout(width='50%', height='80px')));\n", - "\n", - "display(slider)\n" + "G1 = 1/R1\n" ] }, { @@ -100,7 +70,7 @@ "source": [ "### Equation of the inductor:\n", "\n", - "$v_L(t) =L*\\frac{di_L}{dt}$\n", + "$v_L(t) =L\\cdot\\frac{di_L}{dt}$\n", "\n", "### Integration: \n", "\n", @@ -139,13 +109,13 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "fd4cce24040444cd92ccfaa7cc144e07", + "model_id": "93d6f8a1da32411cb43dff5eddd258b8", "version_major": 2, "version_minor": 0 }, @@ -159,12 +129,12 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "36e9b8fe6f59456c9075a6649b12477f", + "model_id": "1dab88196f4145beb49c847dfe3eaf6c", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "FloatProgress(value=0.0, max=0.18)" + "FloatProgress(value=0.0, max=0.0002)" ] }, "metadata": {}, @@ -177,7 +147,10 @@ "\n", "#Assign slider values to simulation parameters\n", "model_name = 'CS_R1L1'\n", - "time_step , final_time = slider.result\n", + "time_step = 0.0001\n", + "#Set final time to calculate first two simulation steps\n", + "final_time = 0.0002\n", + "\n", "\n", "# Nodes\n", "gnd = dpsim.emt.Node.GND()\n", @@ -201,15 +174,48 @@ "\n", "logger = dpsim.Logger(model_name)\n", "logger.log_attribute(n1, 'v');\n", - "logger.log_attribute(r1, 'i_intf');\n", - "logger.log_attribute(l1, 'i_intf');\n", + "#logger.log_attribute(r1, 'i_intf');\n", + "#logger.log_attribute(l1, 'i_intf');\n", "\n", - "sim = dpsim.Simulation(model_name, system, timestep=time_step, duration=final_time, pbar=True, sim_type=1,log_level=4)\n", + "sim = dpsim.Simulation(model_name, system, timestep=time_step, duration=final_time, pbar=True, sim_type=1, solver_type=0, log_level=4)\n", "sim.add_logger(logger)\n", "\n", "sim.start()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Plot Results" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "n1.v: -nan\n" + ] + } + ], + "source": [ + "from villas.dataprocessing.readtools import *\n", + "from villas.dataprocessing.timeseries import *\n", + "import re\n", + "\n", + "work_dir = 'logs/'\n", + "model_name = 'CS_R1L1'\n", + "log_path = work_dir + model_name + '.csv'\n", + "ts_dpsim_emt = read_timeseries_dpsim(log_path, print_status=False)\n", + "for key, val in ts_dpsim_emt.items():\n", + " print(key + ': ' + str(val.values[0]))" + ] + }, { "cell_type": "markdown", "metadata": {},