LCOV - code coverage report
Current view: top level - src/78_effpot - m_spmat_lil.F90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 84.4 % 32 27
Test Date: 2026-09-20 15:27:41 Functions: 57.1 % 7 4

            Line data    Source code
       1              : !!****m* ABINIT/m_spmat_lil
       2              : !! NAME
       3              : !! m_spmat_lil
       4              : !!
       5              : !! FUNCTION
       6              : !! This module contains the a LIL(list of linked list) format of sparse matrix.
       7              : !! It is useful for constructing sparse matrix, but not efficient for calculation. Use this to construct and then convert it to other format (COO, CSR...)
       8              : !! Datatypes:
       9              : !!  LIL_mat_t: LIL matrix
      10              : !!
      11              : !! Subroutines:
      12              : !! TODO: add this when F2003 doc style is determined.
      13              : !!
      14              : !!
      15              : !! COPYRIGHT
      16              : !! Copyright (C) 2001-2026 ABINIT group (hexu)
      17              : !! This file is distributed under the terms of the
      18              : !! GNU General Public License, see ~abinit/COPYING
      19              : !! or http://www.gnu.org/copyleft/gpl.txt .
      20              : !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt .
      21              : !!
      22              : !! SOURCE
      23              : 
      24              : 
      25              : #if defined HAVE_CONFIG_H
      26              : #include "config.h"
      27              : #endif
      28              : #include "abi_common.h"
      29              : 
      30              : module m_spmat_lil
      31              :   use defs_basis
      32              :   use m_abicore
      33              :   use m_errors
      34              :   use m_xmpi
      35              :   use m_spmat_base, only: base_mat2d_t
      36              :   use m_abicore
      37              :   use m_linked_list
      38              :   implicit none
      39              : !!***
      40              : 
      41              :   private
      42              : 
      43              :   ! linked list type sparse matrix
      44              :   ! a array of rows, each row is a linked list.
      45              :   ! used for constructing sparse matrix. Not to do calculations.
      46              :   type,public, extends(base_mat2d_t):: LIL_mat_t
      47              :      type(llist), allocatable :: rows(:)
      48              :    contains
      49              :      procedure :: initialize => lil_mat_t_initialize
      50              :      procedure :: finalize => lil_mat_t_finalize
      51              :      procedure :: insert => lil_mat_t_insert
      52              :      procedure :: add_entry
      53              :      procedure :: get_nnz => lil_mat_t_get_nnz
      54              :      !procedure :: print => LIL_mat_t_print
      55              :     end type LIL_mat_t
      56              : 
      57              :   contains
      58              :   !------------------ LIL ---------------------
      59            2 :   subroutine LIL_mat_t_initialize(self, mshape)
      60              :     class(LIL_mat_t) , intent(inout):: self
      61              :     integer, intent(in):: mshape(:)
      62            2 :     if (size(mshape)/=2) stop 1
      63            2 :     self%ndim=2
      64            2 :     self%nrow=mshape(1)
      65            2 :     self%ncol=mshape(2)
      66         1302 :     ABI_MALLOC(self%rows, (self%nrow))
      67            2 :     ABI_MALLOC(self%mshape, (2))
      68            6 :     self%mshape(:)=mshape(:)
      69            2 :   end subroutine LIL_mat_t_initialize
      70              : 
      71            2 :   subroutine LIL_mat_t_finalize(self)
      72              :     class(LIL_mat_t) , intent(inout):: self
      73              :     integer :: i
      74            2 :     if (allocated(self%rows)) then
      75         1298 :        do i=1, self%nrow, 1
      76         1298 :           call llist_finalize(self%rows(i))
      77              :        end do
      78            2 :        ABI_FREE(self%rows)
      79              :     endif
      80            2 :     self%ncol=0
      81            2 :     self%nrow=0
      82            2 :     ABI_SFREE(self%mshape)
      83            2 :   end subroutine LIL_mat_t_finalize
      84              : 
      85            0 :   subroutine LIL_mat_t_insert(self, irow, icol, val, mode)
      86              :     class(LIL_mat_t) , intent(inout):: self
      87              :     integer, intent(in):: irow, icol, mode
      88              :     real(dp), intent(in):: val
      89            0 :     if(abs(val)>tiny(0.0d0)) then
      90            0 :        call llist_sorted_insert(self%rows(irow), icol, val, mode)
      91              :     end if
      92            0 :   end subroutine LIL_mat_t_insert
      93              : 
      94        33696 :   subroutine add_entry(self, ind, val)
      95              :     class(LIL_mat_t) , intent(inout):: self
      96              :     integer, intent(in):: ind(self%ndim)
      97              :     real(dp), intent(in):: val
      98        33696 :     if(abs(val)>tiny(0.0d0)) then
      99        33696 :        call llist_sorted_insert(self%rows(ind(1)), ind(2), val, mode=1)
     100              :     end if
     101        33696 :   end subroutine add_entry
     102              : 
     103              : 
     104              : !  subroutine LIL_mat_t_print(self, mat)
     105              : !
     106              : !    class(LIL_mat_t) , intent(inout)::self
     107              : !    real(dp), intent(out):: mat(self%nrow,self%ncol)
     108              : !    integer:: irow, icol
     109              : !    real(dp):: val
     110              : !    mat(:,:)=0.0d0
     111              : !    do irow=1, self%nrow
     112              : !       call llist_iter_restart(self%rows(irow))
     113              : !       do while(associated(self%rows(irow)%iter))
     114              : !          !print*, "Irow: " ,irow, "Icol: ", self%rows(irow)%iter%i, "  val: ", self%rows(irow)%iter%val
     115              : !          !TODO print with wrtout
     116              : !          self%rows(irow)%iter=>self%rows(irow)%iter%next
     117              : !       enddo
     118              : !    enddo
     119              : !  end subroutine LIL_mat_t_print
     120              : !
     121              : 
     122            2 :   function LIL_mat_t_get_nnz(ll) result(nnz)
     123              : 
     124              :     class(LIL_mat_t), intent(in)::ll
     125              :     integer ::nnz, irow
     126            2 :     nnz=0
     127         1298 :     do irow=1, ll%nrow
     128         1298 :        nnz=nnz+ll%rows(irow)%length
     129              :     enddo
     130            2 :   end function LIL_mat_t_get_nnz
     131              : 
     132              : 
     133            0 : end module m_spmat_lil
        

Generated by: LCOV version 2.3-1