diff options
author | 2022-05-16 18:37:15 +0200 | |
---|---|---|
committer | 2022-05-16 16:37:15 +0000 | |
commit | 251920a01a5415d974170ddcbf48e88b0ea9f65e (patch) | |
tree | d780c00b8b589f413b6a95c106baa83445c9bc2b /Python/pywarpx/picmi.py | |
parent | 47a0490323adde9d8475e458f886e322be040d05 (diff) | |
download | WarpX-251920a01a5415d974170ddcbf48e88b0ea9f65e.tar.gz WarpX-251920a01a5415d974170ddcbf48e88b0ea9f65e.tar.zst WarpX-251920a01a5415d974170ddcbf48e88b0ea9f65e.zip |
Add STL files support in pywarpx (#3089)
* Added STL files support in pywarpx
* Add new EB bucket
* Added name to file headers
* Fixing year in file headers
* Checking that stl file and imp function are not both specified
* Renamed EB bucket to EB2
* Adding STL documentation
* Implement suggestions from code review
Co-authored-by: lgiacome <lorenzo.giacome@cern.ch>
Diffstat (limited to 'Python/pywarpx/picmi.py')
-rw-r--r-- | Python/pywarpx/picmi.py | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index ae5fc8bd4..bb50ed42d 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -1,5 +1,5 @@ -# Copyright 2018-2020 Andrew Myers, David Grote, Ligia Diana Amorim -# Maxence Thevenet, Remi Lehe, Revathi Jambunathan +# Copyright 2018-2022 Andrew Myers, David Grote, Ligia Diana Amorim +# Maxence Thevenet, Remi Lehe, Revathi Jambunathan, Lorenzo Giacomel # # # This file is part of WarpX. @@ -917,21 +917,43 @@ class EmbeddedBoundary(picmistandard.base._ClassWithInit): """ Custom class to handle set up of embedded boundaries specific to WarpX. If embedded boundary initialization is added to picmistandard this can be - changed to inherit that functionality. + changed to inherit that functionality. The geometry can be specified either as + an implicit function or as an STL file (ASCII or binary). In the latter case the + geometry specified in the STL file can be scaled, translated and inverted. - implicit_function: Analytic expression describing the embedded boundary + - stl_file: STL file path (string), file contains the embedded boundary geometry + - stl_scale: factor by which the STL geometry is scaled (pure number) + - stl_center: vector by which the STL geometry is translated (in meters) + - stl_reverse_normal: if True inverts the orientation of the STL geometry - potential: Analytic expression defining the potential. Can only be specified when the solver is electrostatic. Optional, defaults to 0. Parameters used in the expressions should be given as additional keyword arguments. """ - def __init__(self, implicit_function, potential=None, **kw): + def __init__(self, implicit_function=None, stl_file=None, stl_scale=None, stl_center=None, stl_reverse_normal=False, + potential=None, **kw): + + assert stl_file is None or implicit_function is None, Exception('Only one between implicit_function and ' + 'stl_file can be specified') + self.implicit_function = implicit_function + self.stl_file = stl_file + + if stl_file is None: + assert stl_scale is None, Exception('EB can only be scaled only when using an stl file') + assert stl_center is None, Exception('EB can only be translated only when using an stl file') + assert stl_reverse_normal is False, Exception('EB can only be reversed only when using an stl file') + + self.stl_scale = stl_scale + self.stl_center = stl_center + self.stl_reverse_normal = stl_reverse_normal + self.potential = potential # Handle keyword arguments used in expressions self.user_defined_kw = {} for k in list(kw.keys()): - if (re.search(r'\b%s\b'%k, implicit_function) or - (potential is not None and re.search(r'\b%s\b'%k, potential))): + if (implicit_function is not None and re.search(r'\b%s\b'%k, implicit_function) or + (potential is not None and re.search(r'\b%s\b'%k, potential))): self.user_defined_kw[k] = kw[k] del kw[k] @@ -944,8 +966,16 @@ class EmbeddedBoundary(picmistandard.base._ClassWithInit): # defined in my_constants with the same name but different value. self.mangle_dict = pywarpx.my_constants.add_keywords(self.user_defined_kw) - expression = pywarpx.my_constants.mangle_expression(self.implicit_function, self.mangle_dict) - pywarpx.warpx.eb_implicit_function = expression + if self.implicit_function is not None: + expression = pywarpx.my_constants.mangle_expression(self.implicit_function, self.mangle_dict) + pywarpx.warpx.eb_implicit_function = expression + + if self.stl_file is not None: + pywarpx.eb2.geom_type = "stl" + pywarpx.eb2.stl_file = self.stl_file + pywarpx.eb2.stl_scale = self.stl_scale + pywarpx.eb2.stl_center = self.stl_center + pywarpx.eb2.stl_reverse_normal = self.stl_reverse_normal if self.potential is not None: assert isinstance(solver, ElectrostaticSolver), Exception('The potential is only supported with the ElectrostaticSolver') |