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 ####
85
88
89public:
91 : mName(name), mLogLevel(logLevel),
92 mSLog(CPS::Logger::get(name + "_Solver", logLevel,
93 CPS::Logger::Level::warn)) {}
94
95 virtual ~Solver() {}
96
97 // #### Solver settings ####
100 enum class Type { MNA, DAE, NRP };
102 void setTimeStep(Real timeStep) { mTimeStep = timeStep; }
104 void doFrequencyParallelization(Bool freqParallel) {
105 mFrequencyParallel = freqParallel;
106 }
107
108 virtual void setSystem(const CPS::SystemTopology &system) {}
113
120
121 void setLogSolveTimes(Bool value) { mLogSolveTimes = value; }
122
123 // #### Initialization ####
125 virtual void initialize() {}
127 void setZeroSkipping(Bool enabled) { mZeroSkipping = enabled; }
140 virtual void
142 // not every derived class has a linear solver configuration option
143 }
144
145 virtual void logLUTimes() {
146 // no default implementation for all types of solvers
147 }
148
149 // #### Simulation ####
153 virtual void log(Real time, Int timeStepCount){};
154
157 void setMaxNumberOfIterations(int maxIterations) {
158 mMaxIterations = maxIterations;
159 }
160};
161} // 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:134
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:87
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:90
Real mSteadStIniTimeLimit
steady state initialization time limit
Definition Solver.h:68
virtual void setSystem(const CPS::SystemTopology &system)
Definition Solver.h:108
Bool mInitFromNodesAndTerminals
Definition Solver.h:77
void doSteadyStateInit(Bool f)
activate steady state initialization
Definition Solver.h:130
Bool mLogSolveTimes
Collect step time for logging.
Definition Solver.h:58
Bool getZeroSkipping() const
Definition Solver.h:128
void setTimeStep(Real timeStep)
Definition Solver.h:102
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:157
virtual void initialize()
Definition Solver.h:125
virtual void setDirectLinearSolverConfiguration(DirectLinearSolverConfiguration &)
set direct linear solver configuration (only available in MNA for now)
Definition Solver.h:141
virtual void logLUTimes()
log LU decomposition times, if applicable
Definition Solver.h:145
void doFrequencyParallelization(Bool freqParallel)
Definition Solver.h:104
virtual void setSolverAndComponentBehaviour(Solver::Behaviour behaviour)
set solver and component to initialization or simulation behaviour
Definition Solver.h:136
void setLogSolveTimes(Bool value)
Definition Solver.h:121
Bool mZeroSkipping
Skip exact zero contributions during matrix assembly (enabled by default).
Definition Solver.h:84
virtual void log(Real time, Int timeStepCount)
Log results.
Definition Solver.h:153
@ Initialization
Definition Solver.h:40
Bool mSteadyStateInit
Activates steady state initialization.
Definition Solver.h:72
void doSystemMatrixRecomputation(Bool value)
Definition Solver.h:115
SystemMatrixRecomputationMode mSystemMatrixRecomputationMode
Requested system-matrix recomputation mode.
Definition Solver.h:79
int mMaxIterations
Definition Solver.h:156
void setSteadStIniTimeLimit(Real v)
set steady state initialization time limit
Definition Solver.h:132
void setZeroSkipping(Bool enabled)
Enable or disable skipping exact zero matrix contributions.
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:95
void doInitFromNodesAndTerminals(Bool f)
activate powerflow initialization
Definition Solver.h:138
void setSystemMatrixRecomputationMode(SystemMatrixRecomputationMode mode)
Set the system-matrix recomputation mode.
Definition Solver.h:110
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