@@ -2,87 +2,87 @@ pure module function laplacian(rhs) result(laplacian_rhs)
22 implicit none
33 class(subdomain_t), intent (in ) :: rhs
44 type (subdomain_t) :: laplacian_rhs
5-
5+
66 ! Local variables for array bounds and grid spacing
77 integer :: my_nx, ny, nz, me, num_subdomains
88 real :: dx_val, dy_val, dz_val, dx2_inv, dy2_inv, dz2_inv
9-
9+
1010 ! Get array dimensions and parallel image information
1111 my_nx = size (rhs% s_, 1 )
12- ny = size (rhs% s_, 2 )
12+ ny = size (rhs% s_, 2 )
1313 nz = size (rhs% s_, 3 )
1414 me = this_image()
1515 num_subdomains = num_images()
16-
16+
1717 ! Get grid spacing values
1818 dx_val = rhs% dx()
19- dy_val = rhs% dy()
19+ dy_val = rhs% dy()
2020 dz_val = rhs% dz()
21-
21+
2222 ! Compute inverse squared grid spacings for efficiency
2323 dx2_inv = 1.0 / (dx_val * dx_val)
2424 dy2_inv = 1.0 / (dy_val * dy_val)
2525 dz2_inv = 1.0 / (dz_val * dz_val)
2626
2727 ! Allocate result array with same shape as input
2828 allocate (laplacian_rhs% s_(my_nx, ny, nz))
29-
29+
3030 ! Initialize result to zero
3131 laplacian_rhs% s_ = 0.0
32-
32+
3333 ! Compute 2nd-order central difference Laplacian in interior points
34- ! Laplacian = d²/dx² + d²/dy² + d²/dz²
34+ ! Laplacian = d2/dx2 + d2/dy2 + d2/dz2
3535 do concurrent (i = 2 :my_nx-1 , j = 2 :ny-1 , k = 2 :nz-1 ) default(none) &
3636 shared(laplacian_rhs, rhs, dx2_inv, dy2_inv, dz2_inv, my_nx, ny, nz, me, num_subdomains)
37-
38- ! Second derivative in x-direction: (f(i+1) - 2*f(i) + f(i-1))/dx²
39- ! Second derivative in y-direction: (f(j+1) - 2*f(j) + f(j-1))/dy²
40- ! Second derivative in z-direction: (f(k+1) - 2*f(k) + f(k-1))/dz²
37+
38+ ! Second derivative in x-direction: (f(i+1) - 2*f(i) + f(i-1))/dx2
39+ ! Second derivative in y-direction: (f(j+1) - 2*f(j) + f(j-1))/dy2
40+ ! Second derivative in z-direction: (f(k+1) - 2*f(k) + f(k-1))/dz2
4141 laplacian_rhs% s_(i,j,k) = &
4242 dx2_inv * (rhs% s_(i+1 ,j,k) - 2.0 * rhs% s_(i,j,k) + rhs% s_(i-1 ,j,k)) + &
4343 dy2_inv * (rhs% s_(i,j+1 ,k) - 2.0 * rhs% s_(i,j,k) + rhs% s_(i,j-1 ,k)) + &
4444 dz2_inv * (rhs% s_(i,j,k+1 ) - 2.0 * rhs% s_(i,j,k) + rhs% s_(i,j,k-1 ))
4545 end do
46-
46+
4747 ! Handle boundary conditions at subdomain interfaces for x-direction
4848 ! Left boundary (i=1) - only compute if not the first subdomain
4949 if (me > 1 ) then
5050 do concurrent (j = 2 :ny-1 , k = 2 :nz-1 ) default(none) &
5151 shared(laplacian_rhs, rhs, dx2_inv, dy2_inv, dz2_inv, ny, nz, halo_x)
52-
52+
5353 laplacian_rhs% s_(1 ,j,k) = &
5454 dx2_inv * (rhs% s_(2 ,j,k) - 2.0 * rhs% s_(1 ,j,k) + halo_x(west,j,k)) + &
5555 dy2_inv * (rhs% s_(1 ,j+1 ,k) - 2.0 * rhs% s_(1 ,j,k) + rhs% s_(1 ,j-1 ,k)) + &
5656 dz2_inv * (rhs% s_(1 ,j,k+1 ) - 2.0 * rhs% s_(1 ,j,k) + rhs% s_(1 ,j,k-1 ))
5757 end do
5858 end if
59-
60- ! Right boundary (i=my_nx) - only compute if not the last subdomain
59+
60+ ! Right boundary (i=my_nx) - only compute if not the last subdomain
6161 if (me < num_subdomains) then
6262 do concurrent (j = 2 :ny-1 , k = 2 :nz-1 ) default(none) &
6363 shared(laplacian_rhs, rhs, dx2_inv, dy2_inv, dz2_inv, my_nx, ny, nz, halo_x, num_subdomains)
64-
64+
6565 laplacian_rhs% s_(my_nx,j,k) = &
6666 dx2_inv * (halo_x(east,j,k) - 2.0 * rhs% s_(my_nx,j,k) + rhs% s_(my_nx-1 ,j,k)) + &
6767 dy2_inv * (rhs% s_(my_nx,j+1 ,k) - 2.0 * rhs% s_(my_nx,j,k) + rhs% s_(my_nx,j-1 ,k)) + &
6868 dz2_inv * (rhs% s_(my_nx,j,k+1 ) - 2.0 * rhs% s_(my_nx,j,k) + rhs% s_(my_nx,j,k-1 ))
6969 end do
7070 end if
71-
71+
7272 ! Set boundary values to zero as specified
7373 ! Y boundaries
7474 laplacian_rhs% s_(:, 1 , :) = 0.0
7575 laplacian_rhs% s_(:, ny, :) = 0.0
76-
77- ! Z boundaries
76+
77+ ! Z boundaries
7878 laplacian_rhs% s_(:, :, 1 ) = 0.0
7979 laplacian_rhs% s_(:, :, nz) = 0.0
80-
80+
8181 ! X boundaries for first and last subdomains
8282 if (me == 1 ) then
8383 laplacian_rhs% s_(1 , :, :) = 0.0
8484 end if
85-
85+
8686 if (me == num_subdomains) then
8787 laplacian_rhs% s_(my_nx, :, :) = 0.0
8888 end if
0 commit comments