program roll_springback_bench use fem_precision use fem_error use fem_database, only: database_allocate_model, database_finalize use fem_database_state, only: mat_name, mat_plastic_model, mat_density, & mat_e, mat_nu, mat_yield0, mat_hardening_modulus, mat_plastic_start, & mat_plastic_count, mat_plastic_stress, mat_plastic_strain use fem_material_j2, only: material_update_small_strain_dt use fem_rigid_roller use fem_roller_schedule use fem_roll_metrics implicit none type spring_cfg real(rk) :: thickness = 0.004_rk real(rk) :: half_width = 0.030_rk integer :: strips = 9 integer :: layers = 9 real(rk) :: length = 0.20_rk real(rk) :: radius = 0.05_rk real(rk) :: feed_total = 0.20_rk real(rk) :: down_total = -0.002_rk real(rk) :: angular_speed = 4.0_rk real(rk) :: normal_force = 20000.0_rk real(rk) :: mu = 0.30_rk real(rk) :: reference_speed = 0.20_rk real(rk) :: duration = ONE real(rk) :: elastic_modulus = 210000.0_rk real(rk) :: poisson = 0.30_rk real(rk) :: yield_stress = 250.0_rk real(rk) :: hardening = 10000.0_rk real(rk) :: target_curvature = 3.0_rk integer :: samples = 8 end type spring_cfg type(spring_cfg) :: cfg character(len=512) :: input_file character(len=512) :: out_dir real(rk), allocatable :: x(:) real(rk), allocatable :: z(:) real(rk), allocatable :: strip_weight(:) real(rk), allocatable :: stress(:,:,:) real(rk), allocatable :: state(:,:,:) real(rk), allocatable :: formed_stress(:,:,:) real(rk), allocatable :: formed_state(:,:,:) real(rk), allocatable :: trial_stress(:,:,:) real(rk), allocatable :: trial_state(:,:,:) real(rk) :: plastic_work real(rk) :: unload_plastic_work real(rk) :: friction_energy real(rk) :: mean_pressure real(rk) :: mean_slip real(rk) :: forming_force real(rk) :: roller_torque real(rk) :: peak_moment real(rk) :: residual_moment real(rk) :: release_curv real(rk) :: residual_curv real(rk) :: formed_disp real(rk) :: residual_disp real(rk) :: springback_disp real(rk) :: springback_ratio real(rk) :: max_eqps real(rk) :: zone_fraction integer :: active_points integer :: argc integer :: ierr integer :: stat intrinsic iargc intrinsic getarg argc = iargc() if (argc .lt. 2) then write(*,'(A)') 'Usage: roll_forming_springback_benchmark INPUT.inp OUTPUT_DIR' stop 2 end if call getarg(1, input_file) call getarg(2, out_dir) call read_spring_input(trim(input_file), cfg, ierr) call exit_if_error(ierr) call setup_material(cfg, ierr) call exit_if_error(ierr) allocate(x(cfg%strips), z(cfg%layers), strip_weight(cfg%strips), & stress(NSTRESS,cfg%layers,cfg%strips), & state(NSTATEV_MAX,cfg%layers,cfg%strips), & formed_stress(NSTRESS,cfg%layers,cfg%strips), & formed_state(NSTATEV_MAX,cfg%layers,cfg%strips), & trial_stress(NSTRESS,cfg%layers,cfg%strips), & trial_state(NSTATEV_MAX,cfg%layers,cfg%strips), stat=stat) if (stat .ne. 0) then call error_set(FEM_ERR_INTERNAL, 'failed to allocate springback work arrays', & ierr) call exit_if_error(ierr) end if stress = ZERO state = ZERO formed_stress = ZERO formed_state = ZERO trial_stress = ZERO trial_state = ZERO call init_grid(cfg, x, z, strip_weight) call run_forming(cfg, z, strip_weight, stress, state, formed_stress, & formed_state, plastic_work, friction_energy, mean_pressure, & mean_slip, forming_force, roller_torque, peak_moment, & join_path(out_dir, 'springback_history.csv'), ierr) call exit_if_error(ierr) call solve_release(cfg, z, strip_weight, formed_stress, formed_state, & trial_stress, trial_state, release_curv, residual_moment, & unload_plastic_work, ierr) call exit_if_error(ierr) stress = trial_stress state = trial_state residual_curv = cfg%target_curvature - release_curv call roll_metrics_residual_disp(cfg%target_curvature, cfg%length, & formed_disp, ierr) call exit_if_error(ierr) call roll_metrics_residual_disp(residual_curv, cfg%length, residual_disp, & ierr) call exit_if_error(ierr) call roll_metrics_springback(formed_disp, residual_disp, springback_disp, & springback_ratio, ierr) call exit_if_error(ierr) call plastic_zone_stats(cfg, state, active_points, zone_fraction, max_eqps) call write_summary(join_path(out_dir, 'springback_summary.csv'), cfg, & plastic_work, unload_plastic_work, friction_energy, & mean_pressure, mean_slip, forming_force, roller_torque, & peak_moment, residual_moment, release_curv, residual_curv, & formed_disp, residual_disp, springback_disp, & springback_ratio, active_points, zone_fraction, max_eqps, & ierr) call exit_if_error(ierr) call write_zone(join_path(out_dir, 'plastic_zone.csv'), cfg, x, z, & strip_weight, state, stress, residual_curv, ierr) call exit_if_error(ierr) write(*,'(A,ES12.5,A,ES12.5,A,ES12.5)') & 'springback ratio=', springback_ratio, ' residual_disp=', residual_disp, & ' plastic_work=', plastic_work call database_finalize(ierr) call exit_if_error(ierr) contains subroutine read_spring_input(filename, cfg, ierr) character(len=*), intent(in) :: filename type(spring_cfg), intent(out) :: cfg integer, intent(out) :: ierr character(len=512) :: line character(len=512) :: upper integer :: unit integer :: ios logical :: want_data call set_defaults(cfg) want_data = .false. unit = 91 open(unit=unit, file=trim(filename), status='old', action='read', iostat=ios) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to open roll springback input', ierr) return end if do read(unit,'(A)',iostat=ios) line if (ios .lt. 0) exit if (ios .gt. 0) then close(unit) call error_set(FEM_ERR_INPUT, 'failed to read roll springback input', ierr) return end if if (is_blank_or_comment(line)) cycle call uppercase(line, upper) if (upper(1:1) .eq. '*') then want_data = index(upper, '*ROLL FORMING SPRINGBACK') .eq. 1 else if (want_data) then read(line,*,iostat=ios) cfg%thickness, cfg%half_width, & cfg%strips, cfg%layers, cfg%length, cfg%radius, cfg%feed_total, & cfg%down_total, cfg%angular_speed, cfg%normal_force, cfg%mu, & cfg%reference_speed, cfg%duration, cfg%elastic_modulus, & cfg%poisson, cfg%yield_stress, cfg%hardening, & cfg%target_curvature, cfg%samples close(unit) if (ios .ne. 0) then call error_set(FEM_ERR_INPUT, 'failed to parse roll springback data', & ierr) return end if call validate_cfg(cfg, ierr) return end if end do close(unit) call validate_cfg(cfg, ierr) end subroutine read_spring_input subroutine set_defaults(cfg) type(spring_cfg), intent(out) :: cfg cfg%thickness = 0.004_rk cfg%half_width = 0.030_rk cfg%strips = 9 cfg%layers = 9 cfg%length = 0.20_rk cfg%radius = 0.05_rk cfg%feed_total = 0.20_rk cfg%down_total = -0.002_rk cfg%angular_speed = 4.0_rk cfg%normal_force = 20000.0_rk cfg%mu = 0.30_rk cfg%reference_speed = 0.20_rk cfg%duration = ONE cfg%elastic_modulus = 210000.0_rk cfg%poisson = 0.30_rk cfg%yield_stress = 250.0_rk cfg%hardening = 10000.0_rk cfg%target_curvature = 3.0_rk cfg%samples = 8 end subroutine set_defaults subroutine validate_cfg(cfg, ierr) type(spring_cfg), intent(in) :: cfg integer, intent(out) :: ierr if (cfg%thickness .le. ZERO .or. cfg%half_width .le. ZERO .or. & cfg%strips .lt. 3 .or. cfg%layers .lt. 3 .or. & cfg%length .le. ZERO .or. cfg%radius .le. ZERO .or. & cfg%normal_force .le. ZERO .or. cfg%mu .lt. ZERO .or. & cfg%reference_speed .lt. ZERO .or. cfg%duration .le. ZERO .or. & cfg%elastic_modulus .le. ZERO .or. cfg%poisson .lt. ZERO .or. & cfg%poisson .ge. 0.5_rk .or. cfg%yield_stress .le. ZERO .or. & cfg%hardening .lt. ZERO .or. cfg%target_curvature .le. ZERO .or. & cfg%samples .lt. 3) then call error_set(FEM_ERR_INPUT, 'invalid roll springback benchmark data', ierr) return end if call error_clear(ierr) end subroutine validate_cfg subroutine setup_material(cfg, ierr) type(spring_cfg), intent(in) :: cfg integer, intent(out) :: ierr call database_allocate_model(1, 1, 0, 0, 0, 0, 1, 2, 0, & 0, 0, 0, 0, 0, ierr) if (ierr .ne. FEM_SUCCESS) return mat_name(1) = 'ROLL_J2' mat_plastic_model(1) = 'J2' mat_density(1) = 7850.0_rk mat_e(1) = cfg%elastic_modulus mat_nu(1) = cfg%poisson mat_yield0(1) = cfg%yield_stress mat_hardening_modulus(1) = cfg%hardening mat_plastic_start(1) = 1 mat_plastic_count(1) = 2 mat_plastic_stress(1) = cfg%yield_stress mat_plastic_strain(1) = ZERO mat_plastic_stress(2) = cfg%yield_stress + cfg%hardening * 0.05_rk mat_plastic_strain(2) = 0.05_rk call error_clear(ierr) end subroutine setup_material subroutine init_grid(cfg, x, z, strip_weight) type(spring_cfg), intent(in) :: cfg real(rk), intent(out) :: x(cfg%strips) real(rk), intent(out) :: z(cfg%layers) real(rk), intent(out) :: strip_weight(cfg%strips) integer :: i real(rk) :: dx real(rk) :: dz real(rk) :: scale dx = 2.0_rk * cfg%half_width / real(cfg%strips, rk) dz = cfg%thickness / real(cfg%layers, rk) scale = max(0.25_rk * cfg%half_width, 0.55_rk * cfg%half_width) do i = 1, cfg%strips x(i) = -cfg%half_width + (real(i, rk) - HALF) * dx strip_weight(i) = 0.30_rk + 0.70_rk * exp(-(x(i) / scale) ** 2) end do do i = 1, cfg%layers z(i) = -HALF * cfg%thickness + (real(i, rk) - HALF) * dz end do end subroutine init_grid subroutine run_forming(cfg, z, strip_weight, stress, state, & formed_stress, formed_state, plastic_work, & friction_energy, mean_pressure, mean_slip, & forming_force, roller_torque, peak_moment, & history_path, ierr) type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: z(cfg%layers) real(rk), intent(in) :: strip_weight(cfg%strips) real(rk), intent(inout) :: stress(:,:,:) real(rk), intent(inout) :: state(:,:,:) real(rk), intent(out) :: formed_stress(:,:,:) real(rk), intent(out) :: formed_state(:,:,:) real(rk), intent(out) :: plastic_work real(rk), intent(out) :: friction_energy real(rk), intent(out) :: mean_pressure real(rk), intent(out) :: mean_slip real(rk), intent(out) :: forming_force real(rk), intent(out) :: roller_torque real(rk), intent(out) :: peak_moment character(len=*), intent(in) :: history_path integer, intent(out) :: ierr type(roller_step_state) :: step type(roll_metrics_state) :: metrics real(rk), allocatable :: prev_kappa(:) integer :: i, j, k, unit, ios, stat real(rk) :: dt, time, frac, kappa, local_kappa, dkappa real(rk) :: deps_axial, point_work, sample_energy, sample_slip real(rk) :: sample_force, sample_torque, moment, mean_eqps real(rk) :: contact_width, max_penetration, normal_sum real(rk) :: friction_power integer :: active_count allocate(prev_kappa(cfg%strips), stat=stat) if (stat .ne. 0) then call error_set(FEM_ERR_INTERNAL, 'failed to allocate curvature history', ierr) return end if prev_kappa = ZERO plastic_work = ZERO friction_energy = ZERO mean_pressure = ZERO mean_slip = ZERO forming_force = ZERO roller_torque = ZERO peak_moment = ZERO dt = cfg%duration / real(cfg%samples - 1, rk) call roller_step_init(ZERO, cfg%duration, ZERO, cfg%feed_total, ZERO, & cfg%down_total, cfg%angular_speed, & cfg%angular_speed, cfg%normal_force, & cfg%normal_force, step, ierr) if (ierr .ne. FEM_SUCCESS) return call roll_metrics_reset(metrics) unit = 92 open(unit=unit, file=trim(history_path), status='replace', action='write', & iostat=ios) if (ios .ne. 0) then call error_set(FEM_ERR_OUTPUT, 'failed to open springback history', ierr) return end if write(unit,'(A)') 'sample,phase,time,curvature,tangent_force,' // & 'friction_energy,plastic_work,moment,mean_eqps,active_points' do i = 1, cfg%samples time = dt * real(i - 1, rk) frac = time / cfg%duration kappa = cfg%target_curvature * frac call sample_contact(cfg, step, time, dt, metrics, sample_energy, & sample_slip, sample_force, sample_torque, ierr) if (ierr .ne. FEM_SUCCESS) then close(unit) return end if friction_energy = friction_energy + sample_energy roller_torque = roller_torque + sample_torque do k = 1, cfg%strips local_kappa = kappa * strip_weight(k) dkappa = local_kappa - prev_kappa(k) prev_kappa(k) = local_kappa do j = 1, cfg%layers deps_axial = z(j) * dkappa call update_plane_stress(cfg, deps_axial, dt, stress(:,j,k), & state(:,j,k), stress(:,j,k), & state(:,j,k), ierr) if (ierr .ne. FEM_SUCCESS) then close(unit) return end if point_work = max(ZERO, state(21,j,k) * state(22,j,k)) * point_volume(cfg) plastic_work = plastic_work + point_work end do end do call section_moment(cfg, z, stress, moment) call mean_eqps_value(cfg, state, mean_eqps) call active_point_count(cfg, state, active_count) peak_moment = max(peak_moment, abs(moment)) write(unit,'(I0,A,ES16.8,A,6(ES16.8,A),I0)') i, ',forming,', time, & ',', kappa, ',', sample_force, ',', friction_energy, ',', & plastic_work, ',', moment, ',', mean_eqps, ',', active_count end do close(unit) formed_stress = stress formed_state = state call roll_metrics_summary(metrics, active_count, contact_width, & max_penetration, normal_sum, friction_power, & mean_slip, mean_pressure, ierr) if (ierr .ne. FEM_SUCCESS) return if (active_count .gt. 0) then forming_force = normal_sum / real(active_count, rk) roller_torque = roller_torque / real(active_count, rk) end if deallocate(prev_kappa) call error_clear(ierr) end subroutine run_forming subroutine sample_contact(cfg, step, time, dt, metrics, energy, slip, & force_mag, torque, ierr) type(spring_cfg), intent(in) :: cfg type(roller_step_state), intent(in) :: step real(rk), intent(in) :: time real(rk), intent(in) :: dt type(roll_metrics_state), intent(inout) :: metrics real(rk), intent(out) :: energy real(rk), intent(out) :: slip real(rk), intent(out) :: force_mag real(rk), intent(out) :: torque integer, intent(out) :: ierr real(rk) :: center0(3), center(3), axis(3), feed_dir(3), down_dir(3) real(rk) :: axis_unit(3), velocity(3), point(3), body_velocity(3) real(rk) :: normal(3), roll_dir(3), axial_dir(3) real(rk) :: rel_velocity(3), tangent_velocity(3), friction_force(3) real(rk) :: feed, down, spin, pressure, gap, penetration, normal_speed real(rk) :: power energy = ZERO slip = ZERO force_mag = ZERO torque = ZERO center0 = ZERO axis = (/ ZERO, ZERO, ONE /) body_velocity = ZERO call roller_build_feed_frame(axis, (/ ZERO, ONE, ZERO /), axis_unit, & feed_dir, down_dir, ierr) if (ierr .ne. FEM_SUCCESS) return call roller_step_eval(step, time, feed, down, spin, pressure, ierr) if (ierr .ne. FEM_SUCCESS) return call roller_pose_linear(center0, feed_dir, down_dir, feed, down, center, ierr) if (ierr .ne. FEM_SUCCESS) return call roller_step_velocity(feed_dir, down_dir, cfg%feed_total / cfg%duration, & cfg%down_total / cfg%duration, velocity, ierr) if (ierr .ne. FEM_SUCCESS) return point = center + cfg%radius * (/ ONE, ZERO, ZERO /) call roller_contact_kin(point, body_velocity, center, axis, cfg%radius, & velocity, spin, gap, penetration, normal, roll_dir, & axial_dir, rel_velocity, normal_speed, slip, ierr) if (ierr .ne. FEM_SUCCESS) return tangent_velocity = rel_velocity - normal_speed * normal call roller_regularized_traction(pressure, cfg%mu, tangent_velocity, & cfg%reference_speed, friction_force, ierr) if (ierr .ne. FEM_SUCCESS) return force_mag = norm3(friction_force) torque = cfg%radius * force_mag call roller_friction_work_rate(tangent_velocity, friction_force, power, ierr) if (ierr .ne. FEM_SUCCESS) return energy = max(ZERO, -power * dt) call roll_metrics_add_sample(metrics, .true., penetration, ZERO, pressure, & slip, force_mag, cfg%radius * cfg%thickness, & ierr) end subroutine sample_contact subroutine solve_release(cfg, z, strip_weight, formed_stress, formed_state, & trial_stress, trial_state, release_curv, & residual_moment, unload_work, ierr) type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: z(cfg%layers) real(rk), intent(in) :: strip_weight(cfg%strips) real(rk), intent(in) :: formed_stress(:,:,:) real(rk), intent(in) :: formed_state(:,:,:) real(rk), intent(out) :: trial_stress(:,:,:) real(rk), intent(out) :: trial_state(:,:,:) real(rk), intent(out) :: release_curv real(rk), intent(out) :: residual_moment real(rk), intent(out) :: unload_work integer, intent(out) :: ierr real(rk) :: low, high, mid real(rk) :: moment_low, moment_high, moment_mid real(rk) :: work_mid integer :: iter low = ZERO high = cfg%target_curvature call eval_unload(cfg, z, strip_weight, formed_stress, formed_state, low, & trial_stress, trial_state, moment_low, unload_work, ierr) if (ierr .ne. FEM_SUCCESS) return call eval_unload(cfg, z, strip_weight, formed_stress, formed_state, high, & trial_stress, trial_state, moment_high, work_mid, ierr) if (ierr .ne. FEM_SUCCESS) return do while (same_sign(moment_low, moment_high) .and. & high .lt. 2.5_rk * cfg%target_curvature) high = 1.25_rk * high call eval_unload(cfg, z, strip_weight, formed_stress, formed_state, high, & trial_stress, trial_state, moment_high, work_mid, ierr) if (ierr .ne. FEM_SUCCESS) return end do if (same_sign(moment_low, moment_high)) then call error_set(FEM_ERR_SOLVER, 'failed to bracket springback release', ierr) return end if do iter = 1, 50 mid = HALF * (low + high) call eval_unload(cfg, z, strip_weight, formed_stress, formed_state, mid, & trial_stress, trial_state, moment_mid, work_mid, ierr) if (ierr .ne. FEM_SUCCESS) return if (abs(moment_mid) .le. 1.0e-10_rk * max(ONE, abs(moment_low))) exit if (same_sign(moment_low, moment_mid)) then low = mid moment_low = moment_mid else high = mid moment_high = moment_mid end if end do release_curv = HALF * (low + high) call eval_unload(cfg, z, strip_weight, formed_stress, formed_state, & release_curv, trial_stress, trial_state, residual_moment, & unload_work, ierr) end subroutine solve_release subroutine eval_unload(cfg, z, strip_weight, formed_stress, formed_state, & release_curv, trial_stress, trial_state, moment, & unload_work, ierr) type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: z(cfg%layers) real(rk), intent(in) :: strip_weight(cfg%strips) real(rk), intent(in) :: formed_stress(:,:,:) real(rk), intent(in) :: formed_state(:,:,:) real(rk), intent(out) :: trial_stress(:,:,:) real(rk), intent(out) :: trial_state(:,:,:) real(rk), intent(in) :: release_curv real(rk), intent(out) :: moment real(rk), intent(out) :: unload_work integer, intent(out) :: ierr integer :: j, k real(rk) :: deps_axial real(rk) :: dt dt = cfg%duration / real(cfg%samples - 1, rk) unload_work = ZERO do k = 1, cfg%strips do j = 1, cfg%layers deps_axial = -z(j) * release_curv * strip_weight(k) call update_plane_stress(cfg, deps_axial, dt, formed_stress(:,j,k), & formed_state(:,j,k), trial_stress(:,j,k), & trial_state(:,j,k), ierr) if (ierr .ne. FEM_SUCCESS) return unload_work = unload_work + & max(ZERO, trial_state(21,j,k) * trial_state(22,j,k)) * point_volume(cfg) end do end do call section_moment(cfg, z, trial_stress, moment) call error_clear(ierr) end subroutine eval_unload subroutine update_plane_stress(cfg, axial_deps, dt, stress_in, state_in, & stress_out, state_out, ierr) type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: axial_deps real(rk), intent(in) :: dt real(rk), intent(in) :: stress_in(NSTRESS) real(rk), intent(in) :: state_in(NSTATEV_MAX) real(rk), intent(out) :: stress_out(NSTRESS) real(rk), intent(out) :: state_out(NSTATEV_MAX) integer, intent(out) :: ierr real(rk) :: lateral real(rk) :: residual real(rk) :: residual_pert real(rk) :: tangent real(rk) :: perturb real(rk) :: stress_trial(NSTRESS) real(rk) :: stress_pert(NSTRESS) real(rk) :: state_trial(NSTATEV_MAX) real(rk) :: state_pert(NSTATEV_MAX) integer :: iter lateral = -cfg%poisson * axial_deps perturb = max(1.0e-9_rk, abs(axial_deps) * 1.0e-5_rk) do iter = 1, 24 call update_with_lateral(axial_deps, lateral, dt, stress_in, state_in, & stress_trial, state_trial, ierr) if (ierr .ne. FEM_SUCCESS) return residual = HALF * (stress_trial(2) + stress_trial(3)) if (abs(residual) .le. 1.0e-9_rk * cfg%elastic_modulus) exit call update_with_lateral(axial_deps, lateral + perturb, dt, stress_in, & state_in, stress_pert, state_pert, ierr) if (ierr .ne. FEM_SUCCESS) return residual_pert = HALF * (stress_pert(2) + stress_pert(3)) tangent = (residual_pert - residual) / perturb if (abs(tangent) .le. tiny(ONE)) then call error_set(FEM_ERR_MATERIAL, 'roll springback lateral tangent failed', & ierr) return end if lateral = lateral - residual / tangent end do call update_with_lateral(axial_deps, lateral, dt, stress_in, state_in, & stress_out, state_out, ierr) end subroutine update_plane_stress subroutine update_with_lateral(axial_deps, lateral_deps, dt, stress_in, & state_in, stress_out, state_out, ierr) real(rk), intent(in) :: axial_deps real(rk), intent(in) :: lateral_deps real(rk), intent(in) :: dt real(rk), intent(in) :: stress_in(NSTRESS) real(rk), intent(in) :: state_in(NSTATEV_MAX) real(rk), intent(out) :: stress_out(NSTRESS) real(rk), intent(out) :: state_out(NSTATEV_MAX) integer, intent(out) :: ierr real(rk) :: deps(NSTRESS) deps = ZERO deps(1) = axial_deps deps(2) = lateral_deps deps(3) = lateral_deps call material_update_small_strain_dt(1, dt, deps, state_in, stress_in, & stress_out, state_out, ierr) end subroutine update_with_lateral subroutine section_moment(cfg, z, stress, moment) type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: z(cfg%layers) real(rk), intent(in) :: stress(:,:,:) real(rk), intent(out) :: moment integer :: j, k real(rk) :: area area = point_area(cfg) moment = ZERO do k = 1, cfg%strips do j = 1, cfg%layers moment = moment + stress(1,j,k) * z(j) * area end do end do end subroutine section_moment subroutine mean_eqps_value(cfg, state, mean_eqps) type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: state(:,:,:) real(rk), intent(out) :: mean_eqps integer :: j, k mean_eqps = ZERO do k = 1, cfg%strips do j = 1, cfg%layers mean_eqps = mean_eqps + state(1,j,k) end do end do mean_eqps = mean_eqps / real(cfg%strips * cfg%layers, rk) end subroutine mean_eqps_value subroutine active_point_count(cfg, state, active_count) type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: state(:,:,:) integer, intent(out) :: active_count integer :: j, k active_count = 0 do k = 1, cfg%strips do j = 1, cfg%layers if (state(1,j,k) .gt. 1.0e-10_rk) active_count = active_count + 1 end do end do end subroutine active_point_count subroutine plastic_zone_stats(cfg, state, active_points, zone_fraction, max_eqps) type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: state(:,:,:) integer, intent(out) :: active_points real(rk), intent(out) :: zone_fraction real(rk), intent(out) :: max_eqps integer :: j, k active_points = 0 max_eqps = ZERO do k = 1, cfg%strips do j = 1, cfg%layers max_eqps = max(max_eqps, state(1,j,k)) if (state(1,j,k) .gt. 1.0e-10_rk) active_points = active_points + 1 end do end do zone_fraction = real(active_points, rk) / real(cfg%strips * cfg%layers, rk) end subroutine plastic_zone_stats real(rk) function point_area(cfg) type(spring_cfg), intent(in) :: cfg point_area = (2.0_rk * cfg%half_width / real(cfg%strips, rk)) * & (cfg%thickness / real(cfg%layers, rk)) end function point_area real(rk) function point_volume(cfg) type(spring_cfg), intent(in) :: cfg point_volume = point_area(cfg) * cfg%length end function point_volume subroutine write_summary(path, cfg, plastic_work, unload_work, friction_energy, & mean_pressure, mean_slip, forming_force, & roller_torque, peak_moment, residual_moment, & release_curv, residual_curv, formed_disp, & residual_disp, springback_disp, springback_ratio, & active_points, zone_fraction, max_eqps, ierr) character(len=*), intent(in) :: path type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: plastic_work, unload_work, friction_energy real(rk), intent(in) :: mean_pressure, mean_slip, forming_force real(rk), intent(in) :: roller_torque, peak_moment, residual_moment real(rk), intent(in) :: release_curv, residual_curv real(rk), intent(in) :: formed_disp, residual_disp, springback_disp real(rk), intent(in) :: springback_ratio, zone_fraction, max_eqps integer, intent(in) :: active_points integer, intent(out) :: ierr integer :: unit integer :: ios unit = 93 open(unit=unit, file=trim(path), status='replace', action='write', iostat=ios) if (ios .ne. 0) then call error_set(FEM_ERR_OUTPUT, 'failed to open springback summary', ierr) return end if write(unit,'(A)') 'key,value' write(unit,'(A,I0)') 'samples,', cfg%samples write(unit,'(A,I0)') 'strips,', cfg%strips write(unit,'(A,I0)') 'layers,', cfg%layers write(unit,'(A,I0)') 'total_points,', cfg%strips * cfg%layers write(unit,'(A,ES16.8)') 'thickness,', cfg%thickness write(unit,'(A,ES16.8)') 'half_width,', cfg%half_width write(unit,'(A,ES16.8)') 'length,', cfg%length write(unit,'(A,ES16.8)') 'target_curvature,', cfg%target_curvature write(unit,'(A,ES16.8)') 'release_curvature,', release_curv write(unit,'(A,ES16.8)') 'residual_curvature,', residual_curv write(unit,'(A,ES16.8)') 'formed_displacement,', formed_disp write(unit,'(A,ES16.8)') 'springback_displacement,', springback_disp write(unit,'(A,ES16.8)') 'residual_displacement,', residual_disp write(unit,'(A,ES16.8)') 'springback_ratio,', springback_ratio write(unit,'(A,ES16.8)') 'plastic_work,', plastic_work write(unit,'(A,ES16.8)') 'unload_plastic_work,', unload_work write(unit,'(A,ES16.8)') 'friction_energy,', friction_energy write(unit,'(A,ES16.8)') 'forming_force,', forming_force write(unit,'(A,ES16.8)') 'mean_pressure,', mean_pressure write(unit,'(A,ES16.8)') 'mean_slip,', mean_slip write(unit,'(A,ES16.8)') 'roller_torque,', roller_torque write(unit,'(A,ES16.8)') 'peak_moment,', peak_moment write(unit,'(A,ES16.8)') 'residual_moment,', residual_moment write(unit,'(A,I0)') 'active_plastic_points,', active_points write(unit,'(A,ES16.8)') 'plastic_zone_fraction,', zone_fraction write(unit,'(A,ES16.8)') 'max_eqps,', max_eqps close(unit) call error_clear(ierr) end subroutine write_summary subroutine write_zone(path, cfg, x, z, strip_weight, state, stress, residual_curv, ierr) character(len=*), intent(in) :: path type(spring_cfg), intent(in) :: cfg real(rk), intent(in) :: x(cfg%strips) real(rk), intent(in) :: z(cfg%layers) real(rk), intent(in) :: strip_weight(cfg%strips) real(rk), intent(in) :: state(:,:,:) real(rk), intent(in) :: stress(:,:,:) real(rk), intent(in) :: residual_curv integer, intent(out) :: ierr integer :: unit integer :: ios integer :: j, k integer :: active real(rk) :: residual_strain unit = 94 open(unit=unit, file=trim(path), status='replace', action='write', iostat=ios) if (ios .ne. 0) then call error_set(FEM_ERR_OUTPUT, 'failed to open plastic zone output', ierr) return end if write(unit,'(A)') 'strip,layer,x,z,weight,residual_strain,eqps,' // & 'plastic_increment,stress_x,active' do k = 1, cfg%strips do j = 1, cfg%layers active = 0 if (state(1,j,k) .gt. 1.0e-10_rk) active = 1 residual_strain = z(j) * residual_curv * strip_weight(k) write(unit,'(I0,A,I0,7(A,ES16.8),A,I0)') k, ',', j, ',', x(k), & ',', z(j), ',', strip_weight(k), ',', residual_strain, ',', & state(1,j,k), ',', state(22,j,k), ',', stress(1,j,k), ',', active end do end do close(unit) call error_clear(ierr) end subroutine write_zone logical function same_sign(a, b) real(rk), intent(in) :: a real(rk), intent(in) :: b same_sign = (a .ge. ZERO .and. b .ge. ZERO) .or. & (a .lt. ZERO .and. b .lt. ZERO) end function same_sign real(rk) function norm3(vector) real(rk), intent(in) :: vector(3) norm3 = sqrt(dot_product(vector, vector)) end function norm3 logical function is_blank_or_comment(line) character(len=*), intent(in) :: line integer :: n n = len_trim(line) is_blank_or_comment = n .eq. 0 if (.not. is_blank_or_comment .and. n .ge. 2) then is_blank_or_comment = line(1:2) .eq. '**' end if end function is_blank_or_comment subroutine uppercase(line, upper) character(len=*), intent(in) :: line character(len=*), intent(out) :: upper integer :: i integer :: code upper = line do i = 1, len_trim(upper) code = iachar(upper(i:i)) if (code .ge. iachar('a') .and. code .le. iachar('z')) then upper(i:i) = achar(code - iachar('a') + iachar('A')) end if end do end subroutine uppercase function join_path(dir, name) result(path) character(len=*), intent(in) :: dir character(len=*), intent(in) :: name character(len=512) :: path integer :: n n = len_trim(dir) if (n .le. 0) then path = trim(name) else if (dir(n:n) .eq. '\' .or. dir(n:n) .eq. '/') then path = trim(dir)//trim(name) else path = trim(dir)//'\'//trim(name) end if end function join_path subroutine exit_if_error(ierr) integer, intent(in) :: ierr integer :: code integer :: ierr2 character(len=256) :: msg if (ierr .eq. FEM_SUCCESS) return call fem_get_last_error(code, msg, ierr2) if (ierr2 .eq. FEM_SUCCESS) then write(*,'(A,I0,2A)') 'Error ', code, ': ', trim(msg) else write(*,'(A,I0)') 'Error: ', ierr end if stop 1 end subroutine exit_if_error end program roll_springback_bench