Add Gas source placeholders
This commit is contained in:
+157
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user