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:
32 typedef std::shared_ptr<Solver> Ptr;
33 typedef std::vector<Ptr> List;
34
36
46
47protected:
60
61 // #### Initialization ####
78
81
82public:
84 : mName(name), mLogLevel(logLevel),
85 mSLog(CPS::Logger::get(name + "_Solver", logLevel,
86 CPS::Logger::Level::warn)) {}
87
88 virtual ~Solver() {}
89
90 // #### Solver settings ####
93 enum class Type { MNA, DAE, NRP };
95 void setTimeStep(Real timeStep) { mTimeStep = timeStep; }
97 void doFrequencyParallelization(Bool freqParallel) {
98 mFrequencyParallel = freqParallel;
99 }
100
101 virtual void setSystem(const CPS::SystemTopology &system) {}
106
113
114 void setLogSolveTimes(Bool value) { mLogSolveTimes = value; }
115
116 // #### Initialization ####
118 virtual void initialize() {}
130 virtual void
132 // not every derived class has a linear solver configuration option
133 }
134
135 virtual void logLUTimes() {
136 // no default implementation for all types of solvers
137 }
138
139 // #### Simulation ####
143 virtual void log(Real time, Int timeStepCount){};
144
147 void setMaxNumberOfIterations(int maxIterations) {
148 mMaxIterations = maxIterations;
149 }
150};
151} // 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:49
Real mSteadStIniAccLimit
steady state initialization accuracy limit
Definition Solver.h:65
Bool mSystemMatrixRecomputationEnabled
Effective system-matrix recomputation setting used by the solver.
Definition Solver.h:77
void setSteadStIniAccLimit(Real v)
set steady state initialization accuracy limit
Definition Solver.h:124
std::vector< Ptr > List
Definition Solver.h:33
Real mTimeStep
Time step for fixed step solvers.
Definition Solver.h:57
Behaviour mBehaviour
Solver behaviour initialization or simulation.
Definition Solver.h:80
CPS::Logger::Log mSLog
Logger.
Definition Solver.h:55
CPS::Logger::Level mLogLevel
Logging level.
Definition Solver.h:51
Bool mIsInInitialization
Determines if solver is in initialization phase, which requires different behavior.
Definition Solver.h:69
Solver(String name, CPS::Logger::Level logLevel)
Definition Solver.h:83
Real mSteadStIniTimeLimit
steady state initialization time limit
Definition Solver.h:63
virtual void setSystem(const CPS::SystemTopology &system)
Definition Solver.h:101
Bool mInitFromNodesAndTerminals
Definition Solver.h:72
void doSteadyStateInit(Bool f)
activate steady state initialization
Definition Solver.h:120
Bool mLogSolveTimes
Collect step time for logging.
Definition Solver.h:53
void setTimeStep(Real timeStep)
Definition Solver.h:95
std::shared_ptr< Solver > Ptr
Definition Solver.h:32
Bool mFrequencyParallel
Activates parallelized computation of frequencies.
Definition Solver.h:59
void setMaxNumberOfIterations(int maxIterations)
Definition Solver.h:147
virtual void initialize()
Definition Solver.h:118
virtual void setDirectLinearSolverConfiguration(DirectLinearSolverConfiguration &)
set direct linear solver configuration (only available in MNA for now)
Definition Solver.h:131
virtual void logLUTimes()
log LU decomposition times, if applicable
Definition Solver.h:135
void doFrequencyParallelization(Bool freqParallel)
Definition Solver.h:97
virtual void setSolverAndComponentBehaviour(Solver::Behaviour behaviour)
set solver and component to initialization or simulation behaviour
Definition Solver.h:126
void setLogSolveTimes(Bool value)
Definition Solver.h:114
virtual void log(Real time, Int timeStepCount)
Log results.
Definition Solver.h:143
@ Initialization
Definition Solver.h:35
Bool mSteadyStateInit
Activates steady state initialization.
Definition Solver.h:67
void doSystemMatrixRecomputation(Bool value)
Definition Solver.h:108
SystemMatrixRecomputationMode mSystemMatrixRecomputationMode
Requested system-matrix recomputation mode.
Definition Solver.h:74
int mMaxIterations
Definition Solver.h:146
void setSteadStIniTimeLimit(Real v)
set steady state initialization time limit
Definition Solver.h:122
SystemMatrixRecomputationMode
System-matrix recomputation mode for MNA solvers.
Definition Solver.h:38
@ Enabled
Always enable system-matrix recomputation.
Definition Solver.h:42
@ Auto
Select the mode automatically based on the system topology.
Definition Solver.h:40
@ Disabled
Always disable system-matrix recomputation.
Definition Solver.h:44
virtual CPS::Task::List getTasks()=0
Get tasks for scheduler.
virtual ~Solver()
Definition Solver.h:88
void doInitFromNodesAndTerminals(Bool f)
activate powerflow initialization
Definition Solver.h:128
void setSystemMatrixRecomputationMode(SystemMatrixRecomputationMode mode)
Set the system-matrix recomputation mode.
Definition Solver.h:103
CPS::Logger Logger
Definition DPsim.h:37
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