-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test circuits for new diode model
+ add .cpp and python notebook for first diode example circuit + add python pybind notebook for second diode example circuit * modify "dpsim/examples/cxx/CMakeLists.cpp" to include .cpp of first diode example circuit Signed-off-by: Marvin Tollnitsch <[email protected]>
- Loading branch information
1 parent
3c33e6d
commit b15c933
Showing
4 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "../Examples.h" | ||
#include <DPsim.h> | ||
|
||
using namespace DPsim; | ||
using namespace CPS::EMT; | ||
|
||
void EMT_Ph1_Diode() { | ||
// Define simulation scenario | ||
Real timeStep = 0.0001; | ||
Real finalTime = 0.1; | ||
String simName = "EMT_Ph1_Diode_test"; | ||
Logger::setLogDir("logs/" + simName); | ||
|
||
// Nodes | ||
auto n1 = SimNode::make("n1", PhaseType::Single); | ||
auto n2 = SimNode::make("n1", PhaseType::Single); | ||
|
||
// Components | ||
|
||
auto vs0 = Ph1::VoltageSource::make("vs0"); | ||
vs0->setParameters(CPS::Complex(1., 0.), 50.0); | ||
|
||
auto load = CPS::EMT::Ph1::Resistor::make("Load"); | ||
load->setParameters(10.); | ||
|
||
auto diode = Ph1::Diode::make("Diode"); | ||
|
||
// Topology | ||
load->connect(SimNode::List{n1, n2}); | ||
|
||
diode->connect(SimNode::List{n2, SimNode::GND}); //SimNode::GND, n2 | ||
|
||
vs0->connect(SimNode::List{SimNode::GND, n1}); | ||
|
||
// Define system topology | ||
auto sys = SystemTopology(50, SystemNodeList{n1, n2}, | ||
SystemComponentList{load, vs0, diode}); | ||
|
||
// Logging | ||
auto logger = DataLogger::make(simName); | ||
logger->logAttribute("I_Diode", diode->attribute("i_intf")); | ||
logger->logAttribute("V_Diode", diode->attribute("v_intf")); | ||
|
||
Simulation sim(simName, Logger::Level::info); | ||
sim.doInitFromNodesAndTerminals(true); | ||
sim.setSystem(sys); | ||
sim.addLogger(logger); | ||
sim.setDomain(Domain::EMT); | ||
sim.setSolverType(Solver::Type::ITERATIVEMNA); | ||
sim.setDirectLinearSolverConfiguration(DirectLinearSolverConfiguration()); | ||
sim.setTimeStep(timeStep); | ||
sim.setFinalTime(finalTime); | ||
sim.run(); | ||
} | ||
|
||
int main() { | ||
EMT_Ph1_Diode(); | ||
return 0; | ||
} |
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,125 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# EMT Ph3 Linear Circuit SSN" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Run C++ examples" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import subprocess\n", | ||
"\n", | ||
"#%matplotlib widget\n", | ||
"\n", | ||
"name = 'EMT_Ph1_Diode_test'\n", | ||
"\n", | ||
"dpsim_path = subprocess.Popen(['git', 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE).communicate()[0].rstrip().decode('utf-8')\n", | ||
"\n", | ||
"path_exec = dpsim_path + '/build/dpsim/examples/cxx/'\n", | ||
"sim = subprocess.Popen([path_exec + name], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n", | ||
"print(sim.communicate()[0].decode())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from villas.dataprocessing.readtools import *\n", | ||
"from villas.dataprocessing.timeseries import *\n", | ||
"from villas.dataprocessing.timeseries import TimeSeries as ts\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import re\n", | ||
"import numpy as np\n", | ||
"import math\n", | ||
"\n", | ||
"work_dir = os.getcwd() + \"/logs/\"\n", | ||
"path_logfile = work_dir + name + '/' + name + '.csv'\n", | ||
"ts_dpsim_EMT = read_timeseries_dpsim(path_logfile)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Load Results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"plt.close('all')\n", | ||
"fig1 = plt.figure()\n", | ||
"\n", | ||
"plt.plot(ts_dpsim_EMT['V_Diode'].time, ts_dpsim_EMT['V_Diode'].values, \"r-\", label='V_D')\n", | ||
"\n", | ||
"plt.legend(loc = 4)\n", | ||
"#plt.legend(bbox_to_anchor=(1,1))\n", | ||
"\n", | ||
"plt.title('Diode Voltage')\n", | ||
"plt.xlabel('t [s]')\n", | ||
"plt.ylabel('Voltage [V]')\n", | ||
"\n", | ||
"fig2 = plt.figure()\n", | ||
"\n", | ||
"plt.plot(ts_dpsim_EMT['I_Diode'].time, ts_dpsim_EMT['I_Diode'].values, \"r-\", label='I_D')\n", | ||
"\n", | ||
"plt.legend(loc = 4)\n", | ||
"#plt.legend(bbox_to_anchor=(1,1))\n", | ||
"\n", | ||
"plt.title('Diode Current')\n", | ||
"plt.xlabel('t [s]')\n", | ||
"plt.ylabel('Current [A]')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"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.9.13" | ||
}, | ||
"tests": { | ||
"skip": false | ||
} | ||
}, | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from villas.dataprocessing.readtools import *\n", | ||
"from villas.dataprocessing.timeseries import *\n", | ||
"from villas.dataprocessing.timeseries import TimeSeries as ts\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import numpy as np\n", | ||
"import dpsimpy\n", | ||
"import re\n", | ||
"import os\n", | ||
"\n", | ||
"%matplotlib widget\n", | ||
"\n", | ||
"#Define simulation scenario\n", | ||
"time_step = 0.0001\n", | ||
"final_time = 0.1 #0.006\n", | ||
"simName = \"EMT_Ph1_VS_R1_Diode\"\n", | ||
"\n", | ||
"dpsimpy.Logger.set_log_dir('logs/' + simName)\n", | ||
"\n", | ||
"#Nodes\n", | ||
"gnd = dpsimpy.emt.SimNode.gnd\n", | ||
"n1 = dpsimpy.emt.SimNode(\"n1\", dpsimpy.PhaseType.Single)\n", | ||
"n2 = dpsimpy.emt.SimNode(\"n2\", dpsimpy.PhaseType.Single)\n", | ||
"\n", | ||
"#Components\n", | ||
"vs = dpsimpy.emt.ph1.VoltageSource(\"vs\")\n", | ||
"vs.set_parameters(complex(1.,0.), 50.0);\n", | ||
"\n", | ||
"load = dpsimpy.emt.ph1.Resistor(\"r1\")\n", | ||
"load.set_parameters(10.)\n", | ||
"\n", | ||
"diode = dpsimpy.emt.ph1.Diode(\"Diode\");\n", | ||
"\n", | ||
"#Topology\n", | ||
"vs.connect([gnd, n1]);\n", | ||
"load.connect([n2, n1]);\n", | ||
"diode.connect([gnd, n2]);\n", | ||
"\n", | ||
"sys = dpsimpy.SystemTopology(50, [n1, n2], [vs, load, diode])\n", | ||
"\n", | ||
"#Logging\n", | ||
"logger = dpsimpy.Logger(simName)\n", | ||
"logger.log_attribute(\"I_Diode\", \"i_intf\", diode)\n", | ||
"logger.log_attribute(\"V_Diode\", \"v_intf\", diode)\n", | ||
"logger.log_attribute(\"V_Resistor\", \"v_intf\", load)\n", | ||
"logger.log_attribute(\"V_VS\", \"v_intf\", vs)\n", | ||
"\n", | ||
"# Simulation\n", | ||
"sim = dpsimpy.Simulation(simName)\n", | ||
"sim.set_system(sys)\n", | ||
"sim.set_time_step(time_step)\n", | ||
"sim.set_final_time(final_time)\n", | ||
"sim.set_domain(dpsimpy.Domain.EMT)\n", | ||
"sim.set_solver(dpsimpy.Solver.ITERATIVEMNA)\n", | ||
"sim.add_logger(logger)\n", | ||
"sim.run()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"path_logfile = os.getcwd() + \"/logs/\" + simName + '/' + simName + '.csv'\n", | ||
"ts_dpsim_EMT = read_timeseries_dpsim(path_logfile)\n", | ||
"\n", | ||
"plt.close('all')\n", | ||
"fig1 = plt.figure()\n", | ||
"\n", | ||
"plt.plot(ts_dpsim_EMT['V_Diode'].time, ts_dpsim_EMT['V_Diode'].values, \"b-\", label='V_D')\n", | ||
"plt.plot(ts_dpsim_EMT['V_Resistor'].time, ts_dpsim_EMT['V_Resistor'].values, \"g-\", label='V_R')\n", | ||
"#plt.plot(ts_dpsim_EMT['V_VS'].time, ts_dpsim_EMT['V_VS'].values, \"r-\", label='V_VS')\n", | ||
"\n", | ||
"#difference = ts_dpsim_EMT['V_VS'].values - (ts_dpsim_EMT['V_Resistor'].values+ts_dpsim_EMT['V_Diode'].values)\n", | ||
"#plt.plot(ts_dpsim_EMT['V_VS'].time, difference, \"b-\", label='difference')\n", | ||
"\n", | ||
"plt.legend(loc = 4)\n", | ||
"#plt.legend(bbox_to_anchor=(1,1))\n", | ||
"\n", | ||
"plt.title('Voltages')\n", | ||
"plt.xlabel('t [s]')\n", | ||
"plt.ylabel('Voltage [V]')\n", | ||
"\n", | ||
"fig2 = plt.figure()\n", | ||
"\n", | ||
"plt.plot(ts_dpsim_EMT['I_Diode'].time, ts_dpsim_EMT['I_Diode'].values, \"r-\", label='I_D')\n", | ||
"\n", | ||
"plt.legend(loc = 4)\n", | ||
"\n", | ||
"plt.title('Diode Current')\n", | ||
"plt.xlabel('t [s]')\n", | ||
"plt.ylabel('Current [A]')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"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.9.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |