1
- from mpi4py import MPI
2
1
from pywarpx import picmi
3
2
import numpy as np
4
3
5
- ##########################
6
- # MPI communicator setup
7
- ##########################
4
+ import argparse
5
+ import sys
8
6
9
- # split processor 0 into separate communicator from others
10
- comm_world = MPI .COMM_WORLD
11
- rank = comm_world .Get_rank ()
12
- if rank == 0 :
13
- color = 0
14
- else :
15
- color = 1
16
- new_comm = comm_world .Split (color )
7
+ # Create the parser and add the argument
8
+ parser = argparse .ArgumentParser ()
9
+ parser .add_argument (
10
+ '-u' , '--unique' , action = 'store_true' ,
11
+ help = "Whether injected particles should be treated as unique"
12
+ )
13
+
14
+ # Parse the input
15
+ args , left = parser .parse_known_args ()
16
+ sys .argv = sys .argv [:1 ] + left
17
17
18
18
##########################
19
19
# numerics parameters
75
75
period = 10 ,
76
76
data_list = ['phi' ],
77
77
write_dir = '.' ,
78
- warpx_file_prefix = f'Python_particle_attr_access_plt_ { color } '
78
+ warpx_file_prefix = f"Python_particle_attr_access_ { 'unique_' if args . unique else '' } plt"
79
79
)
80
80
81
81
##########################
98
98
sim .add_diagnostic (field_diag )
99
99
100
100
sim .initialize_inputs ()
101
- sim .initialize_warpx (mpi_comm = new_comm )
101
+ sim .initialize_warpx ()
102
102
103
103
##########################
104
104
# python particle data access
108
108
109
109
_libwarpx .add_real_comp ('electrons' , 'newPid' )
110
110
111
+ my_id = _libwarpx .libwarpx .warpx_getMyProc ()
112
+
111
113
def add_particles ():
112
114
113
- nps = 10
115
+ nps = 10 * ( my_id + 1 )
114
116
x = np .random .rand (nps ) * 0.03
115
117
y = np .zeros (nps )
116
118
z = np .random .random (nps ) * 0.03
@@ -122,7 +124,7 @@ def add_particles():
122
124
123
125
_libwarpx .add_particles (
124
126
species_name = 'electrons' , x = x , y = y , z = z , ux = ux , uy = uy , uz = uz ,
125
- w = w , newPid = newPid , unique_particles = ( not color )
127
+ w = w , newPid = newPid , unique_particles = args . unique
126
128
)
127
129
128
130
callbacks .installbeforestep (add_particles )
@@ -131,16 +133,14 @@ def add_particles():
131
133
# simulation run
132
134
##########################
133
135
134
- sim .step (max_steps - 1 , mpi_comm = new_comm )
136
+ sim .step (max_steps - 1 )
135
137
136
138
##########################
137
- # check that the new PIDs are properly set
139
+ # check that the new PIDs
140
+ # are properly set
138
141
##########################
139
142
140
- if color == 0 :
141
- assert (_libwarpx .get_particle_count ('electrons' ) == 90 )
142
- else :
143
- assert (_libwarpx .get_particle_count ('electrons' ) == 90 )
143
+ assert (_libwarpx .get_particle_count ('electrons' ) == 270 / (2 - args .unique ))
144
144
assert (_libwarpx .get_particle_comp_index ('electrons' , 'w' ) == 0 )
145
145
assert (_libwarpx .get_particle_comp_index ('electrons' , 'newPid' ) == 4 )
146
146
0 commit comments