diff --git a/CMakeLists.txt b/CMakeLists.txt index ab0a399..5488692 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,6 +216,18 @@ set_target_properties(test_gas_summary PROPERTIES Fortran_MODULE_DIRECTORY "${SP add_test(NAME gas_summary COMMAND test_gas_summary) set_tests_properties(gas_summary PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") +add_executable(test_gas_source tests/module/test_gas_source.f90) +target_link_libraries(test_gas_source PRIVATE sphlite_core) +set_target_properties(test_gas_source PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME gas_source COMMAND test_gas_source) +set_tests_properties(gas_source PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_executable(test_gas_source_errors tests/module/test_gas_source_errors.f90) +target_link_libraries(test_gas_source_errors PRIVATE sphlite_core) +set_target_properties(test_gas_source_errors PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") +add_test(NAME gas_source_errors COMMAND test_gas_source_errors) +set_tests_properties(gas_source_errors PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + add_executable(test_solver_gas tests/module/test_solver_gas.f90) target_link_libraries(test_solver_gas PRIVATE sphlite_core) set_target_properties(test_solver_gas PROPERTIES Fortran_MODULE_DIRECTORY "${SPHLITE_MODULE_DIR}") diff --git a/src/gas/sph_gas.f90 b/src/gas/sph_gas.f90 index 89b4e11..7cd61d9 100644 --- a/src/gas/sph_gas.f90 +++ b/src/gas/sph_gas.f90 @@ -1,7 +1,7 @@ module sph_gas use sph_precision, only: rk, SPH_NDIM use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, SPH_ERROR_INPUT, & - sph_error_set + SPH_ERROR_DATABASE, sph_error_set use sph_database, only: npart, SPH_MAX_MATERIALS, particle_phase, & particle_status, material_id, material_count, material_name, & material_type, material_density, & @@ -63,6 +63,12 @@ module sph_gas real(rk) :: gas_material_default_h(SPH_MAX_MATERIALS) = 1.0_rk real(rk) :: gas_material_default_mass(SPH_MAX_MATERIALS) = 1.0_rk real(rk) :: gas_material_default_volume(SPH_MAX_MATERIALS) = 1.0_rk + real(rk), allocatable :: gas_mass_source(:) + real(rk), allocatable :: gas_energy_source(:) + real(rk), allocatable :: gas_momentum_source(:,:) + real(rk) :: gas_source_mass_total = 0.0_rk + real(rk) :: gas_source_energy_total = 0.0_rk + real(rk) :: gas_source_momentum_total(SPH_NDIM) = 0.0_rk contains @@ -118,6 +124,12 @@ contains gas_material_default_h = 1.0_rk gas_material_default_mass = 1.0_rk gas_material_default_volume = 1.0_rk + gas_source_mass_total = 0.0_rk + gas_source_energy_total = 0.0_rk + gas_source_momentum_total = 0.0_rk + if (allocated(gas_mass_source)) deallocate(gas_mass_source) + if (allocated(gas_energy_source)) deallocate(gas_energy_source) + if (allocated(gas_momentum_source)) deallocate(gas_momentum_source) gas_previous_equivalent_radius = 0.0_rk gas_previous_center = 0.0_rk call sph_db_clear_gas_diagnostics() @@ -397,6 +409,8 @@ contains if (.not. gas_material_seen) return call sph_gas_validate_input(ierr) if (ierr /= SPH_SUCCESS) return + call sph_gas_allocate_sources(ierr) + if (ierr /= SPH_SUCCESS) return do i = 1, npart if (particle_status(i) /= SPH_STATUS_ACTIVE) cycle if (.not. sph_gas_is_material_particle(i)) cycle @@ -620,6 +634,138 @@ contains ierr = SPH_SUCCESS end subroutine sph_gas_compute_acceleration + subroutine sph_gas_allocate_sources(ierr) + integer, intent(out) :: ierr + integer :: stat + + ierr = SPH_SUCCESS + if (npart <= 0) return + if (allocated(gas_mass_source)) then + if (size(gas_mass_source) == npart) return + deallocate(gas_mass_source) + deallocate(gas_energy_source) + deallocate(gas_momentum_source) + end if + allocate(gas_mass_source(npart), gas_energy_source(npart), & + gas_momentum_source(SPH_NDIM,npart), stat=stat) + if (stat /= 0) then + call sph_error_set(SPH_ERROR_DATABASE, 'failed to allocate Gas source state') + ierr = SPH_ERROR_DATABASE + return + end if + gas_mass_source = 0.0_rk + gas_energy_source = 0.0_rk + gas_momentum_source = 0.0_rk + end subroutine sph_gas_allocate_sources + + subroutine sph_gas_clear_sources(ierr) + integer, intent(out) :: ierr + + call sph_gas_allocate_sources(ierr) + if (ierr /= SPH_SUCCESS) return + if (allocated(gas_mass_source)) gas_mass_source = 0.0_rk + if (allocated(gas_energy_source)) gas_energy_source = 0.0_rk + if (allocated(gas_momentum_source)) gas_momentum_source = 0.0_rk + gas_source_mass_total = 0.0_rk + gas_source_energy_total = 0.0_rk + gas_source_momentum_total = 0.0_rk + end subroutine sph_gas_clear_sources + + subroutine sph_gas_add_source_by_particle(index, mass_rate, momentum_rate, & + energy_rate, ierr) + integer, intent(in) :: index + real(rk), intent(in) :: mass_rate + real(rk), intent(in) :: momentum_rate(SPH_NDIM) + real(rk), intent(in) :: energy_rate + integer, intent(out) :: ierr + + call sph_gas_allocate_sources(ierr) + if (ierr /= SPH_SUCCESS) return + if (index < 1 .or. index > npart) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas source particle id is out of range') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (.not. sph_gas_is_active_particle(index)) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas source target must be active Gas') + ierr = SPH_ERROR_ARGUMENT + return + end if + if (.not. sph_gas_is_finite(mass_rate) .or. & + .not. sph_gas_is_finite(energy_rate) .or. & + .not. sph_gas_vector_is_finite(momentum_rate)) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas source value is not finite') + ierr = SPH_ERROR_ARGUMENT + return + end if + gas_mass_source(index) = gas_mass_source(index) + mass_rate + gas_energy_source(index) = gas_energy_source(index) + energy_rate + gas_momentum_source(:,index) = gas_momentum_source(:,index) + momentum_rate + call sph_gas_update_source_totals() + end subroutine sph_gas_add_source_by_particle + + subroutine sph_gas_apply_sources_explicit(dt, ierr) + real(rk), intent(in) :: dt + integer, intent(out) :: ierr + integer :: i + real(rk) :: new_mass + real(rk) :: momentum_value(SPH_NDIM) + + ierr = SPH_SUCCESS + if (dt <= 0.0_rk) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas source time step must be positive') + ierr = SPH_ERROR_ARGUMENT + return + end if + call sph_gas_allocate_sources(ierr) + if (ierr /= SPH_SUCCESS) return + do i = 1, npart + if (.not. sph_gas_is_active_particle(i)) cycle + new_mass = mass(i) + dt * gas_mass_source(i) + if (new_mass <= 0.0_rk) then + call sph_error_set(SPH_ERROR_ARGUMENT, 'Gas source produced nonpositive mass') + ierr = SPH_ERROR_ARGUMENT + return + end if + momentum_value = mass(i) * v(:,i) + dt * gas_momentum_source(:,i) + mass(i) = new_mass + v(:,i) = momentum_value / new_mass + internal_energy(i) = internal_energy(i) + dt * gas_energy_source(i) / new_mass + end do + call sph_gas_update_pressure(ierr) + if (ierr /= SPH_SUCCESS) return + call sph_gas_update_source_totals() + end subroutine sph_gas_apply_sources_explicit + + subroutine sph_gas_get_source_summary(mass_source, momentum_source, & + energy_source, ierr) + real(rk), intent(out) :: mass_source + real(rk), intent(out) :: momentum_source(SPH_NDIM) + real(rk), intent(out) :: energy_source + integer, intent(out) :: ierr + + call sph_gas_allocate_sources(ierr) + if (ierr /= SPH_SUCCESS) return + call sph_gas_update_source_totals() + mass_source = gas_source_mass_total + momentum_source = gas_source_momentum_total + energy_source = gas_source_energy_total + end subroutine sph_gas_get_source_summary + + subroutine sph_gas_update_source_totals() + integer :: i + + gas_source_mass_total = 0.0_rk + gas_source_energy_total = 0.0_rk + gas_source_momentum_total = 0.0_rk + if (.not. allocated(gas_mass_source)) return + do i = 1, npart + gas_source_mass_total = gas_source_mass_total + gas_mass_source(i) + gas_source_energy_total = gas_source_energy_total + gas_energy_source(i) + gas_source_momentum_total = gas_source_momentum_total + gas_momentum_source(:,i) + end do + end subroutine sph_gas_update_source_totals + subroutine sph_gas_update_diagnostics(ierr) integer, intent(out) :: ierr integer :: i @@ -901,6 +1047,16 @@ contains sph_gas_is_finite = value == value .and. abs(value) < huge(value) end function sph_gas_is_finite + logical function sph_gas_vector_is_finite(values) + real(rk), intent(in) :: values(SPH_NDIM) + integer :: i + + sph_gas_vector_is_finite = .true. + do i = 1, SPH_NDIM + if (.not. sph_gas_is_finite(values(i))) sph_gas_vector_is_finite = .false. + end do + end function sph_gas_vector_is_finite + function sph_gas_upper(text) result(out) character(len=*), intent(in) :: text character(len=len(text)) :: out diff --git a/src/output/sph_output_csv.f90 b/src/output/sph_output_csv.f90 index 29c6872..906ab18 100644 --- a/src/output/sph_output_csv.f90 +++ b/src/output/sph_output_csv.f90 @@ -7,7 +7,10 @@ module sph_output_csv water_mass, water_momentum, water_max_pressure, water_min_density, & water_max_density, water_dt_cfl, water_dt_accel, water_dt_viscous, & gas_particle_count, gas_mass, gas_volume, gas_center, gas_mean_pressure, & - gas_max_pressure, gas_equivalent_radius, gas_radius_rate, gas_dtcrit + gas_max_pressure, gas_min_density, gas_max_density, gas_momentum, & + gas_equivalent_radius, gas_radius_rate, gas_dt_cfl, gas_dt_accel, & + gas_dtcrit + use sph_gas, only: sph_gas_get_source_summary implicit none integer, parameter :: SPH_OUTPUT_UNIT = 41 @@ -86,9 +89,18 @@ contains real(rk), intent(in) :: time integer, intent(out) :: ierr integer :: ios + integer :: local_ierr real(rk) :: dtcrit + real(rk) :: gas_source_mass + real(rk) :: gas_source_energy + real(rk) :: gas_source_momentum(3) ierr = SPH_SUCCESS + gas_source_mass = 0.0_rk + gas_source_energy = 0.0_rk + gas_source_momentum = 0.0_rk + call sph_gas_get_source_summary(gas_source_mass, gas_source_momentum, & + gas_source_energy, local_ierr) dtcrit = water_dt_cfl if (water_dt_accel > 0.0_rk .and. water_dt_accel < dtcrit) dtcrit = water_dt_accel if (water_dt_viscous > 0.0_rk .and. water_dt_viscous < dtcrit) dtcrit = water_dt_viscous @@ -118,9 +130,21 @@ contains write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_center_z', gas_center(3) write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_mean_pressure', gas_mean_pressure write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_max_pressure', gas_max_pressure + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_momentum_x', gas_momentum(1) + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_momentum_y', gas_momentum(2) + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_momentum_z', gas_momentum(3) + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_min_density', gas_min_density + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_max_density', gas_max_density write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_equivalent_radius', gas_equivalent_radius write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_radius_rate', gas_radius_rate + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_dt_cfl', gas_dt_cfl + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_dt_accel', gas_dt_accel write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_dtcrit', gas_dtcrit + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_source_mass', gas_source_mass + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_source_energy', gas_source_energy + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_source_momentum_x', gas_source_momentum(1) + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_source_momentum_y', gas_source_momentum(2) + write(SPH_OUTPUT_UNIT, '(A,",",ES24.16)') 'gas_source_momentum_z', gas_source_momentum(3) close(unit=SPH_OUTPUT_UNIT) end subroutine sph_output_write_summary diff --git a/src/solver/sph_solver_explicit.f90 b/src/solver/sph_solver_explicit.f90 index b03ca14..b2b193f 100644 --- a/src/solver/sph_solver_explicit.f90 +++ b/src/solver/sph_solver_explicit.f90 @@ -10,7 +10,7 @@ module sph_solver_explicit sph_water_estimate_dt_limits use sph_gas, only: sph_gas_update_pressure, sph_gas_compute_density_rate, & sph_gas_compute_acceleration, sph_gas_update_diagnostics, & - sph_gas_estimate_dt_limits + sph_gas_estimate_dt_limits, sph_gas_apply_sources_explicit use sph_output_csv, only: sph_output_write_step implicit none @@ -62,6 +62,8 @@ contains rho(i) = rho(i) + dt * drho_dt(i) v(:,i) = vhalf(:,i) + 0.5_rk * dt * a(:,i) end do + call sph_gas_apply_sources_explicit(dt, ierr) + if (ierr /= SPH_SUCCESS) return call sph_water_update_diagnostics(ierr) if (ierr /= SPH_SUCCESS) return call sph_gas_update_diagnostics(ierr) diff --git a/tests/module/test_gas_output.f90 b/tests/module/test_gas_output.f90 index 8cc274b..f46b625 100644 --- a/tests/module/test_gas_output.f90 +++ b/tests/module/test_gas_output.f90 @@ -31,9 +31,17 @@ contains call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_center_z') call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_mean_pressure') call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_max_pressure') + call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_momentum_x') + call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_min_density') + call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_max_density') call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_equivalent_radius') call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_radius_rate') + call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_dt_cfl') + call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_dt_accel') call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_dtcrit') + call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_source_mass') + call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_source_energy') + call assert_summary_metric('build-codex-unix/sphlite_00000030_summary.csv', 'gas_source_momentum_x') call sph_finalize(ierr) call assert_ok(ierr, 'finalize failed for Gas output') end subroutine check_gas_summary_output diff --git a/tests/module/test_gas_source.f90 b/tests/module/test_gas_source.f90 new file mode 100644 index 0000000..8333196 --- /dev/null +++ b/tests/module/test_gas_source.f90 @@ -0,0 +1,102 @@ +program test_gas_source + 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 + use sph_database, only: mass, v, internal_energy, pressure + use sph_gas, only: sph_gas_clear_sources, sph_gas_add_source_by_particle, & + sph_gas_apply_sources_explicit, sph_gas_get_source_summary + implicit none + + integer :: ierr + + call check_source_accumulate_and_clear() + call check_source_explicit_apply() + +contains + + subroutine check_source_accumulate_and_clear() + real(rk) :: momentum_source(3) + real(rk) :: mass_source + real(rk) :: energy_source + real(rk) :: add_momentum(3) + + call build_gas_case() + call sph_gas_clear_sources(ierr) + call assert_ok(ierr, 'Gas source clear failed') + add_momentum = (/3.0_rk, 4.0_rk, 5.0_rk/) + call sph_gas_add_source_by_particle(1, 2.0_rk, add_momentum, 7.0_rk, ierr) + call assert_ok(ierr, 'Gas source add failed') + call sph_gas_get_source_summary(mass_source, momentum_source, energy_source, ierr) + call assert_ok(ierr, 'Gas source summary failed') + call assert_close(mass_source, 2.0_rk, 'Gas mass source summary mismatch') + call assert_close(energy_source, 7.0_rk, 'Gas energy source summary mismatch') + call assert_close(momentum_source(2), 4.0_rk, 'Gas momentum source summary mismatch') + + call sph_gas_clear_sources(ierr) + call assert_ok(ierr, 'Gas source second clear failed') + call sph_gas_get_source_summary(mass_source, momentum_source, energy_source, ierr) + call assert_ok(ierr, 'Gas source zero summary failed') + call assert_close(mass_source, 0.0_rk, 'Gas mass source clear mismatch') + call assert_close(energy_source, 0.0_rk, 'Gas energy source clear mismatch') + call assert_close(maxval(abs(momentum_source)), 0.0_rk, 'Gas momentum source clear mismatch') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed after source clear') + end subroutine check_source_accumulate_and_clear + + subroutine check_source_explicit_apply() + real(rk) :: add_momentum(3) + real(rk) :: mass_before + real(rk) :: energy_before + real(rk) :: pressure_before + + call build_gas_case() + mass_before = mass(1) + energy_before = internal_energy(1) + pressure_before = pressure(1) + add_momentum = (/0.5_rk, 0.0_rk, 0.0_rk/) + call sph_gas_clear_sources(ierr) + call assert_ok(ierr, 'Gas source clear before apply failed') + call sph_gas_add_source_by_particle(1, 1.0_rk, add_momentum, 2.0_rk, ierr) + call assert_ok(ierr, 'Gas source add before apply failed') + call sph_gas_apply_sources_explicit(0.1_rk, ierr) + call assert_ok(ierr, 'Gas source explicit apply failed') + if (mass(1) <= mass_before) call fail('Gas source did not increase mass') + if (v(1,1) <= 0.0_rk) call fail('Gas source did not change velocity') + if (internal_energy(1) <= energy_before) call fail('Gas source did not increase energy') + if (pressure(1) <= pressure_before) call fail('Gas source did not update pressure') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed after source apply') + end subroutine check_source_explicit_apply + + subroutine build_gas_case() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for Gas source') + call sph_read_inp('tests/data/gas_air_ideal_031.inp', ierr) + call assert_ok(ierr, 'read failed for Gas source') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for Gas source') + end subroutine build_gas_case + + 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 assert_close(actual, expected, message) + real(rk), intent(in) :: actual + real(rk), intent(in) :: expected + character(len=*), intent(in) :: message + + if (abs(actual - expected) > 1.0e-12_rk) call fail(message) + end subroutine assert_close + + subroutine fail(message) + character(len=*), intent(in) :: message + + write(*, '(A)') trim(message) + stop 1 + end subroutine fail + +end program test_gas_source diff --git a/tests/module/test_gas_source_errors.f90 b/tests/module/test_gas_source_errors.f90 new file mode 100644 index 0000000..c853bfa --- /dev/null +++ b/tests/module/test_gas_source_errors.f90 @@ -0,0 +1,77 @@ +program test_gas_source_errors + 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 + use sph_gas, only: sph_gas_add_source_by_particle + implicit none + + integer :: ierr + + call check_invalid_particle() + call check_invalid_value() + call check_non_gas_particle() + +contains + + subroutine check_invalid_particle() + real(rk) :: zero_momentum(3) + + zero_momentum = 0.0_rk + call build_gas_case() + call sph_gas_add_source_by_particle(0, 1.0_rk, zero_momentum, 1.0_rk, ierr) + if (ierr == SPH_SUCCESS) call fail('invalid Gas source particle did not fail') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed after invalid particle') + end subroutine check_invalid_particle + + subroutine check_invalid_value() + real(rk) :: zero_momentum(3) + + zero_momentum = 0.0_rk + call build_gas_case() + call sph_gas_add_source_by_particle(1, huge(1.0_rk), zero_momentum, 1.0_rk, ierr) + if (ierr == SPH_SUCCESS) call fail('invalid Gas source value did not fail') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed after invalid value') + end subroutine check_invalid_value + + subroutine check_non_gas_particle() + real(rk) :: zero_momentum(3) + + zero_momentum = 0.0_rk + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for non-Gas source') + call sph_read_inp('tests/data/water_minimal_021.inp', ierr) + call assert_ok(ierr, 'read failed for non-Gas source') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for non-Gas source') + call sph_gas_add_source_by_particle(1, 1.0_rk, zero_momentum, 1.0_rk, ierr) + if (ierr == SPH_SUCCESS) call fail('non-Gas source target did not fail') + call sph_finalize(ierr) + call assert_ok(ierr, 'finalize failed after non-Gas source') + end subroutine check_non_gas_particle + + subroutine build_gas_case() + call sph_initialize(ierr) + call assert_ok(ierr, 'initialize failed for Gas source error') + call sph_read_inp('tests/data/gas_air_ideal_031.inp', ierr) + call assert_ok(ierr, 'read failed for Gas source error') + call sph_build_model(ierr) + call assert_ok(ierr, 'build failed for Gas source error') + end subroutine build_gas_case + + 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_source_errors diff --git a/todo.md b/todo.md index 57202a3..d969edb 100644 --- a/todo.md +++ b/todo.md @@ -79,26 +79,26 @@ ## 阶段 D:Gas 源项占位、诊断与输出 -- [ ] 增加 `gas_mass_source(:)` 状态数组。 -- [ ] 增加 `gas_energy_source(:)` 状态数组。 -- [ ] 增加 `gas_momentum_source(:,:)` 状态数组。 -- [ ] 在粒子数量变化或模型初始化时分配 Gas 源项数组。 -- [ ] 在模型清理时释放 Gas 源项数组。 -- [ ] 实现 `sph_gas_clear_sources` 内部过程。 -- [ ] 实现 `sph_gas_add_source_by_particle` 内部过程。 -- [ ] 实现 `sph_gas_apply_sources_explicit` 内部过程。 -- [ ] 实现 `sph_gas_get_source_summary` 内部过程。 -- [ ] 对非法粒子 id 添加 Gas 源项时报 error。 -- [ ] 对非 Gas 粒子添加 Gas 源项时报 error。 -- [ ] 对非法数值源项添加 Gas 源项时报 error。 -- [ ] 增加 Gas 质量源项累计和清零测试。 -- [ ] 增加 Gas 动量源项累计和清零测试。 -- [ ] 增加 Gas 能量源项累计和清零测试。 -- [ ] 增加 Gas 源项显式应用后质量变化测试。 -- [ ] 增加 Gas 源项显式应用后速度或动量变化测试。 -- [ ] 增加 Gas 源项显式应用后内能或能量变化测试。 -- [ ] 扩展 Gas summary,输出动量和密度范围。 -- [ ] 扩展 Gas output,输出稳定的 0.3.1 诊断字段。 +- [x] 增加 `gas_mass_source(:)` 状态数组。 +- [x] 增加 `gas_energy_source(:)` 状态数组。 +- [x] 增加 `gas_momentum_source(:,:)` 状态数组。 +- [x] 在粒子数量变化或模型初始化时分配 Gas 源项数组。 +- [x] 在模型清理时释放 Gas 源项数组。 +- [x] 实现 `sph_gas_clear_sources` 内部过程。 +- [x] 实现 `sph_gas_add_source_by_particle` 内部过程。 +- [x] 实现 `sph_gas_apply_sources_explicit` 内部过程。 +- [x] 实现 `sph_gas_get_source_summary` 内部过程。 +- [x] 对非法粒子 id 添加 Gas 源项时报 error。 +- [x] 对非 Gas 粒子添加 Gas 源项时报 error。 +- [x] 对非法数值源项添加 Gas 源项时报 error。 +- [x] 增加 Gas 质量源项累计和清零测试。 +- [x] 增加 Gas 动量源项累计和清零测试。 +- [x] 增加 Gas 能量源项累计和清零测试。 +- [x] 增加 Gas 源项显式应用后质量变化测试。 +- [x] 增加 Gas 源项显式应用后速度或动量变化测试。 +- [x] 增加 Gas 源项显式应用后内能或能量变化测试。 +- [x] 扩展 Gas summary,输出动量和密度范围。 +- [x] 扩展 Gas output,输出稳定的 0.3.1 诊断字段。 ## 阶段 E:Restart、API、C++、Python 与 CLI