HermesCommon  3.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://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_SOLVER_EPETRA_H_
23 #define __HERMES_COMMON_SOLVER_EPETRA_H_
24 #include "config.h"
25 #ifdef HAVE_EPETRA
26 #undef interface
27 #define EPETRA_NO_64BIT_GLOBAL_INDICES
28 #include "algebra/matrix.h"
29 #include "algebra/vector.h"
30 #include "util/memory_handling.h"
31 #include <Epetra_SerialComm.h>
32 #include <Epetra_Map.h>
33 #include <Epetra_Vector.h>
34 #include <Epetra_CrsGraph.h>
35 #include <Epetra_CrsMatrix.h>
36 #include <EpetraExt_MatrixMatrix.h>
37 #include <EpetraExt_RowMatrixOut.h>
38 #include <EpetraExt_VectorOut.h>
39 #include <Teuchos_TestForException.hpp>
40 
41 namespace Hermes
42 {
43  namespace Solvers
44  {
45  template <typename Scalar> class AmesosSolver;
46  template <typename Scalar> class AztecOOSolver;
47  }
48  namespace Preconditioners
49  {
50  template <typename Scalar> class IfpackPrecond;
51  template <typename Scalar> class MlPrecond;
52  }
53 }
54 
55 namespace Hermes
56 {
57  namespace Algebra
58  {
59  template <typename Scalar>
60  class HERMES_API EpetraMatrix : public SparseMatrix < Scalar >
61  {
62  public:
63  EpetraMatrix();
64  EpetraMatrix(const EpetraMatrix &mat);
65  EpetraMatrix(Epetra_RowMatrix &mat);
66  virtual ~EpetraMatrix();
67 
68  virtual void prealloc(unsigned int n);
69  virtual void pre_add_ij(unsigned int row, unsigned int col);
70  virtual void finish();
71 
72  virtual void alloc();
73  virtual void free();
74  virtual Scalar get(unsigned int m, unsigned int n) const;
75  virtual int get_num_row_entries(unsigned int row);
76  virtual void extract_row_copy(unsigned int row, unsigned int len, unsigned int &n_entries, double *vals, unsigned int *idxs);
77  virtual void zero();
78  virtual void add(unsigned int m, unsigned int n, Scalar v);
79  virtual void multiply_with_vector(Scalar* vector_in, Scalar*& vector_out, bool vector_out_initialized = false) const;
80  virtual void multiply_with_Scalar(Scalar value);
81 
82  virtual void add_sparse_matrix(SparseMatrix<Scalar>* mat);
83 
84  EpetraMatrix* duplicate() { return new EpetraMatrix<Scalar>(*this); }
85 
86  virtual void add(unsigned int m, unsigned int n, Scalar *mat, int *rows, int *cols, const int size);
88  virtual void export_to_file(const char *filename, const char *var_name, MatrixExportFormat fmt, char* number_format = "%lf");
89  virtual unsigned int get_matrix_size() const;
90  virtual unsigned int get_nnz() const;
91  virtual double get_fill_in() const;
92  Epetra_CrsMatrix *mat;
93 
94  protected:
95  Epetra_BlockMap *std_map;
96  Epetra_CrsGraph *grph;
98  Epetra_CrsMatrix *mat_im;
99 
100  bool owner;
101 
102  friend class Hermes::Solvers::AmesosSolver < Scalar > ;
103  friend class Hermes::Solvers::AztecOOSolver < Scalar > ;
104  friend class Hermes::Preconditioners::IfpackPrecond < Scalar > ;
105  friend class Hermes::Preconditioners::MlPrecond < Scalar > ;
106  };
107 
108  template <typename Scalar>
109  class HERMES_API EpetraVector : public Vector < Scalar >
110  {
111  public:
112  EpetraVector();
113  EpetraVector(const Epetra_Vector &v);
114  virtual ~EpetraVector();
115 
116  virtual void alloc(unsigned int ndofs);
117  virtual void free();
118  virtual Scalar get(unsigned int idx) const;
119  virtual void extract(Scalar *v) const;
120  virtual void zero();
122  Vector<Scalar>* duplicate() const;
123  virtual Vector<Scalar>* change_sign();
124  virtual void set(unsigned int idx, Scalar y);
125  virtual void add(unsigned int idx, Scalar y);
126  virtual void add(unsigned int n, unsigned int *idx, Scalar *y);
128  virtual void export_to_file(const char *filename, const char *var_name, MatrixExportFormat fmt, char* number_format = "%lf");
129  Epetra_Vector *vec;
130 
131  protected:
132  Epetra_BlockMap *std_map;
134  Epetra_Vector *vec_im;
135  bool owner;
136 
137  friend class Hermes::Solvers::AmesosSolver < Scalar > ;
138  friend class Hermes::Solvers::AztecOOSolver < Scalar > ;
139  };
140  }
141 }
142 #endif
143 #endif
General (abstract) matrix representation in Hermes.
Definition: matrix.h:36
General namespace for the Hermes library.
Encapsulation of AztecOO linear solver.
Preconditioners built on IFPACK.
Definition: epetra.h:50
General (abstract) vector representation in Hermes.
File containing common definitions, and basic global enums etc. for HermesCommon. ...
General (abstract) sparse matrix representation in Hermes.
MatrixExportFormat
Format of file matrix and vector output.
Encapsulation of Amesos linear solver.
Definition: amesos_solver.h:39
Preconditioners built on ML.
Definition: epetra.h:51
Basic matrix classes and operations.
void change_sign(T **matrix, unsigned int m, unsigned int n)
Changes the sign of a matrix.
Basic vector classes and operations.
Epetra_Vector * vec_im
Imaginary part of the vector, vec holds the real part.
Definition: epetra.h:134
Epetra_CrsMatrix * mat_im
Imaginary part of the matrix, mat holds the real part.
Definition: epetra.h:98