From 8978f6711d63b29709cd119afc3eadea7256bef2 Mon Sep 17 00:00:00 2001 From: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> Date: Wed, 23 Nov 2022 17:45:04 -0800 Subject: allow initial fields to be set through the picmi interface (#3536) --- Python/pywarpx/picmi.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'Python/pywarpx/picmi.py') diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index 9399fd926..5a970ffdf 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -1084,6 +1084,35 @@ class LaserAntenna(picmistandard.PICMI_LaserAntenna): ) / constants.c +class AnalyticInitialField(picmistandard.PICMI_AnalyticAppliedField): + def init(self, kw): + self.mangle_dict = None + + def initialize_inputs(self): + # Note that lower and upper_bound are not used by WarpX + + if self.mangle_dict is None: + # Only do this once so that the same variables are used in this distribution + # is used multiple times + self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw) + + if (self.Ex_expression is not None or + self.Ey_expression is not None or + self.Ez_expression is not None): + pywarpx.warpx.E_ext_grid_init_style = 'parse_e_ext_grid_function' + for sdir, expression in zip(['x', 'y', 'z'], [self.Ex_expression, self.Ey_expression, self.Ez_expression]): + expression = pywarpx.my_constants.mangle_expression(expression, self.mangle_dict) + pywarpx.warpx.__setattr__(f'E{sdir}_external_grid_function(x,y,z)', expression) + + if (self.Bx_expression is not None or + self.By_expression is not None or + self.Bz_expression is not None): + pywarpx.warpx.B_ext_grid_init_style = 'parse_b_ext_grid_function' + for sdir, expression in zip(['x', 'y', 'z'], [self.Bx_expression, self.By_expression, self.Bz_expression]): + expression = pywarpx.my_constants.mangle_expression(expression, self.mangle_dict) + pywarpx.warpx.__setattr__(f'B{sdir}_external_grid_function(x,y,z)', expression) + + class ConstantAppliedField(picmistandard.PICMI_ConstantAppliedField): def initialize_inputs(self): # Note that lower and upper_bound are not used by WarpX -- cgit v1.2.3