aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx
diff options
context:
space:
mode:
authorGravatar MaxThevenet <mthevenet@lbl.gov> 2019-05-02 11:21:13 -0700
committerGravatar MaxThevenet <mthevenet@lbl.gov> 2019-05-02 11:21:13 -0700
commit4f3003521c4f2fe8c8a64b33cc4d56ebb1c5db7c (patch)
tree723c529f1b7a24f86c606fa30479cd43708aedac /Python/pywarpx
parent5c8e911b1569d5015b2153fba05fbd2d798cc392 (diff)
parent341cd1b2af8ae96f261f7979c1dcf126f424cf60 (diff)
downloadWarpX-4f3003521c4f2fe8c8a64b33cc4d56ebb1c5db7c.tar.gz
WarpX-4f3003521c4f2fe8c8a64b33cc4d56ebb1c5db7c.tar.zst
WarpX-4f3003521c4f2fe8c8a64b33cc4d56ebb1c5db7c.zip
fix conflicts
Diffstat (limited to 'Python/pywarpx')
-rw-r--r--Python/pywarpx/Constants.py22
-rw-r--r--Python/pywarpx/Laser.py3
-rw-r--r--Python/pywarpx/Lasers.py14
-rw-r--r--Python/pywarpx/WarpX.py11
-rw-r--r--Python/pywarpx/__init__.py4
-rwxr-xr-xPython/pywarpx/_libwarpx.py1
-rw-r--r--Python/pywarpx/picmi.py80
7 files changed, 87 insertions, 48 deletions
diff --git a/Python/pywarpx/Constants.py b/Python/pywarpx/Constants.py
index eafddd72e..20107ebc4 100644
--- a/Python/pywarpx/Constants.py
+++ b/Python/pywarpx/Constants.py
@@ -3,30 +3,14 @@ from .Bucket import Bucket
class Constants(Bucket):
"""
The purpose of this class is to be hold user defined constants
- The constants will be concatenated into names and values string.
"""
def __init__(self):
- Bucket.__init__(self, 'constants')
+ Bucket.__init__(self, 'my_constants')
def __setattr__(self, name, value):
# Make sure that any constants redefined have a consistent value
if name in self.argvattrs:
- assert self.argvattrs[name] == value, Exception('In consistent values given for user defined constants')
+ assert self.argvattrs[name] == value, Exception('An consistent values given for user defined constants')
Bucket.__setattr__(self, name, value)
- def attrlist(self):
- "Concatenate the attributes into a string"
- if self.argvattrs:
- names = ''
- values = ''
- for attr, value in self.argvattrs.items():
- names += ' ' + attr
- values += ' {}'.format(value)
- return ['constants.use_my_constants = 1',
- 'constants.constant_names = ' + names,
- 'constants.constant_values = ' + values]
- else:
- return []
-
-
-constants = Constants()
+my_constants = Constants()
diff --git a/Python/pywarpx/Laser.py b/Python/pywarpx/Laser.py
deleted file mode 100644
index 0af1e7f90..000000000
--- a/Python/pywarpx/Laser.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from .Bucket import Bucket
-
-laser = Bucket('laser')
diff --git a/Python/pywarpx/Lasers.py b/Python/pywarpx/Lasers.py
new file mode 100644
index 000000000..ba7303d35
--- /dev/null
+++ b/Python/pywarpx/Lasers.py
@@ -0,0 +1,14 @@
+from .Bucket import Bucket
+
+lasers = Bucket('lasers', nlasers=0, names=None)
+lasers_list = []
+
+def newlaser(name):
+ result = Bucket(name)
+ lasers_list.append(result)
+ lasers.nlasers += 1
+ if lasers.names is None:
+ lasers.names = name
+ else:
+ lasers.names += ' ' + name
+ return result
diff --git a/Python/pywarpx/WarpX.py b/Python/pywarpx/WarpX.py
index f58d4f111..5f7477e58 100644
--- a/Python/pywarpx/WarpX.py
+++ b/Python/pywarpx/WarpX.py
@@ -1,11 +1,11 @@
from .Bucket import Bucket
-from .Constants import constants
+from .Constants import my_constants
from .Amr import amr
from .Geometry import geometry
from .Algo import algo
from .Langmuirwave import langmuirwave
from .Interpolation import interpolation
-from .Laser import laser
+from .Lasers import lasers, lasers_list
from . import Particles
from .Particles import particles, particles_list
@@ -18,14 +18,14 @@ class WarpX(Bucket):
def create_argv_list(self):
argv = []
argv += warpx.attrlist()
- argv += constants.attrlist()
+ argv += my_constants.attrlist()
argv += amr.attrlist()
argv += geometry.attrlist()
argv += algo.attrlist()
argv += langmuirwave.attrlist()
argv += interpolation.attrlist()
argv += particles.attrlist()
- argv += laser.attrlist()
+ argv += lasers.attrlist()
# --- Search through species_names and add any predefined particle objects in the list.
particles_list_names = [p.instancename for p in particles_list]
@@ -43,6 +43,9 @@ class WarpX(Bucket):
for particle in particles_list:
argv += particle.attrlist()
+ for laser in lasers_list:
+ argv += laser.attrlist()
+
return argv
def init(self):
diff --git a/Python/pywarpx/__init__.py b/Python/pywarpx/__init__.py
index 1517bbbaf..ef335e029 100644
--- a/Python/pywarpx/__init__.py
+++ b/Python/pywarpx/__init__.py
@@ -1,9 +1,9 @@
from .WarpX import warpx
-from .Constants import constants
+from .Constants import my_constants
from .Amr import amr
from .Geometry import geometry
from .Algo import algo
from .Langmuirwave import langmuirwave
from .Interpolation import interpolation
from .Particles import particles, electrons, positrons, protons, newspecies
-from .Laser import laser
+from .Lasers import lasers
diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index 0eab82f64..5044b1d67 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -174,6 +174,7 @@ def initialize(argv=None):
if argv is None:
argv = sys.argv
amrex_init(argv)
+ libwarpx.warpx_ConvertLabParamsToBoost()
libwarpx.warpx_init()
diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py
index 70d63e467..a5d9fba87 100644
--- a/Python/pywarpx/picmi.py
+++ b/Python/pywarpx/picmi.py
@@ -188,7 +188,7 @@ class AnalyticDistribution(picmistandard.PICMI_AnalyticDistribution):
species.__setattr__('density_function(x,y,z)', self.density_expression)
for k,v in self.user_defined_kw.items():
- setattr(pywarpx.constants, k, v)
+ setattr(pywarpx.my_constants, k, v)
if np.any(np.not_equal(self.rms_velocity, 0.)):
species.momentum_distribution_type = "gaussian"
@@ -251,15 +251,52 @@ class BinomialSmoother(picmistandard.PICMI_BinomialSmoother):
class CylindricalGrid(picmistandard.PICMI_CylindricalGrid):
+ """This assumes that WarpX was compiled with USE_RZ = TRUE
+ """
def init(self, kw):
- raise Exception('WarpX does not support CylindricalGrid')
+ self.max_grid_size = kw.pop('warpx_max_grid_size', 32)
+ self.blocking_factor = kw.pop('warpx_blocking_factor', None)
+
+ def initialize_inputs(self):
+ pywarpx.amr.n_cell = self.number_of_cells
+
+ # Maximum allowable size of each subdomain in the problem domain;
+ # this is used to decompose the domain for parallel calculations.
+ pywarpx.amr.max_grid_size = self.max_grid_size
+
+ assert self.lower_bound[0] >= 0., Exception('Lower radial boundary must be >= 0.')
+ assert self.bc_rmin != 'periodic' and self.bc_rmax != 'periodic', Exception('Radial boundaries can not be periodic')
+ assert self.n_azimuthal_modes is None or self.n_azimuthal_modes == 1, Exception('Only one azimuthal mode supported')
+
+ # Geometry
+ pywarpx.geometry.coord_sys = 1 # RZ
+ pywarpx.geometry.is_periodic = '0 %d'%(self.bc_zmin=='periodic') # Is periodic?
+ pywarpx.geometry.prob_lo = self.lower_bound # physical domain
+ pywarpx.geometry.prob_hi = self.upper_bound
+
+ if self.moving_window_velocity is not None and np.any(np.not_equal(self.moving_window_velocity, 0.)):
+ pywarpx.warpx.do_moving_window = 1
+ if self.moving_window_velocity[0] != 0.:
+ raise Exception('In cylindrical coordinates, a moving window in r can not be done')
+ if self.moving_window_velocity[1] != 0.:
+ pywarpx.warpx.moving_window_dir = 'z'
+ pywarpx.warpx.moving_window_v = self.moving_window_velocity[1]/c # in units of the speed of light
+
+ if self.refined_regions:
+ assert len(self.refined_regions) == 1, Exception('WarpX only supports one refined region.')
+ assert self.refined_regions[0][0] == 1, Exception('The one refined region can only be level 1')
+ pywarpx.amr.max_level = 1
+ pywarpx.warpx.fine_tag_lo = self.refined_regions[0][1]
+ pywarpx.warpx.fine_tag_hi = self.refined_regions[0][2]
+ # The refinement_factor is ignored (assumed to be [2,2])
+ else:
+ pywarpx.amr.max_level = 0
class Cartesian2DGrid(picmistandard.PICMI_Cartesian2DGrid):
def init(self, kw):
self.max_grid_size = kw.pop('warpx_max_grid_size', 32)
self.blocking_factor = kw.pop('warpx_blocking_factor', None)
- self.coord_sys = kw.pop('warpx_coord_sys', 0)
def initialize_inputs(self):
pywarpx.amr.n_cell = self.number_of_cells
@@ -269,7 +306,7 @@ class Cartesian2DGrid(picmistandard.PICMI_Cartesian2DGrid):
pywarpx.amr.max_grid_size = self.max_grid_size
# Geometry
- pywarpx.geometry.coord_sys = self.coord_sys
+ pywarpx.geometry.coord_sys = 0 # Cartesian
pywarpx.geometry.is_periodic = '%d %d'%(self.bc_xmin=='periodic', self.bc_ymin=='periodic') # Is periodic?
pywarpx.geometry.prob_lo = self.lower_bound # physical domain
pywarpx.geometry.prob_hi = self.upper_bound
@@ -298,7 +335,6 @@ class Cartesian3DGrid(picmistandard.PICMI_Cartesian3DGrid):
def init(self, kw):
self.max_grid_size = kw.pop('warpx_max_grid_size', 32)
self.blocking_factor = kw.pop('warpx_blocking_factor', None)
- self.coord_sys = kw.pop('warpx_coord_sys', 0)
def initialize_inputs(self):
pywarpx.amr.n_cell = self.number_of_cells
@@ -310,7 +346,7 @@ class Cartesian3DGrid(picmistandard.PICMI_Cartesian3DGrid):
pywarpx.amr.blocking_factor = self.blocking_factor
# Geometry
- pywarpx.geometry.coord_sys = self.coord_sys
+ pywarpx.geometry.coord_sys = 0 # Cartesian
pywarpx.geometry.is_periodic = '%d %d %d'%(self.bc_xmin=='periodic', self.bc_ymin=='periodic', self.bc_zmin=='periodic') # Is periodic?
pywarpx.geometry.prob_lo = self.lower_bound # physical domain
pywarpx.geometry.prob_hi = self.upper_bound
@@ -370,24 +406,28 @@ class ElectrostaticSolver(picmistandard.PICMI_ElectrostaticSolver):
class GaussianLaser(picmistandard.PICMI_GaussianLaser):
def initialize_inputs(self):
- pywarpx.warpx.use_laser = 1
- pywarpx.laser.profile = "Gaussian"
- pywarpx.laser.wavelength = self.wavelength # The wavelength of the laser (in meters)
- pywarpx.laser.e_max = self.E0 # Maximum amplitude of the laser field (in V/m)
- pywarpx.laser.polarization = [np.cos(self.polarization_angle), np.sin(self.polarization_angle), 0.] # The main polarization vector
- pywarpx.laser.profile_waist = self.waist # The waist of the laser (in meters)
- pywarpx.laser.profile_duration = self.duration # The duration of the laser (in seconds)
- pywarpx.laser.zeta = self.zeta
- pywarpx.laser.beta = self.beta
- pywarpx.laser.phi2 = self.phi2
+ self.laser_number = pywarpx.lasers.nlasers + 1
+ self.name = 'laser{}'.format(self.laser_number)
+
+ self.laser = pywarpx.Lasers.newlaser(self.name)
+
+ self.laser.profile = "Gaussian"
+ self.laser.wavelength = self.wavelength # The wavelength of the laser (in meters)
+ self.laser.e_max = self.E0 # Maximum amplitude of the laser field (in V/m)
+ self.laser.polarization = [np.cos(self.polarization_angle), np.sin(self.polarization_angle), 0.] # The main polarization vector
+ self.laser.profile_waist = self.waist # The waist of the laser (in meters)
+ self.laser.profile_duration = self.duration # The duration of the laser (in seconds)
+ self.laser.zeta = self.zeta
+ self.laser.beta = self.beta
+ self.laser.phi2 = self.phi2
class LaserAntenna(picmistandard.PICMI_LaserAntenna):
def initialize_inputs(self, laser):
- pywarpx.laser.position = self.position # This point is on the laser plane
- pywarpx.laser.direction = self.normal_vector # The plane normal direction
- pywarpx.laser.profile_focal_distance = laser.focal_position[2] - self.position[2] # Focal distance from the antenna (in meters)
- pywarpx.laser.profile_t_peak = (self.position[2] - laser.centroid_position[2])/c # The time at which the laser reaches its peak (in seconds)
+ laser.laser.position = self.position # This point is on the laser plane
+ laser.laser.direction = self.normal_vector # The plane normal direction
+ laser.laser.profile_focal_distance = laser.focal_position[2] - self.position[2] # Focal distance from the antenna (in meters)
+ laser.laser.profile_t_peak = (self.position[2] - laser.centroid_position[2])/c # The time at which the laser reaches its peak (in seconds)
class Simulation(picmistandard.PICMI_Simulation):