LCOV - code coverage report
Current view: top level - include/numerics - petsc_mffd_matrix.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 7 43 16.3 %
Date: 2025-08-19 19:27:09 Functions: 2 27 7.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 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_MFFD_MATRIX_H
      19             : #define LIBMESH_PETSC_MFFD_MATRIX_H
      20             : 
      21             : #include "libmesh/libmesh_config.h"
      22             : 
      23             : #ifdef LIBMESH_HAVE_PETSC
      24             : 
      25             : #include "libmesh/petsc_matrix_base.h"
      26             : 
      27             : namespace libMesh
      28             : {
      29             : 
      30             : /**
      31             :  * This class allows to use a PETSc shell matrix as a PetscMatrix
      32             :  *
      33             :  * \author Alexander Lindsay
      34             :  * \date 2024
      35             :  */
      36             : template <typename T>
      37       75432 : class PetscMFFDMatrix : public PetscMatrixBase<T>
      38             : {
      39             : public:
      40             :   /**
      41             :    * Constructor.  Creates a PetscMFFDMatrix assuming you already have a
      42             :    * valid Mat object.  In this case, m is NOT destroyed by the
      43             :    * PetscMFFDMatrix destructor when this object goes out of scope.  This
      44             :    * allows ownership of m to remain with the original creator, and to
      45             :    * simply provide additional functionality with the PetscMFFDMatrix.
      46             :    */
      47             :   explicit PetscMFFDMatrix(Mat m, const Parallel::Communicator & comm_in);
      48             : 
      49             :   explicit PetscMFFDMatrix(const Parallel::Communicator & comm_in);
      50             : 
      51             :   PetscMFFDMatrix & operator=(Mat m);
      52             : 
      53             :   virtual void init(const numeric_index_type,
      54             :                     const numeric_index_type,
      55             :                     const numeric_index_type,
      56             :                     const numeric_index_type,
      57             :                     const numeric_index_type = 30,
      58             :                     const numeric_index_type = 10,
      59             :                     const numeric_index_type = 1) override;
      60             : 
      61             :   /**
      62             :    * Initialize this matrix using the sparsity structure computed by \p dof_map.
      63             :    * @param type The serial/parallel/ghosted type of the matrix
      64             :    */
      65             :   virtual void init(ParallelType = PARALLEL) override;
      66             : 
      67             :   virtual SparseMatrix<T> & operator=(const SparseMatrix<T> &) override;
      68             : 
      69             :   virtual void zero() override;
      70             :   virtual std::unique_ptr<SparseMatrix<T>> zero_clone() const override;
      71             :   virtual std::unique_ptr<SparseMatrix<T>> clone() const override;
      72             :   virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override;
      73             :   virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override;
      74             :   virtual void add_matrix(const DenseMatrix<T> & dm,
      75             :                           const std::vector<numeric_index_type> & rows,
      76             :                           const std::vector<numeric_index_type> & cols) override;
      77             :   virtual void add_matrix(const DenseMatrix<T> & dm,
      78             :                           const std::vector<numeric_index_type> & dof_indices) override;
      79             :   virtual void add(const T a, const SparseMatrix<T> & X) override;
      80             :   virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override;
      81             :   virtual Real l1_norm() const override;
      82             :   virtual Real linfty_norm() const override;
      83             :   virtual void print_personal(std::ostream & os = libMesh::out) const override;
      84             :   virtual void get_diagonal(NumericVector<T> & dest) const override;
      85             :   virtual void get_transpose(SparseMatrix<T> & dest) const override;
      86             :   virtual void get_row(numeric_index_type i,
      87             :                        std::vector<numeric_index_type> & indices,
      88             :                        std::vector<T> & values) const override;
      89             : };
      90             : 
      91             : template <typename T>
      92             : PetscMFFDMatrix<T>::PetscMFFDMatrix(Mat m, const Parallel::Communicator & comm_in)
      93             :   : PetscMatrixBase<T>(m, comm_in)
      94             : {
      95             : }
      96             : 
      97             : template <typename T>
      98        5590 : PetscMFFDMatrix<T>::PetscMFFDMatrix(const Parallel::Communicator & comm_in)
      99       77534 :   : PetscMatrixBase<T>(comm_in)
     100             : {
     101        2102 : }
     102             : 
     103             : template <typename T>
     104             : PetscMFFDMatrix<T> &
     105         408 : PetscMFFDMatrix<T>::operator=(Mat m)
     106             : {
     107       14154 :   this->_mat = m;
     108       13746 :   return *this;
     109             : }
     110             : 
     111             : template <typename T>
     112             : void
     113           0 : PetscMFFDMatrix<T>::init(const numeric_index_type,
     114             :                          const numeric_index_type,
     115             :                          const numeric_index_type,
     116             :                          const numeric_index_type,
     117             :                          const numeric_index_type,
     118             :                          const numeric_index_type,
     119             :                          const numeric_index_type)
     120             : {
     121           0 :   libmesh_error();
     122             : }
     123             : 
     124             : template <typename T>
     125             : void
     126           0 : PetscMFFDMatrix<T>::init(ParallelType)
     127             : {
     128           0 :   libmesh_error();
     129             : }
     130             : 
     131             : template <typename T>
     132             : SparseMatrix<T> &
     133           0 : PetscMFFDMatrix<T>::operator=(const SparseMatrix<T> &)
     134             : {
     135           0 :   libmesh_error();
     136             : }
     137             : 
     138             : template <typename T>
     139             : void
     140           0 : PetscMFFDMatrix<T>::zero()
     141             : {
     142           0 :   libmesh_error();
     143             : }
     144             : 
     145             : template <typename T>
     146             : std::unique_ptr<SparseMatrix<T>>
     147           0 : PetscMFFDMatrix<T>::zero_clone() const
     148             : {
     149           0 :   libmesh_error();
     150             : }
     151             : 
     152             : template <typename T>
     153             : std::unique_ptr<SparseMatrix<T>>
     154           0 : PetscMFFDMatrix<T>::clone() const
     155             : {
     156           0 :   libmesh_not_implemented();
     157             : }
     158             : 
     159             : template <typename T>
     160             : void
     161           0 : PetscMFFDMatrix<T>::set(const numeric_index_type, const numeric_index_type, const T)
     162             : {
     163           0 :   libmesh_error();
     164             : }
     165             : 
     166             : template <typename T>
     167             : void
     168           0 : PetscMFFDMatrix<T>::add(const numeric_index_type, const numeric_index_type, const T)
     169             : {
     170           0 :   libmesh_error();
     171             : }
     172             : 
     173             : template <typename T>
     174             : void
     175           0 : PetscMFFDMatrix<T>::add_matrix(const DenseMatrix<T> &,
     176             :                                const std::vector<numeric_index_type> &,
     177             :                                const std::vector<numeric_index_type> &)
     178             : {
     179           0 :   libmesh_error();
     180             : }
     181             : 
     182             : template <typename T>
     183             : void
     184           0 : PetscMFFDMatrix<T>::add_matrix(const DenseMatrix<T> &, const std::vector<numeric_index_type> &)
     185             : {
     186           0 :   libmesh_error();
     187             : }
     188             : 
     189             : template <typename T>
     190             : void
     191           0 : PetscMFFDMatrix<T>::add(const T, const SparseMatrix<T> &)
     192             : {
     193           0 :   libmesh_error();
     194             : }
     195             : 
     196             : template <typename T>
     197             : T
     198           0 : PetscMFFDMatrix<T>::operator()(const numeric_index_type, const numeric_index_type) const
     199             : {
     200           0 :   libmesh_error();
     201             : }
     202             : 
     203             : template <typename T>
     204             : Real
     205           0 : PetscMFFDMatrix<T>::l1_norm() const
     206             : {
     207           0 :   libmesh_error();
     208             : }
     209             : 
     210             : template <typename T>
     211             : Real
     212           0 : PetscMFFDMatrix<T>::linfty_norm() const
     213             : {
     214           0 :   libmesh_error();
     215             : }
     216             : 
     217             : template <typename T>
     218             : void
     219           0 : PetscMFFDMatrix<T>::print_personal(std::ostream &) const
     220             : {
     221           0 :   libmesh_error();
     222             : }
     223             : 
     224             : template <typename T>
     225             : void
     226           0 : PetscMFFDMatrix<T>::get_diagonal(NumericVector<T> &) const
     227             : {
     228           0 :   libmesh_error();
     229             : }
     230             : 
     231             : template <typename T>
     232             : void
     233           0 : PetscMFFDMatrix<T>::get_transpose(SparseMatrix<T> &) const
     234             : {
     235           0 :   libmesh_error();
     236             : }
     237             : 
     238             : template <typename T>
     239             : void
     240           0 : PetscMFFDMatrix<T>::get_row(numeric_index_type,
     241             :                             std::vector<numeric_index_type> &,
     242             :                             std::vector<T> &) const
     243             : {
     244           0 :   libmesh_error();
     245             : }
     246             : 
     247             : } // namespace libMesh
     248             : 
     249             : #endif // LIBMESH_HAVE_PETSC
     250             : #endif // LIBMESH_SPARSE_SHELL_MATRIX_H

Generated by: LCOV version 1.14