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
+48
View File
@@ -0,0 +1,48 @@
module sph_control
use sph_precision, only: rk
implicit none
real(rk), parameter :: SPH_DEFAULT_DT = 1.0e-6_rk
real(rk), parameter :: SPH_DEFAULT_END_TIME = 1.0e-6_rk
integer, parameter :: SPH_DEFAULT_MAX_STEPS = 1
integer, parameter :: SPH_DEFAULT_OUTPUT_INTERVAL = 1
real(rk) :: current_time = 0.0_rk
integer :: current_step = 0
real(rk) :: dt_default = SPH_DEFAULT_DT
real(rk) :: end_time = SPH_DEFAULT_END_TIME
integer :: max_steps = SPH_DEFAULT_MAX_STEPS
integer :: output_interval = SPH_DEFAULT_OUTPUT_INTERVAL
character(len=256) :: output_directory = 'output'
contains
subroutine sph_control_reset()
current_time = 0.0_rk
current_step = 0
dt_default = SPH_DEFAULT_DT
end_time = SPH_DEFAULT_END_TIME
max_steps = SPH_DEFAULT_MAX_STEPS
output_interval = SPH_DEFAULT_OUTPUT_INTERVAL
output_directory = 'output'
end subroutine sph_control_reset
subroutine sph_control_set_time(dt, total_time, steps)
real(rk), intent(in) :: dt
real(rk), intent(in) :: total_time
integer, intent(in) :: steps
if (dt > 0.0_rk) dt_default = dt
if (total_time > 0.0_rk) end_time = total_time
if (steps > 0) max_steps = steps
end subroutine sph_control_set_time
subroutine sph_control_get_time(time, step)
real(rk), intent(out) :: time
integer, intent(out) :: step
time = current_time
step = current_step
end subroutine sph_control_get_time
end module sph_control
+41
View File
@@ -0,0 +1,41 @@
module sph_error
use sph_precision, only: SPH_ERROR_MESSAGE_LEN
implicit none
integer, parameter :: SPH_SUCCESS = 0
integer, parameter :: SPH_ERROR_ARGUMENT = 1
integer, parameter :: SPH_ERROR_STATE = 2
integer, parameter :: SPH_ERROR_IO = 3
integer, parameter :: SPH_ERROR_INPUT = 4
integer, parameter :: SPH_ERROR_DATABASE = 5
integer, parameter :: SPH_ERROR_NOT_IMPLEMENTED = 6
integer :: last_error_code = SPH_SUCCESS
character(len=SPH_ERROR_MESSAGE_LEN) :: last_error_message = 'OK'
contains
subroutine sph_error_clear()
last_error_code = SPH_SUCCESS
last_error_message = 'OK'
end subroutine sph_error_clear
subroutine sph_error_set(code, message)
integer, intent(in) :: code
character(len=*), intent(in) :: message
last_error_code = code
last_error_message = ' '
last_error_message = message
end subroutine sph_error_set
subroutine sph_error_get(code, message)
integer, intent(out) :: code
character(len=*), intent(out) :: message
code = last_error_code
message = ' '
message = last_error_message
end subroutine sph_error_get
end module sph_error
+51
View File
@@ -0,0 +1,51 @@
module sph_log
use sph_error, only: SPH_SUCCESS, SPH_ERROR_IO, sph_error_set
implicit none
integer, parameter :: SPH_LOG_UNIT = 97
logical :: sph_log_is_open = .false.
contains
subroutine sph_log_open(filename, ierr)
character(len=*), intent(in) :: filename
integer, intent(out) :: ierr
integer :: ios
ierr = SPH_SUCCESS
if (sph_log_is_open) call sph_log_close(ierr)
open(unit=SPH_LOG_UNIT, file=trim(filename), status='unknown', &
action='write', position='append', iostat=ios)
if (ios /= 0) then
call sph_error_set(SPH_ERROR_IO, 'failed to open log file')
ierr = SPH_ERROR_IO
sph_log_is_open = .false.
return
end if
sph_log_is_open = .true.
end subroutine sph_log_open
subroutine sph_log_close(ierr)
integer, intent(out) :: ierr
integer :: ios
ierr = SPH_SUCCESS
if (sph_log_is_open) then
close(unit=SPH_LOG_UNIT, iostat=ios)
if (ios /= 0) then
call sph_error_set(SPH_ERROR_IO, 'failed to close log file')
ierr = SPH_ERROR_IO
end if
end if
sph_log_is_open = .false.
end subroutine sph_log_close
subroutine sph_log_info(message)
character(len=*), intent(in) :: message
if (sph_log_is_open) then
write(SPH_LOG_UNIT, '(A)') trim(message)
end if
end subroutine sph_log_info
end module sph_log
+11
View File
@@ -0,0 +1,11 @@
module sph_precision
implicit none
integer, parameter :: rk = selected_real_kind(12, 100)
integer, parameter :: SPH_VERSION_MAJOR = 0
integer, parameter :: SPH_VERSION_MINOR = 1
integer, parameter :: SPH_VERSION_PATCH = 0
integer, parameter :: SPH_NDIM = 3
integer, parameter :: SPH_ERROR_MESSAGE_LEN = 256
integer, parameter :: SPH_PATH_LEN = 1024
end module sph_precision