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

Solver Configuration Class #226

Open
wants to merge 6 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
2 changes: 2 additions & 0 deletions dpsim-models/include/dpsim-models/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ namespace CPS {
enum class PowerflowBusType { PV, PQ, VD, None };
enum class GeneratorType {PVNode, IdealVoltageSource, IdealCurrentSource, TransientStability, FullOrder, FullOrderVBR, SG6aOrderVBR, SG6bOrderVBR, SG4OrderVBR, SG3OrderVBR, SG4OrderPCM, SG4OrderTPM, SG6OrderPCM, None};
enum class SGOrder {SG3Order, SG4Order, SG6aOrder, SG6bOrder};
enum DirectLinearSolverImpl{Undef = 0, KLU, SparseLU, DenseLU, CUDADense, CUDASparse, CUDAMagma, Plugin };


// ### Exceptions ###
class Exception : public std::exception { };
Expand Down
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
26 changes: 15 additions & 11 deletions dpsim/examples/cxx/CIM/DP_WSCC9bus_SGReducedOrderVBR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
String faultBusName= "BUS6";
Real inertiaScalingFactor = 1.0;
String logDirectory = "logs";
DirectLinearSolverImpl implementation = DirectLinearSolverImpl::SparseLU;
CPS::DirectLinearSolverImpl implementation = CPS::DirectLinearSolverImpl::SparseLU;

// Find CIM files
std::list<fs::path> filenames;
Expand Down 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