DPsim
Loading...
Searching...
No Matches
KLUAdapter.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
11extern "C" {
12#include <klu.h>
13}
14
15#include <bitset>
16#include <cstdint>
17#include <fstream>
18#include <iostream>
19#include <list>
20#include <memory>
21#include <unordered_map>
22#include <vector>
23
24#include <dpsim/Config.h>
25#include <dpsim/Definitions.h>
27
28namespace DPsim {
31 std::vector<std::pair<UInt, UInt>> mChangedEntries;
32
34 std::vector<Int> mVaryingColumns;
36 std::vector<Int> mVaryingRows;
37
39 klu_common mCommon;
40 klu_numeric *mNumeric = nullptr;
41 klu_symbolic *mSymbolic = nullptr;
42
46 int mPreordering = AMD_ORDERING;
47
49 int mPivotFaults = 0;
50
51 PARTIAL_REFACTORIZATION_METHOD mPartialRefactorizationMethod =
53
55 Int nnz;
56
60 CPS::SparseMatrix mKluMatrix;
61 std::vector<Int> mRowToKluValueIndex;
62
63 void syncKluValues(const SparseMatrix &systemMatrix);
64
65public:
67 ~KLUAdapter() override;
68
70 KLUAdapter();
71
74
76 void preprocessing(SparseMatrix &systemMatrix,
77 std::vector<std::pair<UInt, UInt>>
78 &listVariableSystemMatrixEntries) override;
79
81 void factorize(SparseMatrix &systemMatrix) override;
82
84 void refactorize(SparseMatrix &systemMatrix) override;
85
87 void partialRefactorize(SparseMatrix &systemMatrix,
88 std::vector<std::pair<UInt, UInt>>
89 &listVariableSystemMatrixEntries) override;
90
92 Matrix solve(Matrix &rightSideVector) override;
93
95 void solveInto(Matrix &rightSideVector, Matrix &solution) override;
96
97protected:
99 void printMatrixMarket(SparseMatrix &systemMatrix, int counter) const;
100
102 void applyConfiguration() override;
103};
104} // namespace DPsim
std::shared_ptr< spdlog::logger > Log
Definition Logger.h:34
DirectLinearSolver()=default
Constructor.
void applyConfiguration() override
Apply configuration.
void factorize(SparseMatrix &systemMatrix) override
factorization function with partial pivoting
Matrix solve(Matrix &rightSideVector) override
solution function for a right hand side
void solveInto(Matrix &rightSideVector, Matrix &solution) override
Solve into caller-owned storage to avoid per-step matrix allocation.
void refactorize(SparseMatrix &systemMatrix) override
refactorization without partial pivoting
void printMatrixMarket(SparseMatrix &systemMatrix, int counter) const
Function to print matrix in MatrixMarket's coo format.
void partialRefactorize(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt > > &listVariableSystemMatrixEntries) override
partial refactorization withouth partial pivoting
~KLUAdapter() override
Destructor.
KLUAdapter()
Constructor.
void preprocessing(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt > > &listVariableSystemMatrixEntries) override
preprocessing function pre-ordering and scaling the matrix
Eigen::SparseMatrix< Real, Eigen::ColMajor > SparseMatrix
Sparse matrix for real numbers.
Definition Definitions.h:70
CPS::Int Int
Definition Definitions.h:22
CPS::Matrix Matrix
Definition Definitions.h:24
CPS::SparseMatrixRow SparseMatrix
Definition Definitions.h:26