DPsim
Solver.h
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>
16 #include <dpsim-models/SystemTopology.h>
17 #include <dpsim-models/Task.h>
18 #include <dpsim/Config.h>
19 #include <dpsim/Definitions.h>
20 #include <dpsim/DirectLinearSolverConfiguration.h>
21 
22 namespace DPsim {
25  Real switchTime;
26  UInt systemIndex;
27 };
28 
30 class Solver {
31 public:
32  typedef std::shared_ptr<Solver> Ptr;
33  typedef std::vector<Ptr> List;
34 
35  enum Behaviour { Initialization, Simulation };
36 
37 protected:
39  String mName;
41  CPS::Logger::Level mLogLevel;
43  Bool mLogSolveTimes = true;
45  CPS::Logger::Log mSLog;
47  Real mTimeStep;
49  Bool mFrequencyParallel = false;
50 
51  // #### Initialization ####
55  Real mSteadStIniAccLimit = 0.0001;
57  Bool mSteadyStateInit = false;
59  Bool mIsInInitialization = false;
65 
67  Behaviour mBehaviour = Solver::Behaviour::Simulation;
68 
69 public:
70  Solver(String name, CPS::Logger::Level logLevel)
71  : mName(name), mLogLevel(logLevel),
72  mSLog(CPS::Logger::get(name + "_Solver", logLevel,
73  CPS::Logger::Level::warn)) {}
74 
75  virtual ~Solver() {}
76 
77  // #### Solver settings ####
80  enum class Type { MNA, DAE, NRP };
82  void setTimeStep(Real timeStep) { mTimeStep = timeStep; }
84  void doFrequencyParallelization(Bool freqParallel) {
85  mFrequencyParallel = freqParallel;
86  }
88  virtual void setSystem(const CPS::SystemTopology &system) {}
90  void doSystemMatrixRecomputation(Bool value) {
92  }
93 
94  void setLogSolveTimes(Bool value) { mLogSolveTimes = value; }
95 
96  // #### Initialization ####
98  virtual void initialize() {}
100  void doSteadyStateInit(Bool f) { mSteadyStateInit = f; }
106  virtual void setSolverAndComponentBehaviour(Solver::Behaviour behaviour) {}
110  virtual void
112  // not every derived class has a linear solver configuration option
113  }
115  virtual void logLUTimes() {
116  // no default implementation for all types of solvers
117  }
118 
119  // #### Simulation ####
121  virtual CPS::Task::List getTasks() = 0;
123  virtual void log(Real time, Int timeStepCount){};
124 
126  int mMaxIterations = 10;
127  void setMaxNumberOfIterations(int maxIterations) {
128  mMaxIterations = maxIterations;
129  }
130 };
131 } // namespace DPsim
The Simulation holds a SystemTopology and a Solver.
Definition: Simulation.h:34
Base class for more specific solvers such as MNA, ODE or IDA.
Definition: Solver.h:30
String mName
Name for logging.
Definition: Solver.h:39
Real mSteadStIniAccLimit
steady state initialization accuracy limit
Definition: Solver.h:55
void setSteadStIniAccLimit(Real v)
set steady state initialization accuracy limit
Definition: Solver.h:104
Real mTimeStep
Time step for fixed step solvers.
Definition: Solver.h:47
Bool mSystemMatrixRecomputation
Enable recomputation of system matrix during simulation.
Definition: Solver.h:64
Behaviour mBehaviour
Solver behaviour initialization or simulation.
Definition: Solver.h:67
CPS::Logger::Log mSLog
Logger.
Definition: Solver.h:45
CPS::Logger::Level mLogLevel
Logging level.
Definition: Solver.h:41
Bool mIsInInitialization
Determines if solver is in initialization phase, which requires different behavior.
Definition: Solver.h:59
Real mSteadStIniTimeLimit
steady state initialization time limit
Definition: Solver.h:53
Bool mInitFromNodesAndTerminals
Definition: Solver.h:62
void doSteadyStateInit(Bool f)
activate steady state initialization
Definition: Solver.h:100
Bool mLogSolveTimes
Collect step time for logging.
Definition: Solver.h:43
Bool mFrequencyParallel
Activates parallelized computation of frequencies.
Definition: Solver.h:49
virtual void setDirectLinearSolverConfiguration(DirectLinearSolverConfiguration &)
set direct linear solver configuration (only available in MNA for now)
Definition: Solver.h:111
virtual void logLUTimes()
log LU decomposition times, if applicable
Definition: Solver.h:115
virtual void setSolverAndComponentBehaviour(Solver::Behaviour behaviour)
set solver and component to initialization or simulation behaviour
Definition: Solver.h:106
virtual void log(Real time, Int timeStepCount)
Log results.
Definition: Solver.h:123
Bool mSteadyStateInit
Activates steady state initialization.
Definition: Solver.h:57
int mMaxIterations
Definition: Solver.h:126
void setSteadStIniTimeLimit(Real v)
set steady state initialization time limit
Definition: Solver.h:102
virtual CPS::Task::List getTasks()=0
Get tasks for scheduler.
void doInitFromNodesAndTerminals(Bool f)
activate powerflow initialization
Definition: Solver.h:108
Holds switching time and which system should be activated.
Definition: Solver.h:24