diff --git a/.github/workflows/build_test_linux_fedora.yaml b/.github/workflows/build_test_linux_fedora.yaml index e4d58f21a6..b967991bd8 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 @@ -194,12 +194,18 @@ 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 3/4 + run: ./build/dpsim/examples/cxx/DP_WSCC_9bus_split_decoupled + + - name: Run Binaries 4/4 + run: ./build/dpsim/examples/cxx/EMT_WSCC_9bus_split_decoupled + cpp-check: name: Scan Sourcecode with Cppcheck runs-on: ubuntu-latest 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 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..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,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) override; + // #### General #### /// Initialize component from power flow data void initializeFromNodesAndTerminals(Real frequency) override; 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/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) { 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; diff --git a/dpsim/examples/cxx/CIM/DP_WSCC_9bus_split_decoupled.cpp b/dpsim/examples/cxx/CIM/DP_WSCC_9bus_split_decoupled.cpp new file mode 100644 index 0000000000..60c4a5702f --- /dev/null +++ b/dpsim/examples/cxx/CIM/DP_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/EMT_WSCC_9bus_split_decoupled.cpp b/dpsim/examples/cxx/CIM/EMT_WSCC_9bus_split_decoupled.cpp new file mode 100644 index 0000000000..2b39f66ce2 --- /dev/null +++ b/dpsim/examples/cxx/CIM/EMT_WSCC_9bus_split_decoupled.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/CIM/WSCC-9bus_CIM.cpp b/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp index bf3a79dc53..4d356abbf5 100644 --- a/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp +++ b/dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp @@ -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); diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp index e48e417d65..fc42ddca98 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"); diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp index acd4fe3d91..427981cc5b 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)); diff --git a/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp b/dpsim/examples/cxx/CIM/WSCC_9bus_mult_diakoptics.cpp index ae78a09f89..d89a1fe95f 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"); diff --git a/dpsim/examples/cxx/CMakeLists.txt b/dpsim/examples/cxx/CMakeLists.txt index 0edc927961..11c797f280 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/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/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"); diff --git a/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb b/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb index d237c134b5..5b7eb8c600 100644 --- a/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb +++ b/examples/Notebooks/Performance/WSCC_9bus_parallel.ipynb @@ -16,8 +16,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_coupled ${TOP}/examples/CIM/WSCC-09_RX/*.xml" + "WSCC_9bus_mult_coupled -o copies=1" ] }, { @@ -29,8 +30,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" + "WSCC_9bus_mult_decoupled -o copies=1" ] }, { @@ -42,8 +44,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", - "WSCC_9bus_mult_diakoptics ${TOP}/examples/CIM/WSCC-09_RX/*.xml" + "WSCC_9bus_mult_diakoptics -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_CIM" ] }, { @@ -55,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -72,8 +89,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 +104,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 +119,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 +534,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.5" + "version": "3.10.11" }, "tests": { "skip": true diff --git a/examples/Notebooks/Performance/WSCC_9bus_split.ipynb b/examples/Notebooks/Performance/WSCC_9bus_split.ipynb new file mode 100644 index 0000000000..de3af0b793 --- /dev/null +++ b/examples/Notebooks/Performance/WSCC_9bus_split.ipynb @@ -0,0 +1,172 @@ +{ + "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", + "DP_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", + "EMT_WSCC_9bus_split_decoupled" + ] + }, + { + "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 + ' 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", + " 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": [] + } + ], + "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 +} diff --git a/examples/Python/RuntimeMeas/decoupling_9bus_existing.py b/examples/Python/RuntimeMeas/decoupling_9bus_existing.py index 905697988b..fa7b6636a7 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.DP, dpsimpy.PhaseType.Single, dpsimpy.GeneratorType.IdealVoltageSource) 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.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') 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])