Skip to content

Commit 961bb7a

Browse files
Merge pull request #29 from sogno-platform/examples-refactoring-rebase
Refactoring of SMIB and 3Bus transient stability examples by moving the scenario's global parameters to examples.h. For future work, scenario parameters (which are not imported) should be defined in examples.h for a better overview.
2 parents c5f23cc + 688df67 commit 961bb7a

27 files changed

+509
-727
lines changed

Examples/Cxx/CIM/DP_CIGRE_MV_withDG.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int main(int argc, char** argv){
1212

1313
// Simulation parameters
1414
String simName = "DP_CIGRE_MV_withDG";
15-
Examples::CIGREMV::ScenarioConfig scenario;
15+
Examples::Grids::CIGREMV::ScenarioConfig scenario;
1616
std::list<fs::path> filenames;
1717
Real timeStep;
1818
Real finalTime;
@@ -45,7 +45,7 @@ int main(int argc, char** argv){
4545
Logger::setLogDir("logs/" + simNamePF);
4646
CIM::Reader reader(simNamePF, Logger::Level::debug, Logger::Level::debug);
4747
SystemTopology systemPF = reader.loadCIM(scenario.systemFrequency, filenames, Domain::SP);
48-
Examples::CIGREMV::addInvertersToCIGREMV(systemPF, scenario, Domain::SP);
48+
Examples::Grids::CIGREMV::addInvertersToCIGREMV(systemPF, scenario, Domain::SP);
4949

5050
// define logging
5151
auto loggerPF = DPsim::DataLogger::make(simNamePF);
@@ -70,7 +70,7 @@ int main(int argc, char** argv){
7070
Logger::setLogDir("logs/" + simName);
7171
CIM::Reader reader2(simName, Logger::Level::debug, Logger::Level::debug);
7272
SystemTopology systemDP = reader2.loadCIM(scenario.systemFrequency, filenames, CPS::Domain::DP);
73-
Examples::CIGREMV::addInvertersToCIGREMV(systemDP, scenario, Domain::DP);
73+
Examples::Grids::CIGREMV::addInvertersToCIGREMV(systemDP, scenario, Domain::DP);
7474
reader2.initDynamicSystemTopologyWithPowerflow(systemPF, systemDP);
7575

7676
auto logger = DPsim::DataLogger::make(simName);
@@ -96,7 +96,7 @@ int main(int argc, char** argv){
9696
// log output of PV connected at N11
9797
String pv_name = "pv_N11";
9898
auto pv = systemDP.component<CPS::SimPowerComp<Complex>>(pv_name);
99-
Examples::CIGREMV::logPVAttributes(logger, pv);
99+
Examples::Grids::CIGREMV::logPVAttributes(logger, pv);
100100

101101
Simulation sim(simName, Logger::Level::debug);
102102
sim.setSystem(systemDP);

Examples/Cxx/CIM/DP_CIGRE_MV_withDG_withLoadStep.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using namespace CPS::CIM;
1010
int main(int argc, char** argv){
1111

1212
// Simulation parameters
13-
Examples::CIGREMV::ScenarioConfig scenario;
13+
Examples::Grids::CIGREMV::ScenarioConfig scenario;
1414
std::list<fs::path> filenames;
1515
Real timeStep;
1616
Real finalTime;
@@ -42,7 +42,7 @@ int main(int argc, char** argv){
4242
Logger::setLogDir("logs/" + simNamePF);
4343
CIM::Reader reader(simNamePF, Logger::Level::debug, Logger::Level::debug);
4444
SystemTopology systemPF = reader.loadCIM(scenario.systemFrequency, filenames, Domain::SP);
45-
Examples::CIGREMV::addInvertersToCIGREMV(systemPF, scenario, Domain::SP);
45+
Examples::Grids::CIGREMV::addInvertersToCIGREMV(systemPF, scenario, Domain::SP);
4646

4747
// define logging
4848
auto loggerPF = DPsim::DataLogger::make(simNamePF);
@@ -66,7 +66,7 @@ int main(int argc, char** argv){
6666
Logger::setLogDir("logs/" + simName);
6767
CIM::Reader reader2(simName, Logger::Level::info, Logger::Level::debug);
6868
SystemTopology systemDP = reader2.loadCIM(scenario.systemFrequency, filenames, CPS::Domain::DP);
69-
Examples::CIGREMV::addInvertersToCIGREMV(systemDP, scenario, Domain::DP);
69+
Examples::Grids::CIGREMV::addInvertersToCIGREMV(systemDP, scenario, Domain::DP);
7070
reader.initDynamicSystemTopologyWithPowerflow(systemPF, systemDP);
7171

7272
auto logger = DPsim::DataLogger::make(simName);
@@ -92,13 +92,13 @@ int main(int argc, char** argv){
9292
// log output of PV connected at N11
9393
String pv_name = "pv_N11";
9494
auto pv = systemDP.component<CPS::SimPowerComp<Complex>>(pv_name);
95-
Examples::CIGREMV::logPVAttributes(logger, pv);
95+
Examples::Grids::CIGREMV::logPVAttributes(logger, pv);
9696

9797
// // load step sized relative to nominal load at N11
98-
// std::shared_ptr<SwitchEvent> loadStepEvent = Examples::createEventAddPowerConsumption("N11", 2-timeStep, 5*systemPF.component<CPS::SP::Ph1::Load>("LOAD-H-11")->attribute<CPS::Real>("P")->get(), systemDP, Domain::DP, logger);
98+
// std::shared_ptr<SwitchEvent> loadStepEvent = Examples::Events::createEventAddPowerConsumption("N11", 2-timeStep, 5*systemPF.component<CPS::SP::Ph1::Load>("LOAD-H-11")->attribute<CPS::Real>("P")->get(), systemDP, Domain::DP, logger);
9999

100100
// load step sized in absolute terms
101-
std::shared_ptr<SwitchEvent> loadStepEvent = Examples::createEventAddPowerConsumption("N11", 2-timeStep, 1500.0e3, systemDP, Domain::DP, logger);
101+
std::shared_ptr<SwitchEvent> loadStepEvent = Examples::Events::createEventAddPowerConsumption("N11", 2-timeStep, 1500.0e3, systemDP, Domain::DP, logger);
102102

103103
Simulation sim(simName, Logger::Level::debug);
104104
sim.setSystem(systemDP);

Examples/Cxx/CIM/EMT_CIGRE_MV_withDG.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int main(int argc, char** argv){
1212

1313
// Simulation parameters
1414
String simName = "EMT_CIGRE_MV_withDG";
15-
Examples::CIGREMV::ScenarioConfig scenario;
15+
Examples::Grids::CIGREMV::ScenarioConfig scenario;
1616
std::list<fs::path> filenames;
1717
Real timeStep;
1818
Real finalTime;
@@ -42,7 +42,7 @@ int main(int argc, char** argv){
4242
Logger::setLogDir("logs/" + simNamePF);
4343
CIM::Reader reader(simNamePF, Logger::Level::debug, Logger::Level::debug);
4444
SystemTopology systemPF = reader.loadCIM(scenario.systemFrequency, filenames, Domain::SP);
45-
Examples::CIGREMV::addInvertersToCIGREMV(systemPF, scenario, Domain::SP);
45+
Examples::Grids::CIGREMV::addInvertersToCIGREMV(systemPF, scenario, Domain::SP);
4646

4747
// define logging
4848
auto loggerPF = DPsim::DataLogger::make(simNamePF);
@@ -67,7 +67,7 @@ int main(int argc, char** argv){
6767
Logger::setLogDir("logs/" + simName);
6868
CIM::Reader reader2(simName, Logger::Level::debug, Logger::Level::debug);
6969
SystemTopology systemEMT = reader2.loadCIM(scenario.systemFrequency, filenames, CPS::Domain::EMT, PhaseType::ABC);
70-
Examples::CIGREMV::addInvertersToCIGREMV(systemEMT, scenario, Domain::EMT);
70+
Examples::Grids::CIGREMV::addInvertersToCIGREMV(systemEMT, scenario, Domain::EMT);
7171
reader2.initDynamicSystemTopologyWithPowerflow(systemPF, systemEMT);
7272

7373
auto logger = DPsim::DataLogger::make(simName);
@@ -90,7 +90,7 @@ int main(int argc, char** argv){
9090

9191
// log output of PV connected at N11
9292
auto pv = systemEMT.component<CPS::SimPowerComp<Real>>("pv_N11");
93-
Examples::CIGREMV::logPVAttributes(logger, pv);
93+
Examples::Grids::CIGREMV::logPVAttributes(logger, pv);
9494

9595
Simulation sim(simName, Logger::Level::debug);
9696
sim.setSystem(systemEMT);

Examples/Cxx/CIM/EMT_CIGRE_MV_withDG_withLoadStep.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using namespace CPS::CIM;
1111
int main(int argc, char** argv){
1212

1313
// Simulation parameters
14-
Examples::CIGREMV::ScenarioConfig scenario;
14+
Examples::Grids::CIGREMV::ScenarioConfig scenario;
1515
std::list<fs::path> filenames;
1616
Real timeStep;
1717
Real finalTime;
@@ -42,7 +42,7 @@ int main(int argc, char** argv){
4242
Logger::setLogDir("logs/" + simNamePF);
4343
CIM::Reader reader(simNamePF, Logger::Level::debug, Logger::Level::debug);
4444
SystemTopology systemPF = reader.loadCIM(scenario.systemFrequency, filenames, Domain::SP);
45-
Examples::CIGREMV::addInvertersToCIGREMV(systemPF, scenario, Domain::SP);
45+
Examples::Grids::CIGREMV::addInvertersToCIGREMV(systemPF, scenario, Domain::SP);
4646

4747
// define logging
4848
auto loggerPF = DPsim::DataLogger::make(simNamePF);
@@ -67,7 +67,7 @@ int main(int argc, char** argv){
6767
Logger::setLogDir("logs/" + simName);
6868
CIM::Reader reader2(simName, Logger::Level::debug, Logger::Level::debug);
6969
SystemTopology systemEMT = reader2.loadCIM(scenario.systemFrequency, filenames, CPS::Domain::EMT, PhaseType::ABC);
70-
Examples::CIGREMV::addInvertersToCIGREMV(systemEMT, scenario, Domain::EMT);
70+
Examples::Grids::CIGREMV::addInvertersToCIGREMV(systemEMT, scenario, Domain::EMT);
7171
reader2.initDynamicSystemTopologyWithPowerflow(systemPF, systemEMT);
7272

7373
auto logger = DPsim::DataLogger::make(simName);
@@ -90,9 +90,9 @@ int main(int argc, char** argv){
9090

9191
// log output of PV connected at N11
9292
auto pv = systemEMT.component<CPS::SimPowerComp<Real>>("pv_N11");
93-
Examples::CIGREMV::logPVAttributes(logger, pv);
93+
Examples::Grids::CIGREMV::logPVAttributes(logger, pv);
9494

95-
std::shared_ptr<SwitchEvent3Ph> loadStepEvent = Examples::createEventAddPowerConsumption3Ph("N11", 2-timeStep, 1500.0e3, systemEMT, Domain::EMT, logger);
95+
std::shared_ptr<SwitchEvent3Ph> loadStepEvent = Examples::Events::createEventAddPowerConsumption3Ph("N11", 2-timeStep, 1500.0e3, systemEMT, Domain::EMT, logger);
9696
Simulation sim(simName, Logger::Level::debug);
9797
sim.setSystem(systemEMT);
9898
sim.setTimeStep(timeStep);

Examples/Cxx/CIM/PF_CIGRE_MV_withDG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ int main(int argc, char** argv){
2929
Real timeStep = 1;
3030
Real finalTime = 2;
3131
String simName = "PF_CIGRE_MV_withDG";
32-
Examples::CIGREMV::ScenarioConfig scenario;
32+
Examples::Grids::CIGREMV::ScenarioConfig scenario;
3333
Logger::setLogDir("logs/" + simName);
3434

3535
// read original network topology
3636
CIM::Reader reader(simName, Logger::Level::debug, Logger::Level::debug);
3737
SystemTopology system = reader.loadCIM(scenario.systemFrequency, filenames, Domain::SP);
38-
Examples::CIGREMV::addInvertersToCIGREMV(system, scenario, Domain::SP);
38+
Examples::Grids::CIGREMV::addInvertersToCIGREMV(system, scenario, Domain::SP);
3939

4040
auto loggerPF = DPsim::DataLogger::make(simName);
4141
for (auto node : system.mNodes)

Examples/Cxx/Circuits/DP_Slack_PiLine_PQLoad_with_PF_Init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int main(int argc, char* argv[]) {
123123
loggerDP->addAttribute("f_src", extnetDP->attribute("f_src"));
124124

125125
// load step sized in absolute terms
126-
//std::shared_ptr<SwitchEvent> loadStepEvent = CIM::Examples::createEventAddPowerConsumption("n2", 0.1-timeStepDP, 100e3, systemDP, Domain::DP, loggerDP);
126+
//std::shared_ptr<SwitchEvent> loadStepEvent = CIM::Examples::Events::createEventAddPowerConsumption("n2", 0.1-timeStepDP, 100e3, systemDP, Domain::DP, loggerDP);
127127

128128
// Simulation
129129
Simulation sim(simNameDP, Logger::Level::debug);

Examples/Cxx/Circuits/DP_Slack_PiLine_VSI_Ramp_with_PF_Init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using namespace CPS;
1414

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

17-
CIM::Examples::SGIB::ScenarioConfig scenario;
17+
CIM::Examples::Grids::SGIB::ScenarioConfig scenario;
1818

1919
Real finalTime = 2;
2020
Real timeStep = 0.0001;
@@ -129,10 +129,10 @@ int main(int argc, char* argv[]) {
129129
loggerDP->addAttribute("i12", lineDP->attribute("i_intf"));
130130
loggerDP->addAttribute("f_src", extnetDP->attribute("f_src"));
131131

132-
CIM::Examples::CIGREMV::logPVAttributes(loggerDP, pv);
132+
CIM::Examples::Grids::CIGREMV::logPVAttributes(loggerDP, pv);
133133

134134
// load step sized in absolute terms
135-
// std::shared_ptr<SwitchEvent> loadStepEvent = CIM::Examples::createEventAddPowerConsumption("n2", std::round(5.0/timeStep)*timeStep, 10e6, systemDP, Domain::DP, loggerDP);
135+
// std::shared_ptr<SwitchEvent> loadStepEvent = CIM::Examples::Events::createEventAddPowerConsumption("n2", std::round(5.0/timeStep)*timeStep, 10e6, systemDP, Domain::DP, loggerDP);
136136

137137
// Simulation
138138
Simulation sim(simNameDP, Logger::Level::debug);

Examples/Cxx/Circuits/DP_Slack_PiLine_VSI_with_PF_Init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using namespace CPS;
1414

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

17-
CIM::Examples::SGIB::ScenarioConfig scenario;
17+
CIM::Examples::Grids::SGIB::ScenarioConfig scenario;
1818

1919
Real finalTime = 2;
2020
Real timeStep = 0.0001;
@@ -128,10 +128,10 @@ int main(int argc, char* argv[]) {
128128
loggerDP->addAttribute("v2", n2DP->attribute("v"));
129129
loggerDP->addAttribute("i12", lineDP->attribute("i_intf"));
130130

131-
CIM::Examples::CIGREMV::logPVAttributes(loggerDP, pv);
131+
CIM::Examples::Grids::CIGREMV::logPVAttributes(loggerDP, pv);
132132

133133
// load step sized in absolute terms
134-
// std::shared_ptr<SwitchEvent> loadStepEvent = CIM::Examples::createEventAddPowerConsumption("n2", std::round(5.0/timeStep)*timeStep, 10e6, systemDP, Domain::DP, loggerDP);
134+
// std::shared_ptr<SwitchEvent> loadStepEvent = CIM::Examples::Events::createEventAddPowerConsumption("n2", std::round(5.0/timeStep)*timeStep, 10e6, systemDP, Domain::DP, loggerDP);
135135

136136
// Simulation
137137
Simulation sim(simNameDP, Logger::Level::debug);

0 commit comments

Comments
 (0)