Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mbtrack2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PA
Collective Effects
mbtrack2
Commits
a81fbe10
Commit
a81fbe10
authored
9 months ago
by
Vadim Gubaidulin
Browse files
Options
Downloads
Patches
Plain Diff
Minor changes
parent
e9bdfcb0
No related branches found
No related tags found
1 merge request
!35
2D Particle-in-cell solver
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mbtrack2/pic/__init__.py
+1
-1
1 addition, 1 deletion
mbtrack2/pic/__init__.py
mbtrack2/pic/grid2d.f90
+11
-1
11 additions, 1 deletion
mbtrack2/pic/grid2d.f90
mbtrack2/pic/pic2d.py
+3
-1
3 additions, 1 deletion
mbtrack2/pic/pic2d.py
with
15 additions
and
3 deletions
mbtrack2/pic/__init__.py
+
1
−
1
View file @
a81fbe10
This diff is collapsed.
Click to expand it.
mbtrack2/pic/grid2d.f90
+
11
−
1
View file @
a81fbe10
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
This diff is collapsed.
Click to expand it.
mbtrack2/pic/pic2d.py
+
3
−
1
View file @
a81fbe10
...
@@ -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)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment