SolverMatrix.h 2.93 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

20
21
22
23
24
25
/** \file SolverMatrix.h */

#ifndef AMDIS_SOLVERMATRIX_H
#define AMDIS_SOLVERMATRIX_H

#include "DOFMatrix.h"
26
27
28
29

namespace AMDiS {

  /**
30
   * \brief Helper class to provide complete matrix for ITL solvers and preconditioners
31
   */
32
33
34
35
36
37
38
39
40

  // General case undefined !
  template <typename Matrix>
  class SolverMatrix { };


  // DOFMatrix, i.e. ScalarProblem
  template <>
  class SolverMatrix<DOFMatrix>
41
  {
42
43
44
45
    public : 
      SolverMatrix() : matrix(0) {}

      void setMatrix(const DOFMatrix& A)
46
      {
Thomas Witkowski's avatar
huh  
Thomas Witkowski committed
47
	matrix= &A.getBaseMatrix();
48
49
50
51
52
53
      }

      const DOFMatrix::base_matrix_type& getMatrix() const { return *matrix; }

    private:
      const DOFMatrix::base_matrix_type* matrix;
54
55
56
  };


57
58
59
60
61
62
63
  // VectorProblem
  template <>
  class SolverMatrix<Matrix<DOFMatrix*> >
  {
    public : 
      void setMatrix(const Matrix<DOFMatrix*>& A)
      {
64
65
66
67
68
69
70
	int                 ns= A.getSize();
	std::vector<int>    block_starts(ns+1);
	block_starts[0]= 0;
	for (int i= 0; i < ns; ++i)
	  block_starts[i+1]= block_starts[i] + A[i][i]->getFESpace()->getAdmin()->getUsedSize();

	matrix.change_dim(block_starts[ns], block_starts[ns]);
71
	set_to_zero(matrix);
72
73
74
	DOFMatrix::inserter_type  ins(matrix);
	for (int rb= 0; rb < ns; ++rb)
	  for (int cb= 0; cb < ns; ++cb)
75
	    if (A[rb][cb])
76
	      ins[block_starts[rb]][block_starts[cb]] << A[rb][cb]->getBaseMatrix();	  
77
78
79
80
81
82
83
84
85
86
87
      }

      const DOFMatrix::base_matrix_type& getMatrix() const { return matrix; }

    private:      
       DOFMatrix::base_matrix_type matrix;
  };



} // namespace AMDiS
88

89
#endif // AMDIS_SOLVERMATRIX_H