diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pywarpx/Constants.py | 32 | ||||
-rw-r--r-- | Python/pywarpx/WarpX.py | 2 | ||||
-rw-r--r-- | Python/pywarpx/__init__.py | 1 |
3 files changed, 35 insertions, 0 deletions
diff --git a/Python/pywarpx/Constants.py b/Python/pywarpx/Constants.py new file mode 100644 index 000000000..eafddd72e --- /dev/null +++ b/Python/pywarpx/Constants.py @@ -0,0 +1,32 @@ +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') + + 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') + 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() diff --git a/Python/pywarpx/WarpX.py b/Python/pywarpx/WarpX.py index f1fb9918a..f32dd735c 100644 --- a/Python/pywarpx/WarpX.py +++ b/Python/pywarpx/WarpX.py @@ -1,5 +1,6 @@ from .Bucket import Bucket +from .Constants import constants from .Amr import amr from .Geometry import geometry from .Algo import algo @@ -21,6 +22,7 @@ class WarpX(Bucket): def create_argv_list(self): argv = [] argv += warpx.attrlist() + argv += constants.attrlist() argv += amr.attrlist() argv += geometry.attrlist() argv += algo.attrlist() diff --git a/Python/pywarpx/__init__.py b/Python/pywarpx/__init__.py index c3f824e8f..d3c92d5bc 100644 --- a/Python/pywarpx/__init__.py +++ b/Python/pywarpx/__init__.py @@ -1,5 +1,6 @@ from .WarpX import warpx +from .Constants import constants from .Amr import amr from .Geometry import geometry from .Algo import algo |