319 lines
11 KiB
Fortran
319 lines
11 KiB
Fortran
module sr_benchmark_cli
|
|
use fem_precision
|
|
use fem_control, only: LSOLVER_CG, LSOLVER_BICGSTAB, LSOLVER_GMRES, &
|
|
LPRECOND_NONE, LPRECOND_JACOBI, LPRECOND_GAUSS_SEIDEL, LPRECOND_ILU0
|
|
use fem_strength_reduction_driver, only: SR_SEARCH_MAX_RECORDS
|
|
implicit none
|
|
|
|
private
|
|
|
|
real(rk), parameter :: NL_DEFAULT_TOL = 1.0e-5_rk
|
|
real(rk), parameter :: NL_DEFAULT_SR_TOL = 2.0e-2_rk
|
|
integer, parameter :: MATERIAL_CASE_COUNT = 2
|
|
|
|
type nonlinear_chain_options
|
|
logical :: enabled = .false.
|
|
logical :: allow_cutback = .true.
|
|
logical :: line_search = .true.
|
|
integer :: material_case = 2
|
|
integer :: max_trials = 10
|
|
integer :: max_increments = 100
|
|
integer :: max_newton = 80
|
|
integer :: linear_iter_limit = 5000
|
|
integer :: linear_solver_method = LSOLVER_BICGSTAB
|
|
integer :: linear_precond_method = LPRECOND_JACOBI
|
|
real(rk) :: alpha = 45.0_rk
|
|
real(rk) :: tolerance = NL_DEFAULT_SR_TOL
|
|
real(rk) :: solver_tol = NL_DEFAULT_TOL
|
|
real(rk) :: displacement_limit = ZERO
|
|
real(rk) :: plastic_limit = 0.95_rk
|
|
logical :: write_cloud = .false.
|
|
integer :: cloud_step = 1525
|
|
real(rk) :: cloud_factor = ZERO
|
|
end type nonlinear_chain_options
|
|
|
|
public :: nonlinear_chain_options
|
|
public :: write_usage
|
|
public :: nonlinear_options_default
|
|
public :: parse_optional_arguments
|
|
public :: MATERIAL_CASE_COUNT
|
|
|
|
intrinsic getarg
|
|
|
|
contains
|
|
|
|
subroutine write_usage()
|
|
write(*,'(A)') 'Usage: strength_reduction_benchmark INPUT.inp OUTPUT_DIR [options]'
|
|
write(*,'(A)') 'Options:'
|
|
write(*,'(A)') ' --nonlinear-chain run real nonlinear FE SR trial chain'
|
|
write(*,'(A)') ' --nl-material-case N nonlinear material case, 1 or 2'
|
|
write(*,'(A)') ' --nl-alpha VALUE nonlinear slope angle metadata'
|
|
write(*,'(A)') ' --nl-max-trials N nonlinear SR search trial limit'
|
|
write(*,'(A)') ' --nl-increments N static nonlinear load increments per trial; default 100'
|
|
write(*,'(A)') ' --nl-max-newton N Newton iterations per increment; default 80'
|
|
write(*,'(A)') ' --nl-linear-iter N Krylov iteration cap per Newton correction'
|
|
write(*,'(A)') ' --nl-linear-solver NAME cg, bicgstab, or gmres; default bicgstab'
|
|
write(*,'(A)') ' --nl-preconditioner NAME none, jacobi, gs, or ilu0; default jacobi'
|
|
write(*,'(A)') ' --nl-tol VALUE Newton force tolerance'
|
|
write(*,'(A)') ' --nl-sr-tol VALUE FOS bracket tolerance'
|
|
write(*,'(A)') ' --nl-disp-limit VALUE displacement stop criterion'
|
|
write(*,'(A)') ' --nl-plastic-limit VALUE plastic integration point fraction limit'
|
|
write(*,'(A)') ' --nl-write-cloud run one target-FOS nonlinear trial and write VTK'
|
|
write(*,'(A)') ' --nl-cloud-factor VALUE target cloud strength factor; default PDF FOS'
|
|
write(*,'(A)') ' --nl-cloud-step N VTK step id for target cloud; default 1525'
|
|
write(*,'(A)') ' --nl-no-cutback disable nonlinear load-step cutback'
|
|
write(*,'(A)') ' --nl-no-line-search disable nonlinear line search'
|
|
end subroutine write_usage
|
|
|
|
subroutine nonlinear_options_default(nl)
|
|
type(nonlinear_chain_options), intent(out) :: nl
|
|
|
|
nl%enabled = .false.
|
|
nl%allow_cutback = .true.
|
|
nl%line_search = .true.
|
|
nl%material_case = 2
|
|
nl%max_trials = 10
|
|
nl%max_increments = 100
|
|
nl%max_newton = 80
|
|
nl%linear_iter_limit = 5000
|
|
nl%linear_solver_method = LSOLVER_BICGSTAB
|
|
nl%linear_precond_method = LPRECOND_JACOBI
|
|
nl%alpha = 45.0_rk
|
|
nl%tolerance = NL_DEFAULT_SR_TOL
|
|
nl%solver_tol = NL_DEFAULT_TOL
|
|
nl%displacement_limit = ZERO
|
|
nl%plastic_limit = 0.95_rk
|
|
nl%write_cloud = .false.
|
|
nl%cloud_step = 1525
|
|
nl%cloud_factor = ZERO
|
|
end subroutine nonlinear_options_default
|
|
|
|
subroutine parse_optional_arguments(argc, nl)
|
|
integer, intent(in) :: argc
|
|
type(nonlinear_chain_options), intent(inout) :: nl
|
|
|
|
character(len=512) :: arg
|
|
character(len=512) :: value
|
|
integer :: i
|
|
|
|
i = 3
|
|
do while (i .le. argc)
|
|
call getarg(i, arg)
|
|
call parse_one_option(argc, i, arg, value, nl)
|
|
end do
|
|
|
|
call validate_nonlinear_options(nl)
|
|
end subroutine parse_optional_arguments
|
|
|
|
subroutine parse_one_option(argc, i, arg, value, nl)
|
|
integer, intent(in) :: argc
|
|
integer, intent(inout) :: i
|
|
character(len=*), intent(in) :: arg
|
|
character(len=*), intent(out) :: value
|
|
type(nonlinear_chain_options), intent(inout) :: nl
|
|
|
|
select case (trim(arg))
|
|
case ('--help', '-h')
|
|
call write_usage()
|
|
stop 0
|
|
case ('--nonlinear-chain')
|
|
nl%enabled = .true.
|
|
i = i + 1
|
|
case ('--nl-no-cutback')
|
|
nl%allow_cutback = .false.
|
|
i = i + 1
|
|
case ('--nl-no-line-search')
|
|
nl%line_search = .false.
|
|
i = i + 1
|
|
case ('--nl-material-case')
|
|
call read_option_int(argc, i, arg, value, nl%material_case)
|
|
case ('--nl-alpha')
|
|
call read_option_real(argc, i, arg, value, nl%alpha)
|
|
case ('--nl-max-trials')
|
|
call read_option_int(argc, i, arg, value, nl%max_trials)
|
|
case ('--nl-increments')
|
|
call read_option_int(argc, i, arg, value, nl%max_increments)
|
|
case ('--nl-max-newton')
|
|
call read_option_int(argc, i, arg, value, nl%max_newton)
|
|
case ('--nl-linear-iter')
|
|
call read_option_int(argc, i, arg, value, nl%linear_iter_limit)
|
|
case ('--nl-linear-solver')
|
|
call require_option_value(argc, i, trim(arg), value)
|
|
call read_linear_solver_value(trim(arg), value, nl%linear_solver_method)
|
|
i = i + 2
|
|
case ('--nl-preconditioner')
|
|
call require_option_value(argc, i, trim(arg), value)
|
|
call read_preconditioner_value(trim(arg), value, nl%linear_precond_method)
|
|
i = i + 2
|
|
case ('--nl-tol')
|
|
call read_option_real(argc, i, arg, value, nl%solver_tol)
|
|
case ('--nl-sr-tol')
|
|
call read_option_real(argc, i, arg, value, nl%tolerance)
|
|
case ('--nl-disp-limit')
|
|
call read_option_real(argc, i, arg, value, nl%displacement_limit)
|
|
case ('--nl-plastic-limit')
|
|
call read_option_real(argc, i, arg, value, nl%plastic_limit)
|
|
case ('--nl-write-cloud')
|
|
nl%write_cloud = .true.
|
|
i = i + 1
|
|
case ('--nl-cloud-factor')
|
|
call read_option_real(argc, i, arg, value, nl%cloud_factor)
|
|
case ('--nl-cloud-step')
|
|
call read_option_int(argc, i, arg, value, nl%cloud_step)
|
|
case default
|
|
write(*,'(A,A)') 'Unknown option: ', trim(arg)
|
|
call write_usage()
|
|
stop 2
|
|
end select
|
|
end subroutine parse_one_option
|
|
|
|
subroutine read_option_int(argc, i, arg, value, target)
|
|
integer, intent(in) :: argc
|
|
integer, intent(inout) :: i
|
|
character(len=*), intent(in) :: arg
|
|
character(len=*), intent(out) :: value
|
|
integer, intent(out) :: target
|
|
|
|
call require_option_value(argc, i, trim(arg), value)
|
|
call read_int_value(trim(arg), value, target)
|
|
i = i + 2
|
|
end subroutine read_option_int
|
|
|
|
subroutine read_option_real(argc, i, arg, value, target)
|
|
integer, intent(in) :: argc
|
|
integer, intent(inout) :: i
|
|
character(len=*), intent(in) :: arg
|
|
character(len=*), intent(out) :: value
|
|
real(rk), intent(out) :: target
|
|
|
|
call require_option_value(argc, i, trim(arg), value)
|
|
call read_real_value(trim(arg), value, target)
|
|
i = i + 2
|
|
end subroutine read_option_real
|
|
|
|
subroutine validate_nonlinear_options(nl)
|
|
type(nonlinear_chain_options), intent(in) :: nl
|
|
|
|
if (nl%material_case .lt. 1 .or. &
|
|
nl%material_case .gt. MATERIAL_CASE_COUNT) then
|
|
write(*,'(A)') '--nl-material-case must be 1 or 2'
|
|
stop 2
|
|
end if
|
|
if (nl%max_trials .lt. 1 .or. &
|
|
nl%max_trials .gt. SR_SEARCH_MAX_RECORDS) then
|
|
write(*,'(A,I0)') '--nl-max-trials must be 1..', SR_SEARCH_MAX_RECORDS
|
|
stop 2
|
|
end if
|
|
if (nl%max_increments .lt. 1 .or. nl%max_newton .lt. 1) then
|
|
write(*,'(A)') '--nl-increments and --nl-max-newton must be positive'
|
|
stop 2
|
|
end if
|
|
if (nl%linear_iter_limit .lt. 1) then
|
|
write(*,'(A)') '--nl-linear-iter must be positive'
|
|
stop 2
|
|
end if
|
|
if (nl%linear_solver_method .eq. LSOLVER_CG .and. &
|
|
(nl%linear_precond_method .eq. LPRECOND_GAUSS_SEIDEL .or. &
|
|
nl%linear_precond_method .eq. LPRECOND_ILU0)) then
|
|
write(*,'(A)') '--nl-preconditioner gs/ilu0 requires bicgstab or gmres'
|
|
stop 2
|
|
end if
|
|
if (nl%tolerance .le. ZERO .or. nl%solver_tol .le. ZERO) then
|
|
write(*,'(A)') '--nl-sr-tol and --nl-tol must be positive'
|
|
stop 2
|
|
end if
|
|
if (nl%plastic_limit .le. ZERO .or. nl%plastic_limit .gt. ONE) then
|
|
write(*,'(A)') '--nl-plastic-limit must be in (0, 1]'
|
|
stop 2
|
|
end if
|
|
if (nl%cloud_factor .lt. ZERO) then
|
|
write(*,'(A)') '--nl-cloud-factor must be non-negative'
|
|
stop 2
|
|
end if
|
|
if (nl%cloud_step .lt. 0) then
|
|
write(*,'(A)') '--nl-cloud-step must be non-negative'
|
|
stop 2
|
|
end if
|
|
end subroutine validate_nonlinear_options
|
|
|
|
subroutine require_option_value(argc, index, name, value)
|
|
integer, intent(in) :: argc
|
|
integer, intent(in) :: index
|
|
character(len=*), intent(in) :: name
|
|
character(len=*), intent(out) :: value
|
|
|
|
if (index + 1 .gt. argc) then
|
|
write(*,'(A,A)') 'Missing value for option ', trim(name)
|
|
stop 2
|
|
end if
|
|
call getarg(index + 1, value)
|
|
end subroutine require_option_value
|
|
|
|
subroutine read_int_value(name, text, value)
|
|
character(len=*), intent(in) :: name
|
|
character(len=*), intent(in) :: text
|
|
integer, intent(out) :: value
|
|
integer :: stat
|
|
|
|
read(text, *, iostat=stat) value
|
|
if (stat .ne. 0) then
|
|
write(*,'(A,A,A,A)') 'Invalid integer for ', trim(name), ': ', &
|
|
trim(text)
|
|
stop 2
|
|
end if
|
|
end subroutine read_int_value
|
|
|
|
subroutine read_real_value(name, text, value)
|
|
character(len=*), intent(in) :: name
|
|
character(len=*), intent(in) :: text
|
|
real(rk), intent(out) :: value
|
|
integer :: stat
|
|
|
|
read(text, *, iostat=stat) value
|
|
if (stat .ne. 0) then
|
|
write(*,'(A,A,A,A)') 'Invalid real for ', trim(name), ': ', trim(text)
|
|
stop 2
|
|
end if
|
|
end subroutine read_real_value
|
|
|
|
subroutine read_linear_solver_value(name, text, value)
|
|
character(len=*), intent(in) :: name
|
|
character(len=*), intent(in) :: text
|
|
integer, intent(out) :: value
|
|
|
|
select case (trim(text))
|
|
case ('cg', 'CG')
|
|
value = LSOLVER_CG
|
|
case ('bicgstab', 'BiCGSTAB', 'BICGSTAB')
|
|
value = LSOLVER_BICGSTAB
|
|
case ('gmres', 'GMRES')
|
|
value = LSOLVER_GMRES
|
|
case default
|
|
write(*,'(A,A,A,A)') 'Invalid value for ', trim(name), ': ', trim(text)
|
|
stop 2
|
|
end select
|
|
end subroutine read_linear_solver_value
|
|
|
|
subroutine read_preconditioner_value(name, text, value)
|
|
character(len=*), intent(in) :: name
|
|
character(len=*), intent(in) :: text
|
|
integer, intent(out) :: value
|
|
|
|
select case (trim(text))
|
|
case ('none', 'NONE')
|
|
value = LPRECOND_NONE
|
|
case ('jacobi', 'Jacobi', 'JACOBI')
|
|
value = LPRECOND_JACOBI
|
|
case ('gs', 'GS', 'gauss-seidel', 'GAUSS-SEIDEL', &
|
|
'gauss_seidel', 'GAUSS_SEIDEL')
|
|
value = LPRECOND_GAUSS_SEIDEL
|
|
case ('ilu0', 'ILU0', 'ilu', 'ILU')
|
|
value = LPRECOND_ILU0
|
|
case default
|
|
write(*,'(A,A,A,A)') 'Invalid value for ', trim(name), ': ', trim(text)
|
|
stop 2
|
|
end select
|
|
end subroutine read_preconditioner_value
|
|
|
|
end module sr_benchmark_cli
|