Release SPHLite 0.1.0 framework

This commit is contained in:
Codex
2026-07-02 18:47:38 +08:00
commit ad31c2d5cc
54 changed files with 4710 additions and 0 deletions
+398
View File
@@ -0,0 +1,398 @@
module sph_api
use sph_precision, only: rk, SPH_VERSION_MAJOR, SPH_VERSION_MINOR, &
SPH_VERSION_PATCH
use sph_error, only: SPH_SUCCESS, SPH_ERROR_STATE, sph_error_clear, &
sph_error_set, sph_error_get
use sph_log, only: sph_log_close
use sph_control, only: sph_control_reset, sph_control_get_time
use sph_database, only: sph_db_free, sph_db_get_particle_count
use sph_input_reader, only: sph_input_read, sph_input_build_model
use sph_solver_explicit, only: sph_solver_estimate_stable_dt, &
sph_solver_advance_explicit, sph_solver_run_explicit
use sph_output_csv, only: sph_output_write_csv, sph_output_set_directory, &
sph_output_set_interval
use sph_restart, only: sph_restart_write, sph_restart_read
use sph_coupling_interface, only: sph_coupling_reset
use sph_particle, only: sph_particle_initialize, sph_particle_reset
use sph_material, only: sph_material_initialize, sph_material_reset
use sph_water, only: sph_water_initialize, sph_water_reset
use sph_gas, only: sph_gas_initialize, sph_gas_reset
use sph_explosive, only: sph_explosive_initialize, sph_explosive_reset
use sph_solid, only: sph_solid_initialize, sph_solid_reset
use sph_shell, only: sph_shell_initialize, sph_shell_reset
use sph_api_state, only: sph_api_initialized, sph_api_state_set_initialized
implicit none
contains
subroutine sph_initialize(ierr)
integer, intent(out) :: ierr
call sph_error_clear()
call sph_control_reset()
call sph_db_free()
call sph_coupling_reset()
call sph_particle_initialize()
call sph_material_initialize()
call sph_water_initialize()
call sph_gas_initialize()
call sph_explosive_initialize()
call sph_solid_initialize()
call sph_shell_initialize()
call sph_api_state_set_initialized(.true.)
ierr = SPH_SUCCESS
end subroutine sph_initialize
subroutine sph_finalize(ierr)
integer, intent(out) :: ierr
integer :: local_ierr
call sph_db_free()
call sph_coupling_reset()
call sph_particle_reset()
call sph_material_reset()
call sph_water_reset()
call sph_gas_reset()
call sph_explosive_reset()
call sph_solid_reset()
call sph_shell_reset()
call sph_log_close(local_ierr)
call sph_api_state_set_initialized(.false.)
call sph_error_clear()
ierr = SPH_SUCCESS
end subroutine sph_finalize
subroutine sph_get_version(major, minor, patch, ierr)
integer, intent(out) :: major
integer, intent(out) :: minor
integer, intent(out) :: patch
integer, intent(out) :: ierr
major = SPH_VERSION_MAJOR
minor = SPH_VERSION_MINOR
patch = SPH_VERSION_PATCH
ierr = SPH_SUCCESS
end subroutine sph_get_version
subroutine sph_get_last_error(code, message, ierr)
integer, intent(out) :: code
character(len=*), intent(out) :: message
integer, intent(out) :: ierr
call sph_error_get(code, message)
ierr = SPH_SUCCESS
end subroutine sph_get_last_error
subroutine sph_read_inp(filename, ierr)
character(len=*), intent(in) :: filename
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_read(filename, ierr)
end subroutine sph_read_inp
subroutine sph_build_model(ierr)
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_input_build_model(ierr)
end subroutine sph_build_model
subroutine sph_estimate_stable_dt(dtcrit, ierr)
real(rk), intent(out) :: dtcrit
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) then
dtcrit = 0.0_rk
return
end if
call sph_solver_estimate_stable_dt(dtcrit, ierr)
end subroutine sph_estimate_stable_dt
subroutine sph_advance_explicit(dt, ierr)
real(rk), intent(in) :: dt
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_solver_advance_explicit(dt, ierr)
end subroutine sph_advance_explicit
subroutine sph_run_explicit(ierr)
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_solver_run_explicit(ierr)
end subroutine sph_run_explicit
subroutine sph_get_current_time(time, step, ierr)
real(rk), intent(out) :: time
integer, intent(out) :: step
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) then
time = 0.0_rk
step = 0
return
end if
call sph_control_get_time(time, step)
ierr = SPH_SUCCESS
end subroutine sph_get_current_time
subroutine sph_get_particle_count(count, ierr)
integer, intent(out) :: count
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) then
count = 0
return
end if
call sph_db_get_particle_count(count, ierr)
end subroutine sph_get_particle_count
subroutine sph_write_csv(filename, ierr)
character(len=*), intent(in) :: filename
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_output_write_csv(filename, ierr)
end subroutine sph_write_csv
subroutine sph_set_output_directory(directory, ierr)
character(len=*), intent(in) :: directory
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_output_set_directory(directory, ierr)
end subroutine sph_set_output_directory
subroutine sph_set_output_interval(interval, ierr)
integer, intent(in) :: interval
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_output_set_interval(interval, ierr)
end subroutine sph_set_output_interval
subroutine sph_write_restart(filename, ierr)
character(len=*), intent(in) :: filename
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_restart_write(filename, ierr)
end subroutine sph_write_restart
subroutine sph_read_restart(filename, ierr)
character(len=*), intent(in) :: filename
integer, intent(out) :: ierr
call sph_api_require_initialized(ierr)
if (ierr /= SPH_SUCCESS) return
call sph_restart_read(filename, ierr)
end subroutine sph_read_restart
subroutine sph_api_require_initialized(ierr)
integer, intent(out) :: ierr
ierr = SPH_SUCCESS
if (.not. sph_api_initialized) then
call sph_error_set(SPH_ERROR_STATE, 'SPHLite API is not initialized')
ierr = SPH_ERROR_STATE
end if
end subroutine sph_api_require_initialized
end module sph_api
subroutine sphft_initialize(ierr)
use sph_api, only: sph_initialize
implicit none
integer, intent(out) :: ierr
call sph_initialize(ierr)
end subroutine sphft_initialize
subroutine sphft_finalize(ierr)
use sph_api, only: sph_finalize
implicit none
integer, intent(out) :: ierr
call sph_finalize(ierr)
end subroutine sphft_finalize
subroutine sphft_get_version(major, minor, patch, ierr)
use sph_api, only: sph_get_version
implicit none
integer, intent(out) :: major
integer, intent(out) :: minor
integer, intent(out) :: patch
integer, intent(out) :: ierr
call sph_get_version(major, minor, patch, ierr)
end subroutine sphft_get_version
subroutine sphft_get_last_error_chars(code, chars, capacity, actual, ierr)
use sph_api, only: sph_get_last_error
use sph_error, only: SPH_SUCCESS
implicit none
integer, intent(out) :: code
integer, intent(out) :: chars(*)
integer, intent(in) :: capacity
integer, intent(out) :: actual
integer, intent(out) :: ierr
character(len=256) :: message
integer :: i
integer :: n
call sph_get_last_error(code, message, ierr)
if (capacity <= 0) return
n = len_trim(message)
if (n > capacity - 1) n = capacity - 1
actual = n
do i = 1, n
chars(i) = ichar(message(i:i))
end do
if (capacity > n) chars(n+1) = 0
ierr = SPH_SUCCESS
end subroutine sphft_get_last_error_chars
subroutine sphft_read_inp_chars(chars, count, ierr)
use sph_api, only: sph_read_inp
implicit none
integer, intent(in) :: chars(*)
integer, intent(in) :: count
integer, intent(out) :: ierr
character(len=1024) :: filename
integer :: i
integer :: n
filename = ' '
n = count
if (n > len(filename)) n = len(filename)
do i = 1, n
filename(i:i) = char(chars(i))
end do
call sph_read_inp(filename(1:n), ierr)
end subroutine sphft_read_inp_chars
subroutine sphft_build_model(ierr)
use sph_api, only: sph_build_model
implicit none
integer, intent(out) :: ierr
call sph_build_model(ierr)
end subroutine sphft_build_model
subroutine sphft_estimate_stable_dt(dtcrit, ierr)
use sph_api, only: sph_estimate_stable_dt
use sph_precision, only: rk
implicit none
real(rk), intent(out) :: dtcrit
integer, intent(out) :: ierr
call sph_estimate_stable_dt(dtcrit, ierr)
end subroutine sphft_estimate_stable_dt
subroutine sphft_advance_explicit(dt, ierr)
use sph_api, only: sph_advance_explicit
use sph_precision, only: rk
implicit none
real(rk), intent(in) :: dt
integer, intent(out) :: ierr
call sph_advance_explicit(dt, ierr)
end subroutine sphft_advance_explicit
subroutine sphft_run_explicit(ierr)
use sph_api, only: sph_run_explicit
implicit none
integer, intent(out) :: ierr
call sph_run_explicit(ierr)
end subroutine sphft_run_explicit
subroutine sphft_get_current_time(time, step, ierr)
use sph_api, only: sph_get_current_time
use sph_precision, only: rk
implicit none
real(rk), intent(out) :: time
integer, intent(out) :: step
integer, intent(out) :: ierr
call sph_get_current_time(time, step, ierr)
end subroutine sphft_get_current_time
subroutine sphft_get_particle_count(count, ierr)
use sph_api, only: sph_get_particle_count
implicit none
integer, intent(out) :: count
integer, intent(out) :: ierr
call sph_get_particle_count(count, ierr)
end subroutine sphft_get_particle_count
subroutine sphft_write_csv_chars(chars, count, ierr)
use sph_api, only: sph_write_csv
implicit none
integer, intent(in) :: chars(*)
integer, intent(in) :: count
integer, intent(out) :: ierr
character(len=1024) :: filename
integer :: i
integer :: n
filename = ' '
n = count
if (n > len(filename)) n = len(filename)
do i = 1, n
filename(i:i) = char(chars(i))
end do
call sph_write_csv(filename(1:n), ierr)
end subroutine sphft_write_csv_chars
subroutine sphft_write_restart_chars(chars, count, ierr)
use sph_api, only: sph_write_restart
implicit none
integer, intent(in) :: chars(*)
integer, intent(in) :: count
integer, intent(out) :: ierr
character(len=1024) :: filename
integer :: i
integer :: n
filename = ' '
n = count
if (n > len(filename)) n = len(filename)
do i = 1, n
filename(i:i) = char(chars(i))
end do
call sph_write_restart(filename(1:n), ierr)
end subroutine sphft_write_restart_chars
subroutine sphft_read_restart_chars(chars, count, ierr)
use sph_api, only: sph_read_restart
implicit none
integer, intent(in) :: chars(*)
integer, intent(in) :: count
integer, intent(out) :: ierr
character(len=1024) :: filename
integer :: i
integer :: n
filename = ' '
n = count
if (n > len(filename)) n = len(filename)
do i = 1, n
filename(i:i) = char(chars(i))
end do
call sph_read_restart(filename(1:n), ierr)
end subroutine sphft_read_restart_chars