LCOV - code coverage report
Current view: top level - include/numerics - dense_matrix_base_impl.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 12 47 25.5 %
Date: 2025-08-19 19:27:09 Functions: 4 10 40.0 %
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             : 
      19             : 
      20             : #ifndef LIBMESH_DENSE_MATRIX_BASE_IMPL_H
      21             : #define LIBMESH_DENSE_MATRIX_BASE_IMPL_H
      22             : 
      23             : // Local Includes
      24             : #include "libmesh/dense_matrix.h"
      25             : #include "libmesh/dense_vector_base.h"
      26             : #include "libmesh/dense_vector.h"
      27             : #include "libmesh/int_range.h"
      28             : 
      29             : // C++ includes
      30             : #include <iomanip> // for std::setw()
      31             : 
      32             : namespace libMesh
      33             : {
      34             : 
      35             :   template <typename T>
      36             :   DenseVector<T>
      37          71 :   DenseMatrixBase<T>::diagonal() const
      38             :   {
      39          71 :     DenseVector<T> ret(_m);
      40         524 :     for (decltype(_m) i = 0; i < _m; ++i)
      41         453 :       ret(i) = el(i, i);
      42          71 :     return ret;
      43             :   }
      44             : 
      45             :   template<typename T>
      46      267651 :   void DenseMatrixBase<T>::multiply (DenseMatrixBase<T> & M1,
      47             :                                      const DenseMatrixBase<T> & M2,
      48             :                                      const DenseMatrixBase<T> & M3)
      49             :   {
      50             :     // Assertions to make sure we have been
      51             :     // passed matrices of the correct dimension.
      52           0 :     libmesh_assert_equal_to (M1.m(), M2.m());
      53           0 :     libmesh_assert_equal_to (M1.n(), M3.n());
      54           0 :     libmesh_assert_equal_to (M2.n(), M3.m());
      55             : 
      56           0 :     const unsigned int m_s = M2.m();
      57           0 :     const unsigned int p_s = M2.n();
      58           0 :     const unsigned int n_s = M1.n();
      59             : 
      60             :     // Do it this way because there is a
      61             :     // decent chance (at least for constraint matrices)
      62             :     // that M3(k,j) = 0. when right-multiplying.
      63     2284243 :     for (unsigned int k=0; k<p_s; k++)
      64    39242023 :       for (unsigned int j=0; j<n_s; j++)
      65    37225431 :         if (M3.el(k,j) != 0.)
      66    47424063 :           for (unsigned int i=0; i<m_s; i++)
      67    44186474 :             M1.el(i,j) += M2.el(i,k) * M3.el(k,j);
      68      267651 :   }
      69             : 
      70             : 
      71             : 
      72             :   template<typename T>
      73           0 :   void DenseMatrixBase<T>::condense(const unsigned int iv,
      74             :                                     const unsigned int jv,
      75             :                                     const T val,
      76             :                                     DenseVectorBase<T> & rhs)
      77             :   {
      78           0 :     libmesh_assert_equal_to (this->_m, rhs.size());
      79           0 :     libmesh_assert_equal_to (iv, jv);
      80             : 
      81             : 
      82             :     // move the known value into the RHS
      83             :     // and zero the column
      84           0 :     for (auto i : make_range(this->m()))
      85             :       {
      86           0 :         rhs.el(i) -= this->el(i,jv)*val;
      87           0 :         this->el(i,jv) = 0.;
      88             :       }
      89             : 
      90             :     // zero the row
      91           0 :     for (auto j : make_range(this->n()))
      92           0 :       this->el(iv,j) = 0.;
      93             : 
      94           0 :     this->el(iv,jv) = 1.;
      95           0 :     rhs.el(iv) = val;
      96             : 
      97           0 :   }
      98             : 
      99             : 
     100             :   template<typename T>
     101           0 :   void DenseMatrixBase<T>::print_scientific (std::ostream & os, unsigned precision) const
     102             :   {
     103             :     // save the initial format flags
     104           0 :     std::ios_base::fmtflags os_flags = os.flags();
     105             : 
     106             :     // Print the matrix entries.
     107           0 :     for (auto i : make_range(this->m()))
     108             :       {
     109           0 :         for (auto j : make_range(this->n()))
     110           0 :           os << std::setw(15)
     111           0 :              << std::scientific
     112           0 :              << std::setprecision(precision)
     113           0 :              << this->el(i,j) << " ";
     114             : 
     115           0 :         os << std::endl;
     116             :       }
     117             : 
     118             :     // reset the original format flags
     119           0 :     os.flags(os_flags);
     120           0 :   }
     121             : 
     122             : 
     123             : 
     124             :   template<typename T>
     125           0 :   void DenseMatrixBase<T>::print (std::ostream & os) const
     126             :   {
     127           0 :     for (auto i : make_range(this->m()))
     128             :       {
     129           0 :         for (auto j : make_range(this->n()))
     130           0 :           os << std::setw(8)
     131           0 :              << this->el(i,j) << " ";
     132             : 
     133           0 :         os << std::endl;
     134             :       }
     135             : 
     136           0 :     return;
     137             :   }
     138             : 
     139             : 
     140             : 
     141             : }
     142             : 
     143             : #endif // LIBMESH_DENSE_MATRIX_BASE_IMPL_H

Generated by: LCOV version 1.14