Release FemLite 0.3.0
FemLite CI / build-test (push) Has been cancelled

This commit is contained in:
shenw
2026-06-23 19:28:44 +08:00
parent f838ccc099
commit be02684827
74 changed files with 11618 additions and 201 deletions
+408
View File
@@ -451,6 +451,77 @@ contains
ierr = FEM_SUCCESS
end subroutine fem_get_node_internal_force
subroutine fem_get_node_reaction(node_id, reaction, ierr)
integer, intent(in) :: node_id
real(rk), intent(out) :: reaction(NDOF_NODE)
integer, intent(out) :: ierr
integer :: node
integer :: idir
integer :: dof
if (.not. api_initialized) then
call error_set(FEM_ERR_INTERNAL, 'fem_get_node_reaction called before fem_initialize', ierr)
return
end if
if (.not. allocated(freaction)) then
call error_set(FEM_ERR_INTERNAL, 'reaction vector is not allocated', ierr)
return
end if
node = database_find_node(node_id)
if (node .eq. 0) then
call error_set(FEM_ERR_INPUT, 'reaction query references unknown node', ierr)
return
end if
reaction = ZERO
do idir = 1, NDOF_NODE
dof = dof_id(idir,node)
if (dof .gt. 0) reaction(idir) = freaction(dof)
end do
ierr = FEM_SUCCESS
end subroutine fem_get_node_reaction
subroutine fem_get_nodal_reactions(nnode_in, node_id, reaction, ierr)
integer, intent(in) :: nnode_in
integer, intent(in) :: node_id(nnode_in)
real(rk), intent(out) :: reaction(NDOF_NODE,nnode_in)
integer, intent(out) :: ierr
integer :: item
integer :: node
integer :: idir
integer :: dof
if (.not. api_initialized) then
call error_set(FEM_ERR_INTERNAL, 'fem_get_nodal_reactions called before fem_initialize', ierr)
return
end if
if (.not. allocated(freaction)) then
call error_set(FEM_ERR_INTERNAL, 'reaction vector is not allocated', ierr)
return
end if
if (nnode_in .lt. 0) then
call error_set(FEM_ERR_INPUT, 'number of reaction query nodes is negative', ierr)
return
end if
reaction = ZERO
do item = 1, nnode_in
node = database_find_node(node_id(item))
if (node .eq. 0) then
call error_set(FEM_ERR_INPUT, 'reaction query references unknown node', ierr)
return
end if
do idir = 1, NDOF_NODE
dof = dof_id(idir,node)
if (dof .gt. 0) reaction(idir,item) = freaction(dof)
end do
end do
ierr = FEM_SUCCESS
end subroutine fem_get_nodal_reactions
subroutine fem_get_element_average_state(nelem_in, elem_id, stress_out, &
strain_out, plastic_strain, eqps, &
damage, ierr)
@@ -568,6 +639,25 @@ contains
call output_csv_set_interval(interval, ierr)
end subroutine fem_set_output_interval
subroutine fem_set_rayleigh_damping(alpha_mass, beta_stiffness, ierr)
real(rk), intent(in) :: alpha_mass
real(rk), intent(in) :: beta_stiffness
integer, intent(out) :: ierr
if (.not. api_initialized) then
call error_set(FEM_ERR_INTERNAL, 'fem_set_rayleigh_damping called before fem_initialize', ierr)
return
end if
if (alpha_mass .lt. ZERO .or. beta_stiffness .lt. ZERO) then
call error_set(FEM_ERR_INPUT, 'Rayleigh damping factors must be non-negative', ierr)
return
end if
rayleigh_alpha_mass = alpha_mass
rayleigh_beta_stiffness = beta_stiffness
ierr = FEM_SUCCESS
end subroutine fem_set_rayleigh_damping
subroutine fem_write_output(step, time, ierr)
integer, intent(in) :: step
real(rk), intent(in) :: time
@@ -913,6 +1003,324 @@ contains
call log_info('implicit linear solve completed')
end subroutine fem_solve_implicit_linear
subroutine fem_solve_static_linear(max_iter, tol, iter, res_norm, ierr)
integer, intent(in) :: max_iter
real(rk), intent(in) :: tol
integer, intent(out) :: iter
real(rk), intent(out) :: res_norm
integer, intent(out) :: ierr
real(rk) :: solve_time
if (.not. api_initialized) then
call error_set(FEM_ERR_INTERNAL, 'fem_solve_static_linear called before fem_initialize', ierr)
return
end if
analysis_type = ANALYSIS_STATIC_LINEAR
solve_time = current_time
if (time_end .gt. ZERO) solve_time = time_end
call implicit_solve_linear_static(solve_time, max_iter, tol, iter, res_norm, ierr)
if (ierr .ne. FEM_SUCCESS) return
call element_compute_internal_force(ierr, ZERO)
if (ierr .ne. FEM_SUCCESS) return
current_step = current_step + 1
current_time = solve_time
call log_info('static linear solve completed')
end subroutine fem_solve_static_linear
subroutine fem_solve_static_nonlinear(max_increment_in, max_iter, tol, &
iter, res_norm, ierr)
integer, intent(in) :: max_increment_in
integer, intent(in) :: max_iter
real(rk), intent(in) :: tol
integer, intent(out) :: iter
real(rk), intent(out) :: res_norm
integer, intent(out) :: ierr
real(rk) :: solve_time
if (.not. api_initialized) then
call error_set(FEM_ERR_INTERNAL, 'fem_solve_static_nonlinear called before fem_initialize', ierr)
return
end if
analysis_type = ANALYSIS_STATIC_NONLINEAR
solve_time = current_time
if (time_end .gt. ZERO) solve_time = time_end
call implicit_solve_nonlinear_static(solve_time, max_increment_in, &
max_iter, tol, iter, res_norm, ierr)
if (ierr .ne. FEM_SUCCESS) return
call log_info('static nonlinear solve completed')
end subroutine fem_solve_static_nonlinear
subroutine fem_advance_implicit_newmark(dt, max_iter, tol, iter, res_norm, ierr)
real(rk), intent(in) :: dt
integer, intent(in) :: max_iter
real(rk), intent(in) :: tol
integer, intent(out) :: iter
real(rk), intent(out) :: res_norm
integer, intent(out) :: ierr
if (.not. api_initialized) then
call error_set(FEM_ERR_INTERNAL, 'fem_advance_implicit_newmark called before fem_initialize', 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 (.not. allocated(mass_diag)) then
call error_set(FEM_ERR_INTERNAL, 'mass vector is not allocated', ierr)
return
end if
if (maxval(abs(mass_diag)) .le. tiny(ONE)) then
call element_compute_lumped_mass(ierr)
if (ierr .ne. FEM_SUCCESS) return
end if
analysis_type = ANALYSIS_IMPLICIT_DYNAMIC
call implicit_advance_newmark_linear(dt, newmark_beta, newmark_gamma, &
max_iter, tol, iter, res_norm, ierr)
if (ierr .ne. FEM_SUCCESS) return
current_step = current_step + 1
current_time = current_time + dt
call log_info('implicit Newmark step completed')
end subroutine fem_advance_implicit_newmark
subroutine fem_advance_newmark_nonlinear(dt, max_iter, tol, iter, &
res_norm, ierr)
real(rk), intent(in) :: dt
integer, intent(in) :: max_iter
real(rk), intent(in) :: tol
integer, intent(out) :: iter
real(rk), intent(out) :: res_norm
integer, intent(out) :: ierr
if (.not. api_initialized) then
call error_set(FEM_ERR_INTERNAL, &
'fem_advance_newmark_nonlinear called before fem_initialize', ierr)
return
end if
if (dt .le. ZERO) then
call error_set(FEM_ERR_SOLVER, 'nonlinear Newmark time step must be positive', ierr)
return
end if
if (.not. allocated(mass_diag)) then
call error_set(FEM_ERR_INTERNAL, 'mass vector is not allocated', ierr)
return
end if
if (maxval(abs(mass_diag)) .le. tiny(ONE)) then
call element_compute_lumped_mass(ierr)
if (ierr .ne. FEM_SUCCESS) return
end if
analysis_type = ANALYSIS_IMPLICIT_DYNAMIC
call implicit_newmark_nonlinear_step(dt, newmark_beta, newmark_gamma, &
max_iter, tol, iter, res_norm, ierr)
if (ierr .ne. FEM_SUCCESS) return
current_step = current_step + 1
current_time = current_time + dt
call log_info('nonlinear Newmark step completed')
end subroutine fem_advance_newmark_nonlinear
subroutine fem_run_implicit_newmark(max_iter, tol, iter_total, res_norm, ierr)
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
real(rk) :: dt
real(rk) :: dt_step
real(rk) :: remaining
real(rk) :: time_tol
integer :: iter
integer :: run_steps
integer :: step_limit
iter_total = 0
res_norm = ZERO
if (.not. api_initialized) then
call error_set(FEM_ERR_INTERNAL, 'fem_run_implicit_newmark called before fem_initialize', ierr)
return
end if
if (time_end .le. current_time) then
call error_set(FEM_ERR_SOLVER, 'implicit Newmark run requires a positive end time', ierr)
return
end if
call fem_compute_lumped_mass(ierr)
if (ierr .ne. FEM_SUCCESS) return
if (use_user_dt) then
dt = dt_user
else
call fem_estimate_stable_dt(dt, ierr)
if (ierr .ne. FEM_SUCCESS) return
end if
if (dt .le. ZERO) then
call error_set(FEM_ERR_SOLVER, 'implicit Newmark run requires a positive time step', ierr)
return
end if
call boundary_apply_dirichlet(current_time, ierr)
if (ierr .ne. FEM_SUCCESS) return
if (output_interval .gt. 0) then
call fem_write_output(current_step, current_time, ierr)
if (ierr .ne. FEM_SUCCESS) return
end if
if (nstep_max .gt. 0) then
step_limit = nstep_max
else
step_limit = huge(1)
end if
run_steps = 0
time_tol = max(1.0e-12_rk * max(ONE, abs(time_end)), 1.0e-30_rk)
do
remaining = time_end - current_time
if (remaining .le. time_tol) exit
if (run_steps .ge. step_limit) exit
dt_step = min(dt, remaining)
call fem_advance_implicit_newmark(dt_step, max_iter, tol, iter, res_norm, ierr)
if (ierr .ne. FEM_SUCCESS) return
iter_total = iter_total + iter
run_steps = run_steps + 1
if (output_interval .gt. 0) then
if (mod(current_step, output_interval) .eq. 0 .or. &
time_end - current_time .le. time_tol) then
call fem_write_output(current_step, current_time, ierr)
if (ierr .ne. FEM_SUCCESS) return
end if
end if
end do
if (time_end - current_time .gt. time_tol) then
call error_set(FEM_ERR_SOLVER, 'implicit Newmark run stopped before end time', ierr)
return
end if
ierr = FEM_SUCCESS
end subroutine fem_run_implicit_newmark
subroutine fem_run_newmark_nonlinear(max_iter, tol, iter_total, res_norm, ierr)
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
real(rk) :: dt
real(rk) :: dt_step
real(rk) :: dt_min_eff
real(rk) :: remaining
real(rk) :: time_tol
integer :: iter
integer :: run_steps
integer :: step_limit
integer :: cut_count
iter_total = 0
res_norm = ZERO
if (.not. api_initialized) then
call error_set(FEM_ERR_INTERNAL, &
'fem_run_newmark_nonlinear called before fem_initialize', ierr)
return
end if
if (time_end .le. current_time) then
call error_set(FEM_ERR_SOLVER, &
'nonlinear Newmark run requires a positive end time', ierr)
return
end if
call fem_compute_lumped_mass(ierr)
if (ierr .ne. FEM_SUCCESS) return
if (use_user_dt) then
dt = dt_user
else
call fem_estimate_stable_dt(dt, ierr)
if (ierr .ne. FEM_SUCCESS) return
end if
if (dt .le. ZERO) then
call error_set(FEM_ERR_SOLVER, &
'nonlinear Newmark run requires a positive time step', ierr)
return
end if
call boundary_apply_dirichlet(current_time, ierr)
if (ierr .ne. FEM_SUCCESS) return
if (output_interval .gt. 0) then
call fem_write_output(current_step, current_time, ierr)
if (ierr .ne. FEM_SUCCESS) return
end if
if (nstep_max .gt. 0) then
step_limit = nstep_max
else
step_limit = huge(1)
end if
run_steps = 0
time_tol = max(1.0e-12_rk * max(ONE, abs(time_end)), 1.0e-30_rk)
if (static_min_increment .gt. ZERO) then
dt_min_eff = static_min_increment
else
dt_min_eff = dt * 1.0e-8_rk
end if
dt_min_eff = max(dt_min_eff, time_tol)
do
remaining = time_end - current_time
if (remaining .le. time_tol) exit
if (run_steps .ge. step_limit) exit
dt_step = min(dt, remaining)
cut_count = 0
do
call fem_advance_newmark_nonlinear(dt_step, max_iter, tol, iter, &
res_norm, ierr)
if (ierr .eq. FEM_SUCCESS) exit
if (allow_step_cutback .and. cut_count .lt. max_cutback .and. &
dt_step * cutback_factor .ge. dt_min_eff) then
dt_step = dt_step * cutback_factor
cut_count = cut_count + 1
ierr = FEM_SUCCESS
else
return
end if
end do
iter_total = iter_total + iter
run_steps = run_steps + 1
if (output_interval .gt. 0) then
if (mod(current_step, output_interval) .eq. 0 .or. &
time_end - current_time .le. time_tol) then
call fem_write_output(current_step, current_time, ierr)
if (ierr .ne. FEM_SUCCESS) return
end if
end if
end do
if (time_end - current_time .gt. time_tol) then
call error_set(FEM_ERR_SOLVER, &
'nonlinear Newmark run stopped before end time', ierr)
return
end if
ierr = FEM_SUCCESS
end subroutine fem_run_newmark_nonlinear
subroutine fem_get_current_time(time, step, ierr)
real(rk), intent(out) :: time
integer, intent(out) :: step
+45
View File
@@ -2,18 +2,43 @@ module fem_control
use fem_precision
implicit none
integer, parameter :: ANALYSIS_EXPLICIT_DYNAMIC = 1
integer, parameter :: ANALYSIS_STATIC_LINEAR = 2
integer, parameter :: ANALYSIS_STATIC_NONLINEAR = 3
integer, parameter :: ANALYSIS_IMPLICIT_DYNAMIC = 4
real(rk) :: time_start = ZERO
real(rk) :: time_end = ZERO
real(rk) :: current_time = ZERO
real(rk) :: dt_user = ZERO
real(rk) :: dt_stable = ZERO
real(rk) :: stable_dt_safety = 0.8_rk
real(rk) :: static_initial_increment = ONE
real(rk) :: static_min_increment = ZERO
real(rk) :: static_max_increment = ONE
real(rk) :: load_factor = ONE
real(rk) :: newton_tol_force = 1.0e-8_rk
real(rk) :: newton_tol_disp = 1.0e-8_rk
real(rk) :: newmark_beta = 0.25_rk
real(rk) :: newmark_gamma = 0.5_rk
real(rk) :: rayleigh_alpha_mass = ZERO
real(rk) :: rayleigh_beta_stiffness = ZERO
real(rk) :: line_search_min_alpha = 0.125_rk
real(rk) :: line_search_reduction = 0.5_rk
real(rk) :: line_search_accept_ratio = 0.95_rk
real(rk) :: cutback_factor = 0.5_rk
integer :: current_step = 0
integer :: nstep_max = 0
integer :: analysis_type = ANALYSIS_EXPLICIT_DYNAMIC
integer :: max_increment = 0
integer :: max_newton_iter = 25
integer :: max_cutback = 8
integer :: output_interval = 1
logical :: use_sph_coupling = .false.
logical :: use_user_dt = .false.
logical :: large_deformation = .true.
logical :: use_line_search = .true.
logical :: allow_step_cutback = .false.
contains
@@ -24,12 +49,32 @@ contains
dt_user = ZERO
dt_stable = ZERO
stable_dt_safety = 0.8_rk
static_initial_increment = ONE
static_min_increment = ZERO
static_max_increment = ONE
load_factor = ONE
newton_tol_force = 1.0e-8_rk
newton_tol_disp = 1.0e-8_rk
newmark_beta = 0.25_rk
newmark_gamma = 0.5_rk
rayleigh_alpha_mass = ZERO
rayleigh_beta_stiffness = ZERO
line_search_min_alpha = 0.125_rk
line_search_reduction = 0.5_rk
line_search_accept_ratio = 0.95_rk
cutback_factor = 0.5_rk
current_step = 0
nstep_max = 0
analysis_type = ANALYSIS_EXPLICIT_DYNAMIC
max_increment = 0
max_newton_iter = 25
max_cutback = 8
output_interval = 1
use_sph_coupling = .false.
use_user_dt = .false.
large_deformation = .true.
use_line_search = .true.
allow_step_cutback = .false.
end subroutine control_set_defaults
end module fem_control
+1 -1
View File
@@ -15,7 +15,7 @@ module fem_precision
integer, parameter :: NSTATEV_MAX = 32
integer, parameter :: FEMLITE_VERSION_MAJOR = 0
integer, parameter :: FEMLITE_VERSION_MINOR = 2
integer, parameter :: FEMLITE_VERSION_MINOR = 3
integer, parameter :: FEMLITE_VERSION_PATCH = 0
real(rk), parameter :: ZERO = 0.0_rk