aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx/Constants.py
diff options
context:
space:
mode:
authorGravatar Dave Grote <grote1@llnl.gov> 2018-08-09 17:00:08 -0700
committerGravatar Dave Grote <grote1@llnl.gov> 2018-08-09 17:00:08 -0700
commit640df04795c4b8d110ebea626ec01611541107f1 (patch)
tree60c5c6c4ceca951155941898488969ca5d04890f /Python/pywarpx/Constants.py
parent74c4bd60fffbba26ebff08417c1bb0fcd9fac75f (diff)
downloadWarpX-640df04795c4b8d110ebea626ec01611541107f1.tar.gz
WarpX-640df04795c4b8d110ebea626ec01611541107f1.tar.zst
WarpX-640df04795c4b8d110ebea626ec01611541107f1.zip
Added Constants python class
Diffstat (limited to 'Python/pywarpx/Constants.py')
-rw-r--r--Python/pywarpx/Constants.py32
1 files changed, 32 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()