From ce188a26a22c99f5c4b297c9ffab6fc3c5c0e180 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 22 Feb 2023 15:37:06 -0800 Subject: Reduced diagnostics: charge on the embedded boundary (#3648) * Prepare structure to compute charge inside boundary * Add calculation without embedded boundaries * Use EB area fraction * Skip cells that are not cut-cells * Choose point outside of the EB * Skip covered or regular boxes * Only compile with EB and 3D support * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add test for charge on EB * Add automated test * Add automated Python test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Avoid compilation error * Enable PICMI test * Rename ChargeInsideBoundary to ChargeOnEB * Update comments * Add parser for weighting * Call weighting function * Call weighting function * Add documentation * Update Python test * Add Python test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix compilation errors * Fix access of attribute on GPU * Use difference in surface area * Pick smaller radius in test This is in order to avoid the influence of the boundaries * Update benchmark * Update benchmark * Properly add diagnostic * Update radius in analysis * Update analysis script * Relax tolerance * Fix tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update Python tests * Apply suggestions from code review Co-authored-by: Edoardo Zoni <59625522+EZoni@users.noreply.github.com> * Test one-eighth from Python * Add one-eighth charge in tests * Handle ChargeOnEB * Remove bug when handling charge on eb * Fix Python errors * Fix Python issues * Use more natural setting of tilebox --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Edoardo Zoni <59625522+EZoni@users.noreply.github.com> --- Python/pywarpx/picmi.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'Python/pywarpx/picmi.py') diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index 6a19de3f5..45dfaa3dd 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -2099,6 +2099,9 @@ class ReducedDiagnostic(picmistandard.base._ClassWithInit, WarpXDiagnosticBase): reduced_function: string For diagnostic type 'FieldReduction', the function of the fields to evaluate + weighting_function: string, optional + For diagnostic type 'ChargeOnEB', the function to weight contributions to the total charge + reduction_type: {'Maximum', 'Minimum', or 'Integral'} For diagnostic type 'FieldReduction', the type of reduction @@ -2153,11 +2156,11 @@ class ReducedDiagnostic(picmistandard.base._ClassWithInit, WarpXDiagnosticBase): self._simple_reduced_diagnostics = [ 'ParticleEnergy', 'ParticleMomentum', 'FieldEnergy', 'FieldMomentum', 'FieldMaximum', 'RhoMaximum', 'ParticleNumber', - 'LoadBalanceCosts', 'LoadBalanceEfficiency', + 'LoadBalanceCosts', 'LoadBalanceEfficiency' ] # The species diagnostics require a species to be provided self._species_reduced_diagnostics = [ - 'BeamRelevant', 'ParticleHistogram', 'ParticleExtrema', + 'BeamRelevant', 'ParticleHistogram', 'ParticleExtrema' ] if self.type in self._simple_reduced_diagnostics: @@ -2171,6 +2174,8 @@ class ReducedDiagnostic(picmistandard.base._ClassWithInit, WarpXDiagnosticBase): kw = self._handle_field_probe(**kw) elif self.type == "FieldReduction": kw = self._handle_field_reduction(**kw) + elif self.type == "ChargeOnEB": + kw = self._handle_charge_on_eb(**kw) else: raise RuntimeError( f"{self.type} reduced diagnostic is not yet supported " @@ -2249,6 +2254,19 @@ class ReducedDiagnostic(picmistandard.base._ClassWithInit, WarpXDiagnosticBase): return kw + def _handle_charge_on_eb(self, **kw): + weighting_function = kw.pop("weighting_function", None) + + self.__setattr__("weighting_function(x,y,z)", weighting_function) + + # Check the reduced function expression for constants + for k in list(kw.keys()): + if re.search(r'\b%s\b'%k, weighting_function): + self.user_defined_kw[k] = kw[k] + del kw[k] + + return kw + def initialize_inputs(self): self.add_diagnostic() -- cgit v1.2.3