109 lines
5.0 KiB
Fortran
109 lines
5.0 KiB
Fortran
program test_gas_restart
|
|
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_advance_explicit, sph_write_restart, sph_read_restart, &
|
|
sph_get_gas_summary, sph_get_gas_bubble_metrics, sph_get_gas_dt_limits
|
|
use sph_database, only: particle_phase, gas_volume, gas_center, &
|
|
gas_equivalent_radius, gas_previous_equivalent_radius, gas_radius_rate, &
|
|
gas_dtcrit, SPH_PHASE_GAS
|
|
use sph_gas, only: gas_eos_type, gas_default_h, gas_default_mass, &
|
|
gas_default_volume, gas_body_force, gas_material_count, &
|
|
sph_gas_add_source_by_particle, sph_gas_get_source_summary
|
|
implicit none
|
|
|
|
integer :: ierr
|
|
integer :: eos_type_before
|
|
real(rk) :: volume_before
|
|
real(rk) :: center_before(3)
|
|
real(rk) :: radius_before
|
|
real(rk) :: previous_radius_before
|
|
real(rk) :: radius_rate_before
|
|
real(rk) :: dtcrit_before
|
|
real(rk) :: api_volume
|
|
real(rk) :: api_center(3)
|
|
real(rk) :: api_mean_pressure
|
|
real(rk) :: api_max_pressure
|
|
real(rk) :: api_radius
|
|
real(rk) :: api_radius_rate
|
|
real(rk) :: api_dt_cfl
|
|
real(rk) :: api_dt_accel
|
|
real(rk) :: api_dtcrit
|
|
real(rk) :: source_momentum(3)
|
|
real(rk) :: source_mass
|
|
real(rk) :: source_energy
|
|
|
|
call sph_initialize(ierr)
|
|
call assert_ok(ierr, 'initialize failed for Gas restart')
|
|
call sph_read_inp('tests/data/gas_ideal_minimal_030.inp', ierr)
|
|
call assert_ok(ierr, 'Gas restart input read failed')
|
|
call sph_build_model(ierr)
|
|
call assert_ok(ierr, 'Gas restart build failed')
|
|
call sph_advance_explicit(1.0e-6_rk, ierr)
|
|
call assert_ok(ierr, 'Gas restart advance failed')
|
|
source_momentum = (/0.1_rk, 0.2_rk, 0.3_rk/)
|
|
call sph_gas_add_source_by_particle(1, 0.5_rk, source_momentum, 1.5_rk, ierr)
|
|
call assert_ok(ierr, 'Gas restart source add failed')
|
|
eos_type_before = gas_eos_type
|
|
volume_before = gas_volume
|
|
center_before = gas_center
|
|
radius_before = gas_equivalent_radius
|
|
previous_radius_before = gas_previous_equivalent_radius
|
|
radius_rate_before = gas_radius_rate
|
|
dtcrit_before = gas_dtcrit
|
|
if (gas_default_h <= 0.0_rk .or. gas_default_mass <= 0.0_rk .or. &
|
|
gas_default_volume <= 0.0_rk) call fail('Gas restart defaults missing')
|
|
if (maxval(abs(gas_body_force)) > 1.0e-12_rk) call fail('Gas body force restart mismatch')
|
|
call sph_write_restart('build-codex-unix/restart_gas.tmp', ierr)
|
|
call assert_ok(ierr, 'Gas restart write failed')
|
|
call sph_read_restart('build-codex-unix/restart_gas.tmp', ierr)
|
|
call assert_ok(ierr, 'Gas restart read failed')
|
|
if (particle_phase(1) /= SPH_PHASE_GAS) call fail('Gas restart phase mismatch')
|
|
if (gas_eos_type /= eos_type_before) call fail('Gas restart EOS type mismatch')
|
|
if (gas_material_count /= 1) call fail('Gas restart material table mismatch')
|
|
if (abs(gas_volume - volume_before) > 1.0e-12_rk) call fail('Gas restart volume mismatch')
|
|
if (maxval(abs(gas_center - center_before)) > 1.0e-12_rk) call fail('Gas restart center mismatch')
|
|
if (abs(gas_equivalent_radius - radius_before) > 1.0e-12_rk) then
|
|
call fail('Gas restart equivalent radius mismatch')
|
|
end if
|
|
if (abs(gas_previous_equivalent_radius - previous_radius_before) > 1.0e-12_rk) then
|
|
call fail('Gas restart previous radius mismatch')
|
|
end if
|
|
if (abs(gas_radius_rate - radius_rate_before) > 1.0e-12_rk) call fail('Gas restart radius rate mismatch')
|
|
if (abs(gas_dtcrit - dtcrit_before) > 1.0e-12_rk) call fail('Gas restart dtcrit mismatch')
|
|
call sph_get_gas_summary(api_volume, api_center, api_mean_pressure, api_max_pressure, ierr)
|
|
call assert_ok(ierr, 'Gas summary API after restart failed')
|
|
if (api_volume <= 0.0_rk .or. api_max_pressure <= 0.0_rk) call fail('Gas API summary mismatch')
|
|
call sph_get_gas_bubble_metrics(api_radius, api_radius_rate, api_center, ierr)
|
|
call assert_ok(ierr, 'Gas bubble API after restart failed')
|
|
if (api_radius <= 0.0_rk) call fail('Gas API bubble mismatch')
|
|
call sph_get_gas_dt_limits(api_dt_cfl, api_dt_accel, api_dtcrit, ierr)
|
|
call assert_ok(ierr, 'Gas dt API after restart failed')
|
|
if (api_dt_cfl <= 0.0_rk .or. api_dtcrit <= 0.0_rk) call fail('Gas API dt mismatch')
|
|
call sph_gas_get_source_summary(source_mass, source_momentum, source_energy, ierr)
|
|
call assert_ok(ierr, 'Gas source API after restart failed')
|
|
if (abs(source_mass - 0.5_rk) > 1.0e-12_rk) call fail('Gas source mass restart mismatch')
|
|
if (abs(source_energy - 1.5_rk) > 1.0e-12_rk) call fail('Gas source energy restart mismatch')
|
|
call sph_advance_explicit(1.0e-6_rk, ierr)
|
|
call assert_ok(ierr, 'Gas restart continue step failed')
|
|
call sph_finalize(ierr)
|
|
call assert_ok(ierr, 'finalize failed for Gas restart')
|
|
|
|
contains
|
|
|
|
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_gas_restart
|