134 lines
5.1 KiB
Fortran
134 lines
5.1 KiB
Fortran
program test_pressure_wave_smoke
|
|
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_run_explicit, sph_get_current_time, sph_get_water_summary, &
|
|
sph_set_output_directory, sph_write_output
|
|
use sph_database, only: rho, v
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
integer :: step
|
|
real(rk) :: time
|
|
real(rk) :: initial_mass
|
|
real(rk) :: final_mass
|
|
real(rk) :: momentum(3)
|
|
real(rk) :: max_pressure
|
|
real(rk) :: min_density
|
|
real(rk) :: max_density
|
|
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed')
|
|
call sph_read_inp('tests/data/water_pressure_wave_020.inp', ierr)
|
|
call assert_ok(ierr, 'read pressure wave input failed')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build pressure wave model failed')
|
|
|
|
rho(1) = 1020.0_rk
|
|
call sph_get_water_summary(initial_mass, momentum, max_pressure, &
|
|
min_density, max_density, ierr)
|
|
call assert_ok(ierr, 'initial pressure wave summary failed')
|
|
|
|
call sph_run_explicit(ierr)
|
|
call assert_ok(ierr, 'run pressure wave failed')
|
|
call sph_get_current_time(time, step, ierr)
|
|
call assert_ok(ierr, 'pressure wave time query failed')
|
|
if (step /= 3) call fail('pressure wave step count mismatch')
|
|
if (time <= 0.0_rk) call fail('pressure wave time did not advance')
|
|
|
|
call sph_get_water_summary(final_mass, momentum, max_pressure, &
|
|
min_density, max_density, ierr)
|
|
call assert_ok(ierr, 'final pressure wave summary failed')
|
|
if (.not. is_finite(max_pressure)) call fail('pressure wave pressure is not finite')
|
|
if (max_pressure <= 0.0_rk) call fail('pressure wave pressure perturbation missing')
|
|
if (v(1,2) <= 0.0_rk) call fail('pressure wave did not propagate along +x')
|
|
if (abs(final_mass - initial_mass) > 1.0e-12_rk) call fail('pressure wave mass drifted')
|
|
if (.not. vector_is_finite(momentum)) call fail('pressure wave momentum is not finite')
|
|
if (sqrt(sum(momentum * momentum)) > 1.0e-3_rk) call fail('pressure wave momentum drift too large')
|
|
|
|
call sph_set_output_directory('build-codex-unix', ierr)
|
|
call assert_ok(ierr, 'set pressure wave output directory failed')
|
|
call sph_write_output(step, time, ierr)
|
|
call assert_ok(ierr, 'write pressure wave output failed')
|
|
call check_output_fields(step)
|
|
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed')
|
|
|
|
contains
|
|
|
|
subroutine check_output_fields(step_value)
|
|
integer, intent(in) :: step_value
|
|
character(len=256) :: particle_file
|
|
character(len=256) :: summary_file
|
|
character(len=512) :: line
|
|
logical :: exists
|
|
logical :: found_mass
|
|
logical :: found_pressure
|
|
logical :: found_dtcrit
|
|
integer :: ios
|
|
|
|
write(particle_file, '("build-codex-unix/sphlite_", I8.8, ".csv")') step_value
|
|
inquire(file=trim(particle_file), exist=exists)
|
|
if (.not. exists) call fail('pressure wave particle output missing')
|
|
open(unit=71, file=trim(particle_file), status='old', action='read', iostat=ios)
|
|
if (ios /= 0) call fail('pressure wave particle output open failed')
|
|
read(71, '(A)', iostat=ios) line
|
|
close(unit=71)
|
|
if (ios /= 0) call fail('pressure wave particle output header missing')
|
|
if (index(line, 'pressure') <= 0) call fail('pressure wave pressure field missing')
|
|
if (index(line, 'h') <= 0) call fail('pressure wave h field missing')
|
|
|
|
write(summary_file, '("build-codex-unix/sphlite_", I8.8, "_summary.csv")') step_value
|
|
inquire(file=trim(summary_file), exist=exists)
|
|
if (.not. exists) call fail('pressure wave summary output missing')
|
|
found_mass = .false.
|
|
found_pressure = .false.
|
|
found_dtcrit = .false.
|
|
open(unit=72, file=trim(summary_file), status='old', action='read', iostat=ios)
|
|
if (ios /= 0) call fail('pressure wave summary output open failed')
|
|
do
|
|
read(72, '(A)', iostat=ios) line
|
|
if (ios /= 0) exit
|
|
if (index(line, 'water_mass') > 0) found_mass = .true.
|
|
if (index(line, 'max_pressure') > 0) found_pressure = .true.
|
|
if (index(line, 'dtcrit') > 0) found_dtcrit = .true.
|
|
end do
|
|
close(unit=72)
|
|
if (.not. found_mass) call fail('pressure wave water_mass field missing')
|
|
if (.not. found_pressure) call fail('pressure wave max_pressure field missing')
|
|
if (.not. found_dtcrit) call fail('pressure wave dtcrit field missing')
|
|
end subroutine check_output_fields
|
|
|
|
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
|
|
|
|
logical function is_finite(value)
|
|
real(rk), intent(in) :: value
|
|
|
|
is_finite = (value == value .and. abs(value) < huge(1.0_rk))
|
|
end function is_finite
|
|
|
|
logical function vector_is_finite(values)
|
|
real(rk), intent(in) :: values(3)
|
|
integer :: i
|
|
|
|
vector_is_finite = .true.
|
|
do i = 1, 3
|
|
if (.not. is_finite(values(i))) vector_is_finite = .false.
|
|
end do
|
|
end function vector_is_finite
|
|
|
|
end program test_pressure_wave_smoke
|