test_mesh_index_helpers_m.pf Source File


Contents


Source Code

module test_mesh_index_helpers_m
    use pfunit
    use MPI
    implicit none

contains

    @test(npes = [4])
    subroutine mesh_index_helpers(this)
        !! Test of mesh index helper functions
        use precision_grillix_m, only : GP
        use comm_handler_m, only : comm_handler_t
        use helpers_mesh_sample_m, only : mesh_sample_circular
        use helpers_m, only : almost_equal

        ! from FCI_CORE
        use constants_m, only : two_pi
        use equilibrium_m, only : equilibrium_t
        use circular_equilibrium_m, only : circular_t
        use mesh_cart_m, only : mesh_cart_t

        ! from module to test
        use mesh_index_helpers_m, only : find_neighbor_inds

        implicit none

        class (MpiTestMethod), intent(inout) :: this
        integer :: comm_world, rank, ierr
        type(comm_handler_t) :: comm_handler
        class(equilibrium_t), allocatable :: equi
        type(mesh_cart_t) :: mesh

        real(GP) :: phi, dphi
        integer :: i
        integer, dimension(4) :: nb4ret, nb4ref
        integer, dimension(8) :: nb8ret, nb8ref

        comm_world = this%getMpiCommunicator()
        call MPI_comm_rank(comm_world, rank, ierr)

        if (rank == 0) then
            write(*,*)''
            write(*,*)''
            write(*,'(A80)') &
            'test_mesh_index_helpers --------------------------------------------------'
        endif

        call comm_handler%init(comm_world, 4, 1)
        dphi = TWO_PI / comm_handler%get_nplanes()
        phi = dphi * comm_handler%get_plane()

        ! Create samplemesh ---------------------------------------------------------------------------
        call mesh_sample_circular(equi, phi, mesh)

        ! Test specific index
        nb4ref = [12, 7, 146, 14]
        call find_neighbor_inds(mesh, 13, diagonal=.false., ind_nb=nb4ret)
        do i = 1, 4
            @assertEqual(nb4ret(i), nb4ref(i))
        enddo
        nb8ref = [83, 89, 95, 84, 96, 85, 91, 97]
        call find_neighbor_inds(mesh, 90, diagonal=.true., ind_nb=nb8ret)
        do i = 1, 8
            @assertEqual(nb8ret(i), nb8ref(i))
        enddo

        if (rank == 0) then
            write(*,'(A80)') &
            'test_mesh_index_helpers complete -----------------------------------------'
            write(*,*)''
            write(*,*)''
        endif

    end subroutine
    
end module