DPsim
KLUAdapter.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 extern "C" {
12 #include <klu.h>
13 }
14 
15 #include <bitset>
16 #include <fstream>
17 #include <iostream>
18 #include <list>
19 #include <memory>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include <dpsim/Config.h>
24 #include <dpsim/Definitions.h>
25 #include <dpsim/DirectLinearSolver.h>
26 
27 namespace DPsim {
30  std::vector<std::pair<UInt, UInt>> mChangedEntries;
31 
33  std::vector<Int> mVaryingColumns;
35  std::vector<Int> mVaryingRows;
36 
38  klu_common mCommon;
39  klu_numeric *mNumeric = nullptr;
40  klu_symbolic *mSymbolic = nullptr;
41 
45  int mPreordering = AMD_ORDERING;
46 
48  int mPivotFaults = 0;
49 
50  PARTIAL_REFACTORIZATION_METHOD mPartialRefactorizationMethod =
51  PARTIAL_REFACTORIZATION_METHOD::FACTORIZATION_PATH;
52 
54  Int nnz;
55 
56 public:
58  ~KLUAdapter() override;
59 
61  KLUAdapter();
62 
64  KLUAdapter(CPS::Logger::Log log);
65 
67  void preprocessing(SparseMatrix &systemMatrix,
68  std::vector<std::pair<UInt, UInt>>
69  &listVariableSystemMatrixEntries) override;
70 
72  void factorize(SparseMatrix &systemMatrix) override;
73 
75  void refactorize(SparseMatrix &systemMatrix) override;
76 
78  void partialRefactorize(SparseMatrix &systemMatrix,
79  std::vector<std::pair<UInt, UInt>>
80  &listVariableSystemMatrixEntries) override;
81 
83  Matrix solve(Matrix &rightSideVector) override;
84 
85 protected:
87  void printMatrixMarket(SparseMatrix &systemMatrix, int counter) const;
88 
90  void applyConfiguration() override;
91 };
92 } // namespace DPsim
void applyConfiguration() override
Apply configuration.
Definition: KLUAdapter.cpp:194
void preprocessing(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt >> &listVariableSystemMatrixEntries) override
preprocessing function pre-ordering and scaling the matrix
Definition: KLUAdapter.cpp:40
void factorize(SparseMatrix &systemMatrix) override
factorization function with partial pivoting
Definition: KLUAdapter.cpp:74
Matrix solve(Matrix &rightSideVector) override
solution function for a right hand side
Definition: KLUAdapter.cpp:151
void partialRefactorize(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt >> &listVariableSystemMatrixEntries) override
partial refactorization withouth partial pivoting
Definition: KLUAdapter.cpp:119
void refactorize(SparseMatrix &systemMatrix) override
refactorization without partial pivoting
Definition: KLUAdapter.cpp:104
void printMatrixMarket(SparseMatrix &systemMatrix, int counter) const
Function to print matrix in MatrixMarket's coo format.
Definition: KLUAdapter.cpp:170
~KLUAdapter() override
Destructor.
Definition: KLUAdapter.cpp:14
KLUAdapter()
Constructor.
Definition: KLUAdapter.cpp:22