petsc_matrix.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_PETSC_MATRIX_H 00021 #define LIBMESH_PETSC_MATRIX_H 00022 00023 #include "libmesh/libmesh_common.h" 00024 00025 #ifdef LIBMESH_HAVE_PETSC 00026 00027 // Local includes 00028 #include "libmesh/sparse_matrix.h" 00029 #include "libmesh/petsc_macro.h" 00030 #include "libmesh/parallel.h" 00031 00032 // C++ includes 00033 #include <algorithm> 00034 00035 // Macro to identify and debug functions which should be called in 00036 // parallel on parallel matrices but which may be called in serial on 00037 // serial matrices. This macro will only be valid inside non-static 00038 // PetscMatrix methods 00039 #undef semiparallel_only 00040 #ifndef NDEBUG 00041 #include <cstring> 00042 00043 #define semiparallel_only() do { if (this->initialized()) { const char *mytype; \ 00044 MatGetType(_mat,&mytype); \ 00045 if (!strcmp(mytype, MATSEQAIJ)) \ 00046 parallel_only(); } } while (0) 00047 #else 00048 #define semiparallel_only() 00049 #endif 00050 00051 00055 EXTERN_C_FOR_PETSC_BEGIN 00056 # include <petscmat.h> 00057 EXTERN_C_FOR_PETSC_END 00058 00059 00060 00061 namespace libMesh 00062 { 00063 00064 // Forward Declarations 00065 template <typename T> class DenseMatrix; 00066 00067 00076 template <typename T> 00077 class PetscMatrix : public SparseMatrix<T> 00078 { 00079 public: 00095 PetscMatrix (); 00096 00104 PetscMatrix (Mat m); 00105 00111 ~PetscMatrix (); 00112 00121 void init (const numeric_index_type m, 00122 const numeric_index_type n, 00123 const numeric_index_type m_l, 00124 const numeric_index_type n_l, 00125 const numeric_index_type nnz=30, 00126 const numeric_index_type noz=10); 00127 00136 void init (const numeric_index_type m, 00137 const numeric_index_type n, 00138 const numeric_index_type m_l, 00139 const numeric_index_type n_l, 00140 const std::vector<numeric_index_type>& n_nz, 00141 const std::vector<numeric_index_type>& n_oz); 00142 00146 void init (); 00147 00154 void clear (); 00155 00160 void zero (); 00161 00165 void zero_rows (std::vector<numeric_index_type> & rows, T diag_value = 0.0); 00166 00172 void close () const; 00173 00178 numeric_index_type m () const; 00179 00184 numeric_index_type n () const; 00185 00190 numeric_index_type row_start () const; 00191 00196 numeric_index_type row_stop () const; 00197 00204 void set (const numeric_index_type i, 00205 const numeric_index_type j, 00206 const T value); 00207 00216 void add (const numeric_index_type i, 00217 const numeric_index_type j, 00218 const T value); 00219 00227 void add_matrix (const DenseMatrix<T> &dm, 00228 const std::vector<numeric_index_type> &rows, 00229 const std::vector<numeric_index_type> &cols); 00230 00235 void add_matrix (const DenseMatrix<T> &dm, 00236 const std::vector<numeric_index_type> &dof_indices); 00237 00249 void add (const T a, SparseMatrix<T> &X); 00250 00258 T operator () (const numeric_index_type i, 00259 const numeric_index_type j) const; 00260 00272 Real l1_norm () const; 00273 00286 Real linfty_norm () const; 00287 00292 bool closed() const; 00293 00301 void print_personal(std::ostream& os=libMesh::out) const; 00302 00309 void print_matlab(const std::string name="NULL") const; 00310 00314 virtual void get_diagonal (NumericVector<T>& dest) const; 00315 00320 virtual void get_transpose (SparseMatrix<T>& dest) const; 00321 00325 void swap (PetscMatrix<T> &); 00326 00332 Mat mat () { libmesh_assert (_mat); return _mat; } 00333 00334 protected: 00335 00345 virtual void _get_submatrix(SparseMatrix<T>& submatrix, 00346 const std::vector<numeric_index_type>& rows, 00347 const std::vector<numeric_index_type>& cols, 00348 const bool reuse_submatrix) const; 00349 00350 private: 00351 00355 Mat _mat; 00356 00361 bool _destroy_mat_on_exit; 00362 }; 00363 00364 } // namespace libMesh 00365 00366 #endif // #ifdef LIBMESH_HAVE_PETSC 00367 #endif // LIBMESH_PETSC_MATRIX_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:48 UTC
Hosted By: