UmfPackSolver.h 3.4 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
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file UmfPackSolver.h */

#ifndef AMDIS_UMFPACKSOLVER_H
#define AMDIS_UMFPACKSOLVER_H

25
#if defined HAVE_UMFPACK && defined MTL_HAS_UMFPACK
26

27
28
#include <iostream>
#include <boost/numeric/mtl/operation/two_norm.hpp>
29
#include <boost/numeric/mtl/interface/umfpack_solve.hpp>
Thomas Witkowski's avatar
Thomas Witkowski committed
30
#include "OEMSolver.h"
31

32
33
34
35
36
37
38
39
40
41
42
namespace AMDiS {

  /**
   * \ingroup Solver
   * 
   * \brief
   * Wrapper for the external UMFPACK solver:
   *   http://www.cise.ufl.edu/research/sparse/umfpack/
   *
   * This is a direct solver for large sparse matrices.
   */
43
44

  class UmfPackSolver : public OEMSolver
45
46
  {
  public:
47
48
    /// Creator class used in the OEMSolverMap.
    class Creator : public OEMSolverCreator
49
50
    {
    public:
Thomas Witkowski's avatar
Thomas Witkowski committed
51
      virtual ~Creator() {}
52
53
54
55
      
      /** \brief
       * Returns a new UmfPackSolver object.
       */
Thomas Witkowski's avatar
Thomas Witkowski committed
56
57
      OEMSolver* create() 
      { 
Thomas Witkowski's avatar
Thomas Witkowski committed
58
	return new UmfPackSolver(this->name); 
Thomas Witkowski's avatar
Thomas Witkowski committed
59
      }
60
61
    };

62
63
64
    /// Constructor
    UmfPackSolver(::std::string name) 
      : OEMSolver(name), 
Thomas Witkowski's avatar
Thomas Witkowski committed
65
66
	solver(0),
	store_symbolic(0)
67
68
69
    {
	GET_PARAMETER(0, name + "->store symbolic", "%d", &store_symbolic);
	// GET_PARAMETER(0, name + "->multiple rhs", "%d", &multipleRhs);
70
    }
71
    
72
    /// Destructor
Thomas Witkowski's avatar
Thomas Witkowski committed
73
74
75
76
77
    ~UmfPackSolver() 
    { 
      if (solver) 
	delete solver;
    }
78
79
80
81
82
83
84
85
86
87
88
89

    /// Solves the system directly
    int solveSystem(const DOFMatrix::base_matrix_type&      A,
		    mtl::dense_vector<value_type>&          x,
		    const mtl::dense_vector<value_type>&    b)
    {
	if (!solver)
	    solver= new mtl::matrix::umfpack::solver<matrix_type>(A);
	else if (store_symbolic)
	    solver->update_numeric();
	else
	    solver->update();
90
91
	
	// std::cout << "UmfPackSolver: A = \n" << A << "\n";
92
93
94
95
	int code= (*solver)(x, b);
	mtl::dense_vector<value_type> r= b - A * x;
	std::cout << "UmfPackSolver: ||b-Ax|| = " << two_norm(r) << "\n";
	return code;
96
    }
97

98
99
    
  private:
100
    mtl::matrix::umfpack::solver<matrix_type> *solver;
Thomas Witkowski's avatar
Thomas Witkowski committed
101

102
    int                                       store_symbolic;
103
104
105
106
107
108
109
  };
  
}

#endif // HAVE_UMFPACK

#endif // AMDIS_UMFPACKSOLVER_H