Define the entries of the matrix Ax=b one row at a time Finite difference/Finite volume 2nd order Laplacian: ddu/dxdx = -2 u(i,j,k)/dxdx + u(i-1,j,k)/dxdx + u(i+1,j,k)/dxdx ddu/dydy = -2 u(i,j,k)/dydy + u(i,j-1,k)/dydy + u(i,j+1,k)/dydy ddu/dzdz = -2 u(i,j,k)/dzdz + u(i,j,k-1)/dzdz + u(i,j,k+1)/dzdz
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hypre_obj), | intent(inout) | :: | this |
Hypre machinery |
impure subroutine hypre_obj_BuildMatrixS(this) !> Define the entries of the matrix Ax=b one row at a time ! Finite difference/Finite volume 2nd order Laplacian: ! ddu/dxdx = -2 u(i,j,k)/dxdx + u(i-1,j,k)/dxdx + u(i+1,j,k)/dxdx ! ddu/dydy = -2 u(i,j,k)/dydy + u(i,j-1,k)/dydy + u(i,j+1,k)/dydy ! ddu/dzdz = -2 u(i,j,k)/dzdz + u(i,j,k-1)/dzdz + u(i,j,k+1)/dzdz implicit none class(hypre_obj), intent(inout) :: this !! Hypre machinery ! Work variables real(wp):: values(this%st_size) integer :: sindices(this%st_size) integer :: i,j,k integer :: ierr if (this%st.ne.1) call this%parallel%Stop("Hypre: the build matrix routine requires st=1") ! Stencil indicies ! must match the indices used setting the HYPRE stencil elements do i=1,this%st_size sindices(i) = i-1 end do ! Set values for all interior grid points associate (x=>this%block%x, y=>this%block%y, z=>this%block%z) ! Loop over cell following Hypre convention (from bottom left, to top right) do k=this%block%lo(3),this%block%hi(3) do j=this%block%lo(2),this%block%hi(2) do i=this%block%lo(1),this%block%hi(1) ! Center point (entry=0) values(1) = -2.0_wp/(x(i+1)-x(i))**2 & -2.0_wp/(y(j+1)-y(j))**2 & -2.0_wp/(z(k+1)-z(k))**2 ! X-dir left point (entry = 1) values(2) = 1.0_wp/(x(i+1)-x(i))**2 ! X-dir right point (entry = 2) values(3) = 1.0_wp/(x(i+1)-x(i))**2 ! Y-dir left point (entry = 3) values(4) = 1.0_wp/(y(j+1)-y(j))**2 ! Y-dir right point (entry = 4) values(5) = 1.0_wp/(y(j+1)-y(j))**2 ! Z-dir left point (entry = 5) values(6) = 1.0_wp/(z(k+1)-z(k))**2 ! Z-dir right point (entry = 6) values(7) = 1.0_wp/(z(k+1)-z(k))**2 call HYPRE_StructMatrixSetValues(this%matrix,[i,j,k],this%st_size,& sindices(1:this%st_size),values(1:this%st_size),ierr) end do end do end do end associate return end subroutine hypre_obj_BuildMatrixS