Connect water forces to explicit setup

This commit is contained in:
Codex
2026-07-02 20:44:19 +08:00
parent 52617f2f03
commit 662129d2bb
6 changed files with 241 additions and 27 deletions
+3
View File
@@ -12,6 +12,7 @@ module sph_input_reader
use sph_water, only: sph_water_note_material, sph_water_set_eos, &
sph_water_set_viscosity, sph_water_set_particle_control, &
sph_water_set_body_force, sph_water_apply_initial_conditions
use sph_neighbor, only: sph_neighbor_rebuild
use sph_inp_defs, only: SPH_INPUT_LINE_LEN, SPH_INPUT_FIELD_LEN, &
SPH_INPUT_MAX_FIELDS, SPH_KEY_NODE, SPH_KEY_ELEMENT, SPH_KEY_NSET, &
SPH_KEY_ELSET, SPH_KEY_MATERIAL, SPH_KEY_SECTION, SPH_KEY_SPHLITE, &
@@ -92,6 +93,8 @@ contains
return
end if
call sph_water_apply_initial_conditions(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_neighbor_rebuild(ierr)
end subroutine sph_input_build_model
subroutine sph_input_scan(filename, node_count, ierr)
+13
View File
@@ -3,6 +3,9 @@ module sph_solver_explicit
use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, sph_error_set
use sph_control, only: current_time, current_step, dt_default, end_time, max_steps
use sph_database, only: npart, x, v, a, vhalf
use sph_neighbor, only: sph_neighbor_rebuild
use sph_water, only: sph_water_update_pressure, sph_water_compute_density_rate, &
sph_water_compute_acceleration, sph_water_update_diagnostics
implicit none
contains
@@ -28,11 +31,21 @@ contains
end if
if (npart > 0) then
call sph_neighbor_rebuild(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_water_update_pressure(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_water_compute_density_rate(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_water_compute_acceleration(ierr)
if (ierr /= SPH_SUCCESS) return
do i = 1, npart
vhalf(:,i) = v(:,i) + 0.5_rk * dt * a(:,i)
x(:,i) = x(:,i) + dt * vhalf(:,i)
v(:,i) = vhalf(:,i) + 0.5_rk * dt * a(:,i)
end do
call sph_water_update_diagnostics(ierr)
if (ierr /= SPH_SUCCESS) return
end if
current_time = current_time + dt
+59 -1
View File
@@ -2,7 +2,7 @@ module sph_water
use sph_precision, only: rk, SPH_NDIM
use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, SPH_ERROR_INPUT, sph_error_set
use sph_database, only: npart, particle_phase, particle_status, x, mass, rho, &
volume, pressure, h, v, drho_dt, acc_viscosity, acc_body, &
volume, pressure, h, v, a, drho_dt, acc_pressure, acc_viscosity, acc_body, &
neighbor_count, neighbor_offset, neighbor_list, water_particle_count, water_mass, &
water_momentum, water_max_pressure, water_min_density, water_max_density, &
water_pressure_impulse, SPH_PHASE_WATER, SPH_STATUS_ACTIVE, &
@@ -160,8 +160,12 @@ contains
subroutine sph_water_set_body_force(force, ierr)
real(rk), intent(in) :: force(SPH_NDIM)
integer, intent(out) :: ierr
integer :: i
water_body_force = force
do i = 1, npart
if (sph_water_is_active_particle(i)) acc_body(:,i) = force
end do
ierr = SPH_SUCCESS
end subroutine sph_water_set_body_force
@@ -331,6 +335,60 @@ contains
end do
end subroutine sph_water_compute_viscosity_acceleration
subroutine sph_water_compute_pressure_acceleration(ierr)
integer, intent(out) :: ierr
integer :: i
integer :: n
integer :: j
integer :: index
real(rk) :: rij(SPH_NDIM)
real(rk) :: grad_w(SPH_NDIM)
real(rk) :: pressure_term
ierr = SPH_SUCCESS
if (npart <= 0) return
acc_pressure = 0.0_rk
do i = 1, npart
if (.not. sph_water_is_active_particle(i)) cycle
if (rho(i) <= 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Water density must be positive for pressure force')
ierr = SPH_ERROR_ARGUMENT
return
end if
do n = 1, neighbor_count(i)
index = neighbor_offset(i) + n - 1
j = neighbor_list(index)
if (.not. sph_water_is_active_particle(j)) cycle
if (rho(j) <= 0.0_rk) then
call sph_error_set(SPH_ERROR_ARGUMENT, 'Water neighbor density must be positive')
ierr = SPH_ERROR_ARGUMENT
return
end if
rij = x_vector(i, j)
call sph_kernel_gradient(SPH_KERNEL_DEFAULT, rij, h(i), grad_w, ierr)
if (ierr /= SPH_SUCCESS) return
pressure_term = pressure(i) / (rho(i) * rho(i)) + pressure(j) / (rho(j) * rho(j))
acc_pressure(:,i) = acc_pressure(:,i) - mass(j) * pressure_term * grad_w
end do
end do
end subroutine sph_water_compute_pressure_acceleration
subroutine sph_water_compute_acceleration(ierr)
integer, intent(out) :: ierr
integer :: i
call sph_water_compute_pressure_acceleration(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_water_compute_viscosity_acceleration(ierr)
if (ierr /= SPH_SUCCESS) return
do i = 1, npart
if (sph_water_is_active_particle(i)) then
a(:,i) = acc_pressure(:,i) + acc_viscosity(:,i) + acc_body(:,i)
end if
end do
ierr = SPH_SUCCESS
end subroutine sph_water_compute_acceleration
subroutine sph_water_pair_viscosity(i, j, contribution, ierr)
integer, intent(in) :: i
integer, intent(in) :: j