KASKADE 7 development version
Loading...
Searching...
No Matches
linearsystem.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2012 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef LINEARSYSTEM_HH
14#define LINEARSYSTEM_HH
15
16#include <algorithm>
17#include <cassert>
18#include <iostream>
19#include <vector>
20
21#include "linalg/triplet.hh"
22
23namespace Kaskade
24{
30{
31public:
33 virtual void getMatrix(MatrixAsTriplet<double>& mat) const { getMatrixBlocks(mat,0,nRowBlocks(),0,nColBlocks());}
34
36 virtual void getRHS(std::vector<double>& rhs) const { getRHSBlocks(rhs,0,nRowBlocks()); }
37
39 virtual int size() const {return cols(0,nColBlocks());};
40
41 virtual int rows(int rbegin, int rend) const = 0;
42 virtual int cols(int colbegin, int colend) const = 0;
43
45 virtual void getMatrixBlocks(MatrixAsTriplet<double>& mat, int rbegin, int rend, int colbegin, int colend) const = 0;
46
48 virtual double getValue() const = 0;
49
51 virtual void getRHSBlocks(std::vector<double>& rhs, int rbegin, int rend) const = 0;
52
54 virtual int nColBlocks() const = 0;
55
57 virtual int nRowBlocks() const = 0;
58
59 virtual ~SparseLinearSystem() {};
60};
61
67{
68public:
70 SimpleSparseLinearSystem(std::vector<int>const& ridx, std::vector<int>const& cidx, std::vector<double>const& data, std::vector<double>const& rhs_)
71 {
72 mat.ridx = ridx;
73 mat.cidx = cidx;
74 mat.data = data;
75 rhs = rhs_;
76 }
77
78 virtual void getMatrixBlocks(MatrixAsTriplet<double>& mat_, int rbegin, int rend, int colbegin, int colend)
79 const {mat_=mat;}
80 virtual void getRHSBlocks(std::vector<double>& rhs_, int rbegin, int rend) const { rhs_=rhs;}
81 virtual int cols(int colbegin, int colend) const {return mat.ncols(); }
82 virtual int rows(int rowbegin, int rowend) const {return mat.nrows(); }
83
84 virtual double getValue() const {return 0;}
85
86 virtual int nColBlocks() const {return 1;}
87 virtual int nRowBlocks() const {return 1;}
88
89private:
91 std::vector<double> rhs;
92};
93
94namespace Bridge {
95
96 class UnknownLinearization;
97
99 template<class Vector, class Functional>
101 {
102 public:
103 typedef UnknownLinearization Linearization;
104 };
105}
106} // end of namespace Kaskade
107
108#endif
Traits class to choose the right linearization class.
virtual int rows(int rowbegin, int rowend) const
virtual void getMatrixBlocks(MatrixAsTriplet< double > &mat_, int rbegin, int rend, int colbegin, int colend) const
Return matrix blocks of the linear system in triplet format.
virtual int nRowBlocks() const
number of row blocks
SimpleSparseLinearSystem(std::vector< int >const &ridx, std::vector< int >const &cidx, std::vector< double >const &data, std::vector< double >const &rhs_)
Construction.
virtual double getValue() const
value of function
virtual void getRHSBlocks(std::vector< double > &rhs_, int rbegin, int rend) const
Return components of the right hand side of the linear system.
virtual int nColBlocks() const
number of column blocks
virtual int cols(int colbegin, int colend) const
Abstract base class for a sparse linear system.
virtual void getMatrixBlocks(MatrixAsTriplet< double > &mat, int rbegin, int rend, int colbegin, int colend) const =0
Return matrix blocks of the linear system in triplet format.
virtual void getRHSBlocks(std::vector< double > &rhs, int rbegin, int rend) const =0
Return components of the right hand side of the linear system.
virtual void getMatrix(MatrixAsTriplet< double > &mat) const
Return the matrix of the linear system in triplet format.
virtual int cols(int colbegin, int colend) const =0
virtual int nRowBlocks() const =0
number of row blocks
virtual int size() const
Return the number of variables of the linear system.
virtual int rows(int rbegin, int rend) const =0
virtual int nColBlocks() const =0
number of column blocks
virtual void getRHS(std::vector< double > &rhs) const
Return the right hand side of the linear system.
virtual double getValue() const =0
value of function