program test_solver_gas 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_estimate_stable_dt, sph_get_current_time, & sph_get_gas_summary, sph_get_gas_bubble_metrics, sph_get_gas_dt_limits use sph_database, only: x, v, a, rho, pressure, gas_dtcrit, gas_particle_count, & water_mass implicit none integer :: ierr integer :: step real(rk) :: time call check_gas_single_step() call check_water_single_phase_regression() contains subroutine check_gas_single_step() real(rk) :: dtcrit real(rk) :: x_before(3) 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 call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for Gas solver') call sph_read_inp('tests/data/gas_ideal_minimal_030.inp', ierr) call assert_ok(ierr, 'Gas solver input read failed') call sph_build_model(ierr) call assert_ok(ierr, 'Gas solver build failed') v(:,1) = (/1.0_rk, 0.0_rk, 0.0_rk/) x_before = x(:,1) call sph_estimate_stable_dt(dtcrit, ierr) call assert_ok(ierr, 'Gas dt estimate failed') if (dtcrit <= 0.0_rk) call fail('Gas dtcrit is not positive') if (gas_dtcrit <= 0.0_rk) call fail('Gas dt diagnostic is not positive') call sph_get_gas_summary(api_volume, api_center, api_mean_pressure, api_max_pressure, ierr) call assert_ok(ierr, 'Gas summary API failed') if (api_volume <= 0.0_rk .or. api_max_pressure <= 0.0_rk) call fail('Gas summary API mismatch') call sph_get_gas_bubble_metrics(api_radius, api_radius_rate, api_center, ierr) call assert_ok(ierr, 'Gas bubble API failed') if (api_radius <= 0.0_rk) call fail('Gas bubble API mismatch') call sph_get_gas_dt_limits(api_dt_cfl, api_dt_accel, api_dtcrit, ierr) call assert_ok(ierr, 'Gas dt API failed') if (api_dt_cfl <= 0.0_rk .or. api_dtcrit <= 0.0_rk) call fail('Gas dt API mismatch') call sph_advance_explicit(1.0e-6_rk, ierr) call assert_ok(ierr, 'Gas explicit advance failed') call sph_get_current_time(time, step, ierr) call assert_ok(ierr, 'Gas current time failed') if (step /= 1) call fail('Gas explicit step mismatch') if (abs(time - 1.0e-6_rk) > 1.0e-12_rk) call fail('Gas explicit time mismatch') if (x(1,1) <= x_before(1)) call fail('Gas particle position did not advance') if (.not. finite_vector(x(:,1))) call fail('Gas position is not finite') if (.not. finite_vector(v(:,1))) call fail('Gas velocity is not finite') if (.not. finite_vector(a(:,1))) call fail('Gas acceleration is not finite') if (.not. finite_scalar(rho(1))) call fail('Gas density is not finite') if (.not. finite_scalar(pressure(1))) call fail('Gas pressure is not finite') if (gas_particle_count /= 4) call fail('Gas diagnostics lost particles') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for Gas solver') end subroutine check_gas_single_step subroutine check_water_single_phase_regression() real(rk) :: rho_before call sph_initialize(ierr) call assert_ok(ierr, 'initialize failed for Water regression') call sph_read_inp('tests/data/water_minimal_020.inp', ierr) call assert_ok(ierr, 'Water regression input read failed') call sph_build_model(ierr) call assert_ok(ierr, 'Water regression build failed') rho_before = rho(1) call sph_advance_explicit(1.0e-6_rk, ierr) call assert_ok(ierr, 'Water regression advance failed') if (abs(rho(1) - rho_before) > 1.0e-6_rk) call fail('Gas path changed Water density') if (water_mass <= 0.0_rk) call fail('Water diagnostics were not preserved') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for Water regression') end subroutine check_water_single_phase_regression 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 logical function finite_scalar(value_in) real(rk), intent(in) :: value_in finite_scalar = value_in == value_in .and. abs(value_in) < huge(value_in) end function finite_scalar logical function finite_vector(value_in) real(rk), intent(in) :: value_in(:) finite_vector = all(value_in == value_in) .and. maxval(abs(value_in)) < huge(value_in(1)) end function finite_vector subroutine fail(message) character(len=*), intent(in) :: message write(*, '(A)') trim(message) stop 1 end subroutine fail end program test_solver_gas