-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement print function for attribute lists
Signed-off-by: Jonas Schroeder <jonas.schroeder1@rwth-aachen.de>
- Loading branch information
Showing
4 changed files
with
332 additions
and
1 deletion.
There are no files selected for viewing
283 changes: 283 additions & 0 deletions
283
Examples/Notebooks/Circuits/CS_R2CL print_attributes.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,283 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Circuit CS_R2CL" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import villas.dataprocessing.readtools as rt\n", | ||
"import villas.dataprocessing.plottools as pt\n", | ||
"from villas.dataprocessing.timeseries import TimeSeries as ts" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## DPsim EMT" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# DPsim EMT simulation\n", | ||
"import dpsimpy\n", | ||
"\n", | ||
"name = 'EMT_CS_R2CL'\n", | ||
"\n", | ||
"# Nodes\n", | ||
"gnd = dpsimpy.emt.SimNode.gnd\n", | ||
"n1 = dpsimpy.emt.SimNode('n1')\n", | ||
"n2 = dpsimpy.emt.SimNode('n2')\n", | ||
"\n", | ||
"# Components\n", | ||
"cs = dpsimpy.emt.ph1.CurrentSource('cs')\n", | ||
"cs.I_ref = complex(10, 0)\n", | ||
"cs.f_src = 50\n", | ||
"r1 = dpsimpy.emt.ph1.Resistor('r_1')\n", | ||
"r1.R = 1\n", | ||
"c1 = dpsimpy.emt.ph1.Capacitor('c_1')\n", | ||
"c1.C = 0.001\n", | ||
"l1 = dpsimpy.emt.ph1.Inductor('l_1')\n", | ||
"l1.L = 0.001\n", | ||
"r2 = dpsimpy.emt.ph1.Resistor('r_2')\n", | ||
"r2.R = 1\n", | ||
"\n", | ||
"cs.print_attributes()\n", | ||
"r1.print_attributes()\n", | ||
"c1.print_attributes()\n", | ||
"l1.print_attributes()\n", | ||
"r2.print_attributes()\n", | ||
"\n", | ||
"# Connections\n", | ||
"cs.connect([gnd, n1])\n", | ||
"r1.connect([n1, gnd])\n", | ||
"c1.connect([n1, n2])\n", | ||
"l1.connect([n2, gnd])\n", | ||
"r2.connect([n2, gnd])\n", | ||
"\n", | ||
"# Define system topology\n", | ||
"system = dpsimpy.SystemTopology(50, [gnd, n1, n2], [cs, r1, c1, l1, r2])\n", | ||
"\n", | ||
"# Logging\n", | ||
"logger = dpsimpy.Logger(name)\n", | ||
"logger.log_attribute('n1.v', 'v', n1)\n", | ||
"logger.log_attribute('n2.v', 'v', n2)\n", | ||
"logger.log_attribute('cs.i_intf', 'i_intf', cs)\n", | ||
"logger.log_attribute('c_1.i_intf', 'i_intf', c1)\n", | ||
"\n", | ||
"sim = dpsimpy.Simulation(name)\n", | ||
"sim.set_domain(dpsimpy.Domain.EMT)\n", | ||
"sim.set_system(system)\n", | ||
"sim.set_time_step(0.0001)\n", | ||
"sim.set_final_time(0.1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sim.add_logger(logger)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sim.run()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# read EMT results\n", | ||
"work_dir = 'logs/'\n", | ||
"log_name = 'EMT_CS_R2CL'\n", | ||
"print(work_dir + log_name + '.csv')\n", | ||
"\n", | ||
"ts_dpsim_emt = rt.read_timeseries_dpsim(work_dir + log_name + '.csv')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"v1_emt = 'n1.v'\n", | ||
"v2_emt = 'n2.v'\n", | ||
"i01_emt = 'cs.i_intf'\n", | ||
"i12_emt = 'c_1.i_intf'\n", | ||
"\n", | ||
"ts_dpsim_emt[v1_emt].label = 'v1 EMT'\n", | ||
"ts_dpsim_emt[v2_emt].label = 'v2 EMT'\n", | ||
"ts_dpsim_emt[i01_emt].label = 'i01 EMT'\n", | ||
"ts_dpsim_emt[i12_emt].label = 'i12 EMT'\n", | ||
"pt.plot_timeseries(1, ts_dpsim_emt[v1_emt])\n", | ||
"pt.plot_timeseries(1, ts_dpsim_emt[v2_emt])\n", | ||
"pt.plot_timeseries(2, ts_dpsim_emt[i01_emt])\n", | ||
"pt.plot_timeseries(2, ts_dpsim_emt[i12_emt])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## DPsim DP" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# DPsim DP simulation\n", | ||
"import dpsimpy\n", | ||
"\n", | ||
"name = 'DP_CS_R2CL'\n", | ||
"\n", | ||
"# Nodes\n", | ||
"gnd = dpsimpy.dp.SimNode.gnd\n", | ||
"n1 = dpsimpy.dp.SimNode('n1')\n", | ||
"n2 = dpsimpy.dp.SimNode('n2')\n", | ||
"\n", | ||
"# Components\n", | ||
"cs = dpsimpy.dp.ph1.CurrentSource('cs')\n", | ||
"cs.I_ref = complex(10,0)\n", | ||
"r1 = dpsimpy.dp.ph1.Resistor('r_1')\n", | ||
"r1.R = 1\n", | ||
"c1 = dpsimpy.dp.ph1.Capacitor('c_1')\n", | ||
"c1.C = 0.001\n", | ||
"l1 = dpsimpy.dp.ph1.Inductor('l_1')\n", | ||
"l1.L = 0.001\n", | ||
"r2 = dpsimpy.dp.ph1.Resistor('r_2')\n", | ||
"r2.R = 1\n", | ||
"\n", | ||
"cs.print_attributes()\n", | ||
"r1.print_attributes()\n", | ||
"c1.print_attributes()\n", | ||
"l1.print_attributes()\n", | ||
"r2.print_attributes()\n", | ||
"\n", | ||
"# Connections\n", | ||
"cs.connect([gnd, n1])\n", | ||
"r1.connect([n1, gnd])\n", | ||
"c1.connect([n1, n2])\n", | ||
"l1.connect([n2, gnd])\n", | ||
"r2.connect([n2, gnd])\n", | ||
"\n", | ||
"# Define system topology\n", | ||
"system = dpsimpy.SystemTopology(50, [gnd, n1, n2], [cs, r1, c1, l1, r2]);\n", | ||
"\n", | ||
"# Logging\n", | ||
"logger = dpsimpy.Logger(name)\n", | ||
"logger.log_attribute('n1.v', 'v', n1)\n", | ||
"logger.log_attribute('n2.v', 'v', n2)\n", | ||
"logger.log_attribute('cs.i_intf', 'i_intf', cs)\n", | ||
"logger.log_attribute('c_1.i_intf', 'i_intf', c1)\n", | ||
"\n", | ||
"sim = dpsimpy.Simulation(name)\n", | ||
"sim.set_system(system)\n", | ||
"sim.set_domain(dpsimpy.Domain.DP)\n", | ||
"sim.set_time_step(0.0001)\n", | ||
"sim.set_final_time(0.1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sim.add_logger(logger)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sim.run()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# read DP results\n", | ||
"work_dir = 'logs/'\n", | ||
"log_name = 'DP_CS_R2CL'\n", | ||
"print(work_dir + log_name + '.csv')\n", | ||
"\n", | ||
"ts_dpsim_dp = rt.read_timeseries_dpsim(work_dir + log_name + '.csv')\n", | ||
"\n", | ||
"#convert to emt\n", | ||
"ts_dpsim_dp_emt = ts.frequency_shift_list(ts_dpsim_dp, 50)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"v1_dp = 'n1.v_shift'\n", | ||
"v2_dp = 'n2.v_shift'\n", | ||
"i01_dp = 'cs.i_intf_shift'\n", | ||
"i12_dp = 'c_1.i_intf_shift'\n", | ||
"\n", | ||
"ts_dpsim_dp_emt[v1_dp].label = 'v1 DP'\n", | ||
"ts_dpsim_dp_emt[v2_dp].label = 'v2 DP'\n", | ||
"ts_dpsim_dp_emt[i01_dp].label = 'i01 DP'\n", | ||
"ts_dpsim_dp_emt[i12_dp].label = 'i12 DP'\n", | ||
"pt.plot_timeseries(1, ts_dpsim_dp_emt[v1_dp])\n", | ||
"pt.plot_timeseries(1, ts_dpsim_dp_emt[v2_dp])\n", | ||
"pt.plot_timeseries(2, ts_dpsim_dp_emt[i01_dp])\n", | ||
"pt.plot_timeseries(2, ts_dpsim_dp_emt[i12_dp])" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.7" | ||
}, | ||
"orig_nbformat": 3 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters