Advance V5 nonlinear benchmarks and shell solver

This commit is contained in:
shenw
2026-06-27 16:43:00 +08:00
parent a2a11179d9
commit db68340aaf
84 changed files with 38720 additions and 971 deletions
+111
View File
@@ -14,7 +14,9 @@ program test_linear_solver_cg
call check_nonconvergence()
call check_dispatch_cg_none()
call check_bicgstab_solve()
call check_bicgstab_ilu0_solve()
call check_gmres_solve()
call check_dense_pivot_solve()
call check_invalid_configuration()
contains
@@ -185,6 +187,44 @@ contains
if (ierr .ne. FEM_SUCCESS) call fail(73)
end subroutine check_bicgstab_solve
subroutine check_bicgstab_ilu0_solve()
type(csr_matrix) :: a
integer :: ierr
integer :: iter
integer :: method
integer :: preconditioner
integer :: status_code
real(rk) :: b(3)
real(rk) :: x(3)
real(rk) :: res_norm
call linear_solver_configure(LSOLVER_BICGSTAB, LPRECOND_ILU0, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(7301)
call make_nonsymmetric(a, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(7302)
b = (/ 6.0_rk, 9.0_rk, 6.0_rk /)
x = ZERO
call linear_solver_solve(a, b, x, 30, 1.0e-12_rk, iter, res_norm, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(7303)
if (iter .le. 0) call fail(7304)
if (res_norm .gt. 1.0e-10_rk) call fail(7305)
call check_close(x(1), ONE, 7306)
call check_close(x(2), 2.0_rk, 7307)
call check_close(x(3), 3.0_rk, 7308)
call linear_solver_get_stats(method, preconditioner, iter, res_norm, &
status_code, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(7309)
if (method .ne. LSOLVER_BICGSTAB) call fail(7310)
if (preconditioner .ne. LPRECOND_ILU0) call fail(7311)
if (status_code .ne. LS_STATUS_CONVERGED) call fail(7312)
call csr_free(a, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(7313)
call linear_solver_configure(LSOLVER_CG, LPRECOND_JACOBI, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(7314)
end subroutine check_bicgstab_ilu0_solve
subroutine check_gmres_solve()
type(csr_matrix) :: a
integer :: ierr
@@ -235,6 +275,56 @@ contains
if (ierr .ne. FEM_SUCCESS) call fail(87)
end subroutine check_gmres_solve
subroutine check_dense_pivot_solve()
type(csr_matrix) :: a
integer :: ierr
integer :: iter
integer :: method
integer :: preconditioner
integer :: status_code
integer :: matrix_class
real(rk) :: b(2)
real(rk) :: x(2)
real(rk) :: res_norm
real(rk) :: initial_resid
real(rk) :: final_resid
real(rk) :: relative_resid
call linear_solver_configure(LSOLVER_DENSE, LPRECOND_NONE, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(8601)
call make_indefinite(a, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(8602)
b = (/ -ONE, 7.0_rk /)
x = ZERO
call linear_solver_solve(a, b, x, 10, 1.0e-12_rk, iter, res_norm, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(8603)
if (iter .ne. 2) call fail(8604)
if (res_norm .gt. 1.0e-10_rk) call fail(8605)
call check_close(x(1), 2.0_rk, 8606)
call check_close(x(2), 3.0_rk, 8607)
call linear_solver_get_stats(method, preconditioner, iter, res_norm, &
status_code, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(8608)
if (method .ne. LSOLVER_DENSE) call fail(8609)
if (preconditioner .ne. LPRECOND_NONE) call fail(8610)
if (status_code .ne. LS_STATUS_CONVERGED) call fail(8611)
call linear_solver_get_diagnostics(matrix_class, initial_resid, &
final_resid, relative_resid, &
status_code, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(8612)
if (matrix_class .lt. CSR_CLASS_GENERAL .or. &
matrix_class .gt. CSR_CLASS_SPD_CAND) call fail(8613)
if (initial_resid .le. ONE) call fail(8614)
if (final_resid .gt. 1.0e-10_rk) call fail(8615)
if (relative_resid .gt. 1.0e-10_rk) call fail(8616)
call csr_free(a, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(8617)
call linear_solver_configure(LSOLVER_CG, LPRECOND_JACOBI, ierr)
if (ierr .ne. FEM_SUCCESS) call fail(8618)
end subroutine check_dense_pivot_solve
subroutine check_invalid_configuration()
integer :: ierr
integer :: method
@@ -315,6 +405,27 @@ contains
call csr_add_value(a, 3, 3, 2.0_rk, ierr)
end subroutine make_nonsymmetric
subroutine make_indefinite(a, ierr)
type(csr_matrix), intent(inout) :: a
integer, intent(out) :: ierr
integer :: row_ptr(3)
integer :: col_ind(4)
call csr_init(a)
row_ptr = (/ 1, 3, 5 /)
col_ind = (/ 1, 2, 1, 2 /)
call csr_create_pattern(a, 2, 2, row_ptr, col_ind, ierr)
if (ierr .ne. FEM_SUCCESS) return
call csr_add_value(a, 1, 1, -2.0_rk, ierr)
if (ierr .ne. FEM_SUCCESS) return
call csr_add_value(a, 1, 2, ONE, ierr)
if (ierr .ne. FEM_SUCCESS) return
call csr_add_value(a, 2, 2, 3.0_rk, ierr)
if (ierr .ne. FEM_SUCCESS) return
call csr_add_value(a, 2, 1, -ONE, ierr)
end subroutine make_indefinite
subroutine check_close(actual, expected, code)
real(rk), intent(in) :: actual
real(rk), intent(in) :: expected