aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx
diff options
context:
space:
mode:
authorGravatar Dave Grote <grote1@llnl.gov> 2017-06-28 16:14:16 -0700
committerGravatar Dave Grote <grote1@llnl.gov> 2017-06-28 16:15:23 -0700
commitf6dd7a697a15ff568bfd33abed62066bbd2639c8 (patch)
tree9c73944e511d34ed2866fe9597b8bfef9705370c /Python/pywarpx
parent6dcd85dd5a1adefc90fc186bba5768727b842a6d (diff)
downloadWarpX-f6dd7a697a15ff568bfd33abed62066bbd2639c8.tar.gz
WarpX-f6dd7a697a15ff568bfd33abed62066bbd2639c8.tar.zst
WarpX-f6dd7a697a15ff568bfd33abed62066bbd2639c8.zip
Various fixes to conform to Python PICMI standard
Diffstat (limited to 'Python/pywarpx')
-rw-r--r--Python/pywarpx/AMReX.py7
-rw-r--r--Python/pywarpx/Bucket.py4
-rw-r--r--Python/pywarpx/PGroup.py71
-rw-r--r--Python/pywarpx/PICMI.py24
-rwxr-xr-xPython/pywarpx/_libwarpx.py2
5 files changed, 72 insertions, 36 deletions
diff --git a/Python/pywarpx/AMReX.py b/Python/pywarpx/AMReX.py
index 581133695..bdadc49bd 100644
--- a/Python/pywarpx/AMReX.py
+++ b/Python/pywarpx/AMReX.py
@@ -6,6 +6,7 @@ from .Geometry import geometry
from .Algo import algo
from .Langmuirwave import langmuirwave
from .Interpolation import interpolation
+from . import Particles
from .Particles import particles, particles_list
import ctypes
@@ -24,6 +25,12 @@ class AMReX(object):
argv += interpolation.attrlist()
argv += particles.attrlist()
+ if not particles_list:
+ # --- This is needed in case only species_names has been set,
+ # --- assuming that only the built in particle types are being used.
+ for pstring in particles.species_names.split(' '):
+ particles_list.append(getattr(Particles, pstring))
+
for particle in particles_list:
argv += particle.attrlist()
diff --git a/Python/pywarpx/Bucket.py b/Python/pywarpx/Bucket.py
index 2f4a1704c..916b030d1 100644
--- a/Python/pywarpx/Bucket.py
+++ b/Python/pywarpx/Bucket.py
@@ -25,7 +25,9 @@ class Bucket(object):
"Concatenate the attributes into a string"
result = []
for attr, value in self.argvattrs.iteritems():
- attrstring = '{0}.{1}={2} '.format(self.instancename, attr, value)
+ # --- repr is applied to value so that for floats, all of the digits are included.
+ # --- The strip is then needed when value is a string.
+ attrstring = '{0}.{1}={2} '.format(self.instancename, attr, repr(value).strip("'\""))
result += [attrstring]
return result
diff --git a/Python/pywarpx/PGroup.py b/Python/pywarpx/PGroup.py
index cbc30943b..fa8572c0a 100644
--- a/Python/pywarpx/PGroup.py
+++ b/Python/pywarpx/PGroup.py
@@ -6,8 +6,9 @@ class PGroup(object):
"""Implements a class that has the same API as a warp ParticleGroup instance.
"""
- def __init__(self, igroup):
+ def __init__(self, igroup, ispecie):
self.igroup = igroup
+ self.ispecie = ispecie
self.ns = 1 # Number of species
self.gallot()
@@ -75,81 +76,85 @@ class PGroup(object):
return self.nps.sum()
npmax = property(getnpmax)
- def getxp(self, js=0):
- return _libwarpx.get_particle_x(js)[self.igroup]
+ def getxp(self):
+ return _libwarpx.get_particle_x(self.ispecie)[self.igroup]
xp = property(getxp)
- def getyp(self, js=0):
- return _libwarpx.get_particle_y(js)[self.igroup]
+ def getyp(self):
+ return _libwarpx.get_particle_y(self.ispecie)[self.igroup]
yp = property(getyp)
- def getzp(self, js=0):
- return _libwarpx.get_particle_z(js)[self.igroup]
+ def getzp(self):
+ return _libwarpx.get_particle_z(self.ispecie)[self.igroup]
zp = property(getzp)
- def getuxp(self, js=0):
- return _libwarpx.get_particle_ux(js)[self.igroup]
+ def getuxp(self):
+ return _libwarpx.get_particle_ux(self.ispecie)[self.igroup]
uxp = property(getuxp)
- def getuyp(self, js=0):
- return _libwarpx.get_particle_uy(js)[self.igroup]
+ def getuyp(self):
+ return _libwarpx.get_particle_uy(self.ispecie)[self.igroup]
uyp = property(getuyp)
- def getuzp(self, js=0):
- return _libwarpx.get_particle_uz(js)[self.igroup]
+ def getuzp(self):
+ return _libwarpx.get_particle_uz(self.ispecie)[self.igroup]
uzp = property(getuzp)
- def getpid(self, js=0):
- id = _libwarpx.get_particle_id(js)[self.igroup]
+ def getpid(self):
+ id = _libwarpx.get_particle_id(self.ispecie)[self.igroup]
pid = np.array([id]).T
return pid
pid = property(getpid)
- def getgaminv(self, js=0):
- uxp = self.getuxp(js)
- uyp = self.getuyp(js)
- uzp = self.getuzp(js)
+ def getgaminv(self):
+ uxp = self.getuxp()
+ uyp = self.getuyp()
+ uzp = self.getuzp()
return np.sqrt(1. - (uxp**2 + uyp**2 + uzp**2)/_libwarpx.clight**2)
gaminv = property(getgaminv)
- def getex(self, js=0):
- return _libwarpx.get_particle_Ex(js)[self.igroup]
+ def getex(self):
+ return _libwarpx.get_particle_Ex(self.ispecie)[self.igroup]
ex = property(getex)
- def getey(self, js=0):
- return _libwarpx.get_particle_Ey(js)[self.igroup]
+ def getey(self):
+ return _libwarpx.get_particle_Ey(self.ispecie)[self.igroup]
ey = property(getey)
- def getez(self, js=0):
- return _libwarpx.get_particle_Ez(js)[self.igroup]
+ def getez(self):
+ return _libwarpx.get_particle_Ez(self.ispecie)[self.igroup]
ez = property(getez)
- def getbx(self, js=0):
- return _libwarpx.get_particle_Bx(js)[self.igroup]
+ def getbx(self):
+ return _libwarpx.get_particle_Bx(self.ispecie)[self.igroup]
bx = property(getbx)
- def getby(self, js=0):
- return _libwarpx.get_particle_By(js)[self.igroup]
+ def getby(self):
+ return _libwarpx.get_particle_By(self.ispecie)[self.igroup]
by = property(getby)
- def getbz(self, js=0):
- return _libwarpx.get_particle_Bz(js)[self.igroup]
+ def getbz(self):
+ return _libwarpx.get_particle_Bz(self.ispecie)[self.igroup]
bz = property(getbz)
class PGroups(object):
def __init__(self, ispecie=0):
self.ispecie = ispecie
- xall = _libwarpx.get_particle_x(ispecie)
+
+ def setuppgroups(self):
+ xall = _libwarpx.get_particle_x(self.ispecie)
self.ngroups = len(xall)
self._pgroups = []
for igroup in range(self.ngroups):
- self._pgroups.append(PGroup(igroup))
+ self._pgroups.append(PGroup(igroup, self.ispecie))
def __iter__(self):
+ self.setuppgroups()
for igroup in range(self.ngroups):
yield self._pgroups[igroup]
def __getitem__(self, key):
+ self.setuppgroups()
return self._pgroups[key]
diff --git a/Python/pywarpx/PICMI.py b/Python/pywarpx/PICMI.py
index 95bb758dc..30957970e 100644
--- a/Python/pywarpx/PICMI.py
+++ b/Python/pywarpx/PICMI.py
@@ -4,6 +4,8 @@ from PICMI_Base import *
import numpy as np
from pywarpx import *
+codename = 'WarpX'
+
class Grid(PICMI_Grid):
def init(self, **kw):
@@ -20,8 +22,26 @@ class Grid(PICMI_Grid):
# Geometry
geometry.coord_sys = kw.get('coord_sys', 0) # 0: Cartesian
geometry.is_periodic = '%d %d %d'%(self.bcxmin=='periodic', self.bcymin=='periodic', self.bczmin=='periodic') # Is periodic?
- geometry.prob_lo = '%7.0e %7.0e %7.0e'%(self.xmin, self.ymin, self.zmin) # physical domain
- geometry.prob_hi = '%7.0e %7.0e %7.0e'%(self.xmax, self.ymax, self.zmax)
+ geometry.prob_lo = '%s %s %s'%(repr(self.xmin), repr(self.ymin), repr(self.zmin)) # physical domain
+ geometry.prob_hi = '%s %s %s'%(repr(self.xmax), repr(self.ymax), repr(self.zmax))
+
+ if self.moving_window_velocity is not None and np.any(self.moving_window_velocity != 0):
+ warpx.do_moving_window = 1
+ if self.moving_window_velocity[0] != 0.:
+ warpx.moving_window_dir = 'x'
+ warpx.moving_window_v = self.moving_window_velocity[0]/clight # in units of the speed of light
+ if self.moving_window_velocity[1] != 0.:
+ warpx.moving_window_dir = 'y'
+ warpx.moving_window_v = self.moving_window_velocity[1]/clight # in units of the speed of light
+ if self.moving_window_velocity[2] != 0.:
+ warpx.moving_window_dir = 'z'
+ warpx.moving_window_v = self.moving_window_velocity[2]/clight # in units of the speed of light
+
+ def getmins(self, **kw):
+ return np.array([warpx.getProbLo(0), warpx.getProbLo(1), warpx.getProbLo(2)])
+
+ def getmaxs(self, **kw):
+ return np.array([warpx.getProbHi(0), warpx.getProbHi(1), warpx.getProbHi(2)])
def getxmin(self):
return warpx.getProbLo(0)
diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index e552a2f58..9dcc879c5 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -107,6 +107,8 @@ f.argtypes = (ctypes.c_int, ctypes.c_int,
ndpointer(ctypes.c_double, flags="C_CONTIGUOUS"),
ctypes.c_int)
+libwarpx.warpx_getProbLo.restype = ctypes.c_double
+libwarpx.warpx_getProbHi.restype = ctypes.c_double
libwarpx.warpx_getistep.restype = ctypes.c_int
libwarpx.warpx_gett_new.restype = ctypes.c_double
libwarpx.warpx_getdt.restype = ctypes.c_double