forked from BLAST-WarpX/warpx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPICMI_inputs_prev_pos_2d.py
executable file
·141 lines (111 loc) · 3.2 KB
/
PICMI_inputs_prev_pos_2d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
#
# --- Input file to test the saving of old particle positions
import numpy as np
from pywarpx import particle_containers, picmi
constants = picmi.constants
##########################
# numerics parameters
##########################
dt = 7.5e-10
# --- Nb time steps
max_steps = 10
# --- grid
nx = 64
nz = 64
xmin = 0
xmax = 0.03
zmin = 0
zmax = 0.03
##########################
# numerics components
##########################
grid = picmi.Cartesian2DGrid(
number_of_cells = [nx, nz],
lower_bound = [xmin, zmin],
upper_bound = [xmax, zmax],
lower_boundary_conditions = ['dirichlet', 'periodic'],
upper_boundary_conditions = ['dirichlet', 'periodic'],
lower_boundary_conditions_particles = ['absorbing', 'periodic'],
upper_boundary_conditions_particles = ['absorbing', 'periodic'],
moving_window_velocity = None,
warpx_max_grid_size = 32
)
solver = picmi.ElectrostaticSolver(
grid=grid, method='Multigrid', required_precision=1e-6,
warpx_self_fields_verbosity=0
)
##########################
# physics components
##########################
uniform_plasma_elec = picmi.UniformDistribution(
density = 1e15,
upper_bound = [None] * 3,
rms_velocity = [np.sqrt(constants.kb * 1e3 / constants.m_e)] * 3,
directed_velocity = [0.] * 3
)
electrons = picmi.Species(
particle_type='electron', name='electrons',
initial_distribution=uniform_plasma_elec,
warpx_save_previous_position=True
)
##########################
# diagnostics
##########################
part_diag = picmi.ParticleDiagnostic(
name = 'diag1',
period = 10,
species=[electrons],
write_dir = '.',
warpx_file_prefix = 'Python_prev_positions_plt'
)
field_diag = picmi.FieldDiagnostic(
name = 'diag1',
data_list=['Bx', 'By', 'Bz', 'Ex', 'Ey', 'Ez', 'Jx', 'Jy', 'Jz'],
period = 10,
grid=grid,
write_dir = '.',
warpx_file_prefix = 'Python_prev_positions_plt'
)
##########################
# simulation setup
##########################
sim = picmi.Simulation(
solver = solver,
time_step_size = dt,
max_steps = max_steps,
verbose = 1
)
sim.add_species(
electrons,
layout = picmi.GriddedLayout(
n_macroparticle_per_cell=[1, 1], grid=grid
)
)
sim.add_diagnostic(part_diag)
sim.add_diagnostic(field_diag)
##########################
# simulation run
##########################
sim.step(max_steps - 1)
##########################
# check that the new PIDs
# exist
##########################
elec_wrapper = particle_containers.ParticleContainerWrapper('electrons')
elec_count = elec_wrapper.nps
# check that the runtime attributes have the right indices
assert (elec_wrapper.particle_container.get_comp_index('prev_x') == 6)
assert (elec_wrapper.particle_container.get_comp_index('prev_z') == 7)
# sanity check that the prev_z values are reasonable and
# that the correct number of values are returned
prev_z_vals = elec_wrapper.get_particle_real_arrays('prev_z', 0)
running_count = 0
for z_vals in prev_z_vals:
running_count += len(z_vals)
assert np.all(z_vals < zmax)
assert running_count == elec_wrapper.get_particle_count(True)
##########################
# take the final sim step
##########################
sim.step(1)