Skip to content

Commit

Permalink
use SolverParameters in all examples
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Moraga <[email protected]>
  • Loading branch information
martinmoraga committed Jul 6, 2023
1 parent a2e6859 commit 1fb5738
Show file tree
Hide file tree
Showing 76 changed files with 712 additions and 598 deletions.
10 changes: 6 additions & 4 deletions dpsim/examples/cxx/CIM/CIGRE_MV_PowerFlowTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ int main(int argc, char** argv){
logger->logAttribute(node->name() + ".V", node->attribute("v"));
}

// set solver parameters
auto solverParameters = std::make_shared<SolverParametersMNA>();
solverParameters->setSolverAndComponentBehaviour(Solver::Behaviour::Simulation);
solverParameters->setInitFromNodesAndTerminals(true);

Simulation sim(simName, Logger::Level::info);
sim.setSystem(system);
sim.setTimeStep(1);
sim.setFinalTime(1);
sim.setDomain(Domain::SP);
sim.setSolverType(Solver::Type::NRP);
sim.setSolverAndComponentBehaviour(Solver::Behaviour::Simulation);
sim.doInitFromNodesAndTerminals(true);
sim.setSolverParameters(Domain::SP, Solver::Type::NRP, solverParameters);
sim.addLogger(logger);

sim.run();
Expand Down
14 changes: 8 additions & 6 deletions dpsim/examples/cxx/CIM/CIGRE_MV_PowerFlowTest_LoadProfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ int main(int argc, char** argv){
}
}

// set solver parameters
auto solverParameters = std::make_shared<SolverParametersMNA>();
solverParameters->setSolverAndComponentBehaviour(Solver::Behaviour::Simulation);
solverParameters->setInitFromNodesAndTerminals(true);

//
Simulation sim(simName, Logger::Level::info);
sim.setSystem(system);
sim.setTimeStep(time_step);
sim.setFinalTime(time_end);
sim.setDomain(Domain::SP);
sim.setSolverType(Solver::Type::NRP);
sim.setSolverAndComponentBehaviour(Solver::Behaviour::Simulation);
sim.doInitFromNodesAndTerminals(true);
sim.setSimulationParameters(time_end, time_end);
simPF.setSolverParameters(Domain::SP, Solver::Type::NRP, solverParameters);
sim.addLogger(logger);

sim.run();
Expand Down
26 changes: 15 additions & 11 deletions dpsim/examples/cxx/CIM/DP_CIGRE_MV_withDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ int main(int argc, char** argv){
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// set solver parameters
auto solverParameters = std::make_shared<SolverParametersMNA>();
solverParameters->setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
solverParameters->setInitFromNodesAndTerminals(true);

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

Expand Down Expand Up @@ -106,15 +108,17 @@ int main(int argc, char** argv){
auto pv = systemDP.component<CPS::SimPowerComp<Complex>>(pv_name);
Examples::Grids::CIGREMV::logPVAttributes(logger, pv);

// set solver parameters
auto solverParameterDP = std::make_shared<SolverParametersMNA>();
solverParameterDP->setInitFromNodesAndTerminals(true);
solverParameterDP->setDirectLinearSolverImplementation(CPS::DirectLinearSolverImpl::SparseLU);
solverParameterDP->doSteadyStateInit(steadyStateInit);

//
Simulation sim(simName, Logger::Level::debug);
sim.setSystem(systemDP);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.setDomain(Domain::DP);
sim.setSolverType(Solver::Type::MNA);
sim.doInitFromNodesAndTerminals(true);

sim.doSteadyStateInit(steadyStateInit);
sim.setSimulationParameters(timeStep, finalTime);
sim.setSolverParameters(Domain::DP, Solver::Type::MNA, solverParameterDP);
sim.addLogger(logger);
sim.run();

Expand Down
25 changes: 15 additions & 10 deletions dpsim/examples/cxx/CIM/DP_CIGRE_MV_withDG_withLoadStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ int main(int argc, char** argv){
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// set solver parameters
auto solverParameters = std::make_shared<SolverParametersMNA>();
solverParameters->setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
solverParameters->setInitFromNodesAndTerminals(true);

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

Expand Down Expand Up @@ -108,14 +110,17 @@ int main(int argc, char** argv){
// load step sized in absolute terms
std::shared_ptr<SwitchEvent> loadStepEvent = Examples::Events::createEventAddPowerConsumption("N11", 2-timeStep, 1500.0e3, systemDP, Domain::DP, logger);

// set solver parameters
auto solverParameterDP = std::make_shared<SolverParametersMNA>();
solverParameterDP->setInitFromNodesAndTerminals(true);
solverParameterDP->setDirectLinearSolverImplementation(CPS::DirectLinearSolverImpl::SparseLU);
solverParameterDP->doSystemMatrixRecomputation(false);
solverParameterDP->doSteadyStateInit(true);

Simulation sim(simName, Logger::Level::debug);
sim.setSystem(systemDP);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.setDomain(Domain::DP);
sim.setSolverType(Solver::Type::MNA);
sim.doInitFromNodesAndTerminals(true);
sim.doSteadyStateInit(false);
sim.setSimulationParameters(timeStep, finalTime);
sim.setSolverParameters(Domain::DP, Solver::Type::MNA, solverParameterDP);
sim.addLogger(logger);
sim.addEvent(loadStepEvent);

Expand Down
28 changes: 18 additions & 10 deletions dpsim/examples/cxx/CIM/DP_CIGRE_MV_withoutDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ int main(int argc, char** argv){
{
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// set solver parameters
auto solverParameters = std::make_shared<SolverParametersMNA>();
solverParameters->setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
solverParameters->setInitFromNodesAndTerminals(true);

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

Expand Down Expand Up @@ -93,14 +97,18 @@ int main(int argc, char** argv){
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// set solver parameters
auto solverParameterDP = std::make_shared<SolverParametersMNA>();
solverParameterDP->setInitFromNodesAndTerminals(true);
solverParameterDP->setDirectLinearSolverImplementation(CPS::DirectLinearSolverImpl::SparseLU);
solverParameterDP->doSystemMatrixRecomputation(false);
solverParameterDP->doSteadyStateInit(steadyStateInit);

//
Simulation sim(simName, Logger::Level::debug);
sim.setSystem(systemDP);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.setDomain(Domain::DP);
sim.setSolverType(Solver::Type::MNA);
sim.doInitFromNodesAndTerminals(true);
sim.doSteadyStateInit(steadyStateInit);
sim.setSimulationParameters(timeStep, finalTime);
sim.setSolverParameters(Domain::DP, Solver::Type::MNA, solverParameterSP);
sim.addLogger(logger);

sim.run();
Expand Down
21 changes: 14 additions & 7 deletions dpsim/examples/cxx/CIM/DP_WSCC-9bus_IdealVS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ int main(int argc, char *argv[]) {
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// set solver parameters
auto solverParameters = std::make_shared<SolverParametersMNA>();
solverParameters->setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
solverParameters->setInitFromNodesAndTerminals(true);

// 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.setSolverParameters(Domain::SP, Solver::Type::NRP, solverParameters);
simPF.addLogger(loggerPF);
simPF.run();

Expand Down Expand Up @@ -92,11 +94,16 @@ int main(int argc, char *argv[]) {
logger->logAttribute(comp->name() + ".I", comp->attribute("i_intf"));
}

// set solver parameters
auto solverParameterDP = std::make_shared<SolverParametersMNA>();
solverParameterDP->setInitFromNodesAndTerminals(true);
solverParameterDP->setDirectLinearSolverImplementation(CPS::DirectLinearSolverImpl::SparseLU);

//
Simulation sim(simName, Logger::Level::info);
sim.setSystem(sys);
sim.setDomain(Domain::DP);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.setSimulationParameters(timeStep, finalTime);
sim.setSolverParameters(Domain::DP, Solver::Type::MNA, solverParameterDP);
sim.addLogger(logger);
sim.run();

Expand Down
22 changes: 13 additions & 9 deletions dpsim/examples/cxx/CIM/DP_WSCC9bus_SGReducedOrderIter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,17 @@ int main(int argc, char *argv[]) {
for (auto node : systemPF.mNodes)
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));

// set solver parameters
auto solverParameters = std::make_shared<SolverParametersMNA>();
solverParameters->setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
solverParameters->setInitFromNodesAndTerminals(true);

// run powerflow
Simulation simPF(simNamePF, logLevel);
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.setSolverParameters(Domain::SP, Solver::Type::NRP, solverParameters);
simPF.addLogger(loggerPF);
simPF.run();

Expand Down Expand Up @@ -165,13 +167,15 @@ int main(int argc, char *argv[]) {
}
}

// set solver parameters
auto solverParameterDP = std::make_shared<SolverParametersMNA>();
solverParameterDP->setDirectLinearSolverImplementation(CPS::DirectLinearSolverImpl::SparseLU);

//
Simulation sim(simName, logLevel);
sim.setSystem(sys);
sim.setDomain(Domain::DP);
sim.setSolverType(Solver::Type::MNA);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.setDirectLinearSolverImplementation(DPsim::DirectLinearSolverImpl::SparseLU);
sim.setSimulationParameters(timeStep, finalTime);
simSP.setSolverParameters(Domain::DP, Solver::Type::MNA, solverParameterDP);
sim.addLogger(logger);

// Optionally add switch event
Expand Down
24 changes: 14 additions & 10 deletions dpsim/examples/cxx/CIM/DP_WSCC9bus_SGReducedOrderVBR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@ int main(int argc, char *argv[]) {
for (auto node : systemPF.mNodes)
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));

// set solver parameters
auto solverParameters = std::make_shared<SolverParametersMNA>();
solverParameters->setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
solverParameters->setInitFromNodesAndTerminals(true);

// run powerflow
Simulation simPF(simNamePF, logLevel);
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.setSolverParameters(Domain::SP, Solver::Type::NRP, solverParameters);
simPF.addLogger(loggerPF);
simPF.run();

Expand Down Expand Up @@ -161,14 +163,16 @@ int main(int argc, char *argv[]) {
}
}

// set solver parameters
auto solverParameterDP = std::make_shared<SolverParametersMNA>();
solverParameterDP->setInitFromNodesAndTerminals(true);
solverParameterDP->setDirectLinearSolverImplementation(implementation);
solverParameterDP->doSystemMatrixRecomputation(true);

Simulation sim(simName, logLevel);
sim.setSystem(sys);
sim.setDomain(Domain::DP);
sim.setSolverType(Solver::Type::MNA);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.doSystemMatrixRecomputation(true);
sim.setDirectLinearSolverImplementation(implementation);
simSP.setSimulationParameters(timeStep, finalTime);
simSP.setSolverParameters(Domain::SP, Solver::Type::MNA, solverParameterDP);
sim.addLogger(logger);

// Optionally add switch event
Expand Down
26 changes: 14 additions & 12 deletions dpsim/examples/cxx/CIM/EMT_CIGRE_MV_withDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ int main(int argc, char** argv){
// define logging
auto loggerPF = DPsim::DataLogger::make(simNamePF);
for (auto node : systemPF.mNodes)
{
loggerPF->logAttribute(node->name() + ".V", node->attribute("v"));
}

// set solver parameters
auto solverParameters = std::make_shared<SolverParametersMNA>();
solverParameters->setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
solverParameters->setInitFromNodesAndTerminals(true);

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

Expand Down Expand Up @@ -100,14 +100,16 @@ int main(int argc, char** argv){
auto pv = systemEMT.component<CPS::SimPowerComp<Real>>("pv_N11");
Examples::Grids::CIGREMV::logPVAttributes(logger, pv);

// set solver parameters
auto solverParameterEMT = std::make_shared<SolverParametersMNA>();
solverParameterEMT->setInitFromNodesAndTerminals(true);
solverParameterEMT->setDirectLinearSolverImplementation(CPS::DirectLinearSolverImpl::SparseLU);
solverParameterEMT->doSteadyStateInit(false);

Simulation sim(simName, Logger::Level::debug);
sim.setSystem(systemEMT);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.setDomain(Domain::EMT);
sim.setSolverType(Solver::Type::MNA);
sim.doInitFromNodesAndTerminals(true);
sim.doSteadyStateInit(false);
sim.setSimulationParameters(timeStep, finalTime);
sim.setSolverParameters(Domain::EMT, Solver::Type::MNA, solverParameterEMT);
sim.addLogger(logger);

sim.run();
Expand Down
Loading

0 comments on commit 1fb5738

Please sign in to comment.