HermesCommon  2.0
epetra.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://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_SOLVER_EPETRA_H_
23 #define __HERMES_COMMON_SOLVER_EPETRA_H_
24 #include "config.h"
25 #ifdef HAVE_EPETRA
26 #define EPETRA_NO_64BIT_GLOBAL_INDICES
27 #include "matrix.h"
28 #include <Epetra_SerialComm.h>
29 #include <Epetra_Map.h>
30 #include <Epetra_Vector.h>
31 #include <Epetra_CrsGraph.h>
32 #include <Epetra_CrsMatrix.h>
33 
34 namespace Hermes
35 {
36  namespace Solvers
37  {
38  template <typename Scalar> class AmesosSolver;
39  template <typename Scalar> class AztecOOSolver;
40  template <typename Scalar> class NewtonSolverNOX;
41  }
42  namespace Preconditioners
43  {
44  template <typename Scalar> class IfpackPrecond;
45  template <typename Scalar> class MlPrecond;
46  }
47 }
48 
49 namespace Hermes
50 {
51  namespace Algebra
52  {
53  template <typename Scalar>
54  class HERMES_API EpetraMatrix : public SparseMatrix<Scalar>
55  {
56  public:
57  EpetraMatrix();
58  EpetraMatrix(Epetra_RowMatrix &mat);
59  virtual ~EpetraMatrix();
60 
61  virtual void prealloc(unsigned int n);
62  virtual void pre_add_ij(unsigned int row, unsigned int col);
63  virtual void finish();
64 
65  virtual void alloc();
66  virtual void free();
67  virtual Scalar get(unsigned int m, unsigned int n);
68  virtual int get_num_row_entries(unsigned int row);
69  virtual void extract_row_copy(unsigned int row, unsigned int len, unsigned int &n_entries, double *vals, unsigned int *idxs);
70  virtual void zero();
71  virtual void add(unsigned int m, unsigned int n, Scalar v);
72  virtual void add_to_diagonal(Scalar v);
73  virtual void add_to_diagonal_blocks(int num_stages, EpetraMatrix<Scalar>* mat);
74  virtual void add_sparse_to_diagonal_blocks(int num_stages, SparseMatrix<Scalar>* mat);
75  virtual void multiply_with_vector(Scalar* vector_in, Scalar* vector_out);
76  virtual void add_as_block(unsigned int i, unsigned int j, EpetraMatrix<Scalar>* mat);
77  virtual void add(unsigned int m, unsigned int n, Scalar **mat, int *rows, int *cols);
78  virtual bool dump(FILE *file, const char *var_name, EMatrixDumpFormat fmt = DF_MATLAB_SPARSE, char* number_format = "%lf");
79  virtual unsigned int get_matrix_size() const;
80  virtual unsigned int get_nnz() const;
81  virtual double get_fill_in() const;
82 
83  protected:
84  Epetra_BlockMap *std_map;
85  Epetra_CrsGraph *grph;
86  Epetra_CrsMatrix *mat;
88  Epetra_CrsMatrix *mat_im;
89  bool owner;
90 
91  friend class Hermes::Solvers::AmesosSolver<Scalar>;
92  friend class Hermes::Solvers::AztecOOSolver<Scalar>;
93  friend class Hermes::Solvers::NewtonSolverNOX<Scalar>;
94  friend class Hermes::Preconditioners::IfpackPrecond<Scalar>;
95  friend class Hermes::Preconditioners::MlPrecond<Scalar>;
96  };
97 
98  template <typename Scalar>
99  class HERMES_API EpetraVector : public Vector<Scalar>
100  {
101  public:
102  EpetraVector();
103  EpetraVector(const Epetra_Vector &v);
104  virtual ~EpetraVector();
105 
106  virtual void alloc(unsigned int ndofs);
107  virtual void free();
108  virtual Scalar get(unsigned int idx);
109  virtual void extract(Scalar *v) const;
110  virtual void zero();
111  virtual void change_sign();
112  virtual void set(unsigned int idx, Scalar y);
113  virtual void add(unsigned int idx, Scalar y);
114  virtual void add(unsigned int n, unsigned int *idx, Scalar *y);
115  virtual void add_vector(Vector<Scalar>* vec);
116  virtual void add_vector(Scalar* vec);
117  virtual bool dump(FILE *file, const char *var_name, EMatrixDumpFormat fmt = DF_MATLAB_SPARSE, char* number_format = "%lf");
118 
119  protected:
120  Epetra_BlockMap *std_map;
121  Epetra_Vector *vec;
123  Epetra_Vector *vec_im;
124  bool owner;
125 
126  friend class Hermes::Solvers::AmesosSolver<Scalar>;
127  friend class Hermes::Solvers::AztecOOSolver<Scalar>;
128  friend class Hermes::Solvers::NewtonSolverNOX<Scalar>;
129  };
130  }
131 }
132 #endif
133 #endif