DPsim
DirectLinearSolver.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 <bitset>
12 #include <iostream>
13 #include <list>
14 #include <unordered_map>
15 #include <vector>
16 
17 #include <dpsim-models/Logger.h>
18 #include <dpsim/Config.h>
19 #include <dpsim/Definitions.h>
20 #include <dpsim/DirectLinearSolverConfiguration.h>
21 
22 namespace DPsim {
24 public:
26  DirectLinearSolver() = default;
27 
29  virtual ~DirectLinearSolver() = default;
30 
33 
36 
39 
42 
44  DirectLinearSolver(CPS::Logger::Log log) : mSLog(log) {
45  // no further default configuration of DirectLinearSolver or logger
46  }
47 
49  virtual void preprocessing(
50  SparseMatrix &systemMatrix,
51  std::vector<std::pair<UInt, UInt>> &listVariableSystemMatrixEntries) = 0;
52 
54  virtual void factorize(SparseMatrix &systemMatrix) = 0;
55 
57  virtual void refactorize(SparseMatrix &systemMatrix) = 0;
58 
60  virtual void partialRefactorize(
61  SparseMatrix &systemMatrix,
62  std::vector<std::pair<UInt, UInt>> &listVariableSystemMatrixEntries) = 0;
63 
65  virtual Matrix solve(Matrix &rightSideVector) = 0;
66 
67  virtual void
68  setConfiguration(DirectLinearSolverConfiguration &configuration) {
69  mConfiguration = configuration;
70  this->applyConfiguration();
71  }
72 
73 protected:
75  CPS::Logger::Log mSLog;
76 
79 
80  virtual void applyConfiguration() {
81  // no default application, configuration options vary for each solver
82  // warn user that no configuration setting is used
83  SPDLOG_LOGGER_WARN(mSLog, "Linear solver configuration is not used!");
84  }
85 };
86 } // namespace DPsim
virtual void refactorize(SparseMatrix &systemMatrix)=0
refactorization without partial pivoting
DirectLinearSolver(const DirectLinearSolver &)=default
Copy Constructor.
virtual void preprocessing(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt >> &listVariableSystemMatrixEntries)=0
preprocessing function pre-ordering and scaling the matrix
DirectLinearSolver()=default
Constructor.
DirectLinearSolver(CPS::Logger::Log log)
Constructor with Logger.
DirectLinearSolver(DirectLinearSolver &&)=default
Move Constructor.
virtual void partialRefactorize(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt >> &listVariableSystemMatrixEntries)=0
partial refactorization withouth partial pivoting
DirectLinearSolverConfiguration mConfiguration
Object that carries configuration options.
CPS::Logger::Log mSLog
Stores logger of solver class.
virtual void factorize(SparseMatrix &systemMatrix)=0
factorization function with partial pivoting
virtual Matrix solve(Matrix &rightSideVector)=0
solution function for a right hand side
DirectLinearSolver & operator=(DirectLinearSolver &&)=default
Move Assignment Operator.
DirectLinearSolver & operator=(const DirectLinearSolver &)=default
Copy Assignment Operator.
virtual ~DirectLinearSolver()=default
Destructor.