spx_pif_namelist.f90 Source File


Contents

Source Code


Source Code

!> 与 spx-prepost 交换粒子信息梗概
module spx_pif_namelist

    use spx_kinds, only: rk
    use spx_command_line, only: cli_obj
    use fffc_module, only: operator(.join.), terminal_obj
    use spx_math, only: dimension_ => dim
    implicit none

    private
    public :: pnl_obj

    !> pif.nml 文件数据
    type pif_namelist
        integer :: numbers(5)   !! 弹性实、刚性浮体实、边界虚、总粒子数,刚性浮体数量
        integer, allocatable :: float_objects(:, :) !! 刚性浮体粒子编号
        real(rk) :: hsml        !! 光滑长度
    contains
        procedure :: read
    end type pif_namelist

    type(pif_namelist), target :: pnl_obj

    character(*), parameter :: pif_nml_file = 'pif.nml'

contains

    !> 读取 pif.nml 文件
    subroutine read (self)
        class(pif_namelist), intent(inout) :: self
        integer :: numbers(5)
        integer :: iunit, dim, real_kind
        character(64) :: creator, date_time, version
        real(rk) :: hsml  !! 光滑长度
        integer, allocatable :: float_objects(:, :)
        namelist /pif_attr/ creator, date_time, version, real_kind, numbers, dim, hsml
        namelist /pif_float/ float_objects

        open (newunit=iunit, file=cli_obj%working_directory.join.pif_nml_file, status='old', action='read')
        read (iunit, nml=pif_attr)
        self%numbers = numbers
        self%hsml = hsml

        if (dim /= dimension_) call terminal_obj%error('pif.nml: dimension must be the same as SPX dimension')
        if (real_kind /= rk) call terminal_obj%error('pif.nml: real_kind must be the same as SPX real kind')

        allocate (float_objects(2, numbers(5)))
        read (iunit, nml=pif_float)
        call move_alloc(float_objects, self%float_objects)

        close (iunit)

    end subroutine read

end module spx_pif_namelist