HermesCommon  3.0
mumps_solver.h
Go to the documentation of this file.
1 // This file is part of HermesCommon
2 //
3 // Copyright (c) 2009 hp-FEM group at the University of Nevada, Reno (UNR).
4 // Email: hpfem-group@unr.edu, home page: http://www.hpfem.org/.
5 //
6 // Hermes2D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published
8 // by the Free Software Foundation; either version 2 of the License,
9 // or (at your option) any later version.
10 //
11 // Hermes2D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Hermes2D; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef __HERMES_COMMON_MUMPS_SOLVER_H_
23 #define __HERMES_COMMON_MUMPS_SOLVER_H_
24 #include "config.h"
25 #ifdef WITH_MUMPS
27 #include "algebra/matrix.h"
28 
29 extern "C"
30 {
31 #include <mumps_c_types.h>
32 #include <dmumps_c.h>
33 #include <zmumps_c.h>
34 }
35 
36 #ifdef WITH_MPI
37 #include <mpi.h>
38 #endif
39 
40 namespace Hermes
41 {
42  namespace Solvers
43  {
44  template <typename Scalar> class MumpsSolver;
45  }
46 }
47 namespace Hermes
48 {
49  namespace Algebra
50  {
52  template <typename Scalar> struct mumps_type;
53 
55  template <>
56  struct mumps_type < std::complex<double> >
57  {
59  typedef ZMUMPS_STRUC_C mumps_struct;
61  typedef ZMUMPS_COMPLEX mumps_Scalar;
62  };
63 
65  template <>
66  struct mumps_type < double >
67  {
69  typedef DMUMPS_STRUC_C mumps_struct;
71  typedef double mumps_Scalar;
72  };
73 
75  template <typename Scalar>
77  class MumpsMatrix : public CSCMatrix < Scalar >
78  {
79  public:
80  MumpsMatrix();
81  virtual ~MumpsMatrix();
82 
83  void alloc_data();
84  void free();
85  Scalar get(unsigned int m, unsigned int n) const;
86  void zero();
87 
88  void add(unsigned int m, unsigned int n, Scalar v);
89 
93  void export_to_file(const char *filename, const char *var_name, MatrixExportFormat fmt, char* number_format = "%lf");
94 
98  void import_from_file(const char *filename, const char *var_name, MatrixExportFormat fmt);
99 
101  void multiply_with_Scalar(Scalar value);
102 
104  void multiply_with_vector(Scalar* vector_in, Scalar*& vector_out, bool vector_out_initialized = false) const;
105 
107  void create(unsigned int size, unsigned int nnz, int* ap, int* ai, Scalar* ax);
108 
110  CSMatrix<Scalar>* duplicate() const;
111 
112  protected:
114  int *irn;
116  int *jcn;
119 
120  friend class Solvers::MumpsSolver < Scalar > ;
121  template<typename T> friend SparseMatrix<T>* create_matrix();
122  };
123  }
124 
125  namespace Solvers
126  {
129  template <typename Scalar>
130  class HERMES_API MumpsSolver : public DirectSolver < Scalar >
131  {
132  public:
137  virtual ~MumpsSolver();
138  void free();
139 
140  virtual void solve();
141  virtual int get_matrix_size();
142 
147 
149  bool setup_factorization();
150 
153 
155  bool check_status();
156 
160  bool reinit();
161  private:
162  //wrapper around dmums_c or zmumps_c
163  void mumps_c(typename mumps_type<Scalar>::mumps_struct * param);
164 
166  bool inited;
167 
170  int icntl_14;
172  static const int init_icntl_14 = 1;
174  static const int max_icntl_14 = 128;
175  };
176  }
177 }
178 #endif
179 #endif
unsigned int nnz
Number of non-zero entries ( = Ap[size]).
Definition: cs_matrix.h:123
void free()
Utility method.
General namespace for the Hermes library.
Linear matrix solver functionality.
void create(unsigned int size, unsigned int nnz, int *ap, int *ai, Scalar *ax)
Creates matrix using size, nnz, and the three arrays.
HERMES_API SparseMatrix< Scalar > * create_matrix(bool use_direct_solver=false)
Function returning a matrix according to the users's choice.
Definition: matrix.cpp:298
unsigned int size
matrix size
Definition: matrix.h:97
void multiply_with_Scalar(Scalar value)
Multiplies matrix with a Scalar.
Definition: compat.h:85
General (abstract) sparse matrix representation in Hermes.
MatrixExportFormat
Format of file matrix and vector output.
Vector used with MUMPS solver.
Definition: vector.h:116
int * jcn
Column indices.
Definition: mumps_solver.h:116
General CSC Matrix class. (can be used in umfpack, in that case use the CSCMatrix subclass...
Definition: cs_matrix.h:131
mumps_type< Scalar >::mumps_struct param
MUMPS specific structure with solver parameters.
Definition: mumps_solver.h:152
void zero()
Utility method.
Matrix used with MUMPS solver.
Definition: mumps_solver.h:77
void add(unsigned int m, unsigned int n, Scalar v)
Basic matrix classes and operations.
SimpleVector< Scalar > * rhs
Right hand side.
Definition: mumps_solver.h:146
int * irn
Row indices.
Definition: mumps_solver.h:114
void import_from_file(const char *filename, const char *var_name, MatrixExportFormat fmt)
MumpsMatrix< Scalar > * m
Matrix to solve.
Definition: mumps_solver.h:144
General CS Matrix class. Either row- or column- specific (see subclassses).
Definition: cs_matrix.h:35
mumps_type< Scalar >::mumps_Scalar * Ax
Matrix entries (column-wise).
Definition: mumps_solver.h:118
void multiply_with_vector(Scalar *vector_in, Scalar *&vector_out, bool vector_out_initialized=false) const
Applies the matrix to vector_in and saves result to vector_out.
void export_to_file(const char *filename, const char *var_name, MatrixExportFormat fmt, char *number_format="%lf")
CSMatrix< Scalar > * duplicate() const
Duplicates a matrix (including allocation).