Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
HypreParVector.hpp
Go to the documentation of this file.
00001 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
00002 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
00003 // reserved. See file COPYRIGHT for details.
00004 //
00005 // This file is part of the MFEM library. For more information and source code
00006 // availability see http://mfem.org.
00007 //
00008 // MFEM is free software; you can redistribute it and/or modify it under the
00009 // terms of the GNU Lesser General Public License (as published by the Free
00010 // Software Foundation) version 2.1 dated February 1999.
00011 
00012 /// This HYPRE library interface has been taken originally from MFEM and modified
00013 /// to suit the needs for the MOAB library.
00014 /// Modified by: Vijay Mahadevan
00015 
00016 #ifndef MOAB_HYPREPARVECTOR
00017 #define MOAB_HYPREPARVECTOR
00018 
00019 #include "moab/MOABConfig.h"
00020 #include "moab/Core.hpp"
00021 
00022 #ifdef MOAB_HAVE_EIGEN3
00023 #include <Eigen/Core>
00024 #include <Eigen/Sparse>
00025 #else
00026 #error Configure with Eigen3 enabled
00027 #endif
00028 
00029 #ifdef MOAB_HAVE_MPI
00030 #include "moab/ParallelComm.hpp"
00031 
00032 // hypre header files
00033 #include "HYPRE.h"
00034 #include "HYPRE_IJ_mv.h"
00035 #include "_hypre_IJ_mv.h"
00036 #include "HYPRE_parcsr_ls.h"
00037 // #include "seq_mv.h"
00038 #include "temp_multivector.h"
00039 
00040 #ifdef HYPRE_COMPLEX
00041 #error "MOAB does not work with HYPRE's complex numbers support"
00042 #endif
00043 
00044 #include "hypre_parcsr.hpp"
00045 
00046 namespace moab
00047 {
00048 
00049 class HypreParMatrix;
00050 class HypreSolver;
00051 
00052 /// Wrapper for hypre's parallel vector class
00053 class HypreParVector
00054 {
00055   private:
00056     int own_ParVector, rstart, rend, size, gsize;
00057 
00058     /// The actual object
00059     hypre_ParVector* x_par;
00060     HYPRE_IJVector x;
00061 
00062     friend class HypreParMatrix;
00063     friend class HypreSolver;
00064 
00065     moab::ParallelComm* pcomm;
00066     char initialized;
00067 
00068   public:
00069     /** Creates an empty vector with given global comm. */
00070     HypreParVector( moab::ParallelComm* p_comm );
00071     /** Creates vector with given global size and partitioning of the columns.
00072         Processor P owns columns [col[P],col[P+1]) */
00073     HypreParVector( moab::ParallelComm* p_comm, HYPRE_Int glob_size, HYPRE_Int rstart, HYPRE_Int rend );
00074     /// Creates vector compatible with y
00075     HypreParVector( const HypreParVector& y );
00076     /// Creates vector compatible with (i.e. in the domain of) A or A^T
00077     HypreParVector( HypreParMatrix& A, int tr = 0 );
00078 
00079     int resize( HYPRE_Int glob_size, HYPRE_Int rstart, HYPRE_Int rend );
00080 
00081     /// MPI communicator
00082     moab::ParallelComm* GetParallelCommunicator()
00083     {
00084         return pcomm;
00085     }
00086 
00087     /// Returns the row partitioning
00088     inline HYPRE_Int* Partitioning()
00089     {
00090         return x->partitioning;
00091     }
00092 
00093     /// Returns the global number of rows
00094     inline HYPRE_Int GlobalSize() const
00095     {
00096         return x->global_num_rows;
00097     }
00098 
00099     /// Typecasting to hypre's HYPRE_IJVector*
00100     operator HYPRE_IJVector() const;
00101     // #ifndef HYPRE_PAR_VECTOR_STRUCT
00102     /// Typecasting to hypre's HYPRE_ParVector, a.k.a. void *
00103     operator HYPRE_ParVector() const;
00104     // #endif
00105     /// Changes the ownership of the the vector
00106     HYPRE_IJVector StealParVector()
00107     {
00108         own_ParVector = 0;
00109         return x;
00110     }
00111 
00112     /// Sets ownership of the internal HYPRE_IJVector
00113     void SetOwnership( int own )
00114     {
00115         own_ParVector = own;
00116     }
00117 
00118     /// Gets ownership of the internal HYPRE_IJVector
00119     int GetOwnership() const
00120     {
00121         return own_ParVector;
00122     }
00123 
00124     /// Define '=' for hypre vectors.
00125     HypreParVector& operator=( double d );
00126     HypreParVector& operator=( const HypreParVector& y );
00127 
00128     HYPRE_Int GetValues( const int ndata, const HYPRE_Int* indices, HYPRE_Complex* const _data ) const;
00129 
00130     HYPRE_Int SetValues( const int ndata, const HYPRE_Int* indices, const HYPRE_Complex* const _data );
00131 
00132     HYPRE_Int AddValues( const int ndata, const HYPRE_Int* indices, const HYPRE_Complex* const _data );
00133 
00134     HYPRE_Int GetValue( const HYPRE_Int index, HYPRE_Complex* const _data ) const;
00135 
00136     HYPRE_Int SetValue( const HYPRE_Int index, const HYPRE_Complex _data );
00137 
00138     HYPRE_Int AddValue( const HYPRE_Int index, const HYPRE_Complex _data );
00139 
00140     /** Sets the data of the HYPRE_IJVector to _data.
00141         Must be the same length as the current local size of the vector.
00142         If not, this can lead to an inconsistent vector setup. */
00143     HYPRE_Int SetData( double* p_data, HYPRE_Int* p_col = NULL );
00144 
00145     /** Add the data of the HYPRE_IJVector to _data.
00146         Must be the same length as the current local size of the vector.
00147         If not, this can lead to an inconsistent vector setup. */
00148     HYPRE_Int AddData( double* p_data, HYPRE_Int* p_col = NULL );
00149 
00150     HYPRE_Int verbosity( const HYPRE_Int level );
00151 
00152     HYPRE_Int FinalizeAssembly();
00153 
00154     // const HYPRE_Complex& operator()(int index) const;
00155 
00156     // HYPRE_Complex& operator()(int index);
00157 
00158     /// Prints the locally owned rows in parallel
00159     void Print( const char* fname ) const;
00160 
00161     /// Calls hypre's destroy function
00162     ~HypreParVector();
00163 
00164     static double InnerProduct( HypreParVector& x, HypreParVector& y );
00165 };
00166 
00167 /// Returns the inner product of x and y
00168 double InnerProduct( HypreParVector& x, HypreParVector& y );
00169 double InnerProduct( HypreParVector* x, HypreParVector* y );
00170 
00171 }  // namespace moab
00172 
00173 #endif  // MOAB_HAVE_MPI
00174 
00175 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines