Skip to content

Commit 0605ce2

Browse files
authored
Merge pull request #79 from ECP-WarpX/parser
use parser's setConstant function instead of using string replacement
2 parents b534b68 + 761c825 commit 0605ce2

File tree

23 files changed

+165
-157
lines changed

23 files changed

+165
-157
lines changed

Docs/source/running_cpp/parameters.rst

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,17 @@ distribution or the laser field (see below `Particle initialization` and
103103

104104
The parser reads python-style expressions between double quotes, for instance
105105
``"a0*x**2 * (1-y*1.e2) * (x>0)"`` is a valid expression where ``a0`` is a
106-
user-defined constant and ``x`` and ``y`` are variables. The factor
106+
user-defined constant and ``x`` and ``y`` are variables. The names are case sensitive. The factor
107107
``(x>0)`` is `1` where `x>0` and `0` where `x<=0`. It allows the user to
108108
define functions by intervals. User-defined constants can be used in parsed
109-
functions only (i.e., ``density_function(x,y,z)`` and ``field_function(x,y,t)``,
110-
see below). They are specified with:
109+
functions only (i.e., ``density_function(x,y,z)`` and ``field_function(X,Y,t)``,
110+
see below). User-defined constants can contain only letter, numbers and character _.
111+
The name of each constant has to begin with a letter. The following names are used
112+
by WarpX, and cannot be used as user-defined constants: `x`, `y`, `z`, `X`, `Y`, `t`.
113+
For example, parameters ``a0`` and ``z_plateau`` can be specified with:
111114

112-
* ``constants.use_my_constants`` (`bool`)
113-
Whether to use user-defined constants.
114-
115-
* ``constants.constant_names`` (`strings, separated by spaces`)
116-
A list of variables the user wants to define, e.g., ``constants.constant_names = a0 n0``.
117-
118-
* ``constants.constant_values`` (`floats, sepatated by spaces`)
119-
Values for the user-defined constants., e.g., ``constants.constant_values = 3. 1.e24``.
115+
* ``my_constants.a0 = 3.0``
116+
* ``my_constants.z_plateau = 150.e-6``
120117

121118
Particle initialization
122119
-----------------------
@@ -164,8 +161,7 @@ Particle initialization
164161
It requires additional argument ``<species_name>.density_function(x,y,z)``, which is a
165162
mathematical expression for the density of the species, e.g.
166163
``electrons.density_function(x,y,z) = "n0+n0*x**2*1.e12"`` where ``n0`` is a
167-
user-defined constant, see above. Note that using this density profile will turn
168-
``warpx.serialize_ics`` to ``1``, which may slow down the simulation.
164+
user-defined constant, see above.
169165

170166
* ``<species_name>.momentum_distribution_type`` (`string`)
171167
Distribution of the normalized momentum (`u=p/mc`) for this species. The options are:
@@ -187,8 +183,6 @@ Particle initialization
187183
file. It requires additional arguments ``<species_name>.momentum_function_ux(x,y,z)``,
188184
``<species_name>.momentum_function_uy(x,y,z)`` and ``<species_name>.momentum_function_uz(x,y,z)``,
189185
which gives the distribution of each component of the momentum as a function of space.
190-
Note that using this momentum distribution type will turn
191-
``warpx.serialize_ics`` to ``1``, which may slow down the simulation.
192186

193187
* ``<species_name>.zinject_plane`` (`float`)
194188
Only read if ``<species_name>`` is in ``particles.rigid_injected_species``.

Examples/Physics_applications/laser_acceleration/inputs.2d.boost

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ warpx.dt_snapshots_lab = 1.6678204759907604e-12
4848
#################################
4949
############ PLASMA #############
5050
#################################
51-
constants.use_my_constants = 1
52-
constants.constant_names = zmax rc rmax n0 kp
53-
constants.constant_values = 30.e-2 50.e-6 110.e-6 3.5e24 353352.
51+
my_constants.zmax = 30.e-2
52+
my_constants.rc = 50.e-6
53+
my_constants.rmax = 110.e-6
54+
my_constants.n0 = 3.5e24
55+
my_constants.kp = 353352.
5456

5557
particles.nspecies = 3
5658
particles.species_names = electrons ions beam

Examples/Physics_applications/plasma_acceleration/inputs.2d.boost

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ warpx.cfl = .99
3131
warpx.do_moving_window = 1
3232
warpx.moving_window_dir = z
3333
warpx.moving_window_v = 1. # in units of the speed of light
34-
constants.use_my_constants = 1
35-
constants.constant_names = lramp pi dens
36-
constants.constant_values = 8.e-3 3.141592653589793 1e+23
34+
my_constants.lramp = 8.e-3
35+
my_constants.pi = 3.141592653589793
36+
my_constants.dens = 1e+23
3737
interpolation.nox = 3
3838
interpolation.noy = 3
3939
interpolation.noz = 3

Examples/Physics_applications/plasma_acceleration/inputs.3d.boost

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ warpx.cfl = .99
3030
warpx.do_moving_window = 1
3131
warpx.moving_window_dir = z
3232
warpx.moving_window_v = 1. # in units of the speed of light
33-
constants.use_my_constants = 1
34-
constants.constant_names = lramp pi dens
35-
constants.constant_values = 8.e-3 3.141592653589793 1e+23
33+
my_constants.lramp = 8.e-3
34+
my_constants.pi = 3.141592653589793
35+
my_constants.dens = 1e+23
3636
interpolation.nox = 3
3737
interpolation.noy = 3
3838
interpolation.noz = 3

Examples/Physics_applications/plasma_mirror/inputs.2d

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ algo.particle_pusher = 0
2525
interpolation.nox = 3
2626
interpolation.noy = 3
2727
interpolation.noz = 3
28-
constants.use_my_constants = 1
29-
constants.constant_names = zc zp lgrad nc zp2 zc2
30-
constants.constant_values = 20.e-6 20.05545177444479562e-6 .08e-6 1.74e27 24.e-6 24.05545177444479562e-6
28+
my_constants.zc = 20.e-6
29+
my_constants.zp = 20.05545177444479562e-6
30+
my_constants.lgrad = .08e-6
31+
my_constants.nc = 1.74e27
32+
my_constants.zp2 = 24.e-6
33+
my_constants.zc2 = 24.05545177444479562e-6
3134
warpx.cfl = 1.0
3235
warpx.do_dynamic_scheduling = 0
3336
warpx.load_balance_int = 66

Examples/Tests/Langmuir/inputs.multi.2d.rt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ interpolation.noz = 1
3939
warpx.cfl = 1.0
4040

4141
# Parameters for the plasma wave
42-
constants.use_my_constants = 1
43-
constants.constant_names = epsilon kp k
44-
constants.constant_values = 0.01 376357.71524190728 314159.2653589793
42+
my_constants.epsilon = 0.01
43+
my_constants.kp = 376357.71524190728
44+
my_constants.k = 314159.2653589793
4545
# Note: kp is calculated in SI for a density of 4e24 (i.e. 2e24 electrons + 2e24 positrons)
4646
# k is calculated so as to have 2 periods within the 40e-6 wide box.
4747

Examples/Tests/Langmuir/inputs.multi.rt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ interpolation.noz = 1
3939
warpx.cfl = 1.0
4040

4141
# Parameters for the plasma wave
42-
constants.use_my_constants = 1
43-
constants.constant_names = epsilon kp k
44-
constants.constant_values = 0.01 376357.71524190728 314159.2653589793
42+
my_constants.epsilon = 0.01
43+
my_constants.kp = 376357.71524190728
44+
my_constants.k = 314159.2653589793
4545
# Note: kp is calculated in SI for a density of 4e24 (i.e. 2e24 electrons + 2e24 positrons)
4646
# k is calculated so as to have 2 periods within the 40e-6 wide box.
4747

Python/pywarpx/Constants.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,14 @@
33
class Constants(Bucket):
44
"""
55
The purpose of this class is to be hold user defined constants
6-
The constants will be concatenated into names and values string.
76
"""
87
def __init__(self):
9-
Bucket.__init__(self, 'constants')
8+
Bucket.__init__(self, 'my_constants')
109

1110
def __setattr__(self, name, value):
1211
# Make sure that any constants redefined have a consistent value
1312
if name in self.argvattrs:
14-
assert self.argvattrs[name] == value, Exception('In consistent values given for user defined constants')
13+
assert self.argvattrs[name] == value, Exception('An consistent values given for user defined constants')
1514
Bucket.__setattr__(self, name, value)
1615

17-
def attrlist(self):
18-
"Concatenate the attributes into a string"
19-
if self.argvattrs:
20-
names = ''
21-
values = ''
22-
for attr, value in self.argvattrs.items():
23-
names += ' ' + attr
24-
values += ' {}'.format(value)
25-
return ['constants.use_my_constants = 1',
26-
'constants.constant_names = ' + names,
27-
'constants.constant_values = ' + values]
28-
else:
29-
return []
30-
31-
32-
constants = Constants()
16+
my_constants = Constants()

Python/pywarpx/WarpX.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .Bucket import Bucket
2-
from .Constants import constants
2+
from .Constants import my_constants
33
from .Amr import amr
44
from .Geometry import geometry
55
from .Algo import algo
@@ -18,7 +18,7 @@ class WarpX(Bucket):
1818
def create_argv_list(self):
1919
argv = []
2020
argv += warpx.attrlist()
21-
argv += constants.attrlist()
21+
argv += my_constants.attrlist()
2222
argv += amr.attrlist()
2323
argv += geometry.attrlist()
2424
argv += algo.attrlist()

Python/pywarpx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .WarpX import warpx
2-
from .Constants import constants
2+
from .Constants import my_constants
33
from .Amr import amr
44
from .Geometry import geometry
55
from .Algo import algo

0 commit comments

Comments
 (0)