Skip to content

Commit

Permalink
Adjusted modhypre for openboundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Frans Liqui Lung committed Dec 7, 2021
1 parent 6d9b23a commit dc2300d
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions src/modhypre.f90
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ subroutine inithypre
use mpi
use modmpi, only : myid, myidx, myidy, nprocx, nprocy
use modglobal, only : imax, jmax, kmax, dzf, dzh, dx, dy, itot, jtot, &
solver_id, maxiter, n_pre, n_post, tolerance, precond
solver_id, maxiter, n_pre, n_post, tolerance, precond,lopenbc,lperiodic,lboundary

use modfields, only : rhobf, rhobh

implicit none

! NOTE: we assume kmax is larger than 7,
! when we make the stencil entries
real, allocatable :: values(:)
real, allocatable :: values(:),temp(:)
real cx, cy, cz_down, cz_up, cc

! integer num_ghost(6)
Expand All @@ -118,7 +118,7 @@ subroutine inithypre

! data num_ghost / 3, 3, 3, 3, 0, 0 /

allocate(values(imax*jmax*kmax))
allocate(values(imax*jmax*kmax),temp(max(imax,jmax)))

! Have hypre reuse the comm world
mpi_comm_hypre = MPI_COMM_WORLD
Expand All @@ -143,6 +143,9 @@ subroutine inithypre
periodic(1) = itot
periodic(2) = jtot
periodic(3) = 0
! Remove periodicity if openboundaries are used
if(lopenbc.and..not.lperiodic(1)) periodic(1)=0
if(lopenbc.and..not.lperiodic(3)) periodic(2)=0
call HYPRE_StructGridSetPeriodic(grid, periodic, ierr)

! This is a collective call finalizing the grid assembly
Expand Down Expand Up @@ -256,6 +259,48 @@ subroutine inithypre

call HYPRE_StructMatrixSetBoxValues(matrixA, &
ilower, iupper, 7, stencil_indices, values, ierr)
if(lopenbc) then ! Set potential neuman lateral boundary conditions
if(lboundary(1).and. .not. lperiodic(1)) then
call HYPRE_StructMatrixGetBoxValues(matrixA, &
(/0,myidy*jmax,k-1/),(/0,(myidy+1)*jmax-1,k-1/),1,6,temp,ierr)
do i = 1, jmax*2,2
values(i+0) = 0.
values(i+1) = temp((i+1)/2)+cx
end do
call HYPRE_StructMatrixSetBoxValues(matrixA, &
(/0,myidy*jmax,k-1/),(/0,(myidy+1)*jmax-1,k-1/),2,(/0,6/),values,ierr)
endif
if(lboundary(2).and. .not. lperiodic(2)) then
call HYPRE_StructMatrixGetBoxValues(matrixA, &
(/itot-1,myidy*jmax,k-1/),(/itot-1,(myidy+1)*jmax-1,k-1/),1,6,temp,ierr)
do i = 1, jmax*2,2
values(i+0) = 0.
values(i+1) = temp((i+1)/2)+cx
end do
call HYPRE_StructMatrixSetBoxValues(matrixA, &
(/itot-1,myidy*jmax,k-1/),(/itot-1,(myidy+1)*jmax-1,k-1/),2,(/1,6/),values,ierr)
endif
if(lboundary(3).and. .not. lperiodic(3)) then
call HYPRE_StructMatrixGetBoxValues(matrixA, &
(/myidx*imax,0,k-1/),(/(myidx+1)*imax-1,0,k-1/),1,6,temp,ierr)
do i = 1,imax*2,2
values(i+0) = 0.
values(i+1) = temp((i+1)/2)+cy
end do
call HYPRE_StructMatrixSetBoxValues(matrixA, &
(/myidx*imax,0,k-1/),(/(myidx+1)*imax-1,0,k-1/),2,(/2,6/),values,ierr)
endif
if(lboundary(4).and. .not. lperiodic(4)) then
call HYPRE_StructMatrixGetBoxValues(matrixA, &
(/myidx*imax,jtot-1,k-1/),(/(myidx+1)*imax-1,jtot-1,k-1/),1,6,temp,ierr)
do i = 1,imax*2,2
values(i+0) = 0.
values(i+1) = temp((i+1)/2)+cy
end do
call HYPRE_StructMatrixSetBoxValues(matrixA, &
(/myidx*imax,jtot-1,k-1/),(/(myidx+1)*imax-1,jtot-1,k-1/),2,(/3,6/),values,ierr)
endif
endif
enddo

call HYPRE_StructMatrixAssemble(matrixA, ierr)
Expand Down Expand Up @@ -399,7 +444,7 @@ subroutine inithypre
call exit(-1)
endif

deallocate(values)
deallocate(values,temp)

end subroutine

Expand All @@ -415,7 +460,7 @@ subroutine set_initial_guess(p)
do k=1,kmax
do j=1,jmax
do i=1,imax
values(i,j) = p(i,j,k)
values(i,j) = 0.!p(i,j,k)
enddo
enddo
ilower(3) = k - 1
Expand Down

0 comments on commit dc2300d

Please sign in to comment.