Skip to content

Commit

Permalink
add wscc with full order dcim and vbr syngen
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Dinkelbach <jdinkelbach@eonerc.rwth-aachen.de>
  • Loading branch information
dinkelbachjan authored and m-mirz committed Dec 3, 2021
1 parent 06f8fa0 commit 9dbb644
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 7 deletions.
113 changes: 113 additions & 0 deletions Examples/Cxx/CIM/EMT_WSCC-9bus_FullOrderSG.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* Copyright 2017-2020 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 <iostream>
#include <list>

#include <DPsim.h>

using namespace DPsim;
using namespace CPS::EMT;

int main(int argc, char *argv[]) {

// Simulation parameters
String simName = "EMT_WSCC-9bus_FullOrderSG";
Real timeStep;
Real finalTime;

// Find CIM files
std::list<fs::path> filenames;
CommandLineArgs args(argc, argv);
if (argc <= 1) {
filenames = Utils::findFiles({
"WSCC-09_Dyn_Full_DI.xml",
"WSCC-09_Dyn_Full_EQ.xml",
"WSCC-09_Dyn_Full_SV.xml",
"WSCC-09_Dyn_Full_TP.xml"
}, "/cimdata/WSCC-09_Dyn_Full", "CIMPATH");
timeStep = 10e-6;
finalTime = 0.1;
}
else {
filenames = args.positionalPaths();
timeStep = args.timeStep;
finalTime = args.duration;
}

// ----- POWERFLOW FOR INITIALIZATION -----
// read original network topology
String simNamePF = simName + "_PF";
Logger::setLogDir("logs/" + simNamePF);
CPS::CIM::Reader reader(simNamePF, Logger::Level::debug, Logger::Level::debug);
SystemTopology systemPF = reader.loadCIM(60, filenames, Domain::SP, PhaseType::Single, CPS::GeneratorType::PVNode);
systemPF.component<CPS::SP::Ph1::SynchronGenerator>("GEN1")->modifyPowerFlowBusType(CPS::PowerflowBusType::VD);

// define logging
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
}

// run powerflow
Simulation simPF(simNamePF, Logger::Level::debug);
simPF.setSystem(systemPF);
simPF.setTimeStep(finalTime);
simPF.setFinalTime(2*finalTime);
simPF.setDomain(Domain::SP);
simPF.setSolverType(Solver::Type::NRP);
simPF.setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
simPF.doInitFromNodesAndTerminals(true);
simPF.addLogger(loggerPF);
simPF.run();

// ----- DYNAMIC SIMULATION -----
Logger::setLogDir("logs/"+simName);

CPS::CIM::Reader reader2(simName, Logger::Level::debug, Logger::Level::debug);
SystemTopology sys = reader2.loadCIM(60, filenames, Domain::EMT, PhaseType::ABC, CPS::GeneratorType::FullOrder);

reader2.initDynamicSystemTopologyWithPowerflow(systemPF, sys);
for (auto comp : sys.mComponents) {
if (auto genEMT = std::dynamic_pointer_cast<CPS::EMT::Ph3::SynchronGeneratorDQTrapez>(comp)) {
auto genPF = systemPF.component<CPS::SP::Ph1::SynchronGenerator>(comp->name());
genEMT->terminal(0)->setPower(-genPF->getApparentPower());
}
}

// Logging
auto logger = DataLogger::make(simName);
logger->addAttribute("v1", sys.node<SimNode>("BUS1")->attribute("v"));
logger->addAttribute("v2", sys.node<SimNode>("BUS2")->attribute("v"));
logger->addAttribute("v3", sys.node<SimNode>("BUS3")->attribute("v"));
logger->addAttribute("v4", sys.node<SimNode>("BUS4")->attribute("v"));
logger->addAttribute("v5", sys.node<SimNode>("BUS5")->attribute("v"));
logger->addAttribute("v6", sys.node<SimNode>("BUS6")->attribute("v"));
logger->addAttribute("v7", sys.node<SimNode>("BUS7")->attribute("v"));
logger->addAttribute("v8", sys.node<SimNode>("BUS8")->attribute("v"));
logger->addAttribute("v9", sys.node<SimNode>("BUS9")->attribute("v"));

// log generator's current
for (auto comp : sys.mComponents) {
if (std::dynamic_pointer_cast<CPS::EMT::Ph3::SynchronGeneratorDQTrapez>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

Simulation sim(simName, Logger::Level::info);
sim.setSystem(sys);
sim.setDomain(Domain::EMT);
sim.setSolverType(Solver::Type::MNA);
sim.setMnaSolverImplementation(DPsim::MnaSolverFactory::EigenSparse);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.addLogger(logger);
sim.run();

return 0;
}
114 changes: 114 additions & 0 deletions Examples/Cxx/CIM/EMT_WSCC-9bus_VBR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* Copyright 2017-2020 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 <iostream>
#include <list>

#include <DPsim.h>

using namespace DPsim;
using namespace CPS::EMT;

int main(int argc, char *argv[]) {

// Simulation parameters
String simName = "EMT_WSCC-9bus_VBR";
Real timeStep;
Real finalTime;

// Find CIM files
std::list<fs::path> filenames;
CommandLineArgs args(argc, argv);
if (argc <= 1) {
filenames = Utils::findFiles({
"WSCC-09_Dyn_Full_DI.xml",
"WSCC-09_Dyn_Full_EQ.xml",
"WSCC-09_Dyn_Full_SV.xml",
"WSCC-09_Dyn_Full_TP.xml"
}, "/cimdata/WSCC-09_Dyn_Full", "CIMPATH");
timeStep = 10e-6;
finalTime = 0.1;
}
else {
filenames = args.positionalPaths();
timeStep = args.timeStep;
finalTime = args.duration;
}

// ----- POWERFLOW FOR INITIALIZATION -----
// read original network topology
String simNamePF = simName + "_PF";
Logger::setLogDir("logs/" + simNamePF);
CPS::CIM::Reader reader(simNamePF, Logger::Level::debug, Logger::Level::debug);
SystemTopology systemPF = reader.loadCIM(60, filenames, Domain::SP, PhaseType::Single, CPS::GeneratorType::PVNode);
systemPF.component<CPS::SP::Ph1::SynchronGenerator>("GEN1")->modifyPowerFlowBusType(CPS::PowerflowBusType::VD);

// define logging
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->addAttribute(node->name() + ".V", node->attribute("v"));
}

// run powerflow
Simulation simPF(simNamePF, Logger::Level::debug);
simPF.setSystem(systemPF);
simPF.setTimeStep(finalTime);
simPF.setFinalTime(2*finalTime);
simPF.setDomain(Domain::SP);
simPF.setSolverType(Solver::Type::NRP);
simPF.setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
simPF.doInitFromNodesAndTerminals(true);
simPF.addLogger(loggerPF);
simPF.run();

// ----- DYNAMIC SIMULATION -----
Logger::setLogDir("logs/"+simName);

CPS::CIM::Reader reader2(simName, Logger::Level::debug, Logger::Level::debug);
SystemTopology sys = reader2.loadCIM(60, filenames, Domain::EMT, PhaseType::ABC, CPS::GeneratorType::FullOrderVBR);

reader2.initDynamicSystemTopologyWithPowerflow(systemPF, sys);
for (auto comp : sys.mComponents) {
if (auto genEMT = std::dynamic_pointer_cast<CPS::EMT::Ph3::SynchronGeneratorVBR>(comp)) {
auto genPF = systemPF.component<CPS::SP::Ph1::SynchronGenerator>(comp->name());
genEMT->terminal(0)->setPower(-genPF->getApparentPower());
}
}

// Logging
auto logger = DataLogger::make(simName);
logger->addAttribute("v1", sys.node<SimNode>("BUS1")->attribute("v"));
logger->addAttribute("v2", sys.node<SimNode>("BUS2")->attribute("v"));
logger->addAttribute("v3", sys.node<SimNode>("BUS3")->attribute("v"));
logger->addAttribute("v4", sys.node<SimNode>("BUS4")->attribute("v"));
logger->addAttribute("v5", sys.node<SimNode>("BUS5")->attribute("v"));
logger->addAttribute("v6", sys.node<SimNode>("BUS6")->attribute("v"));
logger->addAttribute("v7", sys.node<SimNode>("BUS7")->attribute("v"));
logger->addAttribute("v8", sys.node<SimNode>("BUS8")->attribute("v"));
logger->addAttribute("v9", sys.node<SimNode>("BUS9")->attribute("v"));

// log generator's current
for (auto comp : sys.mComponents) {
if (std::dynamic_pointer_cast<CPS::EMT::Ph3::SynchronGeneratorVBR>(comp))
logger->addAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

Simulation sim(simName, Logger::Level::info);
sim.setSystem(sys);
sim.setDomain(Domain::EMT);
sim.setSolverType(Solver::Type::MNA);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.doSystemMatrixRecomputation(true);
sim.setMnaSolverImplementation(MnaSolverFactory::MnaSolverImpl::EigenSparse);
sim.addLogger(logger);
sim.run();

return 0;
}
2 changes: 2 additions & 0 deletions Examples/Cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ if(WITH_CIM)
CIM/SP_WSCC-9bus_CIM_Dyn_Switch.cpp
CIM/EMT_WSCC-9bus_IdealVS.cpp
CIM/EMT_WSCC-9bus_IdealCS.cpp
CIM/EMT_WSCC-9bus_FullOrderSG.cpp
CIM/EMT_WSCC-9bus_VBR.cpp
CIM/DP_WSCC-9bus_IdealVS.cpp

# PF(Power Flow) example
Expand Down
19 changes: 13 additions & 6 deletions Include/dpsim/MNASolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ namespace DPsim {
CPS::MNASwitchInterface::List mSwitches;
/// List of switches if they must be accessed as MNAInterface objects
CPS::MNAInterface::List mMNAIntfSwitches;
/// List of components that indicate the solver to recompute the system matrix
/// depending on their state
CPS::MNAVariableCompInterface::List mVariableComps;
/// List of variable components if they must be accessed as MNAInterface objects
CPS::MNAInterface::List mMNAIntfVariableComps;
/// List of signal type components that do not directly interact with the MNA solver
CPS::SimSignalComp::List mSimSignalComps;
/// Current status of all switches encoded as bitset
Expand All @@ -93,6 +88,15 @@ namespace DPsim {
///
std::vector< CPS::Attribute<Matrix>::Ptr > mLeftVectorHarmAttributes;

// #### MNA specific attributes related to system recomputation
/// Number of system matrix recomputations
Int mNumRecomputations;
/// List of components that indicate the solver to recompute the system matrix
/// depending on their state
CPS::MNAVariableCompInterface::List mVariableComps;
/// List of variable components if they must be accessed as MNAInterface objects
CPS::MNAInterface::List mMNAIntfVariableComps;

// #### Attributes related to switching ####
/// Index of the next switching event
UInt mSwitchTimeIndex = 0;
Expand Down Expand Up @@ -178,7 +182,10 @@ namespace DPsim {
public:

/// Destructor
virtual ~MnaSolver() { };
virtual ~MnaSolver() {
if (mSystemMatrixRecomputation)
mSLog->info("Number of system matrix recomputations: {:}", mNumRecomputations);
};

/// Calls subroutines to set up everything that is required before simulation
virtual void initialize() override;
Expand Down
1 change: 1 addition & 0 deletions Include/dpsim/MNASolverEigenSparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace DPsim {
using MnaSolver<VarType>::mSLog;
using MnaSolver<VarType>::mSystemMatrixRecomputation;
using MnaSolver<VarType>::hasVariableComponentChanged;
using MnaSolver<VarType>::mNumRecomputations;

// #### General
/// Create system matrix
Expand Down
2 changes: 1 addition & 1 deletion Source/MNASolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Bool MnaSolver<VarType>::hasVariableComponentChanged() {
for (auto varElem : mVariableComps) {
if (varElem->hasParameterChanged()) {
auto idObj = std::dynamic_pointer_cast<IdentifiedObject>(varElem);
this->mSLog->info("Component ({:s} {:s}) value changed -> Update System Matrix",
this->mSLog->debug("Component ({:s} {:s}) value changed -> Update System Matrix",
idObj->type(), idObj->name());
return true;
}
Expand Down
1 change: 1 addition & 0 deletions Source/MNASolverEigenSparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void MnaSolverEigenSparse<VarType>::recomputeSystemMatrix(Real time) {
// Refactorization of matrix assuming that structure remained
// constant by omitting analyzePattern
mLuFactorizationVariableSystemMatrix.factorize(mVariableSystemMatrix);
++mNumRecomputations;
}

template <>
Expand Down

0 comments on commit 9dbb644

Please sign in to comment.