9 #include "sll_assert.h"
10 #include "sll_errors.h"
17 use iso_fortran_env,
only: output_unit
37 integer,
allocatable :: ipiv(:)
38 real(
wp),
allocatable :: q(:, :)
58 subroutine dgbtrf(m, n, kl, ku, ab, ldab, ipiv, info)
59 integer,
intent(in) :: m
60 integer,
intent(in) :: n
61 integer,
intent(in) :: kl
62 integer,
intent(in) :: ku
63 double precision,
intent(inout) :: ab(ldab, n)
64 integer,
intent(in) :: ldab
65 integer,
intent(out) :: ipiv(min(m, n))
66 integer,
intent(out) :: info
71 subroutine dgbtrs(trans, n, kl, ku, nrhs, ab, ldab, ipiv, b, ldb, info)
72 character(len=1),
intent(in) :: trans
73 integer,
intent(in) :: n
74 integer,
intent(in) :: kl
75 integer,
intent(in) :: ku
76 integer,
intent(in) :: nrhs
77 double precision,
intent(in) :: ab(ldab, n)
78 integer,
intent(in) :: ldab
79 integer,
intent(in) :: ipiv(n)
80 double precision,
intent(inout) :: b(ldb, nrhs)
81 integer,
intent(in) :: ldb
82 integer,
intent(out) :: info
94 integer,
intent(in) :: n
95 integer,
intent(in) :: kl
96 integer,
intent(in) :: ku
116 allocate (self%ipiv(n))
117 allocate (self%q(2*kl + ku + 1, n))
118 self%q(:, :) = 0.0_wp
125 integer,
intent(in) :: i
126 integer,
intent(in) :: j
127 real(wp),
intent(in) :: a_ij
129 sll_assert(max(1, j - self%ku) <= i)
130 sll_assert(i <= min(self%n, j + self%kl))
132 self%q(self%kl + self%ku + 1 + i - j, j) = a_ij
142 character(len=*),
parameter :: &
143 this_sub_name =
"sll_t_spline_matrix_banded % factorize"
144 character(len=256) :: err_msg
147 call dgbtrf(self%n, self%n, self%kl, self%ku, self%q, 2*self%kl + self%ku + 1, &
151 write (err_msg,
'(i0,a)') abs(info),
"-th argument had an illegal value"
152 sll_error(this_sub_name, err_msg)
153 else if (info > 0)
then
154 write (err_msg,
"('U(',i0,',',i0,')',a)") info, info, &
155 " is exactly zero. The factorization has been completed, but the factor" &
156 //
" U is exactly singular, and division by zero will occur if it is used to" &
157 //
" solve a system of equations."
158 sll_error(this_sub_name, err_msg)
166 real(wp),
intent(inout) :: bx(:)
170 character(len=*),
parameter :: &
171 this_sub_name =
"sll_t_spline_matrix_banded % solve_inplace"
172 character(len=256) :: err_msg
174 sll_assert(
size(bx) == self%n)
176 call dgbtrs(
'N', self%n, self%kl, self%ku, 1, self%q, 2*self%kl + self%ku + 1, &
177 self%ipiv, bx, self%n, info)
180 write (err_msg,
'(i0,a)') abs(info),
"-th argument had an illegal value"
181 sll_error(this_sub_name, err_msg)
189 integer,
optional,
intent(in) :: unit
190 character(len=*),
optional,
intent(in) :: fmt
194 character(len=32) :: fmt_loc
196 if (
present(unit))
then
199 unit_loc = output_unit
202 if (
present(fmt))
then
208 write (fmt_loc,
'(a)')
"("//trim(fmt_loc)//
")"
212 if (max(1, j - self%ku) <= i .and. i <= min(self%n, j + self%kl))
then
213 write (unit_loc, fmt_loc, advance=
'no') self%q(self%kl + self%ku + 1 + i - j, j)
215 write (unit_loc, fmt_loc, advance=
'no') 0.0_wp
230 if (
allocated(self%ipiv))
deallocate (self%ipiv)
231 if (
allocated(self%q))
deallocate (self%q)
Derived type for banded matrices.
integer, parameter wp
Working precision.
subroutine s_spline_matrix_banded__init(self, n, kl, ku)
subroutine s_spline_matrix_banded__write(self, unit, fmt)
subroutine s_spline_matrix_banded__factorize(self)
subroutine s_spline_matrix_banded__solve_inplace(self, bx)
subroutine s_spline_matrix_banded__free(self)
subroutine s_spline_matrix_banded__set_element(self, i, j, a_ij)
Abstract class for small matrix library with basic operations: set matrix element,...
Module to select the kind parameter.
integer, parameter, public f64
f64 is the kind type for 64-bit reals (double precision)