aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx/Constants.py
diff options
context:
space:
mode:
authorGravatar David Grote <grote1@llnl.gov> 2021-09-10 15:53:17 -0700
committerGravatar GitHub <noreply@github.com> 2021-09-10 15:53:17 -0700
commitefed8e95fb7cec88737a7f80edae061f8419c0ad (patch)
tree4c1da6574a707c5b2374c0b962ce42bdbd024ec1 /Python/pywarpx/Constants.py
parentfed60c8d17e12ac816f2145f79ab4c580db910b2 (diff)
downloadWarpX-efed8e95fb7cec88737a7f80edae061f8419c0ad.tar.gz
WarpX-efed8e95fb7cec88737a7f80edae061f8419c0ad.tar.zst
WarpX-efed8e95fb7cec88737a7f80edae061f8419c0ad.zip
Various updates related to defining embedded boundaries in Python (#2280)
* Various updated related to defining embedded boundaries in Python * Fix typo in comment Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com>
Diffstat (limited to 'Python/pywarpx/Constants.py')
-rw-r--r--Python/pywarpx/Constants.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/Python/pywarpx/Constants.py b/Python/pywarpx/Constants.py
index 1ae1dda0d..abc0c3e87 100644
--- a/Python/pywarpx/Constants.py
+++ b/Python/pywarpx/Constants.py
@@ -24,20 +24,19 @@ class Constants(Bucket):
def add_keywords(self, kwdict):
mangle_dict = {}
for k,v in kwdict.items():
- # Check if keyword has already been defined
- # WarpX has a single global dictionary of expression variables so each
- # variable must be unique
- if k in self.argvattrs:
- # if so, mangle the name by appending a numerical suffix
- mangle_number = 1
+ # WarpX has a single global dictionary of expression variables, my_constants,
+ # so each variable must be unique.
+ # Check if keyword has already been defined. If so and it has a different
+ # value than the already defined value, then mangle the name.
+ mangle_number = 0
+ k_mangled = k
+ while k_mangled in self.argvattrs and self.argvattrs[k_mangled] != v:
+ mangle_number += 1
k_mangled = f'{k}{mangle_number}'
- while k_mangled in self.argvattrs:
- # make sure that the mangled name has also not already been defined
- mangle_number += 1
- k_mangled = f'{k}{mangle_number}'
+ if mangle_number > 0:
+ # The mangle_dict contains only mangled names
mangle_dict[k] = k_mangled
- k = k_mangled
- setattr(self, k, v)
+ setattr(self, k_mangled, v)
return mangle_dict
def mangle_expression(self, expression, mangle_dict):