DPsim
Loading...
Searching...
No Matches
Solver.h
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#pragma once
10
11#include <iostream>
12#include <list>
13#include <vector>
14
15#include <dpsim-models/Logger.h>
17#include <dpsim-models/Task.h>
18#include <dpsim/Config.h>
19#include <dpsim/Definitions.h>
21
22namespace DPsim {
28
30class Solver {
31public:
35 static constexpr Real DEFAULT_STEAD_ST_INI_ACC_LIMIT = 1e-8;
36
37 typedef std::shared_ptr<Solver> Ptr;
38 typedef std::vector<Ptr> List;
39
41
51
52protected:
65
66 // #### Initialization ####
83
86
87public:
89 : mName(name), mLogLevel(logLevel),
90 mSLog(CPS::Logger::get(name + "_Solver", logLevel,
91 CPS::Logger::Level::warn)) {}
92
93 virtual ~Solver() {}
94
95 // #### Solver settings ####
98 enum class Type { MNA, DAE, NRP };
100 void setTimeStep(Real timeStep) { mTimeStep = timeStep; }
102 void doFrequencyParallelization(Bool freqParallel) {
103 mFrequencyParallel = freqParallel;
104 }
105
106 virtual void setSystem(const CPS::SystemTopology &system) {}
111
118
119 void setLogSolveTimes(Bool value) { mLogSolveTimes = value; }
120
121 // #### Initialization ####
123 virtual void initialize() {}
135 virtual void
137 // not every derived class has a linear solver configuration option
138 }
139
140 virtual void logLUTimes() {
141 // no default implementation for all types of solvers
142 }
143
144 // #### Simulation ####
148 virtual void log(Real time, Int timeStepCount){};
149
152 void setMaxNumberOfIterations(int maxIterations) {
153 mMaxIterations = maxIterations;
154 }
155};
156} // namespace DPsim
spdlog::level::level_enum Level
Definition Logger.h:33
std::shared_ptr< spdlog::logger > Log
Definition Logger.h:34
std::vector< Ptr > List
Definition Task.h:28
String mName
Name for logging.
Definition Solver.h:54
Real mSteadStIniAccLimit
steady state initialization accuracy limit
Definition Solver.h:70
Bool mSystemMatrixRecomputationEnabled
Effective system-matrix recomputation setting used by the solver.
Definition Solver.h:82
void setSteadStIniAccLimit(Real v)
set steady state initialization accuracy limit
Definition Solver.h:129
std::vector< Ptr > List
Definition Solver.h:38
Real mTimeStep
Time step for fixed step solvers.
Definition Solver.h:62
Behaviour mBehaviour
Solver behaviour initialization or simulation.
Definition Solver.h:85
CPS::Logger::Log mSLog
Logger.
Definition Solver.h:60
static constexpr Real DEFAULT_STEAD_ST_INI_TIME_LIMIT
Default steady state initialization time limit.
Definition Solver.h:33
CPS::Logger::Level mLogLevel
Logging level.
Definition Solver.h:56
Bool mIsInInitialization
Determines if solver is in initialization phase, which requires different behavior.
Definition Solver.h:74
Solver(String name, CPS::Logger::Level logLevel)
Definition Solver.h:88
Real mSteadStIniTimeLimit
steady state initialization time limit
Definition Solver.h:68
virtual void setSystem(const CPS::SystemTopology &system)
Definition Solver.h:106
Bool mInitFromNodesAndTerminals
Definition Solver.h:77
void doSteadyStateInit(Bool f)
activate steady state initialization
Definition Solver.h:125
Bool mLogSolveTimes
Collect step time for logging.
Definition Solver.h:58
void setTimeStep(Real timeStep)
Definition Solver.h:100
std::shared_ptr< Solver > Ptr
Definition Solver.h:37
Bool mFrequencyParallel
Activates parallelized computation of frequencies.
Definition Solver.h:64
static constexpr Real DEFAULT_STEAD_ST_INI_ACC_LIMIT
Default steady state initialization accuracy limit.
Definition Solver.h:35
void setMaxNumberOfIterations(int maxIterations)
Definition Solver.h:152
virtual void initialize()
Definition Solver.h:123
virtual void setDirectLinearSolverConfiguration(DirectLinearSolverConfiguration &)
set direct linear solver configuration (only available in MNA for now)
Definition Solver.h:136
virtual void logLUTimes()
log LU decomposition times, if applicable
Definition Solver.h:140
void doFrequencyParallelization(Bool freqParallel)
Definition Solver.h:102
virtual void setSolverAndComponentBehaviour(Solver::Behaviour behaviour)
set solver and component to initialization or simulation behaviour
Definition Solver.h:131
void setLogSolveTimes(Bool value)
Definition Solver.h:119
virtual void log(Real time, Int timeStepCount)
Log results.
Definition Solver.h:148
@ Initialization
Definition Solver.h:40
Bool mSteadyStateInit
Activates steady state initialization.
Definition Solver.h:72
void doSystemMatrixRecomputation(Bool value)
Definition Solver.h:113
SystemMatrixRecomputationMode mSystemMatrixRecomputationMode
Requested system-matrix recomputation mode.
Definition Solver.h:79
int mMaxIterations
Definition Solver.h:151
void setSteadStIniTimeLimit(Real v)
set steady state initialization time limit
Definition Solver.h:127
SystemMatrixRecomputationMode
System-matrix recomputation mode for MNA solvers.
Definition Solver.h:43
@ Enabled
Always enable system-matrix recomputation.
Definition Solver.h:47
@ Auto
Select the mode automatically based on the system topology.
Definition Solver.h:45
@ Disabled
Always disable system-matrix recomputation.
Definition Solver.h:49
virtual CPS::Task::List getTasks()=0
Get tasks for scheduler.
virtual ~Solver()
Definition Solver.h:93
void doInitFromNodesAndTerminals(Bool f)
activate powerflow initialization
Definition Solver.h:133
void setSystemMatrixRecomputationMode(SystemMatrixRecomputationMode mode)
Set the system-matrix recomputation mode.
Definition Solver.h:108
CPS::Logger Logger
Definition DPsim.h:40
CPS::Real Real
Definition Definitions.h:18
CPS::String String
Definition Definitions.h:20
CPS::Int Int
Definition Definitions.h:22
CPS::Bool Bool
Definition Definitions.h:21
CPS::UInt UInt
Definition Definitions.h:23
Holds switching time and which system should be activated.
Definition Solver.h:24