9 #include "sll_assert.h"
10 #include "sll_errors.h"
17 use iso_fortran_env,
only: output_unit
35 integer,
allocatable :: ipiv(:)
36 real(
wp),
allocatable :: a(:, :)
56 subroutine dgetrf(m, n, a, lda, ipiv, info)
57 integer,
intent(in) :: m
58 integer,
intent(in) :: n
59 double precision,
intent(inout) :: a(lda, n)
60 integer,
intent(in) :: lda
61 integer,
intent(out) :: ipiv(min(m, n))
62 integer,
intent(out) :: info
67 subroutine dgetrs(trans, n, nrhs, a, lda, ipiv, b, ldb, info)
68 character(len=1),
intent(in) :: trans
69 integer,
intent(in) :: n
70 integer,
intent(in) :: nrhs
71 double precision,
intent(in) :: a(lda, n)
72 integer,
intent(in) :: lda
73 integer,
intent(in) :: ipiv(n)
74 double precision,
intent(inout) :: b(ldb, nrhs)
75 integer,
intent(in) :: ldb
76 integer,
intent(out) :: info
88 integer,
intent(in) :: n
93 allocate (self%ipiv(n))
94 allocate (self%a(n, n))
102 integer,
intent(in) :: i
103 integer,
intent(in) :: j
104 real(wp),
intent(in) :: a_ij
116 character(len=*),
parameter :: &
117 this_sub_name =
"sll_t_spline_matrix_dense % factorize"
118 character(len=256) :: err_msg
120 sll_assert(
size(self%a, 1) == self%n)
121 sll_assert(
size(self%a, 2) == self%n)
124 call dgetrf(self%n, self%n, self%a, self%n, self%ipiv, info)
127 write (err_msg,
'(i0,a)') abs(info),
"-th argument had an illegal value"
128 sll_error(this_sub_name, err_msg)
129 else if (info > 0)
then
130 write (err_msg,
"('U(',i0,',',i0,')',a)") info, info, &
131 " is exactly zero. The factorization has been completed, but the factor" &
132 //
" U is exactly singular, and division by zero will occur if it is used to" &
133 //
" solve a system of equations."
134 sll_error(this_sub_name, err_msg)
142 real(wp),
intent(inout) :: bx(:)
146 character(len=*),
parameter :: &
147 this_sub_name =
"sll_t_spline_matrix_dense % solve_inplace"
148 character(len=256) :: err_msg
150 sll_assert(
size(self%a, 1) == self%n)
151 sll_assert(
size(self%a, 2) == self%n)
152 sll_assert(
size(bx) == self%n)
155 call dgetrs(
'N', self%n, 1, self%a, self%n, self%ipiv, bx, self%n, info)
158 write (err_msg,
'(i0,a)') abs(info),
"-th argument had an illegal value"
159 sll_error(this_sub_name, err_msg)
167 integer,
optional,
intent(in) :: unit
168 character(len=*),
optional,
intent(in) :: fmt
172 character(len=32) :: fmt_loc
174 if (
present(unit))
then
177 unit_loc = output_unit
180 if (
present(fmt))
then
186 write (fmt_loc,
'(a)')
"('(',i0,'"//trim(fmt_loc)//
")')"
187 write (fmt_loc, fmt_loc)
size(self%a, 2)
189 do i = 1,
size(self%a, 1)
190 write (unit_loc, fmt_loc) self%a(i, :)
200 if (
allocated(self%ipiv))
deallocate (self%ipiv)
201 if (
allocated(self%a))
deallocate (self%a)
Abstract class for small matrix library with basic operations: set matrix element,...
Derived type for dense matrices.
subroutine s_spline_matrix_dense__factorize(self)
subroutine s_spline_matrix_dense__free(self)
subroutine s_spline_matrix_dense__solve_inplace(self, bx)
integer, parameter wp
Working precision.
subroutine s_spline_matrix_dense__init(self, n)
subroutine s_spline_matrix_dense__write(self, unit, fmt)
subroutine s_spline_matrix_dense__set_element(self, i, j, a_ij)
Module to select the kind parameter.
integer, parameter, public f64
f64 is the kind type for 64-bit reals (double precision)