Branch data Line data Source code
1 : : !!****m* ABINIT/m_spmat_base
2 : : !! NAME
3 : : !! m_spmat_base
4 : : !!
5 : : !! FUNCTION
6 : : !! This module contains the base type for sparse matrix.
7 : : !!
8 : : !! Datatypes:
9 : : !! base_mat_t: base sparse 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 : : #if defined HAVE_CONFIG_H
25 : : #include "config.h"
26 : : #endif
27 : : #include "abi_common.h"
28 : :
29 : :
30 : : module m_spmat_base
31 : : use defs_basis
32 : : use m_errors
33 : : use m_abicore
34 : : use m_xmpi
35 : : implicit none
36 : : private
37 : : !!***
38 : :
39 : : !-----------------------------------------------------------------------
40 : : !> @brief base type for sparse matrices
41 : : !-----------------------------------------------------------------------
42 : : type, public :: base_mat_t
43 : : integer :: ndim ! number of dimensions
44 : : integer, allocatable:: mshape(:) ! shape of matrix
45 : : contains
46 : : procedure :: initialize
47 : : procedure :: finalize
48 : : procedure :: add_entry ! add one entry to matrix
49 : : end type base_mat_t
50 : :
51 : : type, public, extends(base_mat_t) :: base_mat2d_t
52 : : integer :: nrow, ncol ! number of rows and columns
53 : : contains
54 : : procedure :: initialize => base_mat2d_t_initialize
55 : : procedure :: mv => base_mat2d_t_mv ! matrix vector multiplication
56 : : end type base_mat2d_t
57 : :
58 : : contains
59 : :
60 : : !-----------------------------------------------------------------------
61 : : !> @brief initialize
62 : : !> @param [in] mshape: shape of matrix
63 : : !-----------------------------------------------------------------------
64 [ - + ]: 3 : subroutine initialize(self, mshape)
65 : : class(base_mat_t), intent(inout) :: self
66 : : integer, intent(in) :: mshape(:)
67 : 3 : self%ndim=size(mshape)
68 [ - + + - : 9 : ABI_MALLOC(self%mshape, (self%ndim))
+ - + - -
+ - + -
+ ]
69 [ + - - + : 12 : self%mshape=mshape
- - + + ]
70 : 3 : end subroutine initialize
71 : :
72 : : !-----------------------------------------------------------------------
73 : : !> @brief finalize
74 : : !-----------------------------------------------------------------------
75 : 0 : subroutine finalize(self)
76 : : class(base_mat_t), intent(inout) :: self
77 : 0 : self%ndim=0
78 [ # # ]: 0 : if (allocated(self%mshape)) then
79 : 0 : ABI_FREE(self%mshape)
80 : : endif
81 : 0 : end subroutine finalize
82 : :
83 : : !-----------------------------------------------------------------------
84 : : !> @brief add one entry to matrix
85 : : !> @param [in] ind: the indices of the entry
86 : : !> @param [in] val: the value of the entry
87 : : !-----------------------------------------------------------------------
88 : 0 : subroutine add_entry(self, ind, val)
89 : : class(base_mat_t), intent(inout) :: self
90 : : integer, intent(in) :: ind(self%ndim)
91 : : real(dp), intent(in) :: val
92 : : ABI_UNUSED(ind)
93 : : ABI_UNUSED(val)
94 : 0 : end subroutine add_entry
95 : :
96 : : !-----------------------------------------------------------------------
97 : : !> @brief initialize
98 : : !> @param [in] mshape: shape of matrix. should be size 2
99 : : !-----------------------------------------------------------------------
100 [ # # ]: 0 : subroutine base_mat2d_t_initialize(self,mshape)
101 : : class(base_mat2d_t), intent(inout) :: self
102 : : integer, intent(in) :: mshape(:)
103 : 0 : call self%base_mat_t%initialize(mshape)
104 : 0 : self%nrow=mshape(1)
105 : 0 : self%ncol=mshape(2)
106 : 0 : end subroutine base_mat2d_t_initialize
107 : :
108 : : !-----------------------------------------------------------------------
109 : : !> @brief Matrix vector multiplication M x = b
110 : : !> @param [in] x
111 : : !> @param [out] b
112 : : !-----------------------------------------------------------------------
113 : 0 : subroutine base_mat2d_t_mv(self, x, b)
114 : : class(base_mat2d_t), intent(in) :: self
115 : : real(dp), intent(in) :: x(self%ncol)
116 : : real(dp), intent(out) :: b(self%nrow)
117 : 0 : ABI_UNUSED_A(x)
118 : 0 : ABI_UNUSED_A(b)
119 : 0 : end subroutine base_mat2d_t_mv
120 : :
121 [ # # # # : 0 : end module m_spmat_base
# # # # #
# # # ]
|