170 lines
6.8 KiB
Fortran
170 lines
6.8 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, x
|
|
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 run_pressure_wave_case('tests/data/water_pressure_wave_020.inp', .true.)
|
|
call run_pressure_wave_case('tests/data/water_pressure_wave_3d_021.inp', .false.)
|
|
|
|
contains
|
|
|
|
subroutine run_pressure_wave_case(filename, linear_case)
|
|
character(len=*), intent(in) :: filename
|
|
logical, intent(in) :: linear_case
|
|
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed')
|
|
call sph_read_inp(filename, ierr)
|
|
call assert_ok(ierr, 'read pressure wave input failed')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'build pressure wave model failed')
|
|
|
|
if (.not. linear_case) then
|
|
if (abs(x(2,3)) <= 0.0_rk .or. abs(x(3,4)) <= 0.0_rk) then
|
|
call fail('3D pressure wave layout is not non-collinear')
|
|
end if
|
|
end if
|
|
|
|
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 (.not. is_finite(min_density)) call fail('pressure wave min density is not finite')
|
|
if (.not. is_finite(max_density)) call fail('pressure wave max density is not finite')
|
|
if (max_pressure <= 0.0_rk) call fail('pressure wave pressure perturbation missing')
|
|
if (linear_case) then
|
|
if (v(1,2) <= 0.0_rk) call fail('pressure wave did not propagate along +x')
|
|
else
|
|
if (v(1,2) <= 0.0_rk .or. v(2,3) <= 0.0_rk .or. v(3,4) <= 0.0_rk) then
|
|
call fail('3D pressure wave did not propagate outward')
|
|
end if
|
|
end if
|
|
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')
|
|
! Smoke threshold only: this is not an engineering accuracy benchmark.
|
|
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')
|
|
end subroutine run_pressure_wave_case
|
|
|
|
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_step
|
|
logical :: found_time
|
|
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, 'id') <= 0) call fail('pressure wave id field missing')
|
|
if (index(line, 'phase') <= 0) call fail('pressure wave phase field missing')
|
|
if (index(line, 'x') <= 0) call fail('pressure wave coordinate field missing')
|
|
if (index(line, 'vx') <= 0) call fail('pressure wave velocity field missing')
|
|
if (index(line, 'rho') <= 0) call fail('pressure wave rho field 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_step = .false.
|
|
found_time = .false.
|
|
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, 'step') > 0) found_step = .true.
|
|
if (index(line, 'time') > 0) found_time = .true.
|
|
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_step) call fail('pressure wave step field missing')
|
|
if (.not. found_time) call fail('pressure wave time field missing')
|
|
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
|