Release SPHLite 0.1.0 framework
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
module sph_database
|
||||
use sph_precision, only: rk, SPH_NDIM
|
||||
use sph_error, only: SPH_SUCCESS, SPH_ERROR_ARGUMENT, SPH_ERROR_DATABASE, sph_error_set
|
||||
implicit none
|
||||
|
||||
integer, parameter :: SPH_PHASE_WATER = 1
|
||||
integer, parameter :: SPH_PHASE_GAS = 2
|
||||
integer, parameter :: SPH_PHASE_EXPLOSIVE = 3
|
||||
integer, parameter :: SPH_PHASE_SOLID = 4
|
||||
integer, parameter :: SPH_PHASE_SHELL = 5
|
||||
integer, parameter :: SPH_PHASE_BOUNDARY = 6
|
||||
integer, parameter :: SPH_PHASE_COUPLING = 7
|
||||
integer, parameter :: SPH_PHASE_SOLID_FAILED = 8
|
||||
integer, parameter :: SPH_PHASE_SHELL_FAILED = 9
|
||||
|
||||
integer, parameter :: SPH_STATUS_ACTIVE = 0
|
||||
integer, parameter :: SPH_STATUS_INACTIVE = 1
|
||||
integer, parameter :: SPH_STATUS_FAILED = 2
|
||||
|
||||
integer :: npart = 0
|
||||
integer, allocatable :: particle_id_ext(:)
|
||||
integer, allocatable :: particle_phase(:)
|
||||
integer, allocatable :: particle_status(:)
|
||||
integer, allocatable :: material_id(:)
|
||||
integer, allocatable :: section_id(:)
|
||||
real(rk), allocatable :: x0(:,:)
|
||||
real(rk), allocatable :: x(:,:)
|
||||
real(rk), allocatable :: v(:,:)
|
||||
real(rk), allocatable :: a(:,:)
|
||||
real(rk), allocatable :: vhalf(:,:)
|
||||
real(rk), allocatable :: mass(:)
|
||||
real(rk), allocatable :: rho(:)
|
||||
real(rk), allocatable :: volume(:)
|
||||
real(rk), allocatable :: pressure(:)
|
||||
real(rk), allocatable :: internal_energy(:)
|
||||
real(rk), allocatable :: temperature(:)
|
||||
real(rk), allocatable :: h(:)
|
||||
|
||||
contains
|
||||
|
||||
subroutine sph_db_allocate(count, ierr)
|
||||
integer, intent(in) :: count
|
||||
integer, intent(out) :: ierr
|
||||
integer :: stat
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (count < 0) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'particle count must be non-negative')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
|
||||
call sph_db_free()
|
||||
npart = count
|
||||
if (count == 0) return
|
||||
|
||||
allocate(particle_id_ext(count), particle_phase(count), particle_status(count), &
|
||||
material_id(count), section_id(count), x0(SPH_NDIM,count), &
|
||||
x(SPH_NDIM,count), v(SPH_NDIM,count), a(SPH_NDIM,count), &
|
||||
vhalf(SPH_NDIM,count), mass(count), rho(count), volume(count), &
|
||||
pressure(count), internal_energy(count), temperature(count), &
|
||||
h(count), stat=stat)
|
||||
if (stat /= 0) then
|
||||
call sph_db_free()
|
||||
call sph_error_set(SPH_ERROR_DATABASE, 'failed to allocate particle database')
|
||||
ierr = SPH_ERROR_DATABASE
|
||||
return
|
||||
end if
|
||||
|
||||
call sph_db_initialize_defaults()
|
||||
end subroutine sph_db_allocate
|
||||
|
||||
subroutine sph_db_initialize_defaults()
|
||||
integer :: i
|
||||
|
||||
if (npart <= 0) return
|
||||
do i = 1, npart
|
||||
particle_id_ext(i) = i
|
||||
particle_phase(i) = SPH_PHASE_SOLID
|
||||
particle_status(i) = SPH_STATUS_ACTIVE
|
||||
material_id(i) = 1
|
||||
section_id(i) = 1
|
||||
x0(:,i) = 0.0_rk
|
||||
x(:,i) = 0.0_rk
|
||||
v(:,i) = 0.0_rk
|
||||
a(:,i) = 0.0_rk
|
||||
vhalf(:,i) = 0.0_rk
|
||||
mass(i) = 1.0_rk
|
||||
rho(i) = 1000.0_rk
|
||||
volume(i) = 1.0_rk
|
||||
pressure(i) = 0.0_rk
|
||||
internal_energy(i) = 0.0_rk
|
||||
temperature(i) = 293.15_rk
|
||||
h(i) = 1.0_rk
|
||||
end do
|
||||
end subroutine sph_db_initialize_defaults
|
||||
|
||||
subroutine sph_db_free()
|
||||
if (allocated(particle_id_ext)) deallocate(particle_id_ext)
|
||||
if (allocated(particle_phase)) deallocate(particle_phase)
|
||||
if (allocated(particle_status)) deallocate(particle_status)
|
||||
if (allocated(material_id)) deallocate(material_id)
|
||||
if (allocated(section_id)) deallocate(section_id)
|
||||
if (allocated(x0)) deallocate(x0)
|
||||
if (allocated(x)) deallocate(x)
|
||||
if (allocated(v)) deallocate(v)
|
||||
if (allocated(a)) deallocate(a)
|
||||
if (allocated(vhalf)) deallocate(vhalf)
|
||||
if (allocated(mass)) deallocate(mass)
|
||||
if (allocated(rho)) deallocate(rho)
|
||||
if (allocated(volume)) deallocate(volume)
|
||||
if (allocated(pressure)) deallocate(pressure)
|
||||
if (allocated(internal_energy)) deallocate(internal_energy)
|
||||
if (allocated(temperature)) deallocate(temperature)
|
||||
if (allocated(h)) deallocate(h)
|
||||
npart = 0
|
||||
end subroutine sph_db_free
|
||||
|
||||
subroutine sph_db_get_particle_count(count, ierr)
|
||||
integer, intent(out) :: count
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
count = npart
|
||||
ierr = SPH_SUCCESS
|
||||
end subroutine sph_db_get_particle_count
|
||||
|
||||
subroutine sph_db_set_node(index, ext_id, coords, ierr)
|
||||
integer, intent(in) :: index
|
||||
integer, intent(in) :: ext_id
|
||||
real(rk), intent(in) :: coords(SPH_NDIM)
|
||||
integer, intent(out) :: ierr
|
||||
|
||||
ierr = SPH_SUCCESS
|
||||
if (index < 1 .or. index > npart) then
|
||||
call sph_error_set(SPH_ERROR_ARGUMENT, 'particle index is out of range')
|
||||
ierr = SPH_ERROR_ARGUMENT
|
||||
return
|
||||
end if
|
||||
particle_id_ext(index) = ext_id
|
||||
x0(:,index) = coords(:)
|
||||
x(:,index) = coords(:)
|
||||
end subroutine sph_db_set_node
|
||||
|
||||
end module sph_database
|
||||
Reference in New Issue
Block a user