Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WSCC_9bus_mult examples and implement splitting examples in DP and EMT #322

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/build_test_linux_fedora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions dpsim-models/include/dpsim-models/DP/DP_Ph1_RXLoad.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class RXLoad : public CompositePowerComp<Complex>,
/// Defines name, component parameters and logging level
RXLoad(String name, Logger::Level logLevel = Logger::Level::off);

SimPowerComp<Complex>::Ptr clone(String name) override;

// #### General ####
/// Initialize component from power flow data
void initializeFromNodesAndTerminals(Real frequency) override;
Expand Down
4 changes: 4 additions & 0 deletions dpsim-models/include/dpsim-models/SystemTopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename VarType>
int checkTopologySubnets(
Expand Down
6 changes: 6 additions & 0 deletions dpsim-models/src/DP/DP_Ph1_RXLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Complex>::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) {
Expand Down
8 changes: 8 additions & 0 deletions dpsim-models/src/SystemTopology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename VarType>
void SystemTopology::splitSubnets(std::vector<SystemTopology> &splitSystems) {
std::unordered_map<typename SimNode<VarType>::Ptr, int> subnet;
Expand Down
113 changes: 113 additions & 0 deletions dpsim/examples/cxx/CIM/DP_WSCC_9bus_split_decoupled.cpp
Original file line number Diff line number Diff line change
@@ -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 <fstream>
#include <iostream>
#include <list>

#include <DPsim.h>
#include <dpsim/ThreadLevelScheduler.h>

using namespace DPsim;
using namespace CPS;

String decoupleLine(SystemTopology &sys, const String &lineName, const String &node1, const String node2) {
auto origLine = sys.component<DP::Ph1::PiLine>(lineName);
Real Rline = origLine->attributeTyped<Real>("R_series")->get();
Real Lline = origLine->attributeTyped<Real>("L_series")->get();
Real Cline = origLine->attributeTyped<Real>("C_parallel")->get();

sys.removeComponent(lineName);

String dline_name = "dline_" + node1 + "_" + node2;

auto line = Signal::DecouplingLine::make(
"dline_" + node1 + "_" + node2, sys.node<DP::SimNode>(node1),
sys.node<DP::SimNode>(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<DP::SimNode>("BUS5")->attribute("v"));
// logger->logAttribute("BUS6.v", sys.node<DP::SimNode>("BUS6")->attribute("v"));
// logger->logAttribute("BUS8.v", sys.node<DP::SimNode>("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<DP::SimNode>(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<OpenMPLevelScheduler>(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<fs::path> 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);
}
121 changes: 121 additions & 0 deletions dpsim/examples/cxx/CIM/EMT_WSCC_9bus_split_decoupled.cpp
Original file line number Diff line number Diff line change
@@ -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 <fstream>
#include <iostream>
#include <list>

#include <DPsim.h>
#include <dpsim/ThreadLevelScheduler.h>

using namespace DPsim;
using namespace CPS;

String decoupleLine(SystemTopology &sys, const String &lineName, const String &node1, const String node2) {
auto origLine = sys.component<EMT::Ph3::PiLine>(lineName);
Matrix Rline = origLine->attributeTyped<Matrix>("R_series")->get();
Matrix Lline = origLine->attributeTyped<Matrix>("L_series")->get();
Matrix Cline = origLine->attributeTyped<Matrix>("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<EMT::SimNode>(node1), sys.node<EMT::SimNode>(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<EMT::SimNode>("BUS5")->attribute("v"));
// logger->logAttribute("BUS6.v", sys.node<EMT::SimNode>("BUS6")->attribute("v"));
// logger->logAttribute("BUS8.v", sys.node<EMT::SimNode>("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<EMT::SimNode>(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<OpenMPLevelScheduler>(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<fs::path> 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);
}
2 changes: 1 addition & 1 deletion dpsim/examples/cxx/CIM/WSCC-9bus_CIM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions dpsim/examples/cxx/CIM/WSCC_9bus_mult_coupled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ void simulateCoupled(std::list<fs::path> filenames, CommandLineArgs &args,
sim.setScheduler(std::make_shared<OpenMPLevelScheduler>(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<DP::SimNode>(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<DP::SimNode>(nodeName)->attribute("v"));
}
}
sim.addLogger(logger);

sim.run();
sim.logStepTimes(simName + "_step_times");
Expand Down
26 changes: 13 additions & 13 deletions dpsim/examples/cxx/CIM/WSCC_9bus_mult_decoupled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ void simulateDecoupled(std::list<fs::path> filenames, Int copies, Int threads,
sim.setScheduler(std::make_shared<OpenMPLevelScheduler>(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<DP::SimNode>(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<DP::SimNode>(nodeName)->attribute("v"));
}
}
sim.addLogger(logger);

//std::ofstream of1("topology_graph.svg");
//sys.topologyGraph().render(of1));
Expand Down
Loading
Loading