Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AnalyticFluxDistribution class #5422

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
1d64d69
Added AnalyticFluxDistribution class
oshapoval Oct 28, 2024
4f7f98a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2024
0dc0f0b
Updated picmistandard to 0.32.0
oshapoval Oct 29, 2024
f8f2f0b
Merge branch 'add_analytic_flux_distribution' of https://github.com/o…
oshapoval Oct 29, 2024
6be6402
Updated AnalyticFluxDistribution class: enabled the flux variable to …
oshapoval Nov 2, 2024
0c5c764
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2024
7905c27
Merge remote-tracking branch 'origin/development' into add_analytic_f…
oshapoval Nov 8, 2024
3d1b6fd
Updated picmistandard to 0.33.0
oshapoval Nov 8, 2024
e2d9c22
Merge remote-tracking branch 'origin' into add_analytic_flux_distribu…
oshapoval Dec 2, 2024
0de3e53
Merge remote-tracking branch 'origin/development' into add_analytic_f…
oshapoval Dec 3, 2024
f908030
Added inject_from_embedded_boundary option to AnalyticFluxDistributio…
oshapoval Dec 4, 2024
335d64c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
1d1e6c3
Refactored code to avoid duplication by creating parent and subclass …
oshapoval Dec 7, 2024
4ccbb6d
Merge branch 'add_analytic_flux_distribution' of https://github.com/o…
oshapoval Dec 7, 2024
d594d71
Clean-up
oshapoval Dec 11, 2024
4e0e5fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 11, 2024
b15246d
Because of the multiple inheritance, the init methods must be explici…
dpgrote Dec 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ openpmd-viewer # for checksumAPI

# PICMI API docs
# note: keep in sync with version in ../requirements.txt
picmistandard==0.31.0
picmistandard==0.33.0
# for development against an unreleased PICMI version, use:
# picmistandard @ git+https://github.com/picmi-standard/picmi.git#subdirectory=PICMI_Python

Expand Down
4 changes: 4 additions & 0 deletions Docs/source/usage/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ Particle distributions can be used for to initialize particles in a particle spe

.. autoclass:: pywarpx.picmi.AnalyticDistribution

.. autoclass:: pywarpx.picmi.UniformFluxDistribution

.. autoclass:: pywarpx.picmi.AnalyticFluxDistribution

.. autoclass:: pywarpx.picmi.ParticleListDistribution

Particle layouts determine how to microscopically place macro particles in a grid cell.
Expand Down
93 changes: 76 additions & 17 deletions Python/pywarpx/picmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,25 +688,42 @@ def setup_parse_momentum_functions(
)


class UniformFluxDistribution(
picmistandard.PICMI_UniformFluxDistribution, DensityDistributionBase
class UniformDistribution(
picmistandard.PICMI_UniformDistribution, DensityDistributionBase
):
def distribution_initialize_inputs(
self, species_number, layout, species, density_scale, source_name
):
self.set_mangle_dict()
self.set_species_attributes(species, layout, source_name)

# --- Only constant density is supported by this class
species.add_new_group_attr(source_name, "profile", "constant")
species.add_new_group_attr(source_name, "density", self.density)
if density_scale is not None:
species.add_new_group_attr(source_name, "density", density_scale)


class FluxDistributionBase(object):
"""This is a base class for both uniform and analytic flux distributions."""

def init(self, kw):
self.inject_from_embedded_boundary = kw.pop(
"warpx_inject_from_embedded_boundary", False
)

def initialize_flux_profile_func(self, species, density_scale, source_name):
"""Initialize the flux profile and flux function."""
pass
Fixed Show fixed Hide fixed

def distribution_initialize_inputs(
self, species_number, layout, species, density_scale, source_name
):
self.fill_in = False
self.set_mangle_dict()
self.set_species_attributes(species, layout, source_name)

species.add_new_group_attr(source_name, "flux_profile", "constant")
species.add_new_group_attr(source_name, "flux", self.flux)
if density_scale is not None:
species.add_new_group_attr(source_name, "flux", density_scale)
self.initialize_flux_profile_func(species, density_scale, source_name)

if not self.inject_from_embedded_boundary:
species.add_new_group_attr(
Expand Down Expand Up @@ -737,20 +754,62 @@ def distribution_initialize_inputs(
)


class UniformDistribution(
picmistandard.PICMI_UniformDistribution, DensityDistributionBase
class AnalyticFluxDistribution(
picmistandard.PICMI_AnalyticFluxDistribution,
FluxDistributionBase,
DensityDistributionBase,
):
def distribution_initialize_inputs(
self, species_number, layout, species, density_scale, source_name
):
self.set_mangle_dict()
self.set_species_attributes(species, layout, source_name)
"""
Parameters
----------

# --- Only constant density is supported by this class
species.add_new_group_attr(source_name, "profile", "constant")
species.add_new_group_attr(source_name, "density", self.density)
warpx_inject_from_embedded_boundary: bool
When true, the flux is injected from the embedded boundaries instead
of a plane.
"""

def init(self, kw):
FluxDistributionBase.init(self, kw)

def initialize_flux_profile_func(self, species, density_scale, source_name):
species.add_new_group_attr(source_name, "flux_profile", "parse_flux_function")
if density_scale is not None:
species.add_new_group_attr(source_name, "density", density_scale)
species.add_new_group_attr(source_name, "flux", density_scale)
expression = pywarpx.my_constants.mangle_expression(self.flux, self.mangle_dict)
if density_scale is None:
species.add_new_group_attr(
source_name, "flux_function(x,y,z,t)", expression
)
else:
species.add_new_group_attr(
source_name,
"flux_function(x,y,z,t)",
"{}*({})".format(density_scale, expression),
)


class UniformFluxDistribution(
picmistandard.PICMI_UniformFluxDistribution,
FluxDistributionBase,
DensityDistributionBase,
):
"""
Parameters
----------

warpx_inject_from_embedded_boundary: bool
When true, the flux is injected from the embedded boundaries instead
of a plane.
"""

def init(self, kw):
FluxDistributionBase.init(self, kw)

def initialize_flux_profile_func(self, species, density_scale, source_name):
species.add_new_group_attr(source_name, "flux_profile", "constant")
species.add_new_group_attr(source_name, "flux", self.flux)
if density_scale is not None:
species.add_new_group_attr(source_name, "flux", density_scale)


class AnalyticDistribution(
Expand Down
2 changes: 1 addition & 1 deletion Python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
package_dir={"pywarpx": "pywarpx"},
description="""Wrapper of WarpX""",
package_data=package_data,
install_requires=["numpy", "picmistandard==0.31.0", "periodictable"],
install_requires=["numpy", "picmistandard==0.33.0", "periodictable"],
python_requires=">=3.8",
zip_safe=False,
)
2 changes: 1 addition & 1 deletion Tools/machines/karolina-it4i/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ python -m pip install --user --upgrade matplotlib
#python -m pip install --user --upgrade yt

# install or update WarpX dependencies
python -m pip install --user --upgrade picmistandard==0.31.0
python -m pip install --user --upgrade picmistandard==0.33.0
python -m pip install --user --upgrade lasy

# optional: for optimas (based on libEnsemble & ax->botorch->gpytorch->pytorch)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ periodictable~=1.5

# PICMI
# note: don't forget to update the version in Docs/requirements.txt, too
picmistandard==0.31.0
picmistandard==0.33.0
# for development against an unreleased PICMI version, use:
#picmistandard @ git+https://github.com/picmi-standard/picmi.git#subdirectory=PICMI_Python

Expand Down
Loading