variable_s.f90 Source File


Contents

Source Code


Source Code

submodule (variable_m) variable_s
    implicit none
contains
        
    pure integer module function get_ndim(self)
        class(variable_t), intent(in) :: self
        get_ndim = self%ndim
    end function

    module subroutine init_variable(self, comm_handler, ndim, staggered, init_vals)
        class(variable_t), intent(inout) :: self
        type(comm_handler_t), intent(in) :: comm_handler  
        integer, intent(in) :: ndim
        logical, intent(in) :: staggered
        real(GP), dimension(ndim), intent(in), optional :: init_vals

        integer :: kk
    
        self%ndim      = ndim
        self%staggered = staggered
        if (.not. allocated(self%vals)) then
            allocate(self%vals(self%ndim))    
        else
            call handle_error('Already allocated', &
                              GRILLIX_ERR_ALLOC, __LINE__, __FILE__)
        endif    
                
        if (present(init_vals)) then
            !$OMP PARALLEL PRIVATE(kk)
            !$OMP DO
            do kk = 1, ndim
                self%vals(kk) = init_vals(kk)
            enddo
            !$OMP END DO
            !$OMP END PARALLEL
        else
            !$OMP PARALLEL PRIVATE(kk)
            !$OMP DO
            do kk = 1, ndim
                self%vals(kk) = 0.0_GP
            enddo
            !$OMP END DO
            !$OMP END PARALLEL
        endif

    end subroutine

    module subroutine destructor(self)
        type(variable_t), intent(inout) :: self
        
        self%hfwd => null()
        self%hbwd => null()
        
        if (allocated(self%ndim_planes)) deallocate(self%ndim_planes)
        if (allocated(self%vals)) deallocate(self%vals)
        if (allocated(self%halos_fwd)) deallocate(self%halos_fwd)
        if (allocated(self%halos_bwd)) deallocate(self%halos_bwd)
        if (allocated(self%req_fwd)) deallocate(self%req_fwd)
        if (allocated(self%req_bwd)) deallocate(self%req_bwd)
        
    end subroutine destructor

end submodule