program test_solid_state_api use sph_precision, only: rk use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, SPH_ERROR_STATE use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, sph_build_model, & sph_get_solid_state, sph_get_solid_diagnostics, & sph_get_solid_reference_quality use sph_database, only: npart, a use sph_solid_state, only: solid_stress, solid_strain, solid_strain_rate, & solid_plastic_strain, solid_damage, solid_softening, solid_strain_rate_eq, & solid_acc_internal, solid_reference_neighbor_count, & solid_reference_degenerate, solid_correction_determinant, & solid_correction_status, solid_failure_status implicit none integer, parameter :: SOLID_STATE_VALUES = 22 integer, parameter :: SOLID_DIAGNOSTICS = 3 integer :: ierr call check_uninitialized_errors() call check_unbuilt_errors() call check_solid_state_values() contains subroutine check_uninitialized_errors() real(rk) :: values(SOLID_STATE_VALUES,1) integer :: failure(1) integer :: ref_count(1) integer :: ref_degenerate(1) integer :: corr_status(1) integer :: count call sph_get_solid_state(1, SOLID_STATE_VALUES, values, failure, ref_count, & ref_degenerate, corr_status, count, ierr) if (ierr /= SPH_ERROR_STATE) call fail('uninitialized Solid state API mismatch') end subroutine check_uninitialized_errors subroutine check_unbuilt_errors() real(rk) :: values(SOLID_STATE_VALUES,1) real(rk) :: diagnostics(SOLID_DIAGNOSTICS) integer :: failure(1) integer :: ref_count(1) integer :: ref_degenerate(1) integer :: corr_status(1) integer :: count integer :: reference_neighbor_min integer :: correction_status_value real(rk) :: correction_det_min call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for Solid state API') call sph_get_solid_state(1, SOLID_STATE_VALUES, values, failure, ref_count, & ref_degenerate, corr_status, count, ierr) if (ierr /= SPH_ERROR_STATE) call fail('unbuilt Solid state API mismatch') call sph_get_solid_diagnostics(SOLID_DIAGNOSTICS, diagnostics, ierr) if (ierr /= SPH_ERROR_STATE) call fail('unbuilt Solid diagnostics API mismatch') call sph_get_solid_reference_quality(reference_neighbor_min, & correction_det_min, correction_status_value, ierr) if (ierr /= SPH_ERROR_STATE) call fail('unbuilt Solid reference API mismatch') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for Solid state API') end subroutine check_unbuilt_errors subroutine check_solid_state_values() real(rk) :: values(SOLID_STATE_VALUES,4) real(rk) :: bad_values(SOLID_STATE_VALUES - 1,4) real(rk) :: small_particle_values(SOLID_STATE_VALUES,3) real(rk) :: diagnostics(SOLID_DIAGNOSTICS) real(rk) :: bad_diagnostics(SOLID_DIAGNOSTICS - 1) integer :: failure(4) integer :: ref_count(4) integer :: ref_degenerate(4) integer :: corr_status(4) integer :: small_failure(3) integer :: small_ref_count(3) integer :: small_ref_degenerate(3) integer :: small_corr_status(3) integer :: count integer :: reference_neighbor_min integer :: correction_status_value real(rk) :: correction_det_min call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for Solid state values') call sph_read_inp('tests/data/solid_elastic_minimal_050.inp', ierr) call assert_ok(ierr, 'read failed for Solid state values') call sph_build_model(ierr) call assert_ok(ierr, 'build failed for Solid state values') call seed_state_values() call sph_get_solid_state(4, SOLID_STATE_VALUES - 1, bad_values, failure, & ref_count, ref_degenerate, corr_status, count, ierr) if (ierr /= SPH_ERROR_ARGUMENT) call fail('Solid state value capacity mismatch') call sph_get_solid_state(3, SOLID_STATE_VALUES, small_particle_values, & small_failure, small_ref_count, small_ref_degenerate, & small_corr_status, count, ierr) if (ierr /= SPH_ERROR_ARGUMENT) call fail('Solid state particle capacity mismatch') call sph_get_solid_diagnostics(SOLID_DIAGNOSTICS - 1, bad_diagnostics, ierr) if (ierr /= SPH_ERROR_ARGUMENT) call fail('Solid diagnostic capacity mismatch') call sph_get_solid_state(4, SOLID_STATE_VALUES, values, failure, ref_count, & ref_degenerate, corr_status, count, ierr) call assert_ok(ierr, 'Solid state query failed') if (count /= npart) call fail('Solid state count mismatch') call assert_state_layout(values, failure, ref_count, ref_degenerate, corr_status) call sph_get_solid_diagnostics(SOLID_DIAGNOSTICS, diagnostics, ierr) call assert_ok(ierr, 'Solid diagnostics query failed') if (abs(diagnostics(1) - 2.5_rk) > 1.0e-12_rk) then call fail('Solid max strain rate diagnostic mismatch') end if if (abs(diagnostics(2) - 3.0_rk) > 1.0e-12_rk) then call fail('Solid max acceleration diagnostic mismatch') end if call sph_get_solid_reference_quality(reference_neighbor_min, & correction_det_min, correction_status_value, ierr) call assert_ok(ierr, 'Solid reference quality query failed') if (reference_neighbor_min /= 4) call fail('Solid reference min mismatch') if (abs(correction_det_min - 0.25_rk) > 1.0e-12_rk) then call fail('Solid correction determinant mismatch') end if if (correction_status_value /= 2) call fail('Solid correction status mismatch') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for Solid state values') end subroutine check_solid_state_values subroutine seed_state_values() solid_stress(:,1) = (/1.0_rk, 2.0_rk, 3.0_rk, 4.0_rk, 5.0_rk, 6.0_rk/) solid_strain(:,1) = (/0.1_rk, 0.2_rk, 0.3_rk, 0.4_rk, 0.5_rk, 0.6_rk/) solid_strain_rate(:,1) = (/10.0_rk, 20.0_rk, 30.0_rk, & 40.0_rk, 50.0_rk, 60.0_rk/) solid_plastic_strain(1) = 0.7_rk solid_damage(1) = 0.8_rk solid_softening(1) = 0.9_rk solid_strain_rate_eq = 0.0_rk solid_strain_rate_eq(1) = 2.5_rk solid_acc_internal = 0.0_rk solid_acc_internal(1,1) = 1.0_rk a = 0.0_rk a(:,1) = (/1.0_rk, 2.0_rk, 2.0_rk/) solid_reference_neighbor_count = 4 solid_reference_degenerate = 0 solid_correction_determinant = 0.50_rk solid_correction_determinant(1) = 0.25_rk solid_correction_status = 1 solid_correction_status(1) = 2 solid_failure_status = 0 solid_failure_status(1) = 2 end subroutine seed_state_values subroutine assert_state_layout(values, failure, ref_count, ref_degenerate, & corr_status) real(rk), intent(in) :: values(SOLID_STATE_VALUES,4) integer, intent(in) :: failure(4) integer, intent(in) :: ref_count(4) integer, intent(in) :: ref_degenerate(4) integer, intent(in) :: corr_status(4) if (maxval(abs(values(1:6,1) - (/1.0_rk, 2.0_rk, 3.0_rk, & 4.0_rk, 5.0_rk, 6.0_rk/))) > 1.0e-12_rk) then call fail('Solid stress layout mismatch') end if if (maxval(abs(values(7:12,1) - (/0.1_rk, 0.2_rk, 0.3_rk, & 0.4_rk, 0.5_rk, 0.6_rk/))) > 1.0e-12_rk) then call fail('Solid strain layout mismatch') end if if (maxval(abs(values(13:18,1) - (/10.0_rk, 20.0_rk, 30.0_rk, & 40.0_rk, 50.0_rk, 60.0_rk/))) > 1.0e-12_rk) then call fail('Solid strain-rate layout mismatch') end if if (abs(values(19,1) - 0.7_rk) > 1.0e-12_rk) then call fail('Solid plastic state layout mismatch') end if if (abs(values(20,1) - 0.8_rk) > 1.0e-12_rk) then call fail('Solid damage state layout mismatch') end if if (abs(values(21,1) - 0.9_rk) > 1.0e-12_rk) then call fail('Solid softening state layout mismatch') end if if (abs(values(22,1) - 2.5_rk) > 1.0e-12_rk) then call fail('Solid equivalent strain-rate layout mismatch') end if if (failure(1) /= 2) call fail('Solid failure status API mismatch') if (ref_count(1) /= 4) call fail('Solid reference count API mismatch') if (ref_degenerate(1) /= 0) call fail('Solid reference degenerate API mismatch') if (corr_status(1) /= 2) call fail('Solid correction status API mismatch') end subroutine assert_state_layout 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_api