aboutsummaryrefslogtreecommitdiff
path: root/Python/pywarpx/Constants.py
blob: abc0c3e8750d25f7b357b074910c3908e5e0979d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright 2018-2019 David Grote
#
# This file is part of WarpX.
#
# License: BSD-3-Clause-LBNL

import re

from .Bucket import Bucket

class Constants(Bucket):
    """
    The purpose of this class is to be hold user defined constants
    """
    def __init__(self):
        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('Inconsistent values given for user defined constants')
        Bucket.__setattr__(self, name, value)

    def add_keywords(self, kwdict):
        mangle_dict = {}
        for k,v in kwdict.items():
            # 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}'
            if mangle_number > 0:
                # The mangle_dict contains only mangled names
                mangle_dict[k] = k_mangled
            setattr(self, k_mangled, v)
        return mangle_dict

    def mangle_expression(self, expression, mangle_dict):
        if expression is None:
            return None
        # For each key in mangle_dict, modify the expression replacing
        # the key with its value, the mangled version of key
        for k,v in mangle_dict.items():
            expression = re.sub(r'\b%s\b'%k, v, expression)
        return expression


my_constants = Constants()
style-obj Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/packages/integrations/react/src (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-04-11[ci] formatGravatar FredKSchott 2-0/+2
2022-04-10fix up changelogsGravatar Fred K. Schott 13-56/+19
2022-04-10[ci] release (#3061)astro@1.0.0-beta.6@astrojs/vue@0.1.0@astrojs/vercel@0.1.0@astrojs/turbolinks@0.1.0@astrojs/tailwind@0.1.1@astrojs/svelte@0.1.0@astrojs/solid-js@0.1.0@astrojs/renderer-solid@0.4.1@astrojs/preact@0.1.0@astrojs/partytown@0.1.1@astrojs/node@0.1.0@astrojs/netlify@0.2.0@astrojs/lit@0.1.0Gravatar github-actions[bot] 76-329/+254
2022-04-10attempt to fix the 'no commits' bug in changesetGravatar Fred K. Schott 1-1/+1
2022-04-10revert releaseGravatar Fred K. Schott 76-225/+329
2022-04-10Update astro changelogGravatar Fred K. Schott 1-29/+0
2022-04-11[ci] formatGravatar FredKSchott 3-34/+34
2022-04-10[ci] release (#3060)Gravatar github-actions[bot] 76-363/+288
2022-04-10update changesetGravatar Fred K. Schott 1-1/+0
2022-04-10update changesetGravatar Fred K. Schott 1-1/+1
2022-04-10update lockfile (#3059)Gravatar Fred K. Schott 29-914/+698
2022-04-10correct changesetsGravatar Fred K. Schott 3-3/+11
2022-04-10chore: webapi test now use chai (#3048)Gravatar Juan Martín Seery 16-814/+539
2022-04-10update test names containing spacesGravatar Fred K. Schott 26-17/+17
2022-04-11[ci] formatGravatar FredKSchott 2-8/+7
2022-04-10Fix SSR static build public file copying. fixes #3016 (#3037)Gravatar Steve Lee 8-5/+48
2022-04-10fix our weird beta release issues (#3031)Gravatar Fred K. Schott 4-6/+116
2022-04-10update tailwind integration readmeGravatar Fred K. Schott 2-9/+38
2022-04-10Fixed MD Lint issues (#3038)Gravatar Rafid Muhymin Wafi 1-12/+11