252 lines
11 KiB
Fortran
252 lines
11 KiB
Fortran
program test_solid_restart_050_compat
|
|
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: npart, particle_phase, particle_status, &
|
|
solid_particle_count, solid_failed_count, SPH_PHASE_SOLID_FAILED, &
|
|
SPH_STATUS_FAILED
|
|
use sph_solid, only: solid_material_count, sph_solid_mark_particle_failed
|
|
use sph_solid_state, only: solid_body_force, solid_stress, solid_strain, &
|
|
solid_plastic_strain, solid_damage, solid_softening, &
|
|
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_050_restart_compat()
|
|
|
|
contains
|
|
|
|
subroutine check_solid_050_restart_compat()
|
|
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_acc_internal(3)
|
|
real(rk) :: dtcrit
|
|
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for Solid 0.5.0 compat')
|
|
call sph_read_inp('tests/data/solid_restart_050.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for Solid 0.5.0 compat')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for Solid 0.5.0 compat')
|
|
call seed_050_state(expected_stress, expected_strain, expected_deformation, &
|
|
expected_correction, expected_acc_internal)
|
|
call sph_estimate_stable_dt(dtcrit, ierr)
|
|
call assert_ok(ierr, 'Solid 0.5.0 compat dt estimate failed')
|
|
expected_acc_internal = solid_acc_internal(:,1)
|
|
call sph_solid_update_diagnostics(ierr)
|
|
call assert_ok(ierr, 'Solid 0.5.0 compat diagnostics failed')
|
|
call sph_write_restart('build-codex-unix/restart_solid_051_seed.tmp', ierr)
|
|
call assert_ok(ierr, 'Solid 0.5.1 seed restart write failed')
|
|
call write_050_compat_restart('build-codex-unix/restart_solid_051_seed.tmp', &
|
|
'build-codex-unix/restart_solid_050_compat.tmp')
|
|
call scramble_solid_state()
|
|
call sph_read_restart('build-codex-unix/restart_solid_050_compat.tmp', ierr)
|
|
call assert_ok(ierr, 'read Solid 0.5.0 compat restart failed')
|
|
call assert_050_state_restored(expected_stress, expected_strain, &
|
|
expected_deformation, expected_correction, expected_acc_internal)
|
|
call assert_051_defaults()
|
|
call sph_advance_explicit(1.0e-8_rk, ierr)
|
|
call assert_ok(ierr, 'continue Solid 0.5.0 compat restart failed')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for Solid 0.5.0 compat')
|
|
end subroutine check_solid_050_restart_compat
|
|
|
|
subroutine seed_050_state(expected_stress, expected_strain, &
|
|
expected_deformation, expected_correction, 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_acc_internal(3)
|
|
|
|
expected_stress = (/7.0_rk, 8.0_rk, 9.0_rk, 1.0_rk, 2.0_rk, 3.0_rk/)
|
|
expected_strain = (/0.11_rk, 0.12_rk, 0.13_rk, &
|
|
0.014_rk, 0.015_rk, 0.016_rk/)
|
|
expected_deformation = reshape((/1.01_rk, 0.02_rk, 0.03_rk, &
|
|
0.04_rk, 1.05_rk, 0.06_rk, 0.07_rk, 0.08_rk, 1.09_rk/), (/3,3/))
|
|
expected_correction = reshape((/0.91_rk, 0.12_rk, 0.13_rk, &
|
|
0.14_rk, 0.95_rk, 0.16_rk, 0.17_rk, 0.18_rk, 0.99_rk/), (/3,3/))
|
|
expected_acc_internal = (/0.25_rk, 0.50_rk, 0.75_rk/)
|
|
solid_body_force = (/0.30_rk, 0.20_rk, 0.10_rk/)
|
|
solid_stress(:,1) = expected_stress
|
|
solid_strain(:,1) = expected_strain
|
|
solid_plastic_strain(1) = 0.225_rk
|
|
solid_damage(1) = 0.45_rk
|
|
solid_softening(1) = 0.55_rk
|
|
solid_deformation_gradient(:,:,1) = expected_deformation
|
|
solid_correction_matrix(:,:,1) = expected_correction
|
|
solid_acc_internal(:,1) = expected_acc_internal
|
|
solid_failure_status(1) = 0
|
|
call sph_solid_mark_particle_failed(4, ierr)
|
|
call assert_ok(ierr, 'mark failed particle failed for Solid 0.5.0 compat')
|
|
end subroutine seed_050_state
|
|
|
|
subroutine write_050_compat_restart(source_filename, target_filename)
|
|
character(len=*), intent(in) :: source_filename
|
|
character(len=*), intent(in) :: target_filename
|
|
character(len=512) :: lines(512)
|
|
character(len=512) :: line
|
|
integer :: line_count
|
|
integer :: i
|
|
integer :: ios
|
|
integer :: solid_start
|
|
integer :: relative_line
|
|
integer :: solid_051_lines
|
|
|
|
line_count = 0
|
|
open(unit=97, file=trim(source_filename), status='old', action='read', &
|
|
iostat=ios)
|
|
if (ios /= 0) call fail('open Solid 0.5.1 restart seed failed')
|
|
do
|
|
read(97, '(A)', iostat=ios) line
|
|
if (ios /= 0) exit
|
|
line_count = line_count + 1
|
|
if (line_count > size(lines)) call fail('Solid 0.5.0 compat fixture too large')
|
|
lines(line_count) = line
|
|
end do
|
|
close(unit=97)
|
|
solid_051_lines = 1 + 6 * solid_material_count + 8 + 9 * npart
|
|
solid_start = line_count - solid_051_lines + 1
|
|
if (solid_start <= 1) call fail('Solid 0.5.0 compat solid block not found')
|
|
lines(1) = 'SPHLITE_RESTART 0 5 0 STATE_0_5'
|
|
open(unit=98, file=trim(target_filename), status='unknown', action='write', &
|
|
iostat=ios)
|
|
if (ios /= 0) call fail('open Solid 0.5.0 compat target failed')
|
|
do i = 1, line_count
|
|
relative_line = i - solid_start + 1
|
|
if (relative_line > 0 .and. skip_051_solid_line(relative_line)) cycle
|
|
write(98, '(A)') trim(lines(i))
|
|
end do
|
|
close(unit=98)
|
|
end subroutine write_050_compat_restart
|
|
|
|
logical function skip_051_solid_line(relative_line)
|
|
integer, intent(in) :: relative_line
|
|
integer :: material_end
|
|
integer :: particle_start
|
|
integer :: particle_line
|
|
|
|
material_end = 1 + 6 * solid_material_count
|
|
skip_051_solid_line = relative_line == material_end + 6 .or. &
|
|
relative_line == material_end + 7
|
|
particle_start = material_end + 9
|
|
if (relative_line < particle_start) return
|
|
particle_line = mod(relative_line - particle_start, 9)
|
|
if (particle_line == 5 .or. particle_line == 6 .or. &
|
|
particle_line == 7) skip_051_solid_line = .true.
|
|
end function skip_051_solid_line
|
|
|
|
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_damage = -999.0_rk
|
|
solid_softening = -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_050_state_restored(expected_stress, expected_strain, &
|
|
expected_deformation, expected_correction, 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_acc_internal(3)
|
|
|
|
if (maxval(abs(solid_body_force - (/0.30_rk, 0.20_rk, 0.10_rk/))) > &
|
|
1.0e-12_rk) call fail('Solid 0.5.0 compat body force mismatch')
|
|
if (maxval(abs(solid_stress(:,1) - expected_stress)) > 1.0e-12_rk) then
|
|
call fail('Solid 0.5.0 compat stress mismatch')
|
|
end if
|
|
if (maxval(abs(solid_strain(:,1) - expected_strain)) > 1.0e-12_rk) then
|
|
call fail('Solid 0.5.0 compat strain mismatch')
|
|
end if
|
|
if (abs(solid_plastic_strain(1) - 0.225_rk) > 1.0e-12_rk) then
|
|
call fail('Solid 0.5.0 compat plastic strain mismatch')
|
|
end if
|
|
if (abs(solid_damage(1) - 0.45_rk) > 1.0e-12_rk) then
|
|
call fail('Solid 0.5.0 compat damage mismatch')
|
|
end if
|
|
if (abs(solid_softening(1) - 0.55_rk) > 1.0e-12_rk) then
|
|
call fail('Solid 0.5.0 compat softening mismatch')
|
|
end if
|
|
if (maxval(abs(solid_deformation_gradient(:,:,1) - expected_deformation)) > &
|
|
1.0e-12_rk) call fail('Solid 0.5.0 compat deformation mismatch')
|
|
if (maxval(abs(solid_correction_matrix(:,:,1) - expected_correction)) > &
|
|
1.0e-12_rk) call fail('Solid 0.5.0 compat correction mismatch')
|
|
if (maxval(abs(solid_acc_internal(:,1) - expected_acc_internal)) > &
|
|
1.0e-12_rk) call fail('Solid 0.5.0 compat acceleration mismatch')
|
|
if (solid_particle_count /= 3) call fail('Solid 0.5.0 compat active count mismatch')
|
|
if (solid_failed_count /= 1) call fail('Solid 0.5.0 compat failed count mismatch')
|
|
if (solid_failure_status(4) /= SPH_STATUS_FAILED) then
|
|
call fail('Solid 0.5.0 compat failure status mismatch')
|
|
end if
|
|
if (particle_status(4) /= SPH_STATUS_FAILED) then
|
|
call fail('Solid 0.5.0 compat particle status mismatch')
|
|
end if
|
|
if (particle_phase(4) /= SPH_PHASE_SOLID_FAILED) then
|
|
call fail('Solid 0.5.0 compat failed phase mismatch')
|
|
end if
|
|
end subroutine assert_050_state_restored
|
|
|
|
subroutine assert_051_defaults()
|
|
if (maxval(abs(solid_correction_determinant)) > 1.0e-12_rk) then
|
|
call fail('Solid 0.5.0 compat correction determinant default mismatch')
|
|
end if
|
|
if (maxval(abs(solid_velocity_gradient)) > 1.0e-12_rk) then
|
|
call fail('Solid 0.5.0 compat velocity gradient default mismatch')
|
|
end if
|
|
if (maxval(abs(solid_strain_rate)) > 1.0e-12_rk) then
|
|
call fail('Solid 0.5.0 compat strain rate default mismatch')
|
|
end if
|
|
if (maxval(abs(solid_strain_rate_eq)) > 1.0e-12_rk) then
|
|
call fail('Solid 0.5.0 compat strain rate eq default mismatch')
|
|
end if
|
|
if (maxval(abs(solid_reference_neighbor_count)) /= 0) then
|
|
call fail('Solid 0.5.0 compat reference neighbor default mismatch')
|
|
end if
|
|
if (maxval(abs(solid_reference_degenerate)) /= 0) then
|
|
call fail('Solid 0.5.0 compat reference degenerate default mismatch')
|
|
end if
|
|
if (maxval(abs(solid_correction_status)) /= 0) then
|
|
call fail('Solid 0.5.0 compat correction status default mismatch')
|
|
end if
|
|
end subroutine assert_051_defaults
|
|
|
|
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_compat
|