777 lines
30 KiB
Fortran
777 lines
30 KiB
Fortran
module fem_solver_newmark
|
|
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_internal
|
|
use fem_element_state
|
|
use fem_boundary
|
|
use fem_implicit_constraints, only: apply_nl_external_tangent, &
|
|
apply_implicit_dirichlet_zero, apply_implicit_dirichlet, &
|
|
apply_implicit_robin, apply_implicit_mpc
|
|
use fem_nonlinear_lifecycle, only: NLC_EVENT_ACCEPT, NLC_EVENT_COMMIT, &
|
|
NLC_EVENT_ITERATION_BEGIN, NLC_EVENT_ITERATION_RESULT, &
|
|
NLC_EVENT_REJECT, NLC_EVENT_TRIAL_BEGIN, &
|
|
nl_lifecycle_begin_increment, nl_lifecycle_record_event
|
|
use fem_solver_implicit_support, only: begin_newmark_convergence, &
|
|
record_convergence_iteration, record_convergence_correction, &
|
|
record_line_search_metrics, mark_convergence_success, &
|
|
mark_convergence_failure, solve_nl_linear_system, &
|
|
assemble_nonlinear_external, zero_prescribed_residual, &
|
|
assemble_linear_stiffness, add_lumped_mass_diagonal, csr_saved_matvec
|
|
implicit none
|
|
|
|
private
|
|
|
|
public :: implicit_advance_newmark_linear
|
|
public :: implicit_newmark_nonlinear_step
|
|
|
|
contains
|
|
|
|
subroutine implicit_advance_newmark_linear(dt, beta, gamma, max_iter, tol, &
|
|
iter, res_norm, ierr)
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: beta
|
|
real(rk), intent(in) :: gamma
|
|
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(:), external(:), u_pred(:), v_pred(:)
|
|
real(rk), allocatable :: damp_vec(:), kdamp(:), damping_force(:)
|
|
real(rk), allocatable :: k_val_original(:)
|
|
real(rk) :: a0, a1, mass_scale, stiff_scale, target_time
|
|
integer :: stat
|
|
|
|
iter = 0
|
|
res_norm = ZERO
|
|
call csr_init(kmat)
|
|
|
|
call newmark_linear_validate(dt, beta, gamma, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
allocate(rhs(ndof), external(ndof), u_pred(ndof), v_pred(ndof), &
|
|
damp_vec(ndof), kdamp(ndof), damping_force(ndof), stat=stat)
|
|
if (stat .ne. 0) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'failed to allocate implicit Newmark workspace', ierr)
|
|
return
|
|
end if
|
|
|
|
call newmark_linear_predict(dt, beta, gamma, u_pred, v_pred, damp_vec, &
|
|
a0, a1, target_time)
|
|
|
|
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
|
|
|
|
allocate(k_val_original(kmat%nnz), stat=stat)
|
|
if (stat .ne. 0) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'failed to allocate Newmark stiffness copy', ierr)
|
|
go to 900
|
|
end if
|
|
k_val_original = kmat%val
|
|
|
|
call assemble_nonlinear_external(target_time, external, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
rhs = external + a0 * mass_diag * u_pred
|
|
if (rayleigh_alpha_mass .gt. ZERO) then
|
|
rhs = rhs + rayleigh_alpha_mass * mass_diag * damp_vec
|
|
end if
|
|
if (rayleigh_beta_stiffness .gt. ZERO) then
|
|
call csr_saved_matvec(kmat, k_val_original, damp_vec, kdamp, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
rhs = rhs + rayleigh_beta_stiffness * kdamp
|
|
end if
|
|
|
|
stiff_scale = ONE + a1 * rayleigh_beta_stiffness
|
|
mass_scale = a0 + a1 * rayleigh_alpha_mass
|
|
if (abs(stiff_scale - ONE) .gt. tiny(ONE)) kmat%val = stiff_scale * kmat%val
|
|
call add_lumped_mass_diagonal(kmat, mass_scale, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
call apply_implicit_robin(kmat, rhs, target_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
|
|
call apply_implicit_dirichlet(kmat, rhs, target_time, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
u = u_pred
|
|
call linear_solver_solve(kmat, rhs, u, max_iter, tol, iter, res_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
call newmark_linear_finish(dt, gamma, a0, target_time, kmat, &
|
|
k_val_original, external, kdamp, &
|
|
damping_force, u_pred, v_pred, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
ierr = FEM_SUCCESS
|
|
|
|
900 continue
|
|
call csr_free(kmat, stat)
|
|
if (allocated(rhs)) deallocate(rhs)
|
|
if (allocated(external)) deallocate(external)
|
|
if (allocated(u_pred)) deallocate(u_pred)
|
|
if (allocated(v_pred)) deallocate(v_pred)
|
|
if (allocated(damp_vec)) deallocate(damp_vec)
|
|
if (allocated(kdamp)) deallocate(kdamp)
|
|
if (allocated(damping_force)) deallocate(damping_force)
|
|
if (allocated(k_val_original)) deallocate(k_val_original)
|
|
end subroutine implicit_advance_newmark_linear
|
|
|
|
subroutine newmark_linear_validate(dt, beta, gamma, ierr)
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: beta
|
|
real(rk), intent(in) :: gamma
|
|
integer, intent(out) :: ierr
|
|
integer :: dof
|
|
|
|
if (ndof .le. 0) then
|
|
call error_set(FEM_ERR_SOLVER, 'implicit Newmark requires positive ndof', ierr)
|
|
return
|
|
end if
|
|
if (dt .le. ZERO) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'implicit Newmark time step must be positive', ierr)
|
|
return
|
|
end if
|
|
if (beta .le. ZERO .or. gamma .le. ZERO) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'implicit Newmark parameters must be positive', ierr)
|
|
return
|
|
end if
|
|
if (rayleigh_alpha_mass .lt. ZERO .or. rayleigh_beta_stiffness .lt. ZERO) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'Rayleigh damping factors must be non-negative', ierr)
|
|
return
|
|
end if
|
|
if (.not. allocated(u) .or. .not. allocated(v) .or. .not. allocated(a)) then
|
|
call error_set(FEM_ERR_INTERNAL, &
|
|
'implicit Newmark requires kinematic vectors', ierr)
|
|
return
|
|
end if
|
|
if (.not. allocated(mass_diag)) then
|
|
call error_set(FEM_ERR_INTERNAL, 'implicit Newmark requires mass vector', ierr)
|
|
return
|
|
end if
|
|
do dof = 1, ndof
|
|
if (mass_diag(dof) .le. ZERO) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'implicit Newmark found non-positive lumped mass', ierr)
|
|
return
|
|
end if
|
|
end do
|
|
ierr = FEM_SUCCESS
|
|
end subroutine newmark_linear_validate
|
|
|
|
subroutine newmark_linear_predict(dt, beta, gamma, u_pred, v_pred, &
|
|
damp_vec, a0, a1, target_time)
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: beta
|
|
real(rk), intent(in) :: gamma
|
|
real(rk), intent(out) :: u_pred(ndof)
|
|
real(rk), intent(out) :: v_pred(ndof)
|
|
real(rk), intent(out) :: damp_vec(ndof)
|
|
real(rk), intent(out) :: a0
|
|
real(rk), intent(out) :: a1
|
|
real(rk), intent(out) :: target_time
|
|
|
|
a0 = ONE / (beta * dt * dt)
|
|
a1 = gamma / (beta * dt)
|
|
target_time = current_time + dt
|
|
u_pred = u + dt * v + dt * dt * (HALF - beta) * a
|
|
v_pred = v + dt * (ONE - gamma) * a
|
|
damp_vec = a1 * u_pred - v_pred
|
|
end subroutine newmark_linear_predict
|
|
|
|
subroutine newmark_linear_finish(dt, gamma, a0, target_time, kmat, kcopy, &
|
|
external, kdamp, damping_force, u_pred, &
|
|
v_pred, ierr)
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: gamma
|
|
real(rk), intent(in) :: a0
|
|
real(rk), intent(in) :: target_time
|
|
type(csr_matrix), intent(in) :: kmat
|
|
real(rk), intent(in) :: kcopy(:)
|
|
real(rk), intent(inout) :: external(ndof)
|
|
real(rk), intent(inout) :: kdamp(ndof)
|
|
real(rk), intent(inout) :: damping_force(ndof)
|
|
real(rk), intent(in) :: u_pred(ndof)
|
|
real(rk), intent(in) :: v_pred(ndof)
|
|
integer, intent(out) :: ierr
|
|
|
|
a = a0 * (u - u_pred)
|
|
v = v_pred + gamma * dt * a
|
|
if (allocated(vhalf)) vhalf = v - HALF * dt * a
|
|
|
|
call boundary_apply_dirichlet(target_time, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
call element_compute_internal_force(ierr, dt)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
call assemble_nonlinear_external(target_time, external, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
damping_force = ZERO
|
|
if (rayleigh_alpha_mass .gt. ZERO) then
|
|
damping_force = damping_force + rayleigh_alpha_mass * mass_diag * v
|
|
end if
|
|
if (rayleigh_beta_stiffness .gt. ZERO) then
|
|
call csr_saved_matvec(kmat, kcopy, v, kdamp, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
damping_force = damping_force + rayleigh_beta_stiffness * kdamp
|
|
end if
|
|
if (allocated(freaction)) then
|
|
freaction = fint + mass_diag * a + damping_force - external
|
|
end if
|
|
ierr = FEM_SUCCESS
|
|
end subroutine newmark_linear_finish
|
|
|
|
subroutine implicit_newmark_nonlinear_step(dt, beta, gamma, max_iter, tol, &
|
|
iter_used, res_norm, ierr)
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: beta
|
|
real(rk), intent(in) :: gamma
|
|
integer, intent(in) :: max_iter
|
|
real(rk), intent(in) :: tol
|
|
integer, intent(out) :: iter_used
|
|
real(rk), intent(out) :: res_norm
|
|
integer, intent(out) :: ierr
|
|
type(csr_matrix) :: kmat
|
|
real(rk), allocatable :: residual(:), external(:), rhs_corr(:), du(:)
|
|
real(rk), allocatable :: u_pred(:), v_pred(:), u_start(:), v_start(:)
|
|
real(rk), allocatable :: a_start(:), vhalf_start(:), u_base(:)
|
|
real(rk), allocatable :: kdamp(:), damping_force(:)
|
|
real(rk) :: a0, a1, target_time, ref_norm
|
|
real(rk) :: trial_res_norm, trial_ref_norm
|
|
integer :: iter, stat, state_ierr
|
|
logical :: converged
|
|
|
|
call begin_newmark_nl_step(dt, beta, gamma, max_iter, tol, kmat, iter_used, &
|
|
res_norm, ref_norm, trial_res_norm, &
|
|
trial_ref_norm, converged, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
allocate(residual(ndof), external(ndof), rhs_corr(ndof), du(ndof), &
|
|
u_pred(ndof), v_pred(ndof), u_start(ndof), v_start(ndof), &
|
|
a_start(ndof), vhalf_start(ndof), u_base(ndof), kdamp(ndof), &
|
|
damping_force(ndof), stat=stat)
|
|
if (stat .ne. 0) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'failed to allocate nonlinear Newmark workspace', ierr)
|
|
go to 900
|
|
end if
|
|
|
|
call newmark_nl_save_state(u_start, v_start, a_start, vhalf_start)
|
|
call newmark_nl_start(dt, beta, gamma, u_pred, v_pred, a0, a1, &
|
|
target_time, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
call element_state_begin_trial(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
call nl_lifecycle_record_event(current_step + 1, current_step + 1, 0, &
|
|
NLC_EVENT_TRIAL_BEGIN, NFAIL_NONE)
|
|
|
|
do iter = 1, max_iter
|
|
call nl_lifecycle_record_event(current_step + 1, current_step + 1, &
|
|
iter, NLC_EVENT_ITERATION_BEGIN, &
|
|
NFAIL_NONE)
|
|
call element_state_restore_trial(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
call newmark_nl_eval_resid(target_time, dt, a0, gamma, u_pred, v_pred, &
|
|
kmat, external, residual, damping_force, &
|
|
kdamp, res_norm, ref_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
iter_used = iter
|
|
call record_convergence_iteration(iter, res_norm, ref_norm, &
|
|
convergence_correction_norm)
|
|
if (res_norm .le. tol .or. res_norm / ref_norm .le. tol) then
|
|
call finish_newmark_nl_success(kmat, external, damping_force, &
|
|
converged, stat)
|
|
call nl_lifecycle_record_event(current_step + 1, current_step + 1, &
|
|
iter, NLC_EVENT_ITERATION_RESULT, &
|
|
convergence_failure_reason_id)
|
|
exit
|
|
end if
|
|
|
|
call apply_newmark_nl_correction(kmat, target_time, dt, a0, a1, &
|
|
u_pred, v_pred, u_base, residual, &
|
|
external, rhs_corr, du, damping_force, &
|
|
kdamp, max_iter, tol, res_norm, &
|
|
ref_norm, trial_res_norm, &
|
|
trial_ref_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
call nl_lifecycle_record_event(current_step + 1, current_step + 1, &
|
|
iter, NLC_EVENT_ITERATION_RESULT, &
|
|
convergence_failure_reason_id)
|
|
end do
|
|
|
|
if (.not. converged) then
|
|
call fail_newmark_nl_nonconverged(ierr)
|
|
go to 900
|
|
end if
|
|
|
|
call element_state_commit_trial(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
call nl_lifecycle_record_event(current_step + 1, current_step + 1, &
|
|
iter_used, NLC_EVENT_COMMIT, NFAIL_NONE)
|
|
call nl_lifecycle_record_event(current_step + 1, current_step + 1, &
|
|
iter_used, NLC_EVENT_ACCEPT, NFAIL_NONE)
|
|
|
|
ierr = FEM_SUCCESS
|
|
|
|
900 continue
|
|
if (ierr .ne. FEM_SUCCESS) then
|
|
call nl_lifecycle_record_event(current_step + 1, current_step + 1, &
|
|
iter_used, NLC_EVENT_ITERATION_RESULT, &
|
|
convergence_failure_reason_id)
|
|
call nl_lifecycle_record_event(current_step + 1, current_step + 1, &
|
|
iter_used, NLC_EVENT_REJECT, &
|
|
convergence_failure_reason_id)
|
|
call newmark_nl_restore_state(u_start, v_start, a_start, vhalf_start)
|
|
call element_state_abort_trial(state_ierr)
|
|
end if
|
|
call csr_free(kmat, stat)
|
|
if (allocated(residual)) deallocate(residual)
|
|
if (allocated(external)) deallocate(external)
|
|
if (allocated(rhs_corr)) deallocate(rhs_corr)
|
|
if (allocated(du)) deallocate(du)
|
|
if (allocated(u_pred)) deallocate(u_pred)
|
|
if (allocated(v_pred)) deallocate(v_pred)
|
|
if (allocated(u_start)) deallocate(u_start)
|
|
if (allocated(v_start)) deallocate(v_start)
|
|
if (allocated(a_start)) deallocate(a_start)
|
|
if (allocated(vhalf_start)) deallocate(vhalf_start)
|
|
if (allocated(u_base)) deallocate(u_base)
|
|
if (allocated(kdamp)) deallocate(kdamp)
|
|
if (allocated(damping_force)) deallocate(damping_force)
|
|
end subroutine implicit_newmark_nonlinear_step
|
|
|
|
subroutine begin_newmark_nl_step(dt, beta, gamma, max_iter, tol, kmat, &
|
|
iter_used, res_norm, ref_norm, &
|
|
trial_res_norm, trial_ref_norm, &
|
|
converged, ierr)
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: beta
|
|
real(rk), intent(in) :: gamma
|
|
integer, intent(in) :: max_iter
|
|
real(rk), intent(in) :: tol
|
|
type(csr_matrix), intent(inout) :: kmat
|
|
integer, intent(out) :: iter_used
|
|
real(rk), intent(out) :: res_norm
|
|
real(rk), intent(out) :: ref_norm
|
|
real(rk), intent(out) :: trial_res_norm
|
|
real(rk), intent(out) :: trial_ref_norm
|
|
logical, intent(out) :: converged
|
|
integer, intent(out) :: ierr
|
|
|
|
iter_used = 0
|
|
res_norm = ZERO
|
|
ref_norm = ONE
|
|
trial_res_norm = ZERO
|
|
trial_ref_norm = ONE
|
|
converged = .false.
|
|
call csr_init(kmat)
|
|
call begin_newmark_convergence(dt)
|
|
call newmark_linear_validate(dt, beta, gamma, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
if (max_iter .le. 0) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'nonlinear Newmark max_iter must be positive', ierr)
|
|
return
|
|
end if
|
|
if (tol .le. ZERO) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'nonlinear Newmark tolerance must be positive', ierr)
|
|
return
|
|
end if
|
|
call nl_lifecycle_begin_increment(current_step + 1, current_step + 1)
|
|
call error_clear(ierr)
|
|
end subroutine begin_newmark_nl_step
|
|
|
|
subroutine apply_newmark_nl_correction(kmat, target_time, dt, a0, a1, &
|
|
u_pred, v_pred, u_base, residual, &
|
|
external, rhs_corr, du, &
|
|
damping_force, kdamp, max_iter, tol, &
|
|
res_norm, ref_norm, trial_res_norm, &
|
|
trial_ref_norm, ierr)
|
|
type(csr_matrix), intent(inout) :: kmat
|
|
real(rk), intent(in) :: target_time
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: a0
|
|
real(rk), intent(in) :: a1
|
|
real(rk), intent(in) :: u_pred(:)
|
|
real(rk), intent(in) :: v_pred(:)
|
|
real(rk), intent(inout) :: u_base(:)
|
|
real(rk), intent(inout) :: residual(:)
|
|
real(rk), intent(inout) :: external(:)
|
|
real(rk), intent(inout) :: rhs_corr(:)
|
|
real(rk), intent(inout) :: du(:)
|
|
real(rk), intent(inout) :: damping_force(:)
|
|
real(rk), intent(inout) :: kdamp(:)
|
|
integer, intent(in) :: max_iter
|
|
real(rk), intent(in) :: tol
|
|
real(rk), intent(inout) :: res_norm
|
|
real(rk), intent(inout) :: ref_norm
|
|
real(rk), intent(out) :: trial_res_norm
|
|
real(rk), intent(out) :: trial_ref_norm
|
|
integer, intent(out) :: ierr
|
|
|
|
du = ZERO
|
|
call newmark_nl_solve_corr(kmat, target_time, a0, a1, residual, &
|
|
rhs_corr, du, max_iter, tol, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
call record_convergence_correction(sqrt(sum(du * du)), res_norm, &
|
|
ref_norm)
|
|
|
|
u_base = u
|
|
call nonlinear_newmark_apply_update(target_time, dt, a0, a1, u_pred, &
|
|
v_pred, u_base, du, res_norm, ref_norm, residual, external, &
|
|
damping_force, kdamp, trial_res_norm, trial_ref_norm, ierr)
|
|
end subroutine apply_newmark_nl_correction
|
|
|
|
subroutine finish_newmark_nl_success(kmat, external, damping_force, &
|
|
converged, stat)
|
|
type(csr_matrix), intent(inout) :: kmat
|
|
real(rk), intent(in) :: external(:)
|
|
real(rk), intent(in) :: damping_force(:)
|
|
logical, intent(out) :: converged
|
|
integer, intent(out) :: stat
|
|
|
|
converged = .true.
|
|
call mark_convergence_success()
|
|
if (allocated(freaction)) then
|
|
freaction = fint + mass_diag * a + damping_force - external
|
|
end if
|
|
call csr_free(kmat, stat)
|
|
end subroutine finish_newmark_nl_success
|
|
|
|
subroutine fail_newmark_nl_nonconverged(ierr)
|
|
integer, intent(out) :: ierr
|
|
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'nonlinear Newmark Newton iteration did not converge', ierr)
|
|
call mark_convergence_failure(CONV_FAIL_NONCONVERGENCE)
|
|
end subroutine fail_newmark_nl_nonconverged
|
|
|
|
subroutine newmark_nl_save_state(u_start, v_start, a_start, vhalf_start)
|
|
real(rk), intent(out) :: u_start(ndof)
|
|
real(rk), intent(out) :: v_start(ndof)
|
|
real(rk), intent(out) :: a_start(ndof)
|
|
real(rk), intent(out) :: vhalf_start(ndof)
|
|
|
|
u_start = u
|
|
v_start = v
|
|
a_start = a
|
|
if (allocated(vhalf)) then
|
|
vhalf_start = vhalf
|
|
else
|
|
vhalf_start = ZERO
|
|
end if
|
|
end subroutine newmark_nl_save_state
|
|
|
|
subroutine newmark_nl_restore_state(u_start, v_start, a_start, vhalf_start)
|
|
real(rk), intent(in) :: u_start(ndof)
|
|
real(rk), intent(in) :: v_start(ndof)
|
|
real(rk), intent(in) :: a_start(ndof)
|
|
real(rk), intent(in) :: vhalf_start(ndof)
|
|
|
|
u = u_start
|
|
v = v_start
|
|
a = a_start
|
|
if (allocated(vhalf)) vhalf = vhalf_start
|
|
end subroutine newmark_nl_restore_state
|
|
|
|
subroutine newmark_nl_start(dt, beta, gamma, u_pred, v_pred, a0, a1, &
|
|
target_time, ierr)
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: beta
|
|
real(rk), intent(in) :: gamma
|
|
real(rk), intent(out) :: u_pred(ndof)
|
|
real(rk), intent(out) :: v_pred(ndof)
|
|
real(rk), intent(out) :: a0
|
|
real(rk), intent(out) :: a1
|
|
real(rk), intent(out) :: target_time
|
|
integer, intent(out) :: ierr
|
|
|
|
a0 = ONE / (beta * dt * dt)
|
|
a1 = gamma / (beta * dt)
|
|
target_time = current_time + dt
|
|
u_pred = u + dt * v + dt * dt * (HALF - beta) * a
|
|
v_pred = v + dt * (ONE - gamma) * a
|
|
u = u_pred
|
|
call boundary_apply_dirichlet(target_time, ierr)
|
|
end subroutine newmark_nl_start
|
|
|
|
subroutine newmark_nl_eval_resid(target_time, dt, a0, gamma, u_pred, &
|
|
v_pred, kmat, external, residual, &
|
|
damping_force, kdamp, res_norm, ref_norm, &
|
|
ierr)
|
|
real(rk), intent(in) :: target_time
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: a0
|
|
real(rk), intent(in) :: gamma
|
|
real(rk), intent(in) :: u_pred(ndof)
|
|
real(rk), intent(in) :: v_pred(ndof)
|
|
type(csr_matrix), intent(inout) :: kmat
|
|
real(rk), intent(inout) :: external(ndof)
|
|
real(rk), intent(inout) :: residual(ndof)
|
|
real(rk), intent(inout) :: damping_force(ndof)
|
|
real(rk), intent(inout) :: kdamp(ndof)
|
|
real(rk), intent(out) :: res_norm
|
|
real(rk), intent(out) :: ref_norm
|
|
integer, intent(out) :: ierr
|
|
integer :: stat
|
|
|
|
a = a0 * (u - u_pred)
|
|
v = v_pred + gamma * dt * a
|
|
if (allocated(vhalf)) vhalf = v - HALF * dt * a
|
|
|
|
call element_compute_internal_force(ierr, dt)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
call assemble_nonlinear_external(target_time, external, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
call csr_free(kmat, stat)
|
|
call assembly_build_csr_pattern(kmat, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
call assemble_linear_stiffness(kmat, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
damping_force = ZERO
|
|
if (rayleigh_alpha_mass .gt. ZERO) then
|
|
damping_force = damping_force + rayleigh_alpha_mass * mass_diag * v
|
|
end if
|
|
if (rayleigh_beta_stiffness .gt. ZERO) then
|
|
call csr_matvec(kmat, v, kdamp, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
damping_force = damping_force + rayleigh_beta_stiffness * kdamp
|
|
end if
|
|
|
|
residual = external - fint - mass_diag * a - damping_force
|
|
call zero_prescribed_residual(residual, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
res_norm = sqrt(sum(residual * residual))
|
|
ref_norm = max(ONE, sqrt(sum(external * external)))
|
|
ierr = FEM_SUCCESS
|
|
end subroutine newmark_nl_eval_resid
|
|
|
|
subroutine newmark_nl_solve_corr(kmat, target_time, a0, a1, residual, &
|
|
rhs_corr, du, max_iter, tol, ierr)
|
|
type(csr_matrix), intent(inout) :: kmat
|
|
real(rk), intent(in) :: target_time
|
|
real(rk), intent(in) :: a0
|
|
real(rk), intent(in) :: a1
|
|
real(rk), intent(in) :: residual(ndof)
|
|
real(rk), intent(inout) :: rhs_corr(ndof)
|
|
real(rk), intent(inout) :: du(ndof)
|
|
integer, intent(in) :: max_iter
|
|
real(rk), intent(in) :: tol
|
|
integer, intent(out) :: ierr
|
|
real(rk) :: mass_scale, stiff_scale, cg_res
|
|
integer :: cg_iter
|
|
integer :: stat
|
|
|
|
stiff_scale = ONE + a1 * rayleigh_beta_stiffness
|
|
mass_scale = a0 + a1 * rayleigh_alpha_mass
|
|
if (abs(stiff_scale - ONE) .gt. tiny(ONE)) kmat%val = stiff_scale * kmat%val
|
|
call add_lumped_mass_diagonal(kmat, mass_scale, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
call apply_nl_external_tangent(kmat, target_time, a1, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
rhs_corr = residual
|
|
call apply_implicit_dirichlet_zero(kmat, rhs_corr, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
call solve_nl_linear_system(kmat, rhs_corr, du, max_iter * 20, tol, &
|
|
cg_iter, cg_res, ierr)
|
|
|
|
900 continue
|
|
call csr_free(kmat, stat)
|
|
end subroutine newmark_nl_solve_corr
|
|
|
|
subroutine nonlinear_newmark_line_search(target_time, dt, a0, a1, &
|
|
u_pred, v_pred, u_base, du, &
|
|
current_res_norm, residual, external, &
|
|
damping_force, kdamp, &
|
|
trial_res_norm, trial_ref_norm, ierr)
|
|
real(rk), intent(in) :: target_time
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: a0
|
|
real(rk), intent(in) :: a1
|
|
real(rk), intent(in) :: u_pred(ndof)
|
|
real(rk), intent(in) :: v_pred(ndof)
|
|
real(rk), intent(in) :: u_base(ndof)
|
|
real(rk), intent(in) :: du(ndof)
|
|
real(rk), intent(in) :: current_res_norm
|
|
real(rk), intent(inout) :: residual(ndof)
|
|
real(rk), intent(inout) :: external(ndof)
|
|
real(rk), intent(inout) :: damping_force(ndof)
|
|
real(rk), intent(inout) :: kdamp(ndof)
|
|
real(rk), intent(out) :: trial_res_norm
|
|
real(rk), intent(out) :: trial_ref_norm
|
|
integer, intent(out) :: ierr
|
|
real(rk) :: alpha
|
|
real(rk) :: next_alpha
|
|
real(rk) :: min_alpha
|
|
real(rk) :: reduction
|
|
real(rk) :: accept_ratio
|
|
|
|
trial_res_norm = current_res_norm
|
|
trial_ref_norm = ONE
|
|
|
|
min_alpha = line_search_min_alpha
|
|
if (min_alpha .le. ZERO .or. min_alpha .gt. ONE) min_alpha = 0.125_rk
|
|
reduction = line_search_reduction
|
|
if (reduction .le. ZERO .or. reduction .ge. ONE) reduction = 0.5_rk
|
|
accept_ratio = line_search_accept_ratio
|
|
if (accept_ratio .le. ZERO) accept_ratio = ONE
|
|
|
|
alpha = ONE
|
|
do
|
|
u = u_base + alpha * du
|
|
call evaluate_newmark_trial_residual(target_time, dt, a0, a1, &
|
|
u_pred, v_pred, residual, external, &
|
|
damping_force, kdamp, &
|
|
trial_res_norm, trial_ref_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
|
|
if (trial_res_norm .le. accept_ratio * current_res_norm .or. &
|
|
alpha .le. min_alpha) exit
|
|
|
|
next_alpha = alpha * reduction
|
|
if (next_alpha .lt. min_alpha) next_alpha = min_alpha
|
|
if (abs(next_alpha - alpha) .le. tiny(ONE)) exit
|
|
alpha = next_alpha
|
|
end do
|
|
|
|
ierr = FEM_SUCCESS
|
|
end subroutine nonlinear_newmark_line_search
|
|
|
|
subroutine nonlinear_newmark_apply_update(target_time, dt, a0, a1, &
|
|
u_pred, v_pred, u_base, du, &
|
|
res_norm, ref_norm, residual, &
|
|
external, damping_force, kdamp, &
|
|
trial_res_norm, trial_ref_norm, &
|
|
ierr)
|
|
real(rk), intent(in) :: target_time
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: a0
|
|
real(rk), intent(in) :: a1
|
|
real(rk), intent(in) :: u_pred(ndof)
|
|
real(rk), intent(in) :: v_pred(ndof)
|
|
real(rk), intent(in) :: u_base(ndof)
|
|
real(rk), intent(in) :: du(ndof)
|
|
real(rk), intent(inout) :: res_norm
|
|
real(rk), intent(inout) :: ref_norm
|
|
real(rk), intent(inout) :: residual(ndof)
|
|
real(rk), intent(inout) :: external(ndof)
|
|
real(rk), intent(inout) :: damping_force(ndof)
|
|
real(rk), intent(inout) :: kdamp(ndof)
|
|
real(rk), intent(out) :: trial_res_norm
|
|
real(rk), intent(out) :: trial_ref_norm
|
|
integer, intent(out) :: ierr
|
|
|
|
if (use_line_search) then
|
|
call nonlinear_newmark_line_search(target_time, dt, a0, a1, &
|
|
u_pred, v_pred, u_base, du, res_norm, residual, external, &
|
|
damping_force, kdamp, trial_res_norm, trial_ref_norm, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
call record_line_search_metrics(res_norm, ref_norm, trial_res_norm, &
|
|
trial_ref_norm)
|
|
else
|
|
u = u + du
|
|
call boundary_apply_dirichlet(target_time, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) return
|
|
end if
|
|
|
|
ierr = FEM_SUCCESS
|
|
end subroutine nonlinear_newmark_apply_update
|
|
|
|
subroutine evaluate_newmark_trial_residual(target_time, dt, a0, a1, &
|
|
u_pred, v_pred, residual, external, &
|
|
damping_force, kdamp, res_norm, &
|
|
ref_norm, ierr)
|
|
real(rk), intent(in) :: target_time
|
|
real(rk), intent(in) :: dt
|
|
real(rk), intent(in) :: a0
|
|
real(rk), intent(in) :: a1
|
|
real(rk), intent(in) :: u_pred(ndof)
|
|
real(rk), intent(in) :: v_pred(ndof)
|
|
real(rk), intent(inout) :: residual(ndof)
|
|
real(rk), intent(inout) :: external(ndof)
|
|
real(rk), intent(inout) :: damping_force(ndof)
|
|
real(rk), intent(inout) :: kdamp(ndof)
|
|
real(rk), intent(out) :: res_norm
|
|
real(rk), intent(out) :: ref_norm
|
|
integer, intent(out) :: ierr
|
|
type(csr_matrix) :: ktmp
|
|
real(rk), allocatable :: kcopy(:)
|
|
integer :: stat
|
|
|
|
res_norm = ZERO
|
|
ref_norm = ONE
|
|
call csr_init(ktmp)
|
|
|
|
call boundary_apply_dirichlet(target_time, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
call element_state_restore_trial(ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
a = a0 * (u - u_pred)
|
|
v = v_pred + a1 / a0 * a
|
|
if (allocated(vhalf)) vhalf = v - HALF * dt * a
|
|
|
|
call element_compute_internal_force(ierr, dt)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
call assemble_nonlinear_external(target_time, external, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
damping_force = ZERO
|
|
if (rayleigh_alpha_mass .gt. ZERO) then
|
|
damping_force = damping_force + rayleigh_alpha_mass * mass_diag * v
|
|
end if
|
|
if (rayleigh_beta_stiffness .gt. ZERO) then
|
|
call assembly_build_csr_pattern(ktmp, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
call assemble_linear_stiffness(ktmp, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
allocate(kcopy(ktmp%nnz), stat=stat)
|
|
if (stat .ne. 0) then
|
|
call error_set(FEM_ERR_SOLVER, &
|
|
'failed to allocate Newmark line-search stiffness copy', ierr)
|
|
go to 900
|
|
end if
|
|
kcopy = ktmp%val
|
|
call csr_saved_matvec(ktmp, kcopy, v, kdamp, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
damping_force = damping_force + rayleigh_beta_stiffness * kdamp
|
|
end if
|
|
|
|
residual = external - fint - mass_diag * a - damping_force
|
|
call zero_prescribed_residual(residual, ierr)
|
|
if (ierr .ne. FEM_SUCCESS) go to 900
|
|
|
|
res_norm = sqrt(sum(residual * residual))
|
|
ref_norm = max(ONE, sqrt(sum(external * external)))
|
|
ierr = FEM_SUCCESS
|
|
|
|
900 continue
|
|
call csr_free(ktmp, stat)
|
|
if (allocated(kcopy)) deallocate(kcopy)
|
|
end subroutine evaluate_newmark_trial_residual
|
|
|
|
end module fem_solver_newmark
|