KASKADE 7 development version
discrete_solver.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-2011 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 DISCRETE_SOLVER_HH
14#define DISCRETE_SOLVER_HH
15
22#include <iostream>
23
24#include <boost/timer/timer.hpp>
25
29//#include "linalg/direct_solver_factory.hh"
30
31namespace Kaskade
32{
42 //template<class Factorization>
43 template <class Scalar, class SparseInt=int>
45 {
46 public:
48 static const bool needMatrix = true;
50 explicit DirectLinearSolver(std::string const& solverName_, bool verbose = false) : report(false), solverName(solverName_)/*, factory(verbose) */{}
51
53
55 void solve(std::vector<double>& sol, SparseLinearSystem& lin)
56 {
58 boost::timer::cpu_timer timer;
59
61 lin.getMatrix(mat);
62
63 // mat.print();
64 factorization.reset(new UMFFactorization<Scalar,int>(mat.nrows(), mat.ridx, mat.cidx, mat.data)/*factory.create(solverName, mat.nrows(), mat.ridx, mat.cidx, mat.data) */);
65 // factorization.reset(new Factorization(mat.nrows(),
66 // matrixtype,
67 // mat.ridx,
68 // mat.cidx,
69 // mat.data));
70 if(report && (double)(timer.elapsed().user)/1e9 > 2.0) {
71 std::cout << "Factorization: " << (double)(timer.elapsed().user)/1e9 << " sec." << std::endl;
72 }
73 resolve(sol,lin);
74 }
76 void resolve(std::vector<double>& sol,
77 SparseLinearSystem const& lin) const
78 {
79 boost::timer::cpu_timer timer;
80 if(report >= 2) std::cout << "Starting Substitution...";
81 std::vector<double> rhs;
82 lin.getRHS(rhs);
83 factorization->solve(rhs,sol);
84 if(report >=2) std::cout << "Finished: " << (double)(timer.elapsed().user)/1e9 << " sec." << std::endl;
85
86 }
87
89 void setRelativeAccuracy(double) {}
90
92 double getRelativeAccuracy() {return 0.0;}
93
95 double getAbsoluteAccuracy() {return 0.0;}
96
97 bool improvementPossible() { return false; }
98
99
102
105 {
106 if(factorization.get()!=nullptr) factorization.reset();
107 }
110
111 private:
112 std::string const& solverName;
113 //DirectSolverFactory<Scalar,SparseInt> factory;
114 std::unique_ptr<Factorization<Scalar,SparseInt> > factorization;
115 };
116}
117#endif
Direct solver.Implements Direct Solver Interface of Algorithms.
void onChangedLinearization()
Do sth if linearization changed.
static const bool needMatrix
needs a matrix
void resolve(std::vector< double > &sol, SparseLinearSystem const &lin) const
solve a system again
void flushFactorization()
flush factorization
void setRelativeAccuracy(double)
Solves always exactly.
double getAbsoluteAccuracy()
Always exact solution.
void solve(std::vector< double > &sol, SparseLinearSystem &lin)
solve a system, keep factorization
double getRelativeAccuracy()
Always exact solution.
DirectLinearSolver(std::string const &solverName_, bool verbose=false)
default constructor
int report
Report of progress (0=no report, 1=brief, 2=verbose)
SparseIndexInt nrows() const
Returns number of rows (computes them, if not known)
Definition: triplet.hh:202
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
Abstract base class for a sparse linear system.
Definition: linearsystem.hh:30
virtual void getMatrix(MatrixAsTriplet< double > &mat) const
Return the matrix of the linear system in triplet format.
Definition: linearsystem.hh:33
virtual void getRHS(std::vector< double > &rhs) const
Return the right hand side of the linear system.
Definition: linearsystem.hh:36
Factorization of sparse linear systems with UMFPack.