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  CPS::Logger::Log mSLog;
45  Real mTimeStep;
47  Bool mFrequencyParallel = false;
48 
49  // #### Initialization ####
53  Real mSteadStIniAccLimit = 0.0001;
55  Bool mSteadyStateInit = false;
57  Bool mIsInInitialization = false;
63 
65  Behaviour mBehaviour = Solver::Behaviour::Simulation;
66 
67 public:
68  Solver(String name, CPS::Logger::Level logLevel)
69  : mName(name), mLogLevel(logLevel),
70  mSLog(CPS::Logger::get(name + "_Solver", logLevel,
71  CPS::Logger::Level::warn)) {}
72 
73  virtual ~Solver() {}
74 
75  // #### Solver settings ####
78  enum class Type { MNA, DAE, NRP };
80  void setTimeStep(Real timeStep) { mTimeStep = timeStep; }
82  void doFrequencyParallelization(Bool freqParallel) {
83  mFrequencyParallel = freqParallel;
84  }
86  virtual void setSystem(const CPS::SystemTopology &system) {}
88  void doSystemMatrixRecomputation(Bool value) {
90  }
91 
92  // #### Initialization ####
94  virtual void initialize() {}
96  void doSteadyStateInit(Bool f) { mSteadyStateInit = f; }
102  virtual void setSolverAndComponentBehaviour(Solver::Behaviour behaviour) {}
106  virtual void
108  // not every derived class has a linear solver configuration option
109  }
111  virtual void logLUTimes() {
112  // no default implementation for all types of solvers
113  }
114 
115  // #### Simulation ####
117  virtual CPS::Task::List getTasks() = 0;
119  virtual void log(Real time, Int timeStepCount){};
120 
122  int mMaxIterations = 10;
123  void setMaxNumberOfIterations(int maxIterations) {
124  mMaxIterations = maxIterations;
125  }
126 };
127 } // 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:53
void setSteadStIniAccLimit(Real v)
set steady state initialization accuracy limit
Definition: Solver.h:100
Real mTimeStep
Time step for fixed step solvers.
Definition: Solver.h:45
Bool mSystemMatrixRecomputation
Enable recomputation of system matrix during simulation.
Definition: Solver.h:62
Behaviour mBehaviour
Solver behaviour initialization or simulation.
Definition: Solver.h:65
CPS::Logger::Log mSLog
Logger.
Definition: Solver.h:43
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:57
Real mSteadStIniTimeLimit
steady state initialization time limit
Definition: Solver.h:51
Bool mInitFromNodesAndTerminals
Definition: Solver.h:60
void doSteadyStateInit(Bool f)
activate steady state initialization
Definition: Solver.h:96
Bool mFrequencyParallel
Activates parallelized computation of frequencies.
Definition: Solver.h:47
virtual void setDirectLinearSolverConfiguration(DirectLinearSolverConfiguration &)
set direct linear solver configuration (only available in MNA for now)
Definition: Solver.h:107
virtual void logLUTimes()
log LU decomposition times, if applicable
Definition: Solver.h:111
virtual void setSolverAndComponentBehaviour(Solver::Behaviour behaviour)
set solver and component to initialization or simulation behaviour
Definition: Solver.h:102
virtual void log(Real time, Int timeStepCount)
Log results.
Definition: Solver.h:119
Bool mSteadyStateInit
Activates steady state initialization.
Definition: Solver.h:55
int mMaxIterations
Definition: Solver.h:122
void setSteadStIniTimeLimit(Real v)
set steady state initialization time limit
Definition: Solver.h:98
virtual CPS::Task::List getTasks()=0
Get tasks for scheduler.
void doInitFromNodesAndTerminals(Bool f)
activate powerflow initialization
Definition: Solver.h:104
Holds switching time and which system should be activated.
Definition: Solver.h:24