Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
HypreParVector.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 /// This HYPRE library interface has been taken originally from MFEM and modified
13 /// to suit the needs for the MOAB library.
14 /// Modified by: Vijay Mahadevan
15 
16 #ifndef MOAB_HYPREPARVECTOR
17 #define MOAB_HYPREPARVECTOR
18 
19 #include "moab/MOABConfig.h"
20 #include "moab/Core.hpp"
21 
22 #ifdef MOAB_HAVE_EIGEN3
23 #include <Eigen/Core>
24 #include <Eigen/Sparse>
25 #else
26 #error Configure with Eigen3 enabled
27 #endif
28 
29 #ifdef MOAB_HAVE_MPI
30 #include "moab/ParallelComm.hpp"
31 
32 // hypre header files
33 #include "HYPRE.h"
34 #include "HYPRE_IJ_mv.h"
35 #include "_hypre_IJ_mv.h"
36 #include "HYPRE_parcsr_ls.h"
37 // #include "seq_mv.h"
38 #include "temp_multivector.h"
39 
40 #ifdef HYPRE_COMPLEX
41 #error "MOAB does not work with HYPRE's complex numbers support"
42 #endif
43 
44 #include "hypre_parcsr.hpp"
45 
46 namespace moab
47 {
48 
49 class HypreParMatrix;
50 class HypreSolver;
51 
52 /// Wrapper for hypre's parallel vector class
53 class HypreParVector
54 {
55  private:
56  int own_ParVector, rstart, rend, size, gsize;
57 
58  /// The actual object
59  hypre_ParVector* x_par;
60  HYPRE_IJVector x;
61 
62  friend class HypreParMatrix;
63  friend class HypreSolver;
64 
65  moab::ParallelComm* pcomm;
66  char initialized;
67 
68  public:
69  /** Creates an empty vector with given global comm. */
70  HypreParVector( moab::ParallelComm* p_comm );
71  /** Creates vector with given global size and partitioning of the columns.
72  Processor P owns columns [col[P],col[P+1]) */
73  HypreParVector( moab::ParallelComm* p_comm, HYPRE_Int glob_size, HYPRE_Int rstart, HYPRE_Int rend );
74  /// Creates vector compatible with y
75  HypreParVector( const HypreParVector& y );
76  /// Creates vector compatible with (i.e. in the domain of) A or A^T
77  HypreParVector( HypreParMatrix& A, int tr = 0 );
78 
79  int resize( HYPRE_Int glob_size, HYPRE_Int rstart, HYPRE_Int rend );
80 
81  /// MPI communicator
82  moab::ParallelComm* GetParallelCommunicator()
83  {
84  return pcomm;
85  }
86 
87  /// Returns the row partitioning
88  inline HYPRE_Int* Partitioning()
89  {
90  return x->partitioning;
91  }
92 
93  /// Returns the global number of rows
94  inline HYPRE_Int GlobalSize() const
95  {
96  return x->global_num_rows;
97  }
98 
99  /// Typecasting to hypre's HYPRE_IJVector*
100  operator HYPRE_IJVector() const;
101  // #ifndef HYPRE_PAR_VECTOR_STRUCT
102  /// Typecasting to hypre's HYPRE_ParVector, a.k.a. void *
103  operator HYPRE_ParVector() const;
104  // #endif
105  /// Changes the ownership of the the vector
106  HYPRE_IJVector StealParVector()
107  {
108  own_ParVector = 0;
109  return x;
110  }
111 
112  /// Sets ownership of the internal HYPRE_IJVector
113  void SetOwnership( int own )
114  {
115  own_ParVector = own;
116  }
117 
118  /// Gets ownership of the internal HYPRE_IJVector
119  int GetOwnership() const
120  {
121  return own_ParVector;
122  }
123 
124  /// Define '=' for hypre vectors.
125  HypreParVector& operator=( double d );
126  HypreParVector& operator=( const HypreParVector& y );
127 
128  HYPRE_Int GetValues( const int ndata, const HYPRE_Int* indices, HYPRE_Complex* const _data ) const;
129 
130  HYPRE_Int SetValues( const int ndata, const HYPRE_Int* indices, const HYPRE_Complex* const _data );
131 
132  HYPRE_Int AddValues( const int ndata, const HYPRE_Int* indices, const HYPRE_Complex* const _data );
133 
134  HYPRE_Int GetValue( const HYPRE_Int index, HYPRE_Complex* const _data ) const;
135 
136  HYPRE_Int SetValue( const HYPRE_Int index, const HYPRE_Complex _data );
137 
138  HYPRE_Int AddValue( const HYPRE_Int index, const HYPRE_Complex _data );
139 
140  /** Sets the data of the HYPRE_IJVector to _data.
141  Must be the same length as the current local size of the vector.
142  If not, this can lead to an inconsistent vector setup. */
143  HYPRE_Int SetData( double* p_data, HYPRE_Int* p_col = NULL );
144 
145  /** Add the data of the HYPRE_IJVector to _data.
146  Must be the same length as the current local size of the vector.
147  If not, this can lead to an inconsistent vector setup. */
148  HYPRE_Int AddData( double* p_data, HYPRE_Int* p_col = NULL );
149 
150  HYPRE_Int verbosity( const HYPRE_Int level );
151 
152  HYPRE_Int FinalizeAssembly();
153 
154  // const HYPRE_Complex& operator()(int index) const;
155 
156  // HYPRE_Complex& operator()(int index);
157 
158  /// Prints the locally owned rows in parallel
159  void Print( const char* fname ) const;
160 
161  /// Calls hypre's destroy function
162  ~HypreParVector();
163 
164  static double InnerProduct( HypreParVector& x, HypreParVector& y );
165 };
166 
167 /// Returns the inner product of x and y
168 double InnerProduct( HypreParVector& x, HypreParVector& y );
169 double InnerProduct( HypreParVector* x, HypreParVector* y );
170 
171 } // namespace moab
172 
173 #endif // MOAB_HAVE_MPI
174 
175 #endif