2026-07-02 18:47:38 +08:00
|
|
|
program test_input
|
|
|
|
|
use sph_error, only: SPH_SUCCESS
|
|
|
|
|
use sph_api, only: sph_initialize, sph_finalize, sph_read_inp, &
|
2026-07-02 22:57:23 +08:00
|
|
|
sph_build_model, sph_get_particle_count, sph_get_input_warning_count, &
|
|
|
|
|
sph_get_last_error
|
2026-07-02 18:47:38 +08:00
|
|
|
use sph_input_reader, only: sph_input_get_warning_count
|
2026-07-02 19:50:44 +08:00
|
|
|
use sph_database, only: material_count, section_count, nset_count, &
|
2026-07-02 22:47:41 +08:00
|
|
|
elset_count, element_count, coupling_region_count, particle_phase, &
|
2026-07-03 00:00:53 +08:00
|
|
|
coupling_region_type, SPH_PHASE_WATER, SPH_REGION_COUPLING_CONTACT, &
|
|
|
|
|
SPH_REGION_COUPLING_CONTINUUM
|
2026-07-02 18:47:38 +08:00
|
|
|
implicit none
|
|
|
|
|
|
|
|
|
|
integer :: ierr
|
|
|
|
|
integer :: count
|
|
|
|
|
integer :: warnings
|
|
|
|
|
|
2026-07-02 19:50:44 +08:00
|
|
|
call check_good_input('tests/data/minimal_particles_011.inp', 4, .true.)
|
|
|
|
|
if (material_count /= 1) call fail('material metadata was not saved')
|
|
|
|
|
if (section_count /= 1) call fail('section metadata was not saved')
|
|
|
|
|
if (nset_count <= 0) call fail('node set metadata was not saved')
|
|
|
|
|
if (elset_count <= 0) call fail('element set metadata was not saved')
|
|
|
|
|
if (element_count <= 0) call fail('element metadata was not saved')
|
|
|
|
|
if (coupling_region_count <= 0) call fail('coupling region metadata was not saved')
|
2026-07-03 00:00:53 +08:00
|
|
|
if (coupling_region_type(1) /= SPH_REGION_COUPLING_CONTACT) then
|
|
|
|
|
call fail('contact coupling region type mismatch')
|
|
|
|
|
end if
|
2026-07-02 19:50:44 +08:00
|
|
|
|
2026-07-02 18:47:38 +08:00
|
|
|
call sph_finalize(ierr)
|
2026-07-02 19:50:44 +08:00
|
|
|
call assert_ok(ierr, 'finalize failed after metadata check')
|
|
|
|
|
|
|
|
|
|
call check_good_input('tests/data/mixed_case_011.inp', 2, .false.)
|
|
|
|
|
call check_good_input('tests/data/output_control_011.inp', 2, .false.)
|
2026-07-03 00:00:53 +08:00
|
|
|
call check_coupling_region_type('tests/data/coupling_region_011.inp', &
|
|
|
|
|
SPH_REGION_COUPLING_CONTINUUM)
|
2026-07-02 22:40:54 +08:00
|
|
|
call check_good_input('tests/data/water_material_case_021.inp', 4, .false.)
|
2026-07-02 22:47:41 +08:00
|
|
|
call check_good_input('tests/data/water_eos_no_p0_021.inp', 1, .false.)
|
|
|
|
|
call check_good_input('tests/data/water_eos_with_b_021.inp', 1, .false.)
|
|
|
|
|
call check_first_phase('tests/data/water_set_name_not_type_021.inp', &
|
|
|
|
|
SPH_PHASE_WATER)
|
2026-07-02 18:47:38 +08:00
|
|
|
|
|
|
|
|
call sph_initialize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'initialize failed for unknown keyword input')
|
|
|
|
|
call sph_read_inp('tests/data/unknown_keyword.inp', ierr)
|
|
|
|
|
call assert_ok(ierr, 'unknown keyword input read failed')
|
|
|
|
|
call sph_input_get_warning_count(warnings)
|
|
|
|
|
if (warnings <= 0) call fail('unknown keyword warning was not recorded')
|
2026-07-02 19:50:44 +08:00
|
|
|
call sph_get_input_warning_count(warnings, ierr)
|
|
|
|
|
call assert_ok(ierr, 'warning count API failed')
|
|
|
|
|
if (warnings <= 0) call fail('warning count API did not report warning')
|
2026-07-02 18:47:38 +08:00
|
|
|
call sph_build_model(ierr)
|
|
|
|
|
call assert_ok(ierr, 'unknown keyword input build failed')
|
|
|
|
|
call sph_finalize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'finalize failed after unknown keyword input')
|
|
|
|
|
|
2026-07-02 22:57:23 +08:00
|
|
|
call sph_initialize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'initialize failed for SPHLITE warning input')
|
|
|
|
|
call sph_read_inp('tests/data/water_unknown_sphlite_warning_021.inp', ierr)
|
|
|
|
|
call assert_ok(ierr, 'SPHLITE warning input read failed')
|
|
|
|
|
call sph_get_input_warning_count(warnings, ierr)
|
|
|
|
|
call assert_ok(ierr, 'SPHLITE warning count API failed')
|
|
|
|
|
if (warnings <= 0) call fail('SPHLITE warning was not reported')
|
|
|
|
|
call sph_build_model(ierr)
|
|
|
|
|
call assert_ok(ierr, 'SPHLITE warning input build failed')
|
|
|
|
|
call sph_finalize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'finalize failed after SPHLITE warning input')
|
|
|
|
|
|
2026-07-02 22:47:41 +08:00
|
|
|
call check_input_fails('tests/data/missing_material_011.inp')
|
2026-07-02 19:50:44 +08:00
|
|
|
call check_bad_input('tests/data/missing_section_011.inp')
|
|
|
|
|
call check_bad_input('tests/data/missing_time_control_011.inp')
|
2026-07-02 22:40:54 +08:00
|
|
|
call check_bad_input('tests/data/water_missing_density_021.inp')
|
2026-07-02 23:01:42 +08:00
|
|
|
call check_repeat_read_replaces_model()
|
2026-07-02 22:47:41 +08:00
|
|
|
call check_input_fails('tests/data/water_section_unknown_material_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_missing_eos_type_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_missing_eos_material_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_missing_eos_rho0_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_missing_eos_c0_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_missing_eos_gamma_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_bad_eos_b_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_eos_non_tait_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_missing_viscosity_field_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_missing_viscosity_type_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_missing_viscosity_material_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_bad_viscosity_alpha_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_bad_viscosity_value_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_bad_viscosity_eta2_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_bad_particle_control_020.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_bad_particle_control_value_021.inp')
|
2026-07-02 22:57:23 +08:00
|
|
|
call check_input_fails('tests/data/water_bad_particle_volume_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_bad_body_force_field_021.inp')
|
|
|
|
|
call check_input_fails('tests/data/water_bad_time_control_021.inp')
|
|
|
|
|
call check_error_context('tests/data/water_missing_eos_rho0_021.inp', ':11:')
|
2026-07-02 18:47:38 +08:00
|
|
|
|
|
|
|
|
contains
|
|
|
|
|
|
2026-07-02 19:50:44 +08:00
|
|
|
subroutine check_good_input(filename, expected_count, leave_open)
|
|
|
|
|
character(len=*), intent(in) :: filename
|
|
|
|
|
integer, intent(in) :: expected_count
|
|
|
|
|
logical, intent(in) :: leave_open
|
|
|
|
|
|
|
|
|
|
call sph_initialize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'initialize failed for good input')
|
|
|
|
|
call sph_read_inp(filename, ierr)
|
|
|
|
|
call assert_ok(ierr, 'good input read failed')
|
|
|
|
|
call sph_build_model(ierr)
|
|
|
|
|
call assert_ok(ierr, 'good model build failed')
|
|
|
|
|
call sph_get_particle_count(count, ierr)
|
|
|
|
|
call assert_ok(ierr, 'good particle count failed')
|
|
|
|
|
if (count /= expected_count) call fail('good input particle count mismatch')
|
|
|
|
|
if (.not. leave_open) then
|
|
|
|
|
call sph_finalize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'finalize failed after good input')
|
|
|
|
|
end if
|
|
|
|
|
end subroutine check_good_input
|
|
|
|
|
|
2026-07-03 00:00:53 +08:00
|
|
|
subroutine check_coupling_region_type(filename, expected_type)
|
|
|
|
|
character(len=*), intent(in) :: filename
|
|
|
|
|
integer, intent(in) :: expected_type
|
|
|
|
|
|
|
|
|
|
call sph_initialize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'initialize failed for coupling type input')
|
|
|
|
|
call sph_read_inp(filename, ierr)
|
|
|
|
|
call assert_ok(ierr, 'coupling type input read failed')
|
|
|
|
|
call sph_build_model(ierr)
|
|
|
|
|
call assert_ok(ierr, 'coupling type model build failed')
|
|
|
|
|
if (coupling_region_count <= 0) call fail('coupling type region missing')
|
|
|
|
|
if (coupling_region_type(1) /= expected_type) call fail('coupling type mismatch')
|
|
|
|
|
call sph_finalize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'finalize failed after coupling type input')
|
|
|
|
|
end subroutine check_coupling_region_type
|
|
|
|
|
|
2026-07-02 23:01:42 +08:00
|
|
|
subroutine check_repeat_read_replaces_model()
|
|
|
|
|
call sph_initialize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'initialize failed for repeat read')
|
|
|
|
|
call sph_read_inp('tests/data/water_minimal_021.inp', ierr)
|
|
|
|
|
call assert_ok(ierr, 'first repeat read failed')
|
|
|
|
|
call sph_build_model(ierr)
|
|
|
|
|
call assert_ok(ierr, 'first repeat build failed')
|
|
|
|
|
call sph_get_particle_count(count, ierr)
|
|
|
|
|
call assert_ok(ierr, 'first repeat count failed')
|
|
|
|
|
if (count /= 4) call fail('first repeat count mismatch')
|
|
|
|
|
call sph_read_inp('tests/data/water_eos_no_p0_021.inp', ierr)
|
|
|
|
|
call assert_ok(ierr, 'second repeat read failed')
|
|
|
|
|
call sph_build_model(ierr)
|
|
|
|
|
call assert_ok(ierr, 'second repeat build failed')
|
|
|
|
|
call sph_get_particle_count(count, ierr)
|
|
|
|
|
call assert_ok(ierr, 'second repeat count failed')
|
|
|
|
|
if (count /= 1) call fail('repeat read did not replace model')
|
|
|
|
|
call sph_finalize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'finalize failed after repeat read')
|
|
|
|
|
end subroutine check_repeat_read_replaces_model
|
|
|
|
|
|
2026-07-02 22:47:41 +08:00
|
|
|
subroutine check_first_phase(filename, expected_phase)
|
|
|
|
|
character(len=*), intent(in) :: filename
|
|
|
|
|
integer, intent(in) :: expected_phase
|
|
|
|
|
|
|
|
|
|
call sph_initialize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'initialize failed for phase input')
|
|
|
|
|
call sph_read_inp(filename, ierr)
|
|
|
|
|
call assert_ok(ierr, 'phase input read failed')
|
|
|
|
|
call sph_build_model(ierr)
|
|
|
|
|
call assert_ok(ierr, 'phase model build failed')
|
|
|
|
|
if (particle_phase(1) /= expected_phase) call fail('input phase mismatch')
|
|
|
|
|
call sph_finalize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'finalize failed after phase input')
|
|
|
|
|
end subroutine check_first_phase
|
|
|
|
|
|
2026-07-02 19:50:44 +08:00
|
|
|
subroutine check_bad_input(filename)
|
|
|
|
|
character(len=*), intent(in) :: filename
|
|
|
|
|
|
|
|
|
|
call sph_initialize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'initialize failed for bad input')
|
|
|
|
|
call sph_read_inp(filename, ierr)
|
|
|
|
|
call assert_ok(ierr, 'bad input read should still parse nodes')
|
|
|
|
|
call sph_build_model(ierr)
|
|
|
|
|
if (ierr == SPH_SUCCESS) call fail('bad input did not fail model build')
|
|
|
|
|
call sph_finalize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'finalize failed after bad input')
|
|
|
|
|
end subroutine check_bad_input
|
|
|
|
|
|
2026-07-02 22:47:41 +08:00
|
|
|
subroutine check_input_fails(filename)
|
|
|
|
|
character(len=*), intent(in) :: filename
|
|
|
|
|
|
|
|
|
|
call sph_initialize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'initialize failed for failing input')
|
|
|
|
|
call sph_read_inp(filename, ierr)
|
|
|
|
|
if (ierr == SPH_SUCCESS) then
|
|
|
|
|
call sph_build_model(ierr)
|
|
|
|
|
if (ierr == SPH_SUCCESS) call fail('failing input built successfully')
|
|
|
|
|
end if
|
|
|
|
|
call sph_finalize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'finalize failed after failing input')
|
|
|
|
|
end subroutine check_input_fails
|
|
|
|
|
|
2026-07-02 22:57:23 +08:00
|
|
|
subroutine check_error_context(filename, line_fragment)
|
|
|
|
|
character(len=*), intent(in) :: filename
|
|
|
|
|
character(len=*), intent(in) :: line_fragment
|
|
|
|
|
integer :: code
|
|
|
|
|
character(len=256) :: message
|
|
|
|
|
|
|
|
|
|
call sph_initialize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'initialize failed for error context')
|
|
|
|
|
call sph_read_inp(filename, ierr)
|
|
|
|
|
if (ierr == SPH_SUCCESS) call fail('error context input did not fail')
|
|
|
|
|
call sph_get_last_error(code, message, ierr)
|
|
|
|
|
call assert_ok(ierr, 'last error query failed')
|
|
|
|
|
if (index(message, trim(filename)) <= 0) call fail('input error missing filename')
|
|
|
|
|
if (index(message, trim(line_fragment)) <= 0) call fail('input error missing line context')
|
|
|
|
|
call sph_finalize(ierr)
|
|
|
|
|
call assert_ok(ierr, 'finalize failed after error context')
|
|
|
|
|
end subroutine check_error_context
|
|
|
|
|
|
2026-07-02 18:47:38 +08:00
|
|
|
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_input
|