317 lines
11 KiB
Fortran
317 lines
11 KiB
Fortran
module fem_solver_implicit
|
|
use fem_precision
|
|
use fem_error
|
|
use fem_control
|
|
use fem_database
|
|
use fem_sparse_csr
|
|
use fem_assembly_csr
|
|
use fem_linear_solver_cg
|
|
use fem_element_stiffness
|
|
use fem_element_internal
|
|
use fem_element_state
|
|
use fem_boundary
|
|
use fem_contact
|
|
use fem_dload_tangent
|
|
use fem_implicit_constraints, only: apply_nl_external_tangent, &
|
|
apply_implicit_dirichlet_zero, apply_implicit_dirichlet, &
|
|
collect_dirichlet_constraints, zero_residual_target, &
|
|
apply_implicit_robin, apply_implicit_mpc
|
|
use fem_solver_implicit_support, only: zero_fixed_rhs, &
|
|
begin_newmark_convergence, begin_static_convergence, &
|
|
record_convergence_iteration, record_convergence_correction, &
|
|
record_line_search_metrics, mark_convergence_success, &
|
|
mark_convergence_failure, update_convergence_metrics, &
|
|
static_increment_bounds, initial_adaptive_dt, &
|
|
nonlinear_static_load_fraction, adapt_static_next_dt, &
|
|
static_eval_residual, clear_implicit_dynamic_vectors, &
|
|
static_solve_correction, solve_nl_linear_system, &
|
|
trace_nonlinear_stage, apply_static_trust_region, &
|
|
update_static_trust_region, assemble_nonlinear_external, &
|
|
zero_prescribed_residual, assemble_linear_stiffness, &
|
|
add_lumped_mass_diagonal, csr_saved_matvec
|
|
use fem_solver_newmark, only: implicit_advance_newmark_linear, &
|
|
implicit_newmark_nonlinear_step
|
|
use fem_solver_static_nonlinear, only: select_static_arc_driver, &
|
|
implicit_solve_static_arc, nonlinear_static_adaptive_loop, &
|
|
nonlinear_static_fixed_loop
|
|
implicit none
|
|
|
|
private
|
|
|
|
public :: implicit_solve_linear_static
|
|
public :: implicit_solve_nonlinear_static
|
|
public :: implicit_advance_newmark_linear
|
|
public :: implicit_newmark_nonlinear_step
|
|
|
|
contains
|
|
|
|
subroutine implicit_solve_linear_static(time, max_iter, tol, iter, res_norm, ierr)
|
|
real(rk), intent(in) :: time
|
|
integer, intent(in) :: max_iter
|
|
real(rk), intent(in) :: tol
|
|
integer, intent(out) :: iter
|
|
real(rk), intent(out) :: res_norm
|
|
integer, intent(out) :: ierr
|
|
type(csr_matrix) :: kmat
|
|
real(rk), allocatable :: rhs(:)
|
|
real(rk), allocatable :: rhs_original(:)
|
|
real(rk), allocatable :: ku_original(:)
|
|
real(rk), allocatable :: k_val_original(:)
|
|
integer :: stat
|
|
integer :: row
|
|
integer :: k
|
|
|
|
iter = 0
|
|
res_norm = ZERO
|
|
call csr_init(kmat)
|
|
|
|
if (ndof .le. 0) then
|
|
call error_set(FEM_ERR_SOLVER, 'implicit linear solve requires positive ndof', ierr)
|
|
return
|
|
end if
|
|
if (.not. allocated(u)) then
|
|
call error_set(FEM_ERR_INTERNAL, 'implicit linear solve requires allocated solution vector', ierr)
|
|
return
|
|
end if
|
|
|
|
allocate(rhs(ndof), rhs_original(ndof), ku_original(ndof), stat=stat)
|
|
if (stat .ne. 0) then
|
|
call error_set(FEM_ERR_SOLVER, 'failed to allocate implicit RHS', ierr)
|
|
return
|
|
end if
|
|
rhs = ZERO
|
|
rhs_original = ZERO
|
|
ku_original = ZERO
|
|
|
|
call assembly_build_csr_pattern(kmat, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
call assemble_linear_stiffness(kmat, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
call boundary_apply_prescribed_loads(time, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
rhs = fext
|
|
if (allocated(fsph)) rhs = rhs + fsph
|
|
if (allocated(fcontact)) rhs = rhs + fcontact
|
|
|
|
call apply_implicit_robin(kmat, rhs, time, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
call apply_implicit_mpc(kmat, rhs, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
allocate(k_val_original(kmat%nnz), stat=stat)
|
|
if (stat .ne. 0) then
|
|
call error_set(FEM_ERR_SOLVER, 'failed to allocate reaction workspace', ierr)
|
|
go to 900
|
|
end if
|
|
k_val_original = kmat%val
|
|
rhs_original = rhs
|
|
|
|
call apply_implicit_dirichlet(kmat, rhs, time, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
u = ZERO
|
|
call linear_solver_solve(kmat, rhs, u, max_iter, tol, iter, res_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
if (allocated(v)) v = ZERO
|
|
if (allocated(a)) a = ZERO
|
|
if (allocated(vhalf)) vhalf = ZERO
|
|
|
|
if (.not. allocated(freaction)) then
|
|
call error_set(FEM_ERR_INTERNAL, 'reaction vector is not allocated', ierr)
|
|
go to 900
|
|
end if
|
|
ku_original = ZERO
|
|
do row = 1, kmat%nrow
|
|
do k = kmat%row_ptr(row), kmat%row_ptr(row+1) - 1
|
|
ku_original(row) = ku_original(row) + &
|
|
k_val_original(k) * u(kmat%col_ind(k))
|
|
end do
|
|
end do
|
|
freaction = ku_original - rhs_original
|
|
|
|
900 continue
|
|
call csr_free(kmat, stat)
|
|
if (allocated(rhs)) deallocate(rhs)
|
|
if (allocated(rhs_original)) deallocate(rhs_original)
|
|
if (allocated(ku_original)) deallocate(ku_original)
|
|
if (allocated(k_val_original)) deallocate(k_val_original)
|
|
end subroutine implicit_solve_linear_static
|
|
|
|
subroutine implicit_solve_nonlinear_static(final_time, num_increment, &
|
|
max_iter, tol, iter_total, &
|
|
res_norm, ierr)
|
|
real(rk), intent(in) :: final_time
|
|
integer, intent(in) :: num_increment
|
|
integer, intent(in) :: max_iter
|
|
real(rk), intent(in) :: tol
|
|
integer, intent(out) :: iter_total
|
|
real(rk), intent(out) :: res_norm
|
|
integer, intent(out) :: ierr
|
|
integer :: ninc
|
|
real(rk) :: start_time
|
|
real(rk) :: dt_inc
|
|
real(rk) :: dt_min_eff
|
|
real(rk) :: dt_max_eff
|
|
real(rk) :: time_tol
|
|
real(rk) :: base_load_factor
|
|
real(rk) :: ramp_start_time
|
|
logical :: adaptive_mode
|
|
logical :: arc_load_mode
|
|
|
|
ninc = 1
|
|
start_time = current_time
|
|
dt_inc = ZERO
|
|
dt_min_eff = ZERO
|
|
dt_max_eff = ZERO
|
|
time_tol = ZERO
|
|
base_load_factor = load_factor
|
|
ramp_start_time = current_time
|
|
adaptive_mode = .false.
|
|
arc_load_mode = .false.
|
|
iter_total = 0
|
|
res_norm = ZERO
|
|
call begin_nonlinear_static_driver(final_time, num_increment, max_iter, &
|
|
tol, ninc, start_time, dt_inc, &
|
|
time_tol, dt_min_eff, dt_max_eff, &
|
|
base_load_factor, ramp_start_time, &
|
|
adaptive_mode, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
call select_static_arc_driver(final_time, arc_load_mode, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
if (arc_load_mode) then
|
|
call implicit_solve_static_arc(final_time, ninc, max_iter, tol, &
|
|
iter_total, res_norm, ierr)
|
|
return
|
|
end if
|
|
if (nonlinear_continuation_method .eq. NLC_ARC_DISP .and. &
|
|
use_disp_path_adaptive) then
|
|
adaptive_mode = .true.
|
|
end if
|
|
|
|
if (adaptive_mode) then
|
|
call nonlinear_static_adaptive_loop(final_time, max_iter, tol, dt_inc, &
|
|
time_tol, dt_min_eff, dt_max_eff, &
|
|
base_load_factor, ramp_start_time, &
|
|
iter_total, res_norm, ierr)
|
|
else
|
|
call nonlinear_static_fixed_loop(ninc, start_time, final_time, max_iter, &
|
|
tol, dt_inc, time_tol, dt_min_eff, &
|
|
base_load_factor, ramp_start_time, &
|
|
iter_total, res_norm, ierr)
|
|
end if
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
call clear_implicit_dynamic_vectors()
|
|
load_factor = base_load_factor
|
|
call error_clear(ierr)
|
|
end subroutine implicit_solve_nonlinear_static
|
|
|
|
subroutine begin_nonlinear_static_driver(final_time, num_increment, max_iter, &
|
|
tol, ninc, start_time, dt_inc, &
|
|
time_tol, dt_min_eff, dt_max_eff, &
|
|
base_load_factor, ramp_start_time, &
|
|
adaptive_mode, ierr)
|
|
real(rk), intent(in) :: final_time
|
|
integer, intent(in) :: num_increment
|
|
integer, intent(in) :: max_iter
|
|
real(rk), intent(in) :: tol
|
|
integer, intent(inout) :: ninc
|
|
real(rk), intent(inout) :: start_time
|
|
real(rk), intent(inout) :: dt_inc
|
|
real(rk), intent(inout) :: time_tol
|
|
real(rk), intent(inout) :: dt_min_eff
|
|
real(rk), intent(inout) :: dt_max_eff
|
|
real(rk), intent(inout) :: base_load_factor
|
|
real(rk), intent(inout) :: ramp_start_time
|
|
logical, intent(inout) :: adaptive_mode
|
|
integer, intent(out) :: ierr
|
|
|
|
call reset_static_nl_diag()
|
|
adaptive_mode = nonlinear_continuation_method .eq. NLC_ADAPT_NEWTON
|
|
if (ndof .le. 0) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'nonlinear static solve requires positive ndof', ierr)
|
|
return
|
|
end if
|
|
if (.not. allocated(u)) then
|
|
call error_set(FEM_ERR_INTERNAL, &
|
|
'nonlinear static solve requires allocated solution vector', ierr)
|
|
return
|
|
end if
|
|
if (max_iter .le. 0) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'nonlinear static max_iter must be positive', ierr)
|
|
return
|
|
end if
|
|
if (tol .le. ZERO) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'nonlinear static tolerance must be positive', ierr)
|
|
return
|
|
end if
|
|
if (final_time .le. current_time) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'nonlinear static final time must be greater than current time', ierr)
|
|
return
|
|
end if
|
|
|
|
call select_static_increment_count(num_increment, ninc)
|
|
start_time = current_time
|
|
dt_inc = (final_time - start_time) / real(ninc, rk)
|
|
time_tol = max(1.0e-12_rk * max(ONE, abs(final_time)), 1.0e-30_rk)
|
|
base_load_factor = load_factor
|
|
ramp_start_time = start_time
|
|
if (time_start .lt. start_time .and. time_start .lt. final_time) then
|
|
ramp_start_time = time_start
|
|
end if
|
|
call static_increment_bounds(final_time, start_time, dt_inc, time_tol, &
|
|
dt_min_eff, dt_max_eff)
|
|
call error_clear(ierr)
|
|
end subroutine begin_nonlinear_static_driver
|
|
|
|
subroutine reset_static_nl_diag()
|
|
convergence_cutback_count = 0
|
|
convergence_last_dt = ZERO
|
|
convergence_last_accepted_time = current_time
|
|
convergence_status_code = CONVERGENCE_STATUS_ITERATING
|
|
convergence_failure_code = CONV_FAIL_NONE
|
|
nlc_last_target_dt = ZERO
|
|
nlc_last_actual_dt = ZERO
|
|
nlc_next_target_dt = ZERO
|
|
nlc_last_trust_radius = ZERO
|
|
nlc_next_trust_radius = ZERO
|
|
nlc_last_arc_constraint = ZERO
|
|
nlc_last_arc_lambda = load_factor
|
|
nlc_last_arc_length = ZERO
|
|
nlc_last_damping = ONE
|
|
nlc_last_merit_ratio = ZERO
|
|
nlc_last_iter = 0
|
|
nlc_last_adjust = NLC_ADJ_NONE
|
|
nlc_last_trust_adjust = NLC_ADJ_NONE
|
|
nlc_last_rejections = 0
|
|
if (nonlinear_continuation_method .eq. NLC_ARC_DISP) call nlc_path_reset()
|
|
end subroutine reset_static_nl_diag
|
|
|
|
subroutine select_static_increment_count(num_increment, ninc)
|
|
integer, intent(in) :: num_increment
|
|
integer, intent(out) :: ninc
|
|
|
|
if (num_increment .gt. 0) then
|
|
ninc = num_increment
|
|
else if (max_increment .gt. 0) then
|
|
ninc = max_increment
|
|
else if (nstep_max .gt. 0) then
|
|
ninc = nstep_max
|
|
else
|
|
ninc = 1
|
|
end if
|
|
if (ninc .le. 0) ninc = 1
|
|
end subroutine select_static_increment_count
|
|
|
|
end module fem_solver_implicit
|