LCOV - code coverage report
Current view: top level - include/numerics - petsc_matrix_shell_matrix.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4537 (bb2485) with base 8fa69b Lines: 4 7 57.1 %
Date: 2026-09-01 19:38:09 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : #ifndef LIBMESH_PETSC_MATRIX_SHELL_MATRIX_H
      19             : #define LIBMESH_PETSC_MATRIX_SHELL_MATRIX_H
      20             : 
      21             : #include "libmesh/libmesh_config.h"
      22             : 
      23             : #ifdef LIBMESH_HAVE_PETSC
      24             : 
      25             : #include "libmesh/petsc_matrix_base.h"
      26             : #include "libmesh/petsc_shell_matrix.h"
      27             : 
      28             : namespace libMesh
      29             : {
      30             : 
      31             : /**
      32             :  * This class allows to use a PETSc shell matrix as a PetscMatrix
      33             :  *
      34             :  * \author Alexander Lindsay
      35             :  * \date 2024
      36             :  */
      37             : template <typename T>
      38         612 : class PetscMatrixShellMatrix : public PetscMatrixBase<T>
      39             : {
      40             : public:
      41             :   explicit PetscMatrixShellMatrix(const Parallel::Communicator & comm_in);
      42             : 
      43             :   virtual void init(const numeric_index_type m,
      44             :                     const numeric_index_type n,
      45             :                     const numeric_index_type m_l,
      46             :                     const numeric_index_type n_l,
      47             :                     const numeric_index_type = 30,
      48             :                     const numeric_index_type = 10,
      49             :                     const numeric_index_type blocksize = 1) override;
      50             : 
      51             :   /**
      52             :    * Initialize this matrix using the sparsity structure computed by \p dof_map.
      53             :    * @param type The serial/parallel/ghosted type of the matrix
      54             :    */
      55             :   virtual void init(ParallelType = PARALLEL) override;
      56             : 
      57             :   virtual SparseMatrix<T> & operator=(const SparseMatrix<T> &) override;
      58             : 
      59           0 :   virtual bool require_sparsity_pattern() const override { return false; }
      60             : 
      61             :   virtual void zero() override;
      62             :   virtual std::unique_ptr<SparseMatrix<T>> zero_clone() const override;
      63             :   virtual std::unique_ptr<SparseMatrix<T>> clone() const override;
      64             :   virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override;
      65             :   virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override;
      66             :   virtual void add_matrix(const DenseMatrix<T> & dm,
      67             :                           const std::vector<numeric_index_type> & rows,
      68             :                           const std::vector<numeric_index_type> & cols) override;
      69             :   virtual void add_matrix(const DenseMatrix<T> & dm,
      70             :                           const std::vector<numeric_index_type> & dof_indices) override;
      71             :   virtual void add(const T a, const SparseMatrix<T> & X) override;
      72             :   virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override;
      73             :   virtual Real l1_norm() const override;
      74             :   virtual Real linfty_norm() const override;
      75             :   virtual void print_personal(std::ostream & os = libMesh::out) const override;
      76             :   virtual void get_diagonal(NumericVector<T> & dest) const override;
      77             :   virtual void get_transpose(SparseMatrix<T> & dest) const override;
      78             :   virtual void get_row(numeric_index_type i,
      79             :                        std::vector<numeric_index_type> & indices,
      80             :                        std::vector<T> & values) const override;
      81             : 
      82             : private:
      83             :   // Make this private because we mark as initialized after we've done our initialization, and we
      84             :   // don't want derived classes to mistakenly register their data as initialized (or not)
      85             :   using PetscMatrixBase<T>::_is_initialized;
      86             : 
      87             :   /// Whether to omit constrained degrees of freedom
      88             :   const bool _omit_constrained_dofs;
      89             : 
      90             :   friend void init_shell_mat<PetscMatrixShellMatrix<T>>(PetscMatrixShellMatrix<T> & obj);
      91             :   friend void init_shell_mat<PetscMatrixShellMatrix<T>>(PetscMatrixShellMatrix<T> & obj,
      92             :                                                         const numeric_index_type m,
      93             :                                                         const numeric_index_type n,
      94             :                                                         const numeric_index_type m_l,
      95             :                                                         const numeric_index_type n_l,
      96             :                                                         const numeric_index_type blocksize_in);
      97             : };
      98             : 
      99             : //-----------------------------------------------------------------------
     100             : // PetscMatrixShellMatrix inline members
     101             : template <typename T>
     102         630 : PetscMatrixShellMatrix<T>::PetscMatrixShellMatrix(const Parallel::Communicator & comm_in)
     103         630 :   : PetscMatrixBase<T>(comm_in), _omit_constrained_dofs(false)
     104             : {
     105          18 : }
     106             : 
     107             : template <typename T>
     108             : SparseMatrix<T> &
     109           0 : PetscMatrixShellMatrix<T>::operator=(const SparseMatrix<T> &)
     110             : {
     111           0 :   libmesh_error();
     112             : }
     113             : 
     114             : } // namespace libMesh
     115             : 
     116             : #endif // LIBMESH_HAVE_PETSC
     117             : #endif // LIBMESH_SPARSE_SHELL_MATRIX_H

Generated by: LCOV version 1.14