Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMarre committed Jul 29, 2024
1 parent 590a867 commit 7dca945
Show file tree
Hide file tree
Showing 25 changed files with 403 additions and 567 deletions.
2 changes: 2 additions & 0 deletions lib/python/picongpu/picmi/distribution/Distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import typing
import pydantic
import typeguard

"""
note on rms_velocity:
Expand All @@ -32,6 +33,7 @@
"""


@typeguard.typechecked
class Distribution(pydantic.BaseModel):
rms_velocity: typing.Tuple[float, float, float] = (0, 0, 0)
"""thermal velocity spread [m/s]"""
Expand Down
50 changes: 25 additions & 25 deletions lib/python/picongpu/picmi/interaction/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

from ... import pypicongpu

from .ionization.groundstateionizationmodel import GroundStateIonizationModel
from .ionization.groundstateionizationmodel import GroundStateIonizationModel, IonizationModel
from .interactioninterface import InteractionInterface
from ..species import Species

import picmistandard
import typeguard


@typeguard.typechecked
class Interaction(InteractionInterface):
"""
Common interface of Particle-In-Cell particle interaction extensions
Expand All @@ -37,7 +39,7 @@ class Interaction(InteractionInterface):
@staticmethod
def update_constant_list(
existing_list: list[pypicongpu.species.constant.Constant],
new_list: dict[str, pypicongpu.species.constant.Constant],
new_list: list[pypicongpu.species.constant.Constant],
) -> None:
"""check if dicts may be merged without overwriting previously set values"""

Expand All @@ -62,38 +64,37 @@ def update_constant_list(
existing_list.extend(new_constant_list)

def get_interaction_constants(
self, species: picmistandard.PICMI_Species
) -> list[pypicongpu.species.constant.Constant]:
self, picmi_species: picmistandard.PICMI_Species
) -> tuple[
list[pypicongpu.species.constant.Constant],
dict[IonizationModel, pypicongpu.species.constant.ionizationmodel.IonizationModel],
]:
"""get list of all constants required by interactions for the given species"""

constant_list = []
ground_state_model_conversion = {}
ionization_model_conversion = {}
for model in self.ground_state_ionization_model_list:
if model.ion_species == Species:
if model.ion_species == picmi_species:
model_constants = model.get_constants()
Interaction.update_constant_list(constant_list, model_constants)

ground_state_model_conversion[model] = model.get_as_pypicongpu()
ionization_model_conversion[model] = model.get_as_pypicongpu()

# add GroundStateIonization constant for entire species
constant_list.append(
pypicongpu.species.constant.GroundStateIonization(
ground_state_ionization_model_list=ground_state_model_conversion.values()
ionization_model_list=ionization_model_conversion.values()
)
)

# add additional interaction sub groups needing constants here
return constant_list, {"ground_state_ionization": ground_state_model_conversion}
return constant_list, ionization_model_conversion

def fill_in_ionization_electron_species(
self,
pypicongpu_by_picmi_species: dict[picmistandard.PICMI_Species, pypicongpu.species.Species],
ionization_model_conversion_by_species: dict[
str,
dict[
picmistandard.PICMI_Species,
dict[GroundStateIonizationModel, pypicongpu.species.constant.ionizationmodel.IonizationModel],
],
ionization_model_conversion_by_type_and_species: dict[
picmistandard.PICMI_Species,
None | dict[IonizationModel, pypicongpu.species.constant.ionizationmodel.IonizationModel],
],
) -> None:
"""
Expand All @@ -115,15 +116,14 @@ def fill_in_ionization_electron_species(
pypicongpu_by_picmi_species)
"""

# groundstate ionization model
for species, ionization_model_conversion in ionization_model_conversion_by_species[
"ground_state_ionization"
].items():
for picmi_ionization_model, pypicongpu_ionization_model in ionization_model_conversion.items():
pypicongpu_ionization_electron_species = pypicongpu_by_picmi_species[
picmi_ionization_model.ionization_electron_species
]
pypicongpu_ionization_model.ionization_electron_species = pypicongpu_ionization_electron_species
# ground state ionization model
for species, ionization_model_conversion in ionization_model_conversion_by_type_and_species.items():
if ionization_model_conversion is not None:
for picmi_ionization_model, pypicongpu_ionization_model in ionization_model_conversion.items():
pypicongpu_ionization_electron_species = pypicongpu_by_picmi_species[
picmi_ionization_model.ionization_electron_species
]
pypicongpu_ionization_model.ionization_electron_species = pypicongpu_ionization_electron_species

def has_ground_state_ionization(self, species: Species) -> bool:
"""does at least one ground state ionization model list species as ion species?"""
Expand Down
2 changes: 2 additions & 0 deletions lib/python/picongpu/picmi/interaction/interactioninterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

import picmistandard
import pydantic
import typeguard


@typeguard.typechecked
class InteractionInterface(pydantic.BaseModel):
"""
interface for forward declaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

from ..groundstateionizationmodel import GroundStateIonizationModel
from ..... import pypicongpu
import typeguard


@typeguard.typechecked
class ThomasFermi(GroundStateIonizationModel):
"""thomas fermi ionization model"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@
from .fieldionization import FieldIonization

from .....pypicongpu.species.constant.ionizationcurrent import None_
from .....pypicongpu.species.constant.ionizationmodel import ADKLinearPolarization, ADKCircularPolarization
from .....pypicongpu.species.constant.ionizationmodel import (
ADKLinearPolarization,
ADKCircularPolarization,
IonizationModel,
)

from ..... import pypicongpu

import enum
import typeguard


@typeguard.typechecked
class ADKVariant(enum.Enum):
LinearPolarization = 0
CircularPolarization = 1


@typeguard.typechecked
class ADK(FieldIonization):
"""Barrier Suppression Ioniztion model"""

Expand All @@ -28,11 +35,11 @@ class ADK(FieldIonization):
ADK_variant: ADKVariant
"""extension to the BSI model"""

def get_as_pypicongpu(self) -> pypicongpu.species.constant.ionizationmodel.IonizationModel:
def get_as_pypicongpu(self) -> IonizationModel:
if self.ADK_variant is ADKVariant.LinearPolarization:
return ADKLinearPolarization(ionization_current=None_)
return ADKLinearPolarization(ionization_current=None_())
if self.ADK_variant is ADKVariant.CircularPolarization:
return ADKCircularPolarization(ionization_current=None_)
return ADKCircularPolarization(ionization_current=None_())

# unknown/unsupported ADK variant
pypicongpu.util.unsupported(f"ADKVariant {self.ADK_variant}")
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
from ..... import pypicongpu

import enum
import typeguard


@typeguard.typechecked
class BSIExtension(enum.Enum):
StarkShift = 0
EffectiveZ = 1
# consider_excitation = 2
# add additional features here


@typeguard.typechecked
class BSI(FieldIonization):
"""Barrier Suppression Ioniztion model"""

Expand All @@ -32,12 +35,12 @@ class BSI(FieldIonization):

def get_as_pypicongpu(self) -> pypicongpu.species.constant.ionizationmodel.IonizationModel:
if self.BSI_extensions == []:
return ionizationmodel.BSI(ionization_current=None_)
return ionizationmodel.BSI(ionization_current=None_())

if self.BSI_extensions == [BSIExtension.StarkShift]:
return ionizationmodel.BSIStarkShifted(ionization_current=None_)
return ionizationmodel.BSIStarkShifted(ionization_current=None_())
if self.BSI_extensions == [BSIExtension.EffectiveZ]:
return ionizationmodel.BSIEffectiveZ(ionization_current=None_)
return ionizationmodel.BSIEffectiveZ(ionization_current=None_())

if len(self.BSI_extensions) > 1:
pypicongpu.util.unsupported("more than one BSI_extension")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
from .ionizationcurrent import IonizationCurrent

import typing
import typeguard


@typeguard.typechecked
class FieldIonization(GroundStateIonizationModel):
"""common interface of all field ionization models"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"""

import pydantic
import typeguard


@typeguard.typechecked
class IonizationCurrent(pydantic.BaseModel):
"""common interface of all ionization current models"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
from .....pypicongpu.species.constant import ionizationmodel

from ..... import pypicongpu
import typeguard


@typeguard.typechecked
class Keldysh(FieldIonization):
"""Barrier Suppression Ioniztion model"""

MODEL_NAME: str = "Keldysh"

def get_as_pypicongpu(self) -> pypicongpu.species.constant.ionizationmodel.IonizationModel:
return ionizationmodel.Keldysh(ionization_current=None_)
return ionizationmodel.Keldysh(ionization_current=None_())
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

from .... import pypicongpu

import typeguard


@typeguard.typechecked
class GroundStateIonizationModel(IonizationModel):
def get_constants(self) -> list[pypicongpu.species.constant.Constant]:
"""get all PyPIConGPU constants required by a ground state ionization model in PIConGPU"""
Expand All @@ -18,4 +21,4 @@ def get_constants(self) -> list[pypicongpu.species.constant.Constant]:

element_properties_const = pypicongpu.species.constant.ElementProperties()
element_properties_const.element = self.ion_species.picongpu_element
return element_properties_const
return [element_properties_const]
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
from .... import pypicongpu

import pydantic
import typeguard


@typeguard.typechecked
class IonizationModel(pydantic.BaseModel):
"""
common interface for all ionization models
Expand All @@ -27,6 +29,20 @@ class IonizationModel(pydantic.BaseModel):
ionization_electron_species: Species
"""PICMI electron species of which to create macro particle upon ionization"""

def __hash__(self):
"""custom hash function for indexing in dicts"""
hash_value = hash(type(self))

for value in self.__dict__.values():
try:
if value is not None:
hash_value += hash(value)
except TypeError:
print(self)
print(type(self))
raise TypeError
return hash_value

def get_constants(self) -> list[pypicongpu.species.constant.Constant]:
raise NotImplementedError("abstract base class only!")

Expand Down
Loading

0 comments on commit 7dca945

Please sign in to comment.