From ec879e140852fc3166bd09901263d49dec34a5c4 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Tue, 8 Oct 2024 10:32:58 +0000 Subject: [PATCH 01/19] Implement DP's RXLoad clone method. Signed-off-by: pipeacosta --- dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h | 2 ++ dpsim-models/src/DP/DP_Ph1_RXLoad.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h b/dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h index b9b86f553a..b2b09d611a 100644 --- a/dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h +++ b/dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h @@ -51,6 +51,8 @@ class RXLoad : public CompositePowerComp, /// Defines name, component parameters and logging level RXLoad(String name, Logger::Level logLevel = Logger::Level::off); + SimPowerComp::Ptr clone(String name); + // #### General #### /// Initialize component from power flow data void initializeFromNodesAndTerminals(Real frequency) override; diff --git a/dpsim-models/src/DP/DP_Ph1_RXLoad.cpp b/dpsim-models/src/DP/DP_Ph1_RXLoad.cpp index 03f53ef9b6..c844644c8c 100644 --- a/dpsim-models/src/DP/DP_Ph1_RXLoad.cpp +++ b/dpsim-models/src/DP/DP_Ph1_RXLoad.cpp @@ -25,6 +25,12 @@ DP::Ph1::RXLoad::RXLoad(String uid, String name, Logger::Level logLevel) DP::Ph1::RXLoad::RXLoad(String name, Logger::Level logLevel) : RXLoad(name, name, logLevel) {} +SimPowerComp::Ptr DP::Ph1::RXLoad::clone(String name) { + auto copy = RXLoad::make(name, mLogLevel); + copy->setParameters(**mActivePower, **mReactivePower, **mNomVoltage); + return copy; +} + void DP::Ph1::RXLoad::initializeFromNodesAndTerminals(Real frequency) { if (!mParametersSet) { From 41e799218038dbe85590db5a04ba0f7fdcc4fb09 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Tue, 8 Oct 2024 10:33:50 +0000 Subject: [PATCH 02/19] Log bus voltages and adapt relative path to work with Notebook WSCC_9bus_parallel.ipynb. Signed-off-by: pipeacosta --- .../cxx/CIM/WSCC_9bus_mult_coupled.cpp | 28 +++++++++---------- .../cxx/CIM/WSCC_9bus_mult_decoupled.cpp | 28 +++++++++---------- .../cxx/CIM/WSCC_9bus_mult_diakoptics.cpp | 28 +++++++++---------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp index e48e417d65..99a2cdaa09 100644 --- a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp +++ b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp @@ -87,19 +87,19 @@ void simulateCoupled(std::list filenames, CommandLineArgs &args, sim.setScheduler(std::make_shared(threads)); // Logging - //auto logger = DataLogger::make(simName); - //for (Int cop = 1; cop <= copies; cop++) { - // for (Int bus = 1; bus <= 9; bus++) { - // String attrName = "v" + std::to_string(bus) + "_" + std::to_string(cop); - // String nodeName = "BUS" + std::to_string(bus) + "_" + std::to_string(cop); - // if (cop == 1) { - // attrName = "v" + std::to_string(bus); - // nodeName = "BUS" + std::to_string(bus); - // } - // logger->logAttribute(attrName, sys.node(nodeName)->attribute("v")); - // } - //} - //sim.addLogger(logger); + auto logger = DataLogger::make(simName); + for (Int cop = 1; cop <= copies; cop++) { + for (Int bus = 1; bus <= 9; bus++) { + String attrName = "v" + std::to_string(bus) + "_" + std::to_string(cop); + String nodeName = "BUS" + std::to_string(bus) + "_" + std::to_string(cop); + if (cop == 1) { + attrName = "v" + std::to_string(bus); + nodeName = "BUS" + std::to_string(bus); + } + logger->logAttribute(attrName, sys.node(nodeName)->attribute("v")); + } + } + sim.addLogger(logger); sim.run(); sim.logStepTimes(simName + "_step_times"); @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) { filenames = DPsim::Utils::findFiles( {"WSCC-09_RX_DI.xml", "WSCC-09_RX_EQ.xml", "WSCC-09_RX_SV.xml", "WSCC-09_RX_TP.xml"}, - "build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); + "../../../build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); //for (Int copies = 0; copies < 20; copies++) { // for (Int threads = 0; threads <= 12; threads = threads+2) diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp index acd4fe3d91..da9e15e6f6 100644 --- a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp +++ b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp @@ -67,19 +67,19 @@ void simulateDecoupled(std::list filenames, Int copies, Int threads, sim.setScheduler(std::make_shared(threads)); // Logging - //auto logger = DataLogger::make(simName); - //for (Int cop = 1; cop <= copies; cop++) { - // for (Int bus = 1; bus <= 9; bus++) { - // String attrName = "v" + std::to_string(bus) + "_" + std::to_string(cop); - // String nodeName = "BUS" + std::to_string(bus) + "_" + std::to_string(cop); - // if (cop == 1) { - // attrName = "v" + std::to_string(bus); - // nodeName = "BUS" + std::to_string(bus); - // } - // logger->logAttribute(attrName, sys.node(nodeName)->attribute("v")); - // } - //} - //sim.addLogger(logger); + auto logger = DataLogger::make(simName); + for (Int cop = 1; cop <= copies; cop++) { + for (Int bus = 1; bus <= 9; bus++) { + String attrName = "v" + std::to_string(bus) + "_" + std::to_string(cop); + String nodeName = "BUS" + std::to_string(bus) + "_" + std::to_string(cop); + if (cop == 1) { + attrName = "v" + std::to_string(bus); + nodeName = "BUS" + std::to_string(bus); + } + logger->logAttribute(attrName, sys.node(nodeName)->attribute("v")); + } + } + sim.addLogger(logger); //std::ofstream of1("topology_graph.svg"); //sys.topologyGraph().render(of1)); @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) { filenames = DPsim::Utils::findFiles( {"WSCC-09_RX_DI.xml", "WSCC-09_RX_EQ.xml", "WSCC-09_RX_SV.xml", "WSCC-09_RX_TP.xml"}, - "build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); + "../../../build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); //for (Int copies = 0; copies < 10; copies++) { // for (Int threads = 0; threads <= 12; threads = threads+2) diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp index ae78a09f89..7b90ea9ebe 100644 --- a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp +++ b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp @@ -88,19 +88,19 @@ void simulateDiakoptics(std::list filenames, Int copies, Int threads, sim.setTearingComponents(sys.mTearComponents); // Logging - //auto logger = DataLogger::make(simName); - //for (Int cop = 1; cop <= copies; cop++) { - // for (Int bus = 1; bus <= 9; bus++) { - // String attrName = "v" + std::to_string(bus) + "_" + std::to_string(cop); - // String nodeName = "BUS" + std::to_string(bus) + "_" + std::to_string(cop); - // if (cop == 1) { - // attrName = "v" + std::to_string(bus); - // nodeName = "BUS" + std::to_string(bus); - // } - // logger->logAttribute(attrName, sys.node(nodeName)->attribute("v")); - // } - //} - //sim.addLogger(logger); + auto logger = DataLogger::make(simName); + for (Int cop = 1; cop <= copies; cop++) { + for (Int bus = 1; bus <= 9; bus++) { + String attrName = "v" + std::to_string(bus) + "_" + std::to_string(cop); + String nodeName = "BUS" + std::to_string(bus) + "_" + std::to_string(cop); + if (cop == 1) { + attrName = "v" + std::to_string(bus); + nodeName = "BUS" + std::to_string(bus); + } + logger->logAttribute(attrName, sys.node(nodeName)->attribute("v")); + } + } + sim.addLogger(logger); sim.run(); sim.logStepTimes(simName + "_step_times"); @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) { filenames = DPsim::Utils::findFiles( {"WSCC-09_RX_DI.xml", "WSCC-09_RX_EQ.xml", "WSCC-09_RX_SV.xml", "WSCC-09_RX_TP.xml"}, - "build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); + "../../../build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); //for (Int copies = 0; copies < 10; copies++) { // for (Int threads = 0; threads <= 12; threads = threads+2) { From 7fc21fb435637eb9551f0f14b9b7d3b56fa484ea Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Tue, 8 Oct 2024 10:35:41 +0000 Subject: [PATCH 03/19] Change domain to DP in reference system. Signed-off-by: pipeacosta --- dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp b/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp index bf3a79dc53..dc33f22b2e 100644 --- a/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp +++ b/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp @@ -30,11 +30,11 @@ int main(int argc, char *argv[]) { "build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); timeStep = 100e-6; - finalTime = 0.1; + finalTime = 0.5; } else { filenames = std::list(argv + 1, argv + argc); - timeStep = args.timeStep; - finalTime = args.duration; + // timeStep = args.timeStep; + // finalTime = args.duration; } // ----- POWERFLOW FOR INITIALIZATION ----- @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) { SystemTopology sys = reader2.loadCIM(60, filenames, Domain::DP, PhaseType::Single, CPS::GeneratorType::IdealVoltageSource); - sys.initWithPowerflow(systemPF, CPS::Domain::EMT); + sys.initWithPowerflow(systemPF, CPS::Domain::DP); // Logging auto logger = DataLogger::make(simName); @@ -88,10 +88,10 @@ int main(int argc, char *argv[]) { logger->logAttribute("v9", sys.node("BUS9")->attribute("v")); // log generator's current - for (auto comp : sys.mComponents) { - if (std::dynamic_pointer_cast(comp)) - logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf")); - } + // for (auto comp : sys.mComponents) { + // if (std::dynamic_pointer_cast(comp)) + // logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf")); + // } Simulation sim(simName, Logger::Level::info); sim.setSystem(sys); From 91a8e0efef7d5c70f36a4a3ed1dc805b974878df Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Tue, 8 Oct 2024 10:37:09 +0000 Subject: [PATCH 04/19] Use one copy in parallel testing Notebook. Signed-off-by: pipeacosta --- .../Performance/WSCC_9bus_parallel.ipynb | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb b/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb index d237c134b5..3ecacc9ef3 100644 --- a/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb +++ b/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb @@ -17,7 +17,9 @@ "TOP=${TOP:-$(git rev-parse --show-toplevel)}\n", "PATH=${TOP}/build/dpsim/examples/cxx\n", "\n", - "WSCC_9bus_mult_coupled ${TOP}/examples/CIM/WSCC-09_RX/*.xml" + "echo ${TOP}\n", + "\n", + "WSCC_9bus_mult_coupled ${TOP}/examples/cxx/CIM/WSCC-09_RX/*.xml -o copies=1" ] }, { @@ -30,7 +32,7 @@ "TOP=${TOP:-$(git rev-parse --show-toplevel)}\n", "PATH=${TOP}/build/dpsim/examples/cxx\n", "\n", - "WSCC_9bus_mult_decoupled ${TOP}/examples/CIM/WSCC-09_RX/*.xml" + "WSCC_9bus_mult_decoupled ${TOP}/examples/CIM/WSCC-09_RX/*.xml -o copies=1" ] }, { @@ -43,7 +45,7 @@ "TOP=${TOP:-$(git rev-parse --show-toplevel)}\n", "PATH=${TOP}/build/dpsim/examples/cxx\n", "\n", - "WSCC_9bus_mult_diakoptics ${TOP}/examples/CIM/WSCC-09_RX/*.xml" + "WSCC_9bus_mult_diakoptics ${TOP}/examples/CIM/WSCC-09_RX/*.xml -o copies=1" ] }, { @@ -72,8 +74,8 @@ "metadata": {}, "outputs": [], "source": [ - "path = 'logs/WSCC_9bus_coupled/'\n", - "logName = 'WSCC_9bus_coupled'\n", + "path = 'logs/WSCC_9bus_coupled_1_0_0/'\n", + "logName = 'WSCC_9bus_coupled_1_0_0'\n", "logFilename = path + logName + '.csv'\n", "print(logFilename)\n", "\n", @@ -87,8 +89,8 @@ "metadata": {}, "outputs": [], "source": [ - "path = 'logs/WSCC_9bus_decoupled/'\n", - "logName = 'WSCC_9bus_decoupled'\n", + "path = 'logs/WSCC_9bus_decoupled_1_0_0/'\n", + "logName = 'WSCC_9bus_decoupled_1_0_0'\n", "logFilename = path + logName + '.csv'\n", "print(logFilename)\n", "\n", @@ -102,8 +104,8 @@ "metadata": {}, "outputs": [], "source": [ - "path = 'logs/WSCC_9bus_diakoptics/'\n", - "logName = 'WSCC_9bus_diakoptics'\n", + "path = 'logs/WSCC_9bus_diakoptics_1_0_0_0/'\n", + "logName = 'WSCC_9bus_diakoptics_1_0_0_0'\n", "logFilename = path + logName + '.csv'\n", "print(logFilename)\n", "\n", @@ -517,7 +519,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.5" + "version": "3.10.11" }, "tests": { "skip": true From 0ea4742584ac4f4b02c4c47f8828d1948c2be73b Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Mon, 14 Oct 2024 08:24:15 +0000 Subject: [PATCH 05/19] Implement removeComponent method. Signed-off-by: pipeacosta --- dpsim-models/include/dpsim-models/SystemTopology.h | 4 ++++ dpsim-models/src/SystemTopology.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/dpsim-models/include/dpsim-models/SystemTopology.h b/dpsim-models/include/dpsim-models/SystemTopology.h index b0178c49e9..2be2e3b456 100644 --- a/dpsim-models/include/dpsim-models/SystemTopology.h +++ b/dpsim-models/include/dpsim-models/SystemTopology.h @@ -147,6 +147,10 @@ class SystemTopology { /// Copy the whole topology the given number of times and add the resulting components and nodes to the topology. void multiply(Int numberCopies); + /// @brief Remove system component + /// @param name name of the component + void removeComponent(const String &name); + /// template int checkTopologySubnets( diff --git a/dpsim-models/src/SystemTopology.cpp b/dpsim-models/src/SystemTopology.cpp index 217100d784..93f3502314 100644 --- a/dpsim-models/src/SystemTopology.cpp +++ b/dpsim-models/src/SystemTopology.cpp @@ -243,6 +243,14 @@ void SystemTopology::reset() { // } } +void SystemTopology::removeComponent(const String &name) { + for (auto it = mComponents.begin(); it != mComponents.end(); ++it) { + if ((*it)->name() == name) { + mComponents.erase(it); + } + } +} + template void SystemTopology::splitSubnets(std::vector &splitSystems) { std::unordered_map::Ptr, int> subnet; From 261f3bb278852404997149bdf4f222930c154cb7 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Mon, 14 Oct 2024 08:25:17 +0000 Subject: [PATCH 06/19] Implement add and remove component functions in dpsimpy. Signed-off-by: pipeacosta --- dpsim/src/pybind/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dpsim/src/pybind/main.cpp b/dpsim/src/pybind/main.cpp index a1392119e1..697d1dabf6 100644 --- a/dpsim/src/pybind/main.cpp +++ b/dpsim/src/pybind/main.cpp @@ -200,6 +200,8 @@ PYBIND11_MODULE(dpsimpy, m) { .def("do_steady_state_init", &DPsim::Simulation::doSteadyStateInit) .def("do_frequency_parallelization", &DPsim::Simulation::doFrequencyParallelization) + .def("do_split_subnets", + &DPsim::Simulation::doSplitSubnets) .def("set_tearing_components", &DPsim::Simulation::setTearingComponents) .def("add_event", &DPsim::Simulation::addEvent) .def("set_solver_component_behaviour", @@ -260,7 +262,10 @@ PYBIND11_MODULE(dpsimpy, m) { .def_readonly("tear_components", &DPsim::SystemTopology::mTearComponents) .def("list_idobjects", &DPsim::SystemTopology::listIdObjects) .def("init_with_powerflow", &DPsim::SystemTopology::initWithPowerflow, - "systemPF"_a, "domain"_a); + "systemPF"_a, "domain"_a) + .def("add_component", &DPsim::SystemTopology::addComponent) + .def("add_components", &DPsim::SystemTopology::addComponents) + .def("remove_component", &DPsim::SystemTopology::removeComponent); py::class_>(m, "Interface"); From 177c85d83c9fef9ec9c8eb6a17d739f5999d0d05 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Mon, 14 Oct 2024 08:28:22 +0000 Subject: [PATCH 07/19] Update decoupling_9bus_existing python script. Signed-off-by: pipeacosta --- .../RuntimeMeas/decoupling_9bus_existing.py | 53 +++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/examples/Python/RuntimeMeas/decoupling_9bus_existing.py b/examples/Python/RuntimeMeas/decoupling_9bus_existing.py index 905697988b..d678fdfada 100644 --- a/examples/Python/RuntimeMeas/decoupling_9bus_existing.py +++ b/examples/Python/RuntimeMeas/decoupling_9bus_existing.py @@ -1,11 +1,11 @@ #!/usr/bin/python3 +import subprocess import asyncio -import dpsim +import dpsimpy import glob import time import logging -from dpsim.Event import Event import villas.dataprocessing.readtools as rt import villas.dataprocessing.plottools as pt @@ -13,41 +13,64 @@ import matplotlib.pyplot as plt def decouple_line(sys, line, node1, node2): - orig_line = system.components[line] + orig_line = system.component(line) sys.remove_component(line) - sys.add_decoupling_line(line, sys.nodes[node1], sys.nodes[node2], orig_line.R_series, orig_line.L_series, orig_line.C_parallel) + R_line = orig_line.attr('R_series').get() + L_line = orig_line.attr('L_series').get() + C_line = orig_line.attr('C_parallel').get() + + line = dpsimpy.signal.DecouplingLine('dline_' + node1 + '_' + node2, + dpsimpy.LogLevel.info) + line.set_parameters(sys.node(node1), sys.node(node2), R_line, L_line, C_line) + + # TODO: Probably interestingn to add the line this way + # sys.add_decoupling_line(line, node1, node2, R_line, L_line, C_line) + + sys.add_component(line) + sys.add_components(line.get_line_components()) def do_sim(name, system): - logger = dpsim.Logger(name) - logger.log_attribute(system.nodes['BUS5'], 'v') - logger.log_attribute(system.nodes['BUS6'], 'v') - logger.log_attribute(system.nodes['BUS8'], 'v') + logger = dpsimpy.Logger(name) - sim = dpsim.Simulation(name, system, timestep=0.0001, duration=0.1, init_steady_state=False, pbar=False, split_subnets=True) + logger.log_attribute('BUS5.V', 'v', system.node('BUS5')) + logger.log_attribute('BUS6.V', 'v', system.node('BUS6')) + logger.log_attribute('BUS8.V', 'v', system.node('BUS8')) + + sim = dpsimpy.Simulation(name, dpsimpy.LogLevel.debug) + sim.set_system(system) + sim.set_time_step(0.0001) + sim.set_final_time(0.1) + # sim.do_steady_state_init(False) + sim.do_split_subnets(True) + sim.do_init_from_nodes_and_terminals(True) sim.add_logger(logger) sim.run() name = 'WSCC-9bus' -files = glob.glob('../dpsim/examples/CIM/WSCC-09/*.xml') -system = dpsim.load_cim(name, files, frequency=60) +dpsim_root_dir = subprocess.Popen(['git', 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE).communicate()[0].rstrip().decode('utf-8') + +files = glob.glob(dpsim_root_dir + '/build/_deps/cim-data-src/WSCC-09/WSCC-09/*.xml') +reader_normal = dpsimpy.CIMReader(name) +system = reader_normal.loadCIM(60, files, dpsimpy.Domain.SP, dpsimpy.PhaseType.Single, dpsimpy.GeneratorType.PVNode) do_sim('normal', system) -system = dpsim.load_cim(name, files, frequency=60) +reader_decoupled = dpsimpy.CIMReader(name) +system = reader_decoupled.loadCIM(60, files, dpsimpy.Domain.SP, dpsimpy.PhaseType.Single, dpsimpy.GeneratorType.PVNode) decouple_line(system, 'LINE75', 'BUS5', 'BUS7') #decouple_line(system, 'LINE78', 'BUS7', 'BUS8') decouple_line(system, 'LINE64', 'BUS6', 'BUS4') decouple_line(system, 'LINE89', 'BUS8', 'BUS9') do_sim('decoupled', system) -normal_dp = rt.read_timeseries_dpsim("Logs/normal.csv") +normal_dp = rt.read_timeseries_dpsim("logs/normal.csv") normal_emt = ts.frequency_shift_list(normal_dp, 60) -decoupled_dp = rt.read_timeseries_dpsim("Logs/decoupled.csv") +decoupled_dp = rt.read_timeseries_dpsim("logs/decoupled.csv") decoupled_emt = ts.frequency_shift_list(decoupled_dp, 60) for i, v in enumerate([5, 6, 8]): - varname = 'BUS' + str(v) + '.v' + varname = 'BUS' + str(v) + '.V_shift' pt.set_timeseries_labels(normal_emt[varname], varname + ' normal') pt.set_timeseries_labels(decoupled_emt[varname], varname + ' decoupled') pt.plot_timeseries(i+1, normal_emt[varname]) From 98e6cb0f241624086b1b9f2cfafafdfcdfb107b6 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Wed, 16 Oct 2024 14:32:14 +0000 Subject: [PATCH 08/19] Implement SP_Ph1_CurrentSource Signed-off-by: pipeacosta --- .../include/dpsim-models/Components.h | 1 + .../dpsim-models/SP/SP_Ph1_CurrentSource.h | 72 ++++++++++++ dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp | 111 ++++++++++++++++++ dpsim/examples/cxx/CMakeLists.txt | 2 + 4 files changed, 186 insertions(+) create mode 100644 dpsim-models/include/dpsim-models/SP/SP_Ph1_CurrentSource.h create mode 100644 dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp diff --git a/dpsim-models/include/dpsim-models/Components.h b/dpsim-models/include/dpsim-models/Components.h index 29a4f0bd58..e6da9e85f0 100644 --- a/dpsim-models/include/dpsim-models/Components.h +++ b/dpsim-models/include/dpsim-models/Components.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include diff --git a/dpsim-models/include/dpsim-models/SP/SP_Ph1_CurrentSource.h b/dpsim-models/include/dpsim-models/SP/SP_Ph1_CurrentSource.h new file mode 100644 index 0000000000..93782d7e3c --- /dev/null +++ b/dpsim-models/include/dpsim-models/SP/SP_Ph1_CurrentSource.h @@ -0,0 +1,72 @@ +/* Copyright 2017-2024 Institute for Automation of Complex Power Systems, + * EONERC, RWTH Aachen University + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + *********************************************************************************/ + +#pragma once + +#include +#include +#include +#include + +namespace CPS { +namespace SP { +namespace Ph1 { +/// \brief Static phasor ideal current source +/// +/// A positive current is flowing out of node1 and into node2. +class CurrentSource : public MNASimPowerComp, + public SharedFactory { +public: + const Attribute::Ptr mCurrentRef; + /// Defines UID, name and logging level + CurrentSource(String uid, String name, + Logger::Level loglevel = Logger::Level::off); + /// Defines name and logging level + CurrentSource(String name, Logger::Level logLevel = Logger::Level::off) + : CurrentSource(name, name, logLevel) {} + /// Defines name, component parameters and logging level + CurrentSource(String name, Complex current, + Logger::Level logLevel = Logger::Level::off); + + void setParameters(Complex current); + + SimPowerComp::Ptr clone(String copySuffix) override; + + // #### General #### + /// Initializes component from power flow data + void initializeFromNodesAndTerminals(Real frequency) override; + + // #### MNA section #### + /// + void mnaCompInitialize(Real omega, Real timeStep, + Attribute::Ptr leftVector) override; + /// Stamps system matrix + void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override {} + /// Stamps right side (source) vector + void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override; + /// + void mnaCompUpdateVoltage(const Matrix &leftVector) override; + + /// Add MNA pre step dependencies + void + mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, + AttributeBase::List &attributeDependencies, + AttributeBase::List &modifiedAttributes) override; + /// Add MNA post step dependencies + void + mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, + AttributeBase::List &attributeDependencies, + AttributeBase::List &modifiedAttributes, + Attribute::Ptr &leftVector) override; + void mnaCompPreStep(Real time, Int timeStepCount) override; + void mnaCompPostStep(Real time, Int timeStepCount, + Attribute::Ptr &leftVector) override; +}; +} // namespace Ph1 +} // namespace SP +} // namespace CPS diff --git a/dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp b/dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp new file mode 100644 index 0000000000..0539b1a4f7 --- /dev/null +++ b/dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp @@ -0,0 +1,111 @@ +/* Copyright 2017-2024 Institute for Automation of Complex Power Systems, + * EONERC, RWTH Aachen University + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + *********************************************************************************/ + +#include + +using namespace CPS; + +SP::Ph1::CurrentSource::CurrentSource(String uid, String name, + Logger::Level logLevel) + : MNASimPowerComp(uid, name, true, true, logLevel), + mCurrentRef(mAttributes->createDynamic("I_ref")) { + setTerminalNumber(2); + **mIntfVoltage = MatrixComp::Zero(1, 1); + **mIntfCurrent = MatrixComp::Zero(1, 1); +} + +SP::Ph1::CurrentSource::CurrentSource(String name, Complex current, + Logger::Level logLevel) + : CurrentSource(name, logLevel) { + setParameters(current); +} + +void SP::Ph1::CurrentSource::setParameters(Complex current) { + **mCurrentRef = current; + mParametersSet = true; +} + +SimPowerComp::Ptr SP::Ph1::CurrentSource::clone(String name) { + auto copy = CurrentSource::make(name, mLogLevel); + copy->setParameters(**mCurrentRef); + return copy; +} + +void SP::Ph1::CurrentSource::initializeFromNodesAndTerminals(Real frequency) { + + (**mIntfVoltage)(0, 0) = initialSingleVoltage(0) - initialSingleVoltage(1); + (**mIntfCurrent)(0, 0) = **mCurrentRef; + + SPDLOG_LOGGER_INFO(mSLog, + "\n--- Initialization from powerflow ---" + "\nVoltage across: {:s}" + "\nCurrent: {:s}" + "\nTerminal 0 voltage: {:s}" + "\nTerminal 1 voltage: {:s}" + "\n--- Initialization from powerflow finished ---", + Logger::phasorToString((**mIntfVoltage)(0, 0)), + Logger::phasorToString((**mIntfCurrent)(0, 0)), + Logger::phasorToString(initialSingleVoltage(0)), + Logger::phasorToString(initialSingleVoltage(1))); +} + +void SP::Ph1::CurrentSource::mnaCompInitialize( + Real omega, Real timeStep, Attribute::Ptr leftVector) { + updateMatrixNodeIndices(); + (**mIntfCurrent)(0, 0) = **mCurrentRef; +} + +void SP::Ph1::CurrentSource::mnaCompAddPreStepDependencies( + AttributeBase::List &prevStepDependencies, + AttributeBase::List &attributeDependencies, + AttributeBase::List &modifiedAttributes) { + attributeDependencies.push_back(mCurrentRef); + modifiedAttributes.push_back(mRightVector); + modifiedAttributes.push_back(mIntfCurrent); +} + +void SP::Ph1::CurrentSource::mnaCompPreStep(Real time, Int timeStepCount) { + mnaCompApplyRightSideVectorStamp(**mRightVector); +} + +void SP::Ph1::CurrentSource::mnaCompApplyRightSideVectorStamp( + Matrix &rightVector) { + (**mIntfCurrent)(0, 0) = **mCurrentRef; + + if (terminalNotGrounded(0)) + Math::setVectorElement(rightVector, matrixNodeIndex(0), + -(**mIntfCurrent)(0, 0)); + if (terminalNotGrounded(1)) + Math::setVectorElement(rightVector, matrixNodeIndex(1), + (**mIntfCurrent)(0, 0)); +} + +void SP::Ph1::CurrentSource::mnaCompAddPostStepDependencies( + AttributeBase::List &prevStepDependencies, + AttributeBase::List &attributeDependencies, + AttributeBase::List &modifiedAttributes, + Attribute::Ptr &leftVector) { + attributeDependencies.push_back(leftVector); + modifiedAttributes.push_back(mIntfVoltage); +} + +void SP::Ph1::CurrentSource::mnaCompPostStep( + Real time, Int timeStepCount, Attribute::Ptr &leftVector) { + mnaCompUpdateVoltage(**leftVector); +} + +void SP::Ph1::CurrentSource::mnaCompUpdateVoltage(const Matrix &leftVector) { + (**mIntfVoltage)(0, 0) = 0; + if (terminalNotGrounded(0)) + (**mIntfVoltage)(0, 0) = + Math::complexFromVectorElement(leftVector, matrixNodeIndex(0)); + if (terminalNotGrounded(1)) + (**mIntfVoltage)(0, 0) = + (**mIntfVoltage)(0, 0) - + Math::complexFromVectorElement(leftVector, matrixNodeIndex(1)); +} diff --git a/dpsim/examples/cxx/CMakeLists.txt b/dpsim/examples/cxx/CMakeLists.txt index 0edc927961..587bac86b6 100644 --- a/dpsim/examples/cxx/CMakeLists.txt +++ b/dpsim/examples/cxx/CMakeLists.txt @@ -191,6 +191,8 @@ if(WITH_CIM) CIM/WSCC_9bus_mult_decoupled.cpp CIM/WSCC_9bus_mult_coupled.cpp CIM/WSCC_9bus_mult_diakoptics.cpp + CIM/WSCC_9bus_split_decoupled.cpp + CIM/WSCC_9bus_split_decoupled_RX.cpp # CIGRE MV examples CIM/PF_CIGRE_MV_withDG.cpp From e17a6980a308d57b81a44d8f1249730a11919f5e Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Wed, 16 Oct 2024 14:43:46 +0000 Subject: [PATCH 09/19] Add SP_Ph1_CurrentSource to CMakeLists Signed-off-by: pipeacosta --- dpsim-models/src/CMakeLists.txt | 1 + dpsim/examples/cxx/CMakeLists.txt | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/dpsim-models/src/CMakeLists.txt b/dpsim-models/src/CMakeLists.txt index 400cefc4dc..486fac6c97 100644 --- a/dpsim-models/src/CMakeLists.txt +++ b/dpsim-models/src/CMakeLists.txt @@ -107,6 +107,7 @@ list(APPEND MODELS_SOURCES EMT/EMT_Ph3_SSN_Full_Serial_RLC.cpp SP/SP_Ph1_VoltageSource.cpp + SP/SP_Ph1_CurrentSource.cpp SP/SP_Ph1_Capacitor.cpp SP/SP_Ph1_Inductor.cpp SP/SP_Ph1_Resistor.cpp diff --git a/dpsim/examples/cxx/CMakeLists.txt b/dpsim/examples/cxx/CMakeLists.txt index 587bac86b6..0edc927961 100644 --- a/dpsim/examples/cxx/CMakeLists.txt +++ b/dpsim/examples/cxx/CMakeLists.txt @@ -191,8 +191,6 @@ if(WITH_CIM) CIM/WSCC_9bus_mult_decoupled.cpp CIM/WSCC_9bus_mult_coupled.cpp CIM/WSCC_9bus_mult_diakoptics.cpp - CIM/WSCC_9bus_split_decoupled.cpp - CIM/WSCC_9bus_split_decoupled_RX.cpp # CIGRE MV examples CIM/PF_CIGRE_MV_withDG.cpp From 5dd8353cea7bcbda92204a59fcfa27e3e82a9130 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Sat, 19 Oct 2024 08:50:41 +0000 Subject: [PATCH 10/19] Fix simulation domain in decoupling_9bus_existing Signed-off-by: pipeacosta --- examples/Python/RuntimeMeas/decoupling_9bus_existing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Python/RuntimeMeas/decoupling_9bus_existing.py b/examples/Python/RuntimeMeas/decoupling_9bus_existing.py index d678fdfada..fa7b6636a7 100644 --- a/examples/Python/RuntimeMeas/decoupling_9bus_existing.py +++ b/examples/Python/RuntimeMeas/decoupling_9bus_existing.py @@ -52,11 +52,11 @@ def do_sim(name, system): files = glob.glob(dpsim_root_dir + '/build/_deps/cim-data-src/WSCC-09/WSCC-09/*.xml') reader_normal = dpsimpy.CIMReader(name) -system = reader_normal.loadCIM(60, files, dpsimpy.Domain.SP, dpsimpy.PhaseType.Single, dpsimpy.GeneratorType.PVNode) +system = reader_normal.loadCIM(60, files, dpsimpy.Domain.DP, dpsimpy.PhaseType.Single, dpsimpy.GeneratorType.IdealVoltageSource) do_sim('normal', system) reader_decoupled = dpsimpy.CIMReader(name) -system = reader_decoupled.loadCIM(60, files, dpsimpy.Domain.SP, dpsimpy.PhaseType.Single, dpsimpy.GeneratorType.PVNode) +system = reader_decoupled.loadCIM(60, files, dpsimpy.Domain.DP, dpsimpy.PhaseType.Single, dpsimpy.GeneratorType.IdealVoltageSource) decouple_line(system, 'LINE75', 'BUS5', 'BUS7') #decouple_line(system, 'LINE78', 'BUS7', 'BUS8') decouple_line(system, 'LINE64', 'BUS6', 'BUS4') From 5085c08da2d4ee3674e56a87035958399e08a2b4 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Sat, 19 Oct 2024 08:53:51 +0000 Subject: [PATCH 11/19] WIP: Improve nine bus parallel Notebook by using the CIMPATH variable Signed-off-by: pipeacosta --- .../cxx/CIM/WSCC_9bus_mult_coupled.cpp | 2 +- .../cxx/CIM/WSCC_9bus_mult_decoupled.cpp | 2 +- .../Performance/WSCC_9bus_parallel.ipynb | 25 +++++++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp index 99a2cdaa09..fc42ddca98 100644 --- a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp +++ b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) { filenames = DPsim::Utils::findFiles( {"WSCC-09_RX_DI.xml", "WSCC-09_RX_EQ.xml", "WSCC-09_RX_SV.xml", "WSCC-09_RX_TP.xml"}, - "../../../build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); + "build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); //for (Int copies = 0; copies < 20; copies++) { // for (Int threads = 0; threads <= 12; threads = threads+2) diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp index da9e15e6f6..427981cc5b 100644 --- a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp +++ b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) { filenames = DPsim::Utils::findFiles( {"WSCC-09_RX_DI.xml", "WSCC-09_RX_EQ.xml", "WSCC-09_RX_SV.xml", "WSCC-09_RX_TP.xml"}, - "../../../build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); + "build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); //for (Int copies = 0; copies < 10; copies++) { // for (Int threads = 0; threads <= 12; threads = threads+2) diff --git a/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb b/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb index 3ecacc9ef3..5b7eb8c600 100644 --- a/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb +++ b/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb @@ -16,10 +16,23 @@ "%%bash\n", "TOP=${TOP:-$(git rev-parse --show-toplevel)}\n", "PATH=${TOP}/build/dpsim/examples/cxx\n", + "export CIMPATH=${TOP}/build/_deps/cim-data-src/WSCC-09/WSCC-09_RX\n", "\n", - "echo ${TOP}\n", + "WSCC_9bus_mult_coupled -o copies=1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%bash\n", + "TOP=${TOP:-$(git rev-parse --show-toplevel)}\n", + "PATH=${TOP}/build/dpsim/examples/cxx\n", + "export CIMPATH=${TOP}/build/_deps/cim-data-src/WSCC-09/WSCC-09_RX\n", "\n", - "WSCC_9bus_mult_coupled ${TOP}/examples/cxx/CIM/WSCC-09_RX/*.xml -o copies=1" + "WSCC_9bus_mult_decoupled -o copies=1" ] }, { @@ -31,8 +44,9 @@ "%%bash\n", "TOP=${TOP:-$(git rev-parse --show-toplevel)}\n", "PATH=${TOP}/build/dpsim/examples/cxx\n", + "export CIMPATH=${TOP}/build/_deps/cim-data-src/WSCC-09/WSCC-09_RX\n", "\n", - "WSCC_9bus_mult_decoupled ${TOP}/examples/CIM/WSCC-09_RX/*.xml -o copies=1" + "WSCC_9bus_mult_diakoptics -o copies=1" ] }, { @@ -44,8 +58,9 @@ "%%bash\n", "TOP=${TOP:-$(git rev-parse --show-toplevel)}\n", "PATH=${TOP}/build/dpsim/examples/cxx\n", + "export CIMPATH=${TOP}/build/_deps/cim-data-src/WSCC-09/WSCC-09_RX\n", "\n", - "WSCC_9bus_mult_diakoptics ${TOP}/examples/CIM/WSCC-09_RX/*.xml -o copies=1" + "WSCC-9bus_CIM" ] }, { @@ -57,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ From 64f5c211a3e656f88b22337f0b08b52ee12a8c35 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Sat, 19 Oct 2024 09:25:26 +0000 Subject: [PATCH 12/19] Implement new tests for the WSCC9bus system with decoupling line Signed-off-by: pipeacosta --- .../workflows/build_test_linux_fedora.yaml | 8 +- .../cxx/CIM/WSCC_9bus_split_decoupled.cpp | 113 ++++++++++++++++ .../cxx/CIM/WSCC_9bus_split_decoupled_EMT.cpp | 121 ++++++++++++++++++ dpsim/examples/cxx/CMakeLists.txt | 2 + 4 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled.cpp create mode 100644 dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled_EMT.cpp diff --git a/.github/workflows/build_test_linux_fedora.yaml b/.github/workflows/build_test_linux_fedora.yaml index e4d58f21a6..261853a496 100644 --- a/.github/workflows/build_test_linux_fedora.yaml +++ b/.github/workflows/build_test_linux_fedora.yaml @@ -64,7 +64,7 @@ jobs: - name: Configure CMake shell: bash working-directory: ${{ github.workspace }}/build - run: cmake -DCIM_VERSION=CGMES_2.4.15_16FEB2016 $GITHUB_WORKSPACE + run: cmake -DCIM_VERSION=CGMES_2.4.15_16FEB2016 $GITHUB_WORKSPACE - name: Build every target shell: bash @@ -200,6 +200,12 @@ jobs: - name: Run Binaries 2/2 run: ./build/dpsim/examples/cxx/WSCC_9bus_mult_decoupled + - name: Run Binaries 2/2 + run: ./build/dpsim/examples/cxx/WSCC_9bus_split_decoupled + + - name: Run Binaries 2/2 + run: ./build/dpsim/examples/cxx/WSCC_9bus_split_decoupled_EMT + cpp-check: name: Scan Sourcecode with Cppcheck runs-on: ubuntu-latest diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled.cpp new file mode 100644 index 0000000000..60c4a5702f --- /dev/null +++ b/dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled.cpp @@ -0,0 +1,113 @@ +/* Copyright 2017-2021 Institute for Automation of Complex Power Systems, + * EONERC, RWTH Aachen University + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + *********************************************************************************/ + +#include +#include +#include + +#include +#include + +using namespace DPsim; +using namespace CPS; + +String decoupleLine(SystemTopology &sys, const String &lineName, const String &node1, const String node2) { + auto origLine = sys.component(lineName); + Real Rline = origLine->attributeTyped("R_series")->get(); + Real Lline = origLine->attributeTyped("L_series")->get(); + Real Cline = origLine->attributeTyped("C_parallel")->get(); + + sys.removeComponent(lineName); + + String dline_name = "dline_" + node1 + "_" + node2; + + auto line = Signal::DecouplingLine::make( + "dline_" + node1 + "_" + node2, sys.node(node1), + sys.node(node2), Rline, Lline, Cline, Logger::Level::debug + ); + sys.addComponent(line); + sys.addComponents(line->getLineComponents()); + + return dline_name; +} + +void doSim(String &name, SystemTopology &sys, Int threads) { + + // Logging + auto logger = DataLogger::make(name); + // logger->logAttribute("BUS5.v", sys.node("BUS5")->attribute("v")); + // logger->logAttribute("BUS6.v", sys.node("BUS6")->attribute("v")); + // logger->logAttribute("BUS8.v", sys.node("BUS8")->attribute("v")); + for (Int bus = 1; bus <= 9; bus++) { + String attrName = "v" + std::to_string(bus); + String nodeName = "BUS" + std::to_string(bus); + logger->logAttribute(attrName, sys.node(nodeName)->attribute("v")); + } + + Simulation sim(name, Logger::Level::debug); + sim.setSystem(sys); + sim.setTimeStep(0.0001); + sim.setFinalTime(0.5); + sim.setDomain(Domain::DP); + sim.doSplitSubnets(true); + sim.doInitFromNodesAndTerminals(true); + sim.addLogger(logger); + if (threads > 0) + sim.setScheduler(std::make_shared(threads)); + + //std::ofstream of1("topology_graph.svg"); + //sys.topologyGraph().render(of1)); + + sim.run(); + sim.logStepTimes(name + "_step_times"); +} + +int main(int argc, char *argv[]) { + CommandLineArgs args(argc, argv); + + std::list filenames; + filenames = DPsim::Utils::findFiles( + {"WSCC-09_DI.xml", "WSCC-09_EQ.xml", "WSCC-09_SV.xml", + "WSCC-09_TP.xml"}, + "build/_deps/cim-data-src/WSCC-09/WSCC-09", "CIMPATH"); + + Int numThreads = 0; + Int numSeq = 0; + + if (args.options.find("threads") != args.options.end()) + numThreads = args.getOptionInt("threads"); + if (args.options.find("seq") != args.options.end()) + numSeq = args.getOptionInt("seq"); + + std::cout << "Simulate with " << numThreads + << " threads, sequence number " << numSeq << std::endl; + + // Monolithic Simulation + String simNameMonolithic = "WSCC-9bus_monolithic_DP"; + Logger::setLogDir("logs/" + simNameMonolithic); + CIM::Reader readerMonolithic(simNameMonolithic, Logger::Level::debug, Logger::Level::debug); + SystemTopology systemMonolithic = + readerMonolithic.loadCIM(60, filenames, Domain::DP, PhaseType::Single, + CPS::GeneratorType::IdealVoltageSource); + + doSim(simNameMonolithic, systemMonolithic, 0); + + // Decoupled Simulation + String simNameDecoupled = "WSCC_9bus_split_decoupled_DP_" + std::to_string(numThreads) + "_" + std::to_string(numSeq); + Logger::setLogDir("logs/" + simNameDecoupled); + CIM::Reader readerDecoupled(simNameDecoupled, Logger::Level::debug, Logger::Level::debug); + SystemTopology systemDecoupled = readerDecoupled.loadCIM(60, filenames, Domain::DP, PhaseType::Single, + CPS::GeneratorType::IdealVoltageSource); + + String dline_75 = decoupleLine(systemDecoupled, "LINE75", "BUS5", "BUS7"); + // decouple_line(system, "LINE78", "BUS7", "BUS8"); + String dline_64 = decoupleLine(systemDecoupled, "LINE64", "BUS6", "BUS4"); + String dline_89 = decoupleLine(systemDecoupled, "LINE89", "BUS8", "BUS9"); + + doSim(simNameDecoupled, systemDecoupled, numThreads); +} diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled_EMT.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled_EMT.cpp new file mode 100644 index 0000000000..2b39f66ce2 --- /dev/null +++ b/dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled_EMT.cpp @@ -0,0 +1,121 @@ +/* Copyright 2017-2021 Institute for Automation of Complex Power Systems, + * EONERC, RWTH Aachen University + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + *********************************************************************************/ + +#include +#include +#include + +#include +#include + +using namespace DPsim; +using namespace CPS; + +String decoupleLine(SystemTopology &sys, const String &lineName, const String &node1, const String node2) { + auto origLine = sys.component(lineName); + Matrix Rline = origLine->attributeTyped("R_series")->get(); + Matrix Lline = origLine->attributeTyped("L_series")->get(); + Matrix Cline = origLine->attributeTyped("C_parallel")->get(); + + sys.removeComponent(lineName); + + String dline_name = "dline_" + node1 + "_" + node2; + + auto line = Signal::DecouplingLineEMT::make( + "dline_" + node1 + "_" + node2, + Logger::Level::debug + ); + + Real Rline_scalar = Rline(0,0); + Real Lline_scalar = Lline(0,0); + Real Cline_scalar = Cline(0,0); + + line->setParameters( + sys.node(node1), sys.node(node2), + Rline_scalar, Lline_scalar, Cline_scalar); + sys.addComponent(line); + sys.addComponents(line->getLineComponents()); + + return dline_name; +} + +void doSim(String &name, SystemTopology &sys, Int threads) { + + // Logging + auto logger = DataLogger::make(name); + // logger->logAttribute("BUS5.v", sys.node("BUS5")->attribute("v")); + // logger->logAttribute("BUS6.v", sys.node("BUS6")->attribute("v")); + // logger->logAttribute("BUS8.v", sys.node("BUS8")->attribute("v")); + for (Int bus = 1; bus <= 9; bus++) { + String attrName = "v" + std::to_string(bus); + String nodeName = "BUS" + std::to_string(bus); + logger->logAttribute(attrName, sys.node(nodeName)->attribute("v")); + } + + Simulation sim(name, Logger::Level::debug); + sim.setSystem(sys); + sim.setTimeStep(0.0001); + sim.setFinalTime(0.5); + sim.setDomain(Domain::EMT); + sim.doSplitSubnets(true); + sim.doInitFromNodesAndTerminals(true); + sim.addLogger(logger); + if (threads > 0) + sim.setScheduler(std::make_shared(threads)); + + //std::ofstream of1("topology_graph.svg"); + //sys.topologyGraph().render(of1)); + + sim.run(); + sim.logStepTimes(name + "_step_times"); +} + +int main(int argc, char *argv[]) { + CommandLineArgs args(argc, argv); + + std::list filenames; + filenames = DPsim::Utils::findFiles( + {"WSCC-09_DI.xml", "WSCC-09_EQ.xml", "WSCC-09_SV.xml", + "WSCC-09_TP.xml"}, + "build/_deps/cim-data-src/WSCC-09/WSCC-09", "CIMPATH"); + + Int numThreads = 0; + Int numSeq = 0; + + if (args.options.find("threads") != args.options.end()) + numThreads = args.getOptionInt("threads"); + if (args.options.find("seq") != args.options.end()) + numSeq = args.getOptionInt("seq"); + + std::cout << "Simulate with " << numThreads + << " threads, sequence number " << numSeq << std::endl; + + // Monolithic Simulation + String simNameMonolithic = "WSCC-9bus_monolithic_EMT"; + Logger::setLogDir("logs/" + simNameMonolithic); + CIM::Reader readerMonolithic(simNameMonolithic, Logger::Level::debug, Logger::Level::debug); + SystemTopology systemMonolithic = + readerMonolithic.loadCIM(60, filenames, Domain::EMT, PhaseType::ABC, + CPS::GeneratorType::IdealVoltageSource); + + doSim(simNameMonolithic, systemMonolithic, 0); + + // Decoupled Simulation + String simNameDecoupled = "WSCC_9bus_split_decoupled_EMT_" + std::to_string(numThreads) + "_" + std::to_string(numSeq); + Logger::setLogDir("logs/" + simNameDecoupled); + CIM::Reader readerDecoupled(simNameDecoupled, Logger::Level::debug, Logger::Level::debug); + SystemTopology systemDecoupled = readerDecoupled.loadCIM(60, filenames, Domain::EMT, PhaseType::ABC, + CPS::GeneratorType::IdealVoltageSource); + + String dline_75 = decoupleLine(systemDecoupled, "LINE75", "BUS5", "BUS7"); + // decouple_line(system, "LINE78", "BUS7", "BUS8"); + String dline_64 = decoupleLine(systemDecoupled, "LINE64", "BUS6", "BUS4"); + String dline_89 = decoupleLine(systemDecoupled, "LINE89", "BUS8", "BUS9"); + + doSim(simNameDecoupled, systemDecoupled, numThreads); +} diff --git a/dpsim/examples/cxx/CMakeLists.txt b/dpsim/examples/cxx/CMakeLists.txt index 0edc927961..b7833b1c85 100644 --- a/dpsim/examples/cxx/CMakeLists.txt +++ b/dpsim/examples/cxx/CMakeLists.txt @@ -191,6 +191,8 @@ if(WITH_CIM) CIM/WSCC_9bus_mult_decoupled.cpp CIM/WSCC_9bus_mult_coupled.cpp CIM/WSCC_9bus_mult_diakoptics.cpp + CIM/WSCC_9bus_split_decoupled.cpp + CIM/WSCC_9bus_split_decoupled_EMT.cpp # CIGRE MV examples CIM/PF_CIGRE_MV_withDG.cpp From 090454fa90a9378e219e6ab58b817509ef2d17b1 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Sat, 19 Oct 2024 09:28:32 +0000 Subject: [PATCH 13/19] Implement new Notebook for the WSCC_9bus system with decoupling line Signed-off-by: pipeacosta --- .../Performance/WSCC_9bus_split.ipynb | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 examples/Notebooks/Performance/WSCC_9bus_split.ipynb diff --git a/examples/Notebooks/Performance/WSCC_9bus_split.ipynb b/examples/Notebooks/Performance/WSCC_9bus_split.ipynb new file mode 100644 index 0000000000..5ff94536b5 --- /dev/null +++ b/examples/Notebooks/Performance/WSCC_9bus_split.ipynb @@ -0,0 +1,165 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Run" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Split system in DP, using decoupling line" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%bash\n", + "TOP=${TOP:-$(git rev-parse --show-toplevel)}\n", + "PATH=${TOP}/build/dpsim/examples/cxx\n", + "export CIMPATH=${TOP}/build/_deps/cim-data-src/WSCC-09/WSCC-09\n", + "\n", + "WSCC_9bus_split_decoupled" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Split System in EMT, using decoupling line" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%bash\n", + "TOP=${TOP:-$(git rev-parse --show-toplevel)}\n", + "PATH=${TOP}/build/dpsim/examples/cxx\n", + "export CIMPATH=${TOP}/build/_deps/cim-data-src/WSCC-09/WSCC-09\n", + "\n", + "WSCC_9bus_split_decoupled_EMT" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Validate Results" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "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\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd\n", + "#%matplotlib widget" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "path_split_dp = 'logs/WSCC_9bus_split_decoupled_DP_0_0/'\n", + "logName_split_dp = 'WSCC_9bus_split_decoupled_DP_0_0'\n", + "logFilename_split_dp = path_split_dp + logName_split_dp + '.csv'\n", + "print(logFilename_split_dp)\n", + "\n", + "path_split_emt = 'logs/WSCC_9bus_split_decoupled_EMT_0_0/'\n", + "logName_split_emt = 'WSCC_9bus_split_decoupled_EMT_0_0'\n", + "logFilename_split_emt = path_split_emt + logName_split_emt + '.csv'\n", + "print(logFilename_split_emt)\n", + "\n", + "path_mono_dp = 'logs/WSCC-9bus_monolithic_DP/'\n", + "logName_mono_dp = 'WSCC-9bus_monolithic_DP'\n", + "logFilename_mono_dp = path_mono_dp + logName_mono_dp + '.csv'\n", + "print(logFilename_mono_dp)\n", + "\n", + "path_mono_emt = 'logs/WSCC-9bus_monolithic_EMT/'\n", + "logName_mono_emt = 'WSCC-9bus_monolithic_EMT'\n", + "logFilename_mono_emt = path_mono_emt + logName_mono_emt + '.csv'\n", + "print(logFilename_mono_emt)\n", + "\n", + "decoupled_dp_split = rt.read_timeseries_dpsim(logFilename_split_dp)\n", + "mono_dp = rt.read_timeseries_dpsim(logFilename_mono_dp)\n", + "decoupled_emt_split = rt.read_timeseries_dpsim(logFilename_split_emt)\n", + "mono_emt = rt.read_timeseries_dpsim(logFilename_mono_emt)\n", + "\n", + "# for v in range(1, 10):\n", + "for i, v in enumerate([5]):\n", + " varname = 'v' + str(v)\n", + " pt.set_timeseries_labels(mono_dp[varname], varname + ' Monolithic, DP')\n", + " pt.plot_timeseries('decoupled', mono_dp[varname])\n", + " pt.set_timeseries_labels(decoupled_dp_split[varname], varname + ' DP')\n", + " pt.plot_timeseries('decoupled', decoupled_dp_split[varname], '--')\n", + " plt.title('WSCC-09 with 3 lines replaced by decoupling equivalents')\n", + " plt.xlabel('Time [s]')\n", + " plt.ylabel('Voltage [V]')\n", + "\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "decoupled_emt_split = rt.read_timeseries_dpsim(logFilename_split_emt)\n", + "\n", + "for i, v in enumerate([5]):\n", + " varname_emt = 'v' + str(v) + '_0'\n", + " pt.set_timeseries_labels(mono_emt[varname_emt], varname_emt + ' EMT')\n", + " pt.plot_timeseries('decoupled, shifted', mono_emt[varname_emt])\n", + " pt.set_timeseries_labels(decoupled_emt_split[varname_emt], varname_emt + ' EMT')\n", + " pt.plot_timeseries('decoupled, shifted', decoupled_emt_split[varname_emt], '--')\n", + " plt.title('WSCC-09 with 3 lines replaced by decoupling equivalents')\n", + " plt.xlabel('Time [s]')\n", + " plt.ylabel('Voltage [V]')\n", + "\n", + "plt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.10.11" + }, + "tests": { + "skip": true + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 898681f4addca832631d6b5118c99a49343df541 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Sun, 20 Oct 2024 09:47:28 +0200 Subject: [PATCH 14/19] Fix compilation using Clang Signed-off-by: pipeacosta --- dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h b/dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h index b2b09d611a..ff6d2bd80c 100644 --- a/dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h +++ b/dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h @@ -51,7 +51,7 @@ class RXLoad : public CompositePowerComp, /// Defines name, component parameters and logging level RXLoad(String name, Logger::Level logLevel = Logger::Level::off); - SimPowerComp::Ptr clone(String name); + SimPowerComp::Ptr clone(String name) override; // #### General #### /// Initialize component from power flow data From eac8adaf11a599a31196dea87c9759e66738a2ed Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Thu, 24 Oct 2024 12:34:46 +0000 Subject: [PATCH 15/19] Undo changes to the WSCC-9bus_CIM example. Signed-off-by: pipeacosta --- dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp b/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp index dc33f22b2e..4d356abbf5 100644 --- a/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp +++ b/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp @@ -30,11 +30,11 @@ int main(int argc, char *argv[]) { "build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); timeStep = 100e-6; - finalTime = 0.5; + finalTime = 0.1; } else { filenames = std::list(argv + 1, argv + argc); - // timeStep = args.timeStep; - // finalTime = args.duration; + timeStep = args.timeStep; + finalTime = args.duration; } // ----- POWERFLOW FOR INITIALIZATION ----- @@ -88,10 +88,10 @@ int main(int argc, char *argv[]) { logger->logAttribute("v9", sys.node("BUS9")->attribute("v")); // log generator's current - // for (auto comp : sys.mComponents) { - // if (std::dynamic_pointer_cast(comp)) - // logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf")); - // } + for (auto comp : sys.mComponents) { + if (std::dynamic_pointer_cast(comp)) + logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf")); + } Simulation sim(simName, Logger::Level::info); sim.setSystem(sys); From 1e72e45673024c3bed83b6677082a17e67f8fcc0 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Wed, 30 Oct 2024 07:43:07 +0000 Subject: [PATCH 16/19] Rename split decoupling line examples. Signed-off-by: pipeacosta --- .github/workflows/build_test_linux_fedora.yaml | 12 ++++++------ ...coupled.cpp => DP_WSCC_9bus_split_decoupled.cpp} | 0 ...ed_EMT.cpp => EMT_WSCC_9bus_split_decoupled.cpp} | 0 dpsim/examples/cxx/CMakeLists.txt | 4 ++-- .../Notebooks/Performance/WSCC_9bus_split.ipynb | 13 ++++++++++--- 5 files changed, 18 insertions(+), 11 deletions(-) rename dpsim/examples/cxx/CIM/{WSCC_9bus_split_decoupled.cpp => DP_WSCC_9bus_split_decoupled.cpp} (100%) rename dpsim/examples/cxx/CIM/{WSCC_9bus_split_decoupled_EMT.cpp => EMT_WSCC_9bus_split_decoupled.cpp} (100%) diff --git a/.github/workflows/build_test_linux_fedora.yaml b/.github/workflows/build_test_linux_fedora.yaml index 261853a496..b967991bd8 100644 --- a/.github/workflows/build_test_linux_fedora.yaml +++ b/.github/workflows/build_test_linux_fedora.yaml @@ -194,17 +194,17 @@ jobs: run: | chmod -R +x ./build/dpsim/examples/cxx - - name: Run Binaries 1/2 + - name: Run Binaries 1/4 run: ./build/dpsim/examples/cxx/WSCC_9bus_mult_coupled - - name: Run Binaries 2/2 + - name: Run Binaries 2/4 run: ./build/dpsim/examples/cxx/WSCC_9bus_mult_decoupled - - name: Run Binaries 2/2 - run: ./build/dpsim/examples/cxx/WSCC_9bus_split_decoupled + - name: Run Binaries 3/4 + run: ./build/dpsim/examples/cxx/DP_WSCC_9bus_split_decoupled - - name: Run Binaries 2/2 - run: ./build/dpsim/examples/cxx/WSCC_9bus_split_decoupled_EMT + - name: Run Binaries 4/4 + run: ./build/dpsim/examples/cxx/EMT_WSCC_9bus_split_decoupled cpp-check: name: Scan Sourcecode with Cppcheck diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled.cpp b/dpsim/examples/cxx/CIM/DP_WSCC_9bus_split_decoupled.cpp similarity index 100% rename from dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled.cpp rename to dpsim/examples/cxx/CIM/DP_WSCC_9bus_split_decoupled.cpp diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled_EMT.cpp b/dpsim/examples/cxx/CIM/EMT_WSCC_9bus_split_decoupled.cpp similarity index 100% rename from dpsim/examples/cxx/CIM/WSCC_9bus_split_decoupled_EMT.cpp rename to dpsim/examples/cxx/CIM/EMT_WSCC_9bus_split_decoupled.cpp diff --git a/dpsim/examples/cxx/CMakeLists.txt b/dpsim/examples/cxx/CMakeLists.txt index b7833b1c85..11c797f280 100644 --- a/dpsim/examples/cxx/CMakeLists.txt +++ b/dpsim/examples/cxx/CMakeLists.txt @@ -191,8 +191,8 @@ if(WITH_CIM) CIM/WSCC_9bus_mult_decoupled.cpp CIM/WSCC_9bus_mult_coupled.cpp CIM/WSCC_9bus_mult_diakoptics.cpp - CIM/WSCC_9bus_split_decoupled.cpp - CIM/WSCC_9bus_split_decoupled_EMT.cpp + CIM/DP_WSCC_9bus_split_decoupled.cpp + CIM/EMT_WSCC_9bus_split_decoupled.cpp # CIGRE MV examples CIM/PF_CIGRE_MV_withDG.cpp diff --git a/examples/Notebooks/Performance/WSCC_9bus_split.ipynb b/examples/Notebooks/Performance/WSCC_9bus_split.ipynb index 5ff94536b5..de3af0b793 100644 --- a/examples/Notebooks/Performance/WSCC_9bus_split.ipynb +++ b/examples/Notebooks/Performance/WSCC_9bus_split.ipynb @@ -25,7 +25,7 @@ "PATH=${TOP}/build/dpsim/examples/cxx\n", "export CIMPATH=${TOP}/build/_deps/cim-data-src/WSCC-09/WSCC-09\n", "\n", - "WSCC_9bus_split_decoupled" + "DP_WSCC_9bus_split_decoupled" ] }, { @@ -46,7 +46,7 @@ "PATH=${TOP}/build/dpsim/examples/cxx\n", "export CIMPATH=${TOP}/build/_deps/cim-data-src/WSCC-09/WSCC-09\n", "\n", - "WSCC_9bus_split_decoupled_EMT" + "EMT_WSCC_9bus_split_decoupled" ] }, { @@ -126,7 +126,7 @@ "\n", "for i, v in enumerate([5]):\n", " varname_emt = 'v' + str(v) + '_0'\n", - " pt.set_timeseries_labels(mono_emt[varname_emt], varname_emt + ' EMT')\n", + " pt.set_timeseries_labels(mono_emt[varname_emt], varname_emt + ' Monolithic, EMT')\n", " pt.plot_timeseries('decoupled, shifted', mono_emt[varname_emt])\n", " pt.set_timeseries_labels(decoupled_emt_split[varname_emt], varname_emt + ' EMT')\n", " pt.plot_timeseries('decoupled, shifted', decoupled_emt_split[varname_emt], '--')\n", @@ -136,6 +136,13 @@ "\n", "plt.show()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From cf86ca78f73f884c1ba3ff7d42ffbc934c54d606 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Wed, 30 Oct 2024 08:11:52 +0000 Subject: [PATCH 17/19] Fix path to CIM files in decoupling line diakoptics example. Signed-off-by: pipeacosta --- dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp index 7b90ea9ebe..d89a1fe95f 100644 --- a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp +++ b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) { filenames = DPsim::Utils::findFiles( {"WSCC-09_RX_DI.xml", "WSCC-09_RX_EQ.xml", "WSCC-09_RX_SV.xml", "WSCC-09_RX_TP.xml"}, - "../../../build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); + "build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH"); //for (Int copies = 0; copies < 10; copies++) { // for (Int threads = 0; threads <= 12; threads = threads+2) { From 47eacf1828f4e7d892b9cfd5e5a88f97f43740d2 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Wed, 30 Oct 2024 08:43:05 +0000 Subject: [PATCH 18/19] Remove SP_Ph1_CurrentSource component. Signed-off-by: pipeacosta --- .../include/dpsim-models/Components.h | 1 - .../dpsim-models/SP/SP_Ph1_CurrentSource.h | 72 ------------ dpsim-models/src/CMakeLists.txt | 1 - dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp | 111 ------------------ 4 files changed, 185 deletions(-) delete mode 100644 dpsim-models/include/dpsim-models/SP/SP_Ph1_CurrentSource.h delete mode 100644 dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp diff --git a/dpsim-models/include/dpsim-models/Components.h b/dpsim-models/include/dpsim-models/Components.h index e6da9e85f0..29a4f0bd58 100644 --- a/dpsim-models/include/dpsim-models/Components.h +++ b/dpsim-models/include/dpsim-models/Components.h @@ -11,7 +11,6 @@ #include #include -#include #include #include #include diff --git a/dpsim-models/include/dpsim-models/SP/SP_Ph1_CurrentSource.h b/dpsim-models/include/dpsim-models/SP/SP_Ph1_CurrentSource.h deleted file mode 100644 index 93782d7e3c..0000000000 --- a/dpsim-models/include/dpsim-models/SP/SP_Ph1_CurrentSource.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright 2017-2024 Institute for Automation of Complex Power Systems, - * EONERC, RWTH Aachen University - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - *********************************************************************************/ - -#pragma once - -#include -#include -#include -#include - -namespace CPS { -namespace SP { -namespace Ph1 { -/// \brief Static phasor ideal current source -/// -/// A positive current is flowing out of node1 and into node2. -class CurrentSource : public MNASimPowerComp, - public SharedFactory { -public: - const Attribute::Ptr mCurrentRef; - /// Defines UID, name and logging level - CurrentSource(String uid, String name, - Logger::Level loglevel = Logger::Level::off); - /// Defines name and logging level - CurrentSource(String name, Logger::Level logLevel = Logger::Level::off) - : CurrentSource(name, name, logLevel) {} - /// Defines name, component parameters and logging level - CurrentSource(String name, Complex current, - Logger::Level logLevel = Logger::Level::off); - - void setParameters(Complex current); - - SimPowerComp::Ptr clone(String copySuffix) override; - - // #### General #### - /// Initializes component from power flow data - void initializeFromNodesAndTerminals(Real frequency) override; - - // #### MNA section #### - /// - void mnaCompInitialize(Real omega, Real timeStep, - Attribute::Ptr leftVector) override; - /// Stamps system matrix - void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override {} - /// Stamps right side (source) vector - void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override; - /// - void mnaCompUpdateVoltage(const Matrix &leftVector) override; - - /// Add MNA pre step dependencies - void - mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, - AttributeBase::List &attributeDependencies, - AttributeBase::List &modifiedAttributes) override; - /// Add MNA post step dependencies - void - mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, - AttributeBase::List &attributeDependencies, - AttributeBase::List &modifiedAttributes, - Attribute::Ptr &leftVector) override; - void mnaCompPreStep(Real time, Int timeStepCount) override; - void mnaCompPostStep(Real time, Int timeStepCount, - Attribute::Ptr &leftVector) override; -}; -} // namespace Ph1 -} // namespace SP -} // namespace CPS diff --git a/dpsim-models/src/CMakeLists.txt b/dpsim-models/src/CMakeLists.txt index 486fac6c97..400cefc4dc 100644 --- a/dpsim-models/src/CMakeLists.txt +++ b/dpsim-models/src/CMakeLists.txt @@ -107,7 +107,6 @@ list(APPEND MODELS_SOURCES EMT/EMT_Ph3_SSN_Full_Serial_RLC.cpp SP/SP_Ph1_VoltageSource.cpp - SP/SP_Ph1_CurrentSource.cpp SP/SP_Ph1_Capacitor.cpp SP/SP_Ph1_Inductor.cpp SP/SP_Ph1_Resistor.cpp diff --git a/dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp b/dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp deleted file mode 100644 index 0539b1a4f7..0000000000 --- a/dpsim-models/src/SP/SP_Ph1_CurrentSource.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright 2017-2024 Institute for Automation of Complex Power Systems, - * EONERC, RWTH Aachen University - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - *********************************************************************************/ - -#include - -using namespace CPS; - -SP::Ph1::CurrentSource::CurrentSource(String uid, String name, - Logger::Level logLevel) - : MNASimPowerComp(uid, name, true, true, logLevel), - mCurrentRef(mAttributes->createDynamic("I_ref")) { - setTerminalNumber(2); - **mIntfVoltage = MatrixComp::Zero(1, 1); - **mIntfCurrent = MatrixComp::Zero(1, 1); -} - -SP::Ph1::CurrentSource::CurrentSource(String name, Complex current, - Logger::Level logLevel) - : CurrentSource(name, logLevel) { - setParameters(current); -} - -void SP::Ph1::CurrentSource::setParameters(Complex current) { - **mCurrentRef = current; - mParametersSet = true; -} - -SimPowerComp::Ptr SP::Ph1::CurrentSource::clone(String name) { - auto copy = CurrentSource::make(name, mLogLevel); - copy->setParameters(**mCurrentRef); - return copy; -} - -void SP::Ph1::CurrentSource::initializeFromNodesAndTerminals(Real frequency) { - - (**mIntfVoltage)(0, 0) = initialSingleVoltage(0) - initialSingleVoltage(1); - (**mIntfCurrent)(0, 0) = **mCurrentRef; - - SPDLOG_LOGGER_INFO(mSLog, - "\n--- Initialization from powerflow ---" - "\nVoltage across: {:s}" - "\nCurrent: {:s}" - "\nTerminal 0 voltage: {:s}" - "\nTerminal 1 voltage: {:s}" - "\n--- Initialization from powerflow finished ---", - Logger::phasorToString((**mIntfVoltage)(0, 0)), - Logger::phasorToString((**mIntfCurrent)(0, 0)), - Logger::phasorToString(initialSingleVoltage(0)), - Logger::phasorToString(initialSingleVoltage(1))); -} - -void SP::Ph1::CurrentSource::mnaCompInitialize( - Real omega, Real timeStep, Attribute::Ptr leftVector) { - updateMatrixNodeIndices(); - (**mIntfCurrent)(0, 0) = **mCurrentRef; -} - -void SP::Ph1::CurrentSource::mnaCompAddPreStepDependencies( - AttributeBase::List &prevStepDependencies, - AttributeBase::List &attributeDependencies, - AttributeBase::List &modifiedAttributes) { - attributeDependencies.push_back(mCurrentRef); - modifiedAttributes.push_back(mRightVector); - modifiedAttributes.push_back(mIntfCurrent); -} - -void SP::Ph1::CurrentSource::mnaCompPreStep(Real time, Int timeStepCount) { - mnaCompApplyRightSideVectorStamp(**mRightVector); -} - -void SP::Ph1::CurrentSource::mnaCompApplyRightSideVectorStamp( - Matrix &rightVector) { - (**mIntfCurrent)(0, 0) = **mCurrentRef; - - if (terminalNotGrounded(0)) - Math::setVectorElement(rightVector, matrixNodeIndex(0), - -(**mIntfCurrent)(0, 0)); - if (terminalNotGrounded(1)) - Math::setVectorElement(rightVector, matrixNodeIndex(1), - (**mIntfCurrent)(0, 0)); -} - -void SP::Ph1::CurrentSource::mnaCompAddPostStepDependencies( - AttributeBase::List &prevStepDependencies, - AttributeBase::List &attributeDependencies, - AttributeBase::List &modifiedAttributes, - Attribute::Ptr &leftVector) { - attributeDependencies.push_back(leftVector); - modifiedAttributes.push_back(mIntfVoltage); -} - -void SP::Ph1::CurrentSource::mnaCompPostStep( - Real time, Int timeStepCount, Attribute::Ptr &leftVector) { - mnaCompUpdateVoltage(**leftVector); -} - -void SP::Ph1::CurrentSource::mnaCompUpdateVoltage(const Matrix &leftVector) { - (**mIntfVoltage)(0, 0) = 0; - if (terminalNotGrounded(0)) - (**mIntfVoltage)(0, 0) = - Math::complexFromVectorElement(leftVector, matrixNodeIndex(0)); - if (terminalNotGrounded(1)) - (**mIntfVoltage)(0, 0) = - (**mIntfVoltage)(0, 0) - - Math::complexFromVectorElement(leftVector, matrixNodeIndex(1)); -} From 7f04b31b6799fb82ce3297ea0fad6d6091f3d457 Mon Sep 17 00:00:00 2001 From: pipeacosta Date: Thu, 7 Nov 2024 11:22:34 +0100 Subject: [PATCH 19/19] Add splitting decoupling line examples to rocky profiling workflow. Signed-off-by: pipeacosta --- .../build_test_linux_rocky_profiling.yaml | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_test_linux_rocky_profiling.yaml b/.github/workflows/build_test_linux_rocky_profiling.yaml index c92aa8d046..476a0151ae 100644 --- a/.github/workflows/build_test_linux_rocky_profiling.yaml +++ b/.github/workflows/build_test_linux_rocky_profiling.yaml @@ -38,7 +38,7 @@ jobs: ## Tests ## test-examples-1: - name: Test Examples 1/2 + name: Test Examples 1/4 needs: [profiling] uses: sogno-platform/dpsim/.github/workflows/run_and_profile_example.yaml@${{github.ref}} with: @@ -46,9 +46,25 @@ jobs: name: WSCC_9bus_mult_decoupled test-examples-2: - name: Test Examples 2/2 + name: Test Examples 2/4 needs: [profiling] uses: sogno-platform/dpsim/.github/workflows/run_and_profile_example.yaml@${{github.ref}} with: path: ./build/dpsim/examples/cxx/WSCC_9bus_mult_coupled name: WSCC_9bus_mult_coupled + + test-examples-3: + name: Test Examples 3/4 + needs: [profiling] + uses: sogno-platform/dpsim/.github/workflows/run_and_profile_example.yaml@${{github.ref}} + with: + path: ./build/dpsim/examples/cxx/EMT_WSCC_9bus_split_decoupled + name: WSCC_9bus_split_decoupled + + test-examples-4: + name: Test Examples 4/4 + needs: [profiling] + uses: sogno-platform/dpsim/.github/workflows/run_and_profile_example.yaml@${{github.ref}} + with: + path: ./build/dpsim/examples/cxx/DP_WSCC_9bus_split_decoupled + name: WSCC_9bus_split_decoupled