BlockPreconditioner.h 3.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/******************************************************************************
 *
 * Extension of AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: Simon Praetorius et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
#ifndef BLOCK_PRECONDITIONER_H
#define BLOCK_PRECONDITIONER_H

#include "solver/ITL_Preconditioner.h"
#include "solver/SolverMatrix.h"

namespace AMDiS {

  struct BlockPreconditioner : BasePreconditioner
  {
    typedef SolverMatrix<Matrix<DOFMatrix*> > BlockMatrix;
    
    BlockPreconditioner() : A(NULL), fullMatrix(NULL) {}
    
    virtual ~BlockPreconditioner() {}
    
    /// extract iranges from BlockMatrix to be used to extract sub-vectors and sub-matrices.
    void init(const BlockMatrix& A_, const MTLTypes::MTLMatrix& fullMatrix_) 
    {
      A = &A_;
      fullMatrix = &fullMatrix_;
      
      VectorialMapper mapper(A_);
      rows.resize(mapper.getNumComponents());
      int start = 0;
      for (int i = 0; i < mapper.getNumComponents(); i++) {
	mapper.setRow(i+1);
	int finish = mapper.row(0);
	rows[i].set(start, finish);
	start = finish;
      }
    }
  
    virtual void solve(const MTLTypes::MTLVector& b, MTLTypes::MTLVector& x) const
    { FUNCNAME("BlockPreconditioner::solve()");
      TEST_EXIT(false)("Noch nicht implementiert!\n");
    }
    
    virtual void adjoint_solve(const MTLTypes::MTLVector& x, MTLTypes::MTLVector& y) const
    { FUNCNAME("BlockPreconditioner::adjoint_solve()");
      TEST_EXIT(false)("Noch nicht implementiert!\n");
    }
    
  protected:
    
    template<typename SolverType, typename RunnerType>
    void createSubSolver(std::string param, SolverType*& solver, RunnerType*& runner, std::string solverType = "0")
    {
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
      // definition of standard-backends
#if defined HAVE_PARALLEL_PETSC
      string backend("p_petsc");
#elif defined HAVE_PARALLEL_MTL
      string backend("p_mtl");
#elif defined HAVE_PETSC
      string backend("petsc");
#else
      string backend("mtl");
#endif
    
      // === read backend-name ===
      string initFileStr = param + "->solver";    
      Parameters::get(initFileStr + "->backend", backend);

      // === read solver-name ===
81
      Parameters::get(initFileStr, solverType);
82
83
84
85
      
      if (backend != "0" && backend != "no" && backend != "")
	solverType = backend + "_" + solverType;
    
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
      LinearSolverCreator *solverCreator = 
	dynamic_cast<LinearSolverCreator*>(CreatorMap<LinearSolver>::getCreator(solverType, initFileStr));
      TEST_EXIT(solverCreator)
	("No valid solver type found in parameter \"%s\"\n", initFileStr.c_str());
      solverCreator->setName(initFileStr);
      solver = dynamic_cast<SolverType*>(solverCreator->create());
      assert(solver != NULL);
      
      runner = dynamic_cast<RunnerType*>(solver->getRunner());
      assert(runner != NULL);
    }
    
    
    const SolverMatrix<Matrix<DOFMatrix*> >* A;
    const MTLTypes::MTLMatrix* fullMatrix;
    
    std::vector<mtl::irange> rows;
  };

} // end namespace

#endif // BLOCK_PRECONDITIONER_H