KASKADE 7 development version
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.
SparseIndexInt nrows() const
Returns number of rows (computes them, if not known)
Definition: triplet.hh:202
SparseIndexInt ncols() const
Returns number of cols (computes them, if not known)
Definition: triplet.hh:215
std::vector< SparseIndexInt > ridx
row indices
Definition: triplet.hh:669
std::vector< SparseIndexInt > cidx
column indices
Definition: triplet.hh:671
std::vector< Scalar > data
data
Definition: triplet.hh:673
Simple Implementation for SparseLinearSystem.
Definition: linearsystem.hh:67
virtual int rows(int rowbegin, int rowend) const
Definition: linearsystem.hh:82
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.
Definition: linearsystem.hh:78
virtual int nRowBlocks() const
number of row blocks
Definition: linearsystem.hh:87
SimpleSparseLinearSystem(std::vector< int >const &ridx, std::vector< int >const &cidx, std::vector< double >const &data, std::vector< double >const &rhs_)
Construction.
Definition: linearsystem.hh:70
virtual double getValue() const
value of function
Definition: linearsystem.hh:84
virtual void getRHSBlocks(std::vector< double > &rhs_, int rbegin, int rend) const
Return components of the right hand side of the linear system.
Definition: linearsystem.hh:80
virtual int nColBlocks() const
number of column blocks
Definition: linearsystem.hh:86
virtual int cols(int colbegin, int colend) const
Definition: linearsystem.hh:81
Abstract base class for a sparse linear system.
Definition: linearsystem.hh:30
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.
Definition: linearsystem.hh:33
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.
Definition: linearsystem.hh:39
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.
Definition: linearsystem.hh:36
virtual double getValue() const =0
value of function