Subroutine to smooth a matrix form field, the pressure for instance.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=R8), | intent(inout), | dimension(nx, ny) | :: | mat | matrix |
|
integer(kind=I4), | intent(in) | :: | nx | matrix x size |
||
integer(kind=I4), | intent(in) | :: | ny | matrix y size |
||
integer(kind=I4), | intent(in) | :: | s | kernel size |
subroutine smooth_mat(mat, nx, ny, s)
implicit none
integer(kind=I4), intent(in) :: nx !! *matrix x size*
integer(kind=I4), intent(in) :: ny !! *matrix y size*
integer(kind=I4), intent(in) :: s !! *kernel size*
real(kind=R8), intent(inout), dimension(nx, ny) :: mat !! *matrix*
integer(kind=I4), dimension(3,3) :: kernel3
integer(kind=I4), dimension(5,5) :: kernel5
real(kind=R8), dimension(5,5) :: mi_mat
real(kind=R8), dimension(:,:), allocatable :: mat_tmp
integer(kind=I4) :: i, j
allocate( mat_tmp(nx, ny) )
if (s==3) then
kernel3(1:3, 1:3) = reshape((/1,2,1, & !
2,4,2, & !
1,2,1/), (/3,3/))
do j = 1 +1, nx -1
do i = 1 +1, ny -1
mi_mat(1:3, 1:3) = mat(i-1:i+1, j-1:j+1)
mat_tmp(i, j) = sum( mi_mat(1:3, 1:3)*kernel3(1:3, 1:3) )/16.
enddo
enddo
do j = 1 +1, nx -1
do i = 1 +1, ny -1
mat(i, j) = mat_tmp(i, j)
enddo
enddo
endif
if (s==5) then
kernel5(1:5, 1:5) = reshape((/ 1, 4, 6, 4, 1, & !
4,16,24,16, 4, & !
6,24,36,24, 6, & !
4,16,24,16, 4, & !
1, 4, 6, 4, 1 /), (/5,5/))
do j = 1 +2, nx -2
do i = 1 +2, ny -2
mi_mat(1:5, 1:5) = mat(i-2:i+2, j-2:j+2)
mat_tmp(i, j) = sum( mi_mat(1:5, 1:5)*kernel5(1:5, 1:5) )/256.
enddo
enddo
do j = 1 +2, nx -2
do i = 1 +2, ny -2
mat(i, j) = mat_tmp(i, j)
enddo
enddo
endif
deallocate(mat_tmp)
return
endsubroutine smooth_mat