20 #include "sll_working_precision.h"
21 #include "sll_memory.h"
22 #include "sll_assert.h"
53 sll_int32,
dimension(:),
pointer :: row_ptr
54 sll_int32,
dimension(:),
pointer :: col_ind
55 sll_real64,
dimension(:),
pointer :: val
94 local_to_global_row, &
96 local_to_global_col, &
97 num_local_dof_col)
result(mat)
100 sll_int32,
intent(in) :: num_rows
101 sll_int32,
intent(in) :: num_cols
102 sll_int32,
intent(in) :: num_elts
103 sll_int32,
dimension(:, :),
intent(in) :: local_to_global_row
104 sll_int32,
intent(in) :: num_local_dof_row
105 sll_int32,
dimension(:, :),
intent(in) :: local_to_global_col
106 sll_int32,
intent(in) :: num_local_dof_col
110 sll_allocate(mat, ierr)
116 local_to_global_row, &
118 local_to_global_col, &
139 local_to_global_row, &
141 local_to_global_col, &
145 sll_int32,
intent(in) :: num_rows
146 sll_int32,
intent(in) :: num_cols
147 sll_int32,
intent(in) :: num_elts
148 sll_int32,
dimension(:, :),
intent(in) :: local_to_global_row
149 sll_int32,
intent(in) :: num_local_dof_row
150 sll_int32,
dimension(:, :),
intent(in) :: local_to_global_col
151 sll_int32,
intent(in) :: num_local_dof_col
154 sll_int32,
pointer :: lpi_columns(:, :)
155 sll_int32,
pointer :: lpi_occ(:)
160 sll_allocate(lpi_columns(num_rows, 0:coef*num_local_dof_col), ierr)
161 sll_allocate(lpi_occ(num_rows + 1), ierr)
163 lpi_columns(:, :) = 0
170 local_to_global_row, &
172 local_to_global_col, &
176 mat%num_rows = num_rows
177 mat%num_cols = num_cols
181 local_to_global_row, &
183 local_to_global_col, &
192 mat%linear_solver%iparm(iparm_transpose_solve) = api_yes
193 sll_allocate(mat%linear_solver, ierr)
194 call initialize(mat%linear_solver, num_rows, num_nz)
196 mat%linear_solver%avals = 0._f64
198 sll_deallocate_array(lpi_columns, ierr)
199 sll_deallocate_array(lpi_occ, ierr)
209 mat%num_nz = mat_a%num_nz + 2*mat_a%num_rows
210 print *,
'num_nz mat, num_nz mat_tot', mat_a%num_nz, mat%num_nz
211 mat%num_rows = mat_a%num_rows + 1
212 print *,
'num_rows mat, num_rows mat_tot', mat_a%num_rows, mat%num_rows
213 mat%num_cols = mat_a%num_cols + 1
214 print *,
'num_cols mat, num_cols mat_tot', mat_a%num_cols, mat%num_cols
216 mat%linear_solver%avals = 0._f64
227 sll_allocate(mat, ierr)
243 sll_int32,
dimension(:),
intent(in) :: ia_in
244 sll_int32,
dimension(:),
intent(in) :: ja_in
245 real(8),
dimension(:),
intent(in) :: a_in
246 sll_int32,
intent(in) :: num_rows_in
247 sll_int32,
intent(in) :: num_nz_in
248 real(8),
dimension(:),
intent(in) :: constraint_vec
249 sll_int32,
dimension(:),
intent(out) :: ia_out
250 sll_int32,
dimension(:),
intent(out) :: ja_out
251 real(8),
dimension(:),
intent(out) :: a_out
253 sll_int32 :: num_rows_out
254 sll_int32 :: num_nz_out
259 num_rows_out = num_rows_in + 1
260 num_nz_out = num_nz_in + 2*num_rows_in
262 if (
size(ia_in) < num_rows_in + 1)
then
263 print *,
'#problem of size of ia_in',
size(ia_in), num_rows_in + 1
266 if (
size(ja_in) < num_nz_in)
then
267 print *,
'#problem of size of ja_in',
size(ja_in), num_nz_in
270 if (
size(a_in) < num_nz_in)
then
271 print *,
'#problem of size of a_in',
size(a_in), num_nz_in
274 if (
size(ia_out) < num_rows_out + 1)
then
275 print *,
'#problem of size of ia_out',
size(ia_out), num_rows_out + 1
278 if (
size(ja_out) < num_nz_out)
then
279 print *,
'#problem of size of ja_out',
size(ja_out), num_nz_out
282 if (
size(a_out) < num_nz_out)
then
283 print *,
'#problem of size of a_out',
size(a_out), num_nz_out
286 if (ia_in(num_rows_in + 1) .ne. num_nz_in + 1)
then
287 print *,
'#bad value of ia_in(num_rows_in+1)', ia_in(num_rows_in + 1), num_nz_in + 1
292 do i = 1, num_rows_in
294 do k = ia_in(i), ia_in(i + 1) - 1
299 a_out(s) = constraint_vec(i)
300 ja_out(s) = num_rows_out
303 ia_out(num_rows_in + 1) = s
304 do i = 1, num_rows_in
305 a_out(s) = constraint_vec(i)
309 ia_out(num_rows_in + 2) = s
311 if (ia_out(num_rows_out + 1) .ne. num_nz_out + 1)
then
312 print *,
'#bad value of ia_out(num_rows_out+1)', ia_out(num_rows_out + 1), num_nz_out + 1
328 sll_real64,
dimension(:),
intent(in) :: input
329 sll_real64,
dimension(:),
intent(out) :: output
335 do i = 1, mat%num_rows
337 k_1 = mat%linear_solver%colptr(i)
338 k_2 = mat%linear_solver%colptr(i + 1) - 1
340 dot_product(mat%linear_solver%avals(k_1:k_2), &
341 input(mat%linear_solver%row(k_1:k_2)))
350 sll_real64,
intent(in) :: val
351 sll_int32,
intent(in) :: a
352 sll_int32,
intent(in) :: a_prime
358 do k = mat%linear_solver%colptr(a), mat%linear_solver%colptr(a + 1) - 1
359 j = mat%linear_solver%row(k)
360 if (j == a_prime)
then
361 mat%linear_solver%avals(k) = mat%linear_solver%avals(k) + val
371 sll_real64,
dimension(:),
intent(in) :: val
374 if (
size(val) < mat%num_nz)
then
375 print *,
'#Problem of size of val',
size(val), mat%num_nz
376 print *,
'#at line', __line__
377 print *,
'#in file', __file__
378 print *,
'#in subroutine set_values_csr_matrix'
382 mat%linear_solver%avals(1:mat%num_nz) = val(1:mat%num_nz)
389 sll_real64,
dimension(:) :: apr_u
390 sll_real64,
dimension(:) :: apr_b
395 call solve(mat%linear_solver, apr_u)
400 ai_nR, ai_nC, ai_nel, api_LM_1, ai_nen_1, api_LM_2, ai_nen_2, api_columns, api_occ)
404 sll_int32 :: ai_nr, ai_nc
405 sll_int32,
dimension(:, :),
intent(in) :: api_lm_1, api_lm_2
406 sll_int32 :: ai_nel, ai_nen_1, ai_nen_2
407 sll_int32,
dimension(:, :),
pointer :: api_columns
408 sll_int32,
dimension(:),
pointer :: api_occ
410 sll_int32 :: e, b_1, a_1, b_2, a_2, i
412 sll_int32,
dimension(2) :: lpi_size
414 sll_int32,
dimension(:, :),
pointer :: lpi_columns
421 a_1 = api_lm_1(b_1, e)
428 a_2 = api_lm_2(b_2, e)
435 do i = 1, api_columns(a_1, 0)
437 if (api_columns(a_1, i) /= a_2)
then
446 if (.not. ll_done)
then
448 api_occ(a_1) = api_occ(a_1) + 1
452 api_columns(a_1, 0) = api_columns(a_1, 0) + 1
453 api_columns(a_1, api_columns(a_1, 0)) = a_2
456 lpi_size(1) =
SIZE(api_columns, 1)
457 lpi_size(2) =
SIZE(api_columns, 2)
458 if (lpi_size(2) < api_columns(a_1, 0))
then
459 ALLOCATE (lpi_columns(lpi_size(1), lpi_size(2)))
460 lpi_columns = api_columns
462 DEALLOCATE (api_columns)
464 ALLOCATE (api_columns(lpi_size(1), 2*lpi_size(2)))
465 api_columns(1:lpi_size(1), 1:lpi_size(2)) = lpi_columns(1:lpi_size(1), 1:lpi_size(2))
467 DEALLOCATE (lpi_columns)
479 result = sum(api_occ(1:ai_nr))
497 sll_int32,
dimension(:, :),
intent(in) :: api_lm_1
498 sll_int32,
dimension(:, :),
intent(in) :: api_lm_2
500 sll_int32 :: ai_nen_1
501 sll_int32 :: ai_nen_2
502 sll_int32,
dimension(:, :),
pointer :: api_columns
503 sll_int32,
dimension(:),
pointer :: api_occ
504 sll_int32,
dimension(:),
intent(out) :: row_ptr
505 sll_int32,
dimension(:),
intent(out) :: col_ind
506 sll_int32,
intent(in) :: num_rows
508 sll_int32 :: e, b_1, a_1, i,
size
509 sll_int32 :: err, flag
510 sll_int32,
dimension(:),
pointer :: lpr_tmp
515 row_ptr(i + 1) = row_ptr(1) + sum(api_occ(1:i))
522 a_1 = api_lm_1(b_1, e)
524 if (api_columns(a_1, 0) == 0) cycle
525 size = api_columns(a_1, 0)
526 allocate (lpr_tmp(size), stat=err)
527 if (err .ne. 0) flag = 10
528 lpr_tmp(1:size) = api_columns(a_1, 1:size)
531 col_ind(row_ptr(a_1) + i - 1) = int(lpr_tmp(i))
533 api_columns(a_1, 0) = 0
544 sll_real64,
dimension(:) :: apr_u
545 sll_real64,
dimension(:) :: apr_b
546 sll_real64,
dimension(:),
pointer :: masse_tot
recursive subroutine, public sll_s_qsortc(A)
Sparse matrix linear solver utilities.
subroutine, public sll_s_csr_add_one_constraint(ia_in, ja_in, a_in, num_rows_in, num_nz_in, constraint_vec, ia_out, ja_out, a_out)
subroutine, public sll_s_add_to_csr_matrix(mat, val, row, col)
type(sll_t_csr_matrix) function, pointer, public sll_f_new_csr_matrix_with_constraint(mat_a)
subroutine, public sll_s_delete_csr_matrix(csr_mat)
subroutine sll_s_csr_matrix_init(mat, num_rows, num_cols, num_elts, local_to_global_row, num_local_dof_row, local_to_global_col, num_local_dof_col)
initialization of CSR matrix type thanks to the global index of each local dof of each element
subroutine, public sll_s_mult_csr_matrix_vector(mat, input, output)
subroutine, public sll_s_solve_csr_matrix(mat, b, u)
subroutine, public sll_s_csr_matrix_init_with_constraint(mat, mat_a)
integer(kind=i32) function sll_count_non_zero_elts(ai_nR, ai_nC, ai_nel, api_LM_1, ai_nen_1, api_LM_2, ai_nen_2, api_columns, api_occ)
subroutine init_sparsematrix(ai_nel, api_LM_1, ai_nen_1, api_LM_2, ai_nen_2, api_columns, api_occ, row_ptr, col_ind, num_rows)
subroutine, public sll_s_factorize_csr_matrix(mat)
subroutine, public sll_s_solve_csr_matrix_perper(mat, b, u, masse_tot)
subroutine set_values_csr_matrix(mat, val)