Skip to content
Snippets Groups Projects
Commit a81fbe10 authored by Vadim Gubaidulin's avatar Vadim Gubaidulin
Browse files

Minor changes

parent e9bdfcb0
No related branches found
No related tags found
1 merge request!352D Particle-in-cell solver
subroutine deposit_cic(nx, ny, x_min, y_min, dx, dy, & subroutine deposit_cic(nx, ny, x_min, y_min, dx, dy, &
x, y, q, n_particles, rho) x, y, q, n_particles, rho)
use omp_lib
implicit none implicit none
integer, intent(in) :: nx, ny ! Number of grid points in x and y directions integer, intent(in) :: nx, ny ! Number of grid points in x and y directions
...@@ -13,6 +14,7 @@ subroutine deposit_cic(nx, ny, x_min, y_min, dx, dy, & ...@@ -13,6 +14,7 @@ subroutine deposit_cic(nx, ny, x_min, y_min, dx, dy, &
integer :: i, i_grid, j_grid integer :: i, i_grid, j_grid
real(8) :: wx, wy real(8) :: wx, wy
!$omp parallel do private(i, i_grid, j_grid, wx, wy)
do i = 1, n_particles do i = 1, n_particles
i_grid = int((x(i) - x_min) / dx) i_grid = int((x(i) - x_min) / dx)
...@@ -22,18 +24,24 @@ subroutine deposit_cic(nx, ny, x_min, y_min, dx, dy, & ...@@ -22,18 +24,24 @@ subroutine deposit_cic(nx, ny, x_min, y_min, dx, dy, &
wy = ((y(i) - y_min) / dy) - dble(j_grid) wy = ((y(i) - y_min) / dy) - dble(j_grid)
if (i_grid >= 0 .and. i_grid < nx-1 .and. j_grid >= 0 .and. j_grid < ny-1) then if (i_grid >= 0 .and. i_grid < nx-1 .and. j_grid >= 0 .and. j_grid < ny-1) then
!$omp atomic
rho(i_grid+1, j_grid+1) = rho(i_grid+1, j_grid+1) + q * (1.0d0 - wx) * (1.0d0 - wy) rho(i_grid+1, j_grid+1) = rho(i_grid+1, j_grid+1) + q * (1.0d0 - wx) * (1.0d0 - wy)
!$omp atomic
rho(i_grid+2, j_grid+1) = rho(i_grid+2, j_grid+1) + q * wx * (1.0d0 - wy) rho(i_grid+2, j_grid+1) = rho(i_grid+2, j_grid+1) + q * wx * (1.0d0 - wy)
!$omp atomic
rho(i_grid+1, j_grid+2) = rho(i_grid+1, j_grid+2) + q * (1.0d0 - wx) * wy rho(i_grid+1, j_grid+2) = rho(i_grid+1, j_grid+2) + q * (1.0d0 - wx) * wy
!$omp atomic
rho(i_grid+2, j_grid+2) = rho(i_grid+2, j_grid+2) + q * wx * wy rho(i_grid+2, j_grid+2) = rho(i_grid+2, j_grid+2) + q * wx * wy
end if end if
end do end do
!$omp end parallel do
end subroutine deposit_cic end subroutine deposit_cic
subroutine interpolate_electric_field(nx, ny, n_particles, x_min, x_max, y_min, y_max, & subroutine interpolate_electric_field(nx, ny, n_particles, x_min, x_max, y_min, y_max, &
x_particles, y_particles, Ex_grid, Ey_grid, & x_particles, y_particles, Ex_grid, Ey_grid, &
Ex_interp, Ey_interp) Ex_interp, Ey_interp)
use omp_lib
implicit none implicit none
! Input parameters ! Input parameters
...@@ -54,6 +62,7 @@ subroutine interpolate_electric_field(nx, ny, n_particles, x_min, x_max, y_min, ...@@ -54,6 +62,7 @@ subroutine interpolate_electric_field(nx, ny, n_particles, x_min, x_max, y_min,
dy = (y_max - y_min) / dble(ny - 1) dy = (y_max - y_min) / dble(ny - 1)
! Loop over each particle to interpolate electric fields ! Loop over each particle to interpolate electric fields
!$omp parallel do private(i, j, px, x_rel, y_rel, wx, wy, ex, ey)
do px = 1, n_particles do px = 1, n_particles
! Find the indices of the lower-left grid point ! Find the indices of the lower-left grid point
i = int((x_particles(px) - x_min) / dx) i = int((x_particles(px) - x_min) / dx)
...@@ -86,5 +95,6 @@ subroutine interpolate_electric_field(nx, ny, n_particles, x_min, x_max, y_min, ...@@ -86,5 +95,6 @@ subroutine interpolate_electric_field(nx, ny, n_particles, x_min, x_max, y_min,
Ey_interp(px) = 0.0d0 Ey_interp(px) = 0.0d0
end if end if
end do end do
!$omp end parallel do
end subroutine interpolate_electric_field end subroutine interpolate_electric_field
...@@ -23,7 +23,9 @@ class PICSolver2D: ...@@ -23,7 +23,9 @@ class PICSolver2D:
'''Implemented in fortran pic2d.f90''' '''Implemented in fortran pic2d.f90'''
grid2d.deposit_cic(self.x_min, self.y_min, self.dx, self.dy, x, y, q, grid2d.deposit_cic(self.x_min, self.y_min, self.dx, self.dy, x, y, q,
self.rho) self.rho)
self.rho /= (epsilon_0 * self.dx * self.dy * self.rho.sum()) total_charge = self.rho.sum()
if total_charge != 0:
self.rho /= (epsilon_0 * self.dx * self.dy * total_charge)
# Original Python implementation (only to quickly check that fortran version is much faster before the merge request) # Original Python implementation (only to quickly check that fortran version is much faster before the merge request)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment