110 lines
5.5 KiB
Fortran
110 lines
5.5 KiB
Fortran
program test_solid_state_build
|
|
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
|
|
use sph_database, only: npart, rho, particle_phase, SPH_PHASE_SOLID, SPH_PHASE_WATER
|
|
use sph_solid, only: solid_material_count
|
|
use sph_solid_state, only: solid_density, solid_shear_modulus, &
|
|
solid_bulk_modulus, solid_wave_speed, solid_stress, solid_strain, &
|
|
solid_plastic_strain, solid_plastic_strain_rate, solid_temperature, &
|
|
solid_damage, solid_softening, solid_internal_energy, &
|
|
solid_deformation_gradient, solid_correction_matrix, solid_failure_status
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
|
|
call check_solid_only_state()
|
|
call check_mixed_state_defaults()
|
|
|
|
contains
|
|
|
|
subroutine check_solid_only_state()
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for Solid state input')
|
|
call sph_read_inp('tests/data/solid_johnson_cook_failure_050.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for Solid state input')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for Solid state input')
|
|
if (solid_material_count /= 1) call fail('Solid state material count mismatch')
|
|
call assert_solid_state_allocated(npart)
|
|
if (abs(solid_density(1) - 7850.0_rk) > 1.0e-8_rk) call fail('Solid density mismatch')
|
|
if (solid_shear_modulus(1) <= 0.0_rk) call fail('Solid shear modulus missing')
|
|
if (solid_bulk_modulus(1) <= 0.0_rk) call fail('Solid bulk modulus missing')
|
|
if (solid_wave_speed(1) <= 0.0_rk) call fail('Solid wave speed missing')
|
|
if (any(abs(solid_stress(:,1:npart)) > 0.0_rk)) call fail('Solid stress not zeroed')
|
|
if (any(abs(solid_strain(:,1:npart)) > 0.0_rk)) call fail('Solid strain not zeroed')
|
|
if (any(abs(solid_plastic_strain(1:npart)) > 0.0_rk)) call fail('Solid plastic strain not zeroed')
|
|
if (any(abs(solid_plastic_strain_rate(1:npart)) > 0.0_rk)) call fail('Solid plastic strain rate not zeroed')
|
|
if (any(abs(solid_damage(1:npart)) > 0.0_rk)) call fail('Solid damage not zeroed')
|
|
if (any(abs(solid_internal_energy(1:npart)) > 0.0_rk)) call fail('Solid internal energy not zeroed')
|
|
if (any(abs(solid_softening(1:npart) - 1.0_rk) > 1.0e-12_rk)) call fail('Solid softening default mismatch')
|
|
call assert_identity(solid_deformation_gradient(:,:,1), 'Solid deformation gradient default mismatch')
|
|
call assert_identity(solid_correction_matrix(:,:,1), 'Solid correction matrix default mismatch')
|
|
if (rho(1) <= 0.0_rk) call fail('Solid density was not applied to particle state')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for Solid state input')
|
|
if (allocated(solid_stress)) call fail('Solid state was not released by finalize')
|
|
end subroutine check_solid_only_state
|
|
|
|
subroutine check_mixed_state_defaults()
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for mixed Solid state input')
|
|
call sph_read_inp('tests/data/solid_state_mixed_050.inp', ierr)
|
|
call assert_ok(ierr, 'read failed for mixed Solid state input')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build failed for mixed Solid state input')
|
|
call assert_solid_state_allocated(npart)
|
|
if (particle_phase(1) /= SPH_PHASE_SOLID) call fail('mixed Solid phase mismatch')
|
|
if (particle_phase(2) /= SPH_PHASE_WATER) call fail('mixed Water phase mismatch')
|
|
if (abs(solid_softening(1) - 1.0_rk) > 1.0e-12_rk) call fail('active Solid softening mismatch')
|
|
if (abs(solid_softening(2)) > 0.0_rk) call fail('non-Solid softening default mismatch')
|
|
if (abs(solid_temperature(2)) > 0.0_rk) call fail('non-Solid temperature default mismatch')
|
|
if (any(abs(solid_deformation_gradient(:,:,2)) > 0.0_rk)) call fail('non-Solid deformation default mismatch')
|
|
if (any(abs(solid_correction_matrix(:,:,2)) > 0.0_rk)) call fail('non-Solid correction default mismatch')
|
|
if (solid_failure_status(2) /= 0) call fail('non-Solid failure status default mismatch')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for mixed Solid state input')
|
|
end subroutine check_mixed_state_defaults
|
|
|
|
subroutine assert_solid_state_allocated(expected_count)
|
|
integer, intent(in) :: expected_count
|
|
|
|
if (.not. allocated(solid_stress)) call fail('Solid stress was not allocated')
|
|
if (size(solid_stress, 1) /= 6) call fail('Solid stress component count mismatch')
|
|
if (size(solid_stress, 2) /= expected_count) call fail('Solid stress particle count mismatch')
|
|
if (.not. allocated(solid_deformation_gradient)) call fail('Solid deformation gradient missing')
|
|
if (.not. allocated(solid_correction_matrix)) call fail('Solid correction matrix missing')
|
|
end subroutine assert_solid_state_allocated
|
|
|
|
subroutine assert_identity(matrix, message)
|
|
real(rk), intent(in) :: matrix(:,:)
|
|
character(len=*), intent(in) :: message
|
|
integer :: i
|
|
integer :: j
|
|
real(rk) :: expected
|
|
|
|
do i = 1, size(matrix, 1)
|
|
do j = 1, size(matrix, 2)
|
|
expected = 0.0_rk
|
|
if (i == j) expected = 1.0_rk
|
|
if (abs(matrix(i,j) - expected) > 1.0e-12_rk) call fail(message)
|
|
end do
|
|
end do
|
|
end subroutine assert_identity
|
|
|
|
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_state_build
|