286 lines
13 KiB
Fortran
286 lines
13 KiB
Fortran
program test_solid_restart_050
|
|
use sph_precision, only: rk
|
|
use sph_error, only: SPH_SUCCESS
|
|
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model, &
|
|
sph_estimate_stable_dt, sph_advance_explicit, sph_write_restart, &
|
|
sph_read_restart
|
|
use sph_database, only: particle_phase, particle_status, solid_particle_count, &
|
|
solid_failed_count, solid_dtcrit, SPH_PHASE_SOLID_FAILED, SPH_STATUS_FAILED
|
|
use sph_solid, only: solid_material_count, solid_material_names, &
|
|
solid_elastic_e, solid_elastic_nu, solid_johnson_cook_defined, &
|
|
solid_jc_a, solid_failure_defined, solid_failure_d, solid_softening_width, &
|
|
sph_solid_mark_particle_failed
|
|
use sph_solid_state, only: solid_body_force, solid_stress, solid_strain, &
|
|
solid_plastic_strain, solid_plastic_strain_rate, solid_temperature, &
|
|
solid_damage, solid_softening, solid_internal_energy, &
|
|
solid_reference_volume, solid_deformation_gradient, &
|
|
solid_correction_matrix, solid_correction_determinant, &
|
|
solid_velocity_gradient, solid_strain_rate, solid_strain_rate_eq, &
|
|
solid_acc_internal, solid_reference_neighbor_count, &
|
|
solid_reference_degenerate, solid_correction_status, solid_failure_status
|
|
use sph_solid_dynamics, only: sph_solid_update_diagnostics
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
|
|
call check_solid_restart_round_trip()
|
|
|
|
contains
|
|
|
|
subroutine check_solid_restart_round_trip()
|
|
real(rk) :: expected_stress(6)
|
|
real(rk) :: expected_strain(6)
|
|
real(rk) :: expected_deformation(3,3)
|
|
real(rk) :: expected_correction(3,3)
|
|
real(rk) :: expected_velocity_gradient(3,3)
|
|
real(rk) :: expected_strain_rate(6)
|
|
real(rk) :: expected_acc_internal(3)
|
|
real(rk) :: expected_dtcrit
|
|
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for Solid restart')
|
|
call sph_read_inp('tests/data/solid_restart_050.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for Solid restart')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for Solid restart')
|
|
call seed_solid_restart_state(expected_stress, expected_strain, &
|
|
expected_deformation, expected_correction, expected_velocity_gradient, &
|
|
expected_strain_rate, expected_acc_internal)
|
|
call sph_estimate_stable_dt(expected_dtcrit, ierr)
|
|
call assert_ok(ierr, 'Solid restart dt estimate failed')
|
|
expected_acc_internal = solid_acc_internal(:,1)
|
|
expected_dtcrit = solid_dtcrit
|
|
call sph_solid_update_diagnostics(ierr)
|
|
call assert_ok(ierr, 'Solid restart diagnostics failed')
|
|
call sph_write_restart('build-codex-unix/restart_solid_050.tmp', ierr)
|
|
call assert_ok(ierr, 'Solid restart write failed')
|
|
call assert_restart_state_version('build-codex-unix/restart_solid_050.tmp', &
|
|
'STATE_0_8_1')
|
|
call scramble_solid_state()
|
|
call sph_read_restart('build-codex-unix/restart_solid_050.tmp', ierr)
|
|
call assert_ok(ierr, 'Solid restart read failed')
|
|
call assert_material_table_restored()
|
|
call assert_particle_state_restored(expected_stress, expected_strain, &
|
|
expected_deformation, expected_correction, expected_velocity_gradient, &
|
|
expected_strain_rate, expected_acc_internal)
|
|
if (solid_particle_count /= 3) call fail('Solid restart active count mismatch')
|
|
if (solid_failed_count /= 1) call fail('Solid restart failed count mismatch')
|
|
if (abs(solid_dtcrit - expected_dtcrit) > 1.0e-12_rk) then
|
|
call fail('Solid restart dtcrit mismatch')
|
|
end if
|
|
call sph_advance_explicit(1.0e-8_rk, ierr)
|
|
call assert_ok(ierr, 'Solid restart continuation failed')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for Solid restart')
|
|
end subroutine check_solid_restart_round_trip
|
|
|
|
subroutine seed_solid_restart_state(expected_stress, expected_strain, &
|
|
expected_deformation, expected_correction, expected_velocity_gradient, &
|
|
expected_strain_rate, expected_acc_internal)
|
|
real(rk), intent(out) :: expected_stress(6)
|
|
real(rk), intent(out) :: expected_strain(6)
|
|
real(rk), intent(out) :: expected_deformation(3,3)
|
|
real(rk), intent(out) :: expected_correction(3,3)
|
|
real(rk), intent(out) :: expected_velocity_gradient(3,3)
|
|
real(rk), intent(out) :: expected_strain_rate(6)
|
|
real(rk), intent(out) :: expected_acc_internal(3)
|
|
|
|
expected_stress = (/11.0_rk, 22.0_rk, 33.0_rk, &
|
|
4.0_rk, 5.0_rk, 6.0_rk/)
|
|
expected_strain = (/0.01_rk, 0.02_rk, 0.03_rk, &
|
|
0.004_rk, 0.005_rk, 0.006_rk/)
|
|
expected_deformation = reshape((/1.10_rk, 0.01_rk, 0.02_rk, &
|
|
0.03_rk, 1.20_rk, 0.04_rk, 0.05_rk, 0.06_rk, 1.30_rk/), (/3,3/))
|
|
expected_correction = reshape((/0.90_rk, 0.07_rk, 0.08_rk, &
|
|
0.09_rk, 0.80_rk, 0.10_rk, 0.11_rk, 0.12_rk, 0.70_rk/), (/3,3/))
|
|
expected_velocity_gradient = reshape((/0.01_rk, 0.02_rk, 0.03_rk, &
|
|
0.04_rk, 0.05_rk, 0.06_rk, 0.07_rk, 0.08_rk, 0.09_rk/), (/3,3/))
|
|
expected_strain_rate = (/0.10_rk, 0.20_rk, 0.30_rk, &
|
|
0.04_rk, 0.05_rk, 0.06_rk/)
|
|
expected_acc_internal = (/1.1_rk, 2.2_rk, 3.3_rk/)
|
|
solid_body_force = (/0.10_rk, 0.20_rk, 0.30_rk/)
|
|
solid_stress(:,1) = expected_stress
|
|
solid_strain(:,1) = expected_strain
|
|
solid_plastic_strain(1) = 0.125_rk
|
|
solid_plastic_strain_rate(1) = 2.5_rk
|
|
solid_temperature(1) = 310.0_rk
|
|
solid_damage(1) = 0.35_rk
|
|
solid_softening(1) = 0.65_rk
|
|
solid_internal_energy(1) = 9.5_rk
|
|
solid_reference_volume(1) = 0.00123_rk
|
|
solid_deformation_gradient(:,:,1) = expected_deformation
|
|
solid_correction_matrix(:,:,1) = expected_correction
|
|
solid_correction_determinant(1) = 0.875_rk
|
|
solid_velocity_gradient(:,:,1) = expected_velocity_gradient
|
|
solid_strain_rate(:,1) = expected_strain_rate
|
|
solid_strain_rate_eq(1) = 1.75_rk
|
|
solid_acc_internal(:,1) = expected_acc_internal
|
|
solid_reference_neighbor_count(1) = 3
|
|
solid_reference_degenerate(1) = 1
|
|
solid_correction_status(1) = 2
|
|
solid_failure_status(1) = 0
|
|
call sph_solid_mark_particle_failed(4, ierr)
|
|
call assert_ok(ierr, 'mark Solid failed particle for restart failed')
|
|
end subroutine seed_solid_restart_state
|
|
|
|
subroutine scramble_solid_state()
|
|
solid_body_force = -999.0_rk
|
|
solid_stress = -999.0_rk
|
|
solid_strain = -999.0_rk
|
|
solid_plastic_strain = -999.0_rk
|
|
solid_plastic_strain_rate = -999.0_rk
|
|
solid_temperature = -999.0_rk
|
|
solid_damage = -999.0_rk
|
|
solid_softening = -999.0_rk
|
|
solid_internal_energy = -999.0_rk
|
|
solid_reference_volume = -999.0_rk
|
|
solid_deformation_gradient = -999.0_rk
|
|
solid_correction_matrix = -999.0_rk
|
|
solid_correction_determinant = -999.0_rk
|
|
solid_velocity_gradient = -999.0_rk
|
|
solid_strain_rate = -999.0_rk
|
|
solid_strain_rate_eq = -999.0_rk
|
|
solid_acc_internal = -999.0_rk
|
|
solid_reference_neighbor_count = -999
|
|
solid_reference_degenerate = -999
|
|
solid_correction_status = -999
|
|
solid_failure_status = -999
|
|
end subroutine scramble_solid_state
|
|
|
|
subroutine assert_material_table_restored()
|
|
if (solid_material_count /= 1) call fail('Solid restart material count mismatch')
|
|
if (trim(solid_material_names(1)) /= 'STEEL_RESTART') then
|
|
call fail('Solid restart material name mismatch')
|
|
end if
|
|
if (abs(solid_elastic_e(1) - 210.0e9_rk) > 1.0e-3_rk) then
|
|
call fail('Solid restart elastic modulus mismatch')
|
|
end if
|
|
if (abs(solid_elastic_nu(1) - 0.30_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart Poisson ratio mismatch')
|
|
end if
|
|
if (.not. solid_johnson_cook_defined(1)) then
|
|
call fail('Solid restart Johnson-Cook flag missing')
|
|
end if
|
|
if (abs(solid_jc_a(1) - 792.0e6_rk) > 1.0e-3_rk) then
|
|
call fail('Solid restart Johnson-Cook A mismatch')
|
|
end if
|
|
if (.not. solid_failure_defined(1)) call fail('Solid restart failure flag missing')
|
|
if (abs(solid_failure_d(1,1) - 0.05_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart failure parameter mismatch')
|
|
end if
|
|
if (abs(solid_softening_width(1) - 0.25_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart softening width mismatch')
|
|
end if
|
|
end subroutine assert_material_table_restored
|
|
|
|
subroutine assert_particle_state_restored(expected_stress, expected_strain, &
|
|
expected_deformation, expected_correction, expected_velocity_gradient, &
|
|
expected_strain_rate, expected_acc_internal)
|
|
real(rk), intent(in) :: expected_stress(6)
|
|
real(rk), intent(in) :: expected_strain(6)
|
|
real(rk), intent(in) :: expected_deformation(3,3)
|
|
real(rk), intent(in) :: expected_correction(3,3)
|
|
real(rk), intent(in) :: expected_velocity_gradient(3,3)
|
|
real(rk), intent(in) :: expected_strain_rate(6)
|
|
real(rk), intent(in) :: expected_acc_internal(3)
|
|
|
|
if (maxval(abs(solid_body_force - (/0.10_rk, 0.20_rk, 0.30_rk/))) > &
|
|
1.0e-12_rk) call fail('Solid restart body force mismatch')
|
|
if (maxval(abs(solid_stress(:,1) - expected_stress)) > 1.0e-12_rk) then
|
|
call fail('Solid restart stress mismatch')
|
|
end if
|
|
if (maxval(abs(solid_strain(:,1) - expected_strain)) > 1.0e-12_rk) then
|
|
call fail('Solid restart strain mismatch')
|
|
end if
|
|
if (abs(solid_plastic_strain(1) - 0.125_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart plastic strain mismatch')
|
|
end if
|
|
if (abs(solid_plastic_strain_rate(1) - 2.5_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart plastic rate mismatch')
|
|
end if
|
|
if (abs(solid_temperature(1) - 310.0_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart temperature mismatch')
|
|
end if
|
|
if (abs(solid_damage(1) - 0.35_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart damage mismatch')
|
|
end if
|
|
if (abs(solid_softening(1) - 0.65_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart softening mismatch')
|
|
end if
|
|
if (abs(solid_internal_energy(1) - 9.5_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart internal energy mismatch')
|
|
end if
|
|
if (abs(solid_reference_volume(1) - 0.00123_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart reference volume mismatch')
|
|
end if
|
|
if (maxval(abs(solid_deformation_gradient(:,:,1) - expected_deformation)) > &
|
|
1.0e-12_rk) call fail('Solid restart deformation mismatch')
|
|
if (maxval(abs(solid_correction_matrix(:,:,1) - expected_correction)) > &
|
|
1.0e-12_rk) call fail('Solid restart correction mismatch')
|
|
if (abs(solid_correction_determinant(1) - 0.875_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart correction determinant mismatch')
|
|
end if
|
|
if (maxval(abs(solid_velocity_gradient(:,:,1) - expected_velocity_gradient)) > &
|
|
1.0e-12_rk) call fail('Solid restart velocity gradient mismatch')
|
|
if (maxval(abs(solid_strain_rate(:,1) - expected_strain_rate)) > &
|
|
1.0e-12_rk) call fail('Solid restart strain rate mismatch')
|
|
if (abs(solid_strain_rate_eq(1) - 1.75_rk) > 1.0e-12_rk) then
|
|
call fail('Solid restart equivalent strain rate mismatch')
|
|
end if
|
|
if (maxval(abs(solid_acc_internal(:,1) - expected_acc_internal)) > &
|
|
1.0e-12_rk) call fail('Solid restart internal acceleration mismatch')
|
|
if (solid_reference_neighbor_count(1) /= 3) then
|
|
call fail('Solid restart reference neighbor count mismatch')
|
|
end if
|
|
if (solid_reference_degenerate(1) /= 1) then
|
|
call fail('Solid restart reference degeneracy mismatch')
|
|
end if
|
|
if (solid_correction_status(1) /= 2) then
|
|
call fail('Solid restart correction status mismatch')
|
|
end if
|
|
if (solid_failure_status(4) /= SPH_STATUS_FAILED) then
|
|
call fail('Solid restart failure status mismatch')
|
|
end if
|
|
if (particle_status(4) /= SPH_STATUS_FAILED) call fail('Solid restart status mismatch')
|
|
if (particle_phase(4) /= SPH_PHASE_SOLID_FAILED) then
|
|
call fail('Solid restart failed phase mismatch')
|
|
end if
|
|
end subroutine assert_particle_state_restored
|
|
|
|
subroutine assert_restart_state_version(filename, expected_state)
|
|
character(len=*), intent(in) :: filename
|
|
character(len=*), intent(in) :: expected_state
|
|
character(len=64) :: tag
|
|
character(len=32) :: state_version
|
|
integer :: major
|
|
integer :: minor
|
|
integer :: patch
|
|
integer :: ios
|
|
|
|
open(unit=96, file=trim(filename), status='old', action='read', iostat=ios)
|
|
if (ios /= 0) call fail('Solid restart header open failed')
|
|
read(96, *, iostat=ios) tag, major, minor, patch, state_version
|
|
close(unit=96)
|
|
if (ios /= 0) call fail('Solid restart header read failed')
|
|
if (trim(tag) /= 'SPHLITE_RESTART') call fail('Solid restart header tag mismatch')
|
|
if (trim(state_version) /= trim(expected_state)) then
|
|
call fail('Solid restart state version mismatch')
|
|
end if
|
|
end subroutine assert_restart_state_version
|
|
|
|
subroutine assert_ok(ierr_value, message)
|
|
integer, intent(in) :: ierr_value
|
|
character(len=*), intent(in) :: message
|
|
|
|
if (ierr_value /= SPH_SUCCESS) call fail(message)
|
|
end subroutine assert_ok
|
|
|
|
subroutine fail(message)
|
|
character(len=*), intent(in) :: message
|
|
|
|
write(*, '(A)') trim(message)
|
|
stop 1
|
|
end subroutine fail
|
|
|
|
end program test_solid_restart_050
|