Skip to content
Snippets Groups Projects
Select Git revision
  • 6bd4c2dc6537997c1822be1b551270de1e938671
  • develop default protected
  • feature/gmsh-reader
  • origin/stage/bouguettaia
  • feature/kinetic-schemes
  • feature/reconstruction
  • feature/local-dt-fsi
  • feature/composite-scheme-sources
  • feature/composite-scheme-other-fluxes
  • feature/serraille
  • feature/variational-hydro
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • master protected
  • feature/escobar-smoother
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

Connectivity.cpp

Blame
  • CRSMatrix.hpp 1.68 KiB
    #ifndef CRS_MATRIX_HPP
    #define CRS_MATRIX_HPP
    
    #include <Array.hpp>
    #include <Kokkos_StaticCrsGraph.hpp>
    #include <PugsAssert.hpp>
    
    #include <SparseMatrixDescriptor.hpp>
    
    #include <Vector.hpp>
    
    #include <iostream>
    
    template <typename DataType = double, typename IndexType = size_t>
    class CRSMatrix
    {
      using MutableDataType = std::remove_const_t<DataType>;
    
     private:
      using HostMatrix = Kokkos::StaticCrsGraph<IndexType, Kokkos::HostSpace>;
    
      HostMatrix m_host_matrix;
      Array<const DataType> m_values;
    
     public:
      PUGS_INLINE
      size_t
      numberOfRows() const
      {
        return m_host_matrix.numRows();
      }
    
      template <typename DataType2>
      Vector<MutableDataType>
      operator*(const Vector<DataType2>& x) const
      {
        static_assert(std::is_same<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>(),
                      "Cannot multiply matrix and vector of different type");
    
        Assert(x.size() == m_host_matrix.numRows());
    
        Vector<MutableDataType> Ax{m_host_matrix.numRows()};
        auto host_row_map = m_host_matrix.row_map;
    
        parallel_for(
          m_host_matrix.numRows(), PUGS_LAMBDA(const IndexType& i_row) {
            const auto row_begin = host_row_map(i_row);
            const auto row_end   = host_row_map(i_row + 1);
            MutableDataType sum{0};
            for (IndexType j = row_begin; j < row_end; ++j) {
              sum += m_values[j] * x[m_host_matrix.entries(j)];
            }
            Ax[i_row] = sum;
          });
    
        return Ax;
      }
    
      CRSMatrix(const SparseMatrixDescriptor<DataType, IndexType>& M)
      {
        m_host_matrix = Kokkos::create_staticcrsgraph<HostMatrix>("connectivity_matrix", M.graphVector());
        m_values      = M.valueArray();
      }
      ~CRSMatrix() = default;
    };
    
    #endif   // CRS_MATRIX_HPP