Skip to content

Commit

Permalink
refactor simulation init manager init
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMarre committed Aug 3, 2024
1 parent a3bc981 commit 1bbfe4b
Show file tree
Hide file tree
Showing 31 changed files with 259 additions and 259 deletions.
18 changes: 13 additions & 5 deletions lib/python/picongpu/picmi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
PICMI for PIConGPU
"""

from .simulation import Simulation
from .grid import Cartesian3DGrid
from .solver import ElectromagneticSolver
Expand All @@ -10,9 +9,10 @@
from .layout import PseudoRandomLayout
from . import constants

from .distribution import FoilDistribution
from .distribution import UniformDistribution
from .distribution import GaussianDistribution
from .distribution import FoilDistribution, UniformDistribution, GaussianDistribution
from .interaction import Interaction
from .interaction.ionization.fieldionization import ADK, ADKVariant, BSI, BSIExtension, Keldysh
from .interaction.ionization.electroniccollisionalequilibrium import ThomasFermi

import picmistandard

Expand All @@ -27,12 +27,20 @@
"GaussianLaser",
"Species",
"PseudoRandomLayout",
"constants",
"FoilDistribution",
"UniformDistribution",
"GaussianDistribution",
"constants",
"ADK",
"ADKVariant",
"BSI",
"BSIExtension",
"Keldysh",
"ThomasFermi",
"Interaction",
]


codename = "picongpu"
"""
name of this PICMI implementation
Expand Down
4 changes: 2 additions & 2 deletions lib/python/picongpu/picmi/distribution/FoilDistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def picongpu_get_rms_velocity_si(self) -> typing.Tuple[float, float, float]:

def get_as_pypicongpu(self) -> species.operation.densityprofile.DensityProfile:
util.unsupported("fill in", self.fill_in)
util.unsupported("lower bound", self.lower_bound, [None, None, None])
util.unsupported("upper bound", self.upper_bound, [None, None, None])
util.unsupported("lower bound", self.lower_bound, (None, None, None))
util.unsupported("upper bound", self.upper_bound, (None, None, None))

foilProfile = species.operation.densityprofile.Foil()
foilProfile.density_si = self.density
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def get_as_pypicongpu(self) -> species.operation.densityprofile.DensityProfile:
util.unsupported("fill in not active", self.fill_in, True)

# @todo support bounds, Brian Marre, 2024
util.unsupported("lower bound", self.lower_bound, [None, None, None])
util.unsupported("upper bound", self.upper_bound, [None, None, None])
util.unsupported("lower bound", self.lower_bound, (None, None, None))
util.unsupported("upper bound", self.upper_bound, (None, None, None))

gaussian_profile = species.operation.densityprofile.Gaussian()

Expand Down
4 changes: 2 additions & 2 deletions lib/python/picongpu/picmi/distribution/UniformDistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def picongpu_get_rms_velocity_si(self) -> typing.Tuple[float, float, float]:

def get_as_pypicongpu(self) -> species.operation.densityprofile.DensityProfile:
util.unsupported("fill in", self.fill_in)
util.unsupported("lower bound", self.lower_bound, [None, None, None])
util.unsupported("upper bound", self.upper_bound, [None, None, None])
util.unsupported("lower bound", self.lower_bound, (None, None, None))
util.unsupported("upper bound", self.upper_bound, (None, None, None))

profile = species.operation.densityprofile.Uniform()
profile.density_si = self.density
Expand Down
3 changes: 1 addition & 2 deletions lib/python/picongpu/picmi/interaction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .interactioninterface import InteractionInterface
from .interaction import Interaction
from . import ionization

__all__ = ["InteractionInterface", "Interaction", "ionization"]
__all__ = ["Interaction", "ionization"]
29 changes: 18 additions & 11 deletions lib/python/picongpu/picmi/interaction/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
from ... import pypicongpu

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

import picmistandard

import typeguard
import pydantic


@typeguard.typechecked
class Interaction(InteractionInterface):
class Interaction(pydantic.BaseModel):
"""
Common interface of Particle-In-Cell particle interaction extensions
Expand Down Expand Up @@ -71,20 +71,23 @@ def get_interaction_constants(
]:
"""get list of all constants required by interactions for the given species"""

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

# add GroundStateIonization constant for entire species
constant_list.append(
pypicongpu.species.constant.GroundStateIonization(
ionization_model_list=ionization_model_conversion.values()
if has_ionization:
# add GroundStateIonization constant for entire species
constant_list.append(
pypicongpu.species.constant.GroundStateIonization(
ionization_model_list=ionization_model_conversion.values()
)
)
)

# add additional interaction sub groups needing constants here
return constant_list, ionization_model_conversion
Expand Down Expand Up @@ -125,16 +128,20 @@ def fill_in_ionization_electron_species(
]
pypicongpu_ionization_model.ionization_electron_species = pypicongpu_ionization_electron_species

def has_ground_state_ionization(self, species: Species) -> bool:
def __has_ground_state_ionization(self, species) -> bool:
"""does at least one ground state ionization model list species as ion species?"""

for ionization_model in self.ground_state_ionization_model_list:
if species == ionization_model.ion_species:
return True
return False

def has_ionization(self, species: Species) -> bool:
def has_ionization(self, species) -> bool:
"""does at least one ionization model list species as ion species?"""
from ..species import Species

assert isinstance(species, Species)

# add additional groups of ionization models here
ionization_configured = self.has_ground_state_ionization(species)
ionization_configured = self.__has_ground_state_ionization(species)
return ionization_configured
31 changes: 0 additions & 31 deletions lib/python/picongpu/picmi/interaction/interactioninterface.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

import typeguard


Expand All @@ -17,4 +18,6 @@ class ThomasFermi(GroundStateIonizationModel):
MODEL_NAME: str = "ThomasFermi"

def get_as_pypicongpu(self) -> pypicongpu.species.constant.ionizationmodel.IonizationModel:
self.check()

return pypicongpu.species.constant.ionizationmodel.ThomasFermi()
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class ADK(FieldIonization):
"""extension to the BSI model"""

def get_as_pypicongpu(self) -> IonizationModel:
self.check()

if self.ADK_variant is ADKVariant.LinearPolarization:
return ADKLinearPolarization(ionization_current=None_())
if self.ADK_variant is ADKVariant.CircularPolarization:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

from .fieldionization import FieldIonization

from ..... import pypicongpu
from .....pypicongpu.species.constant.ionizationcurrent import None_
from .....pypicongpu.species.constant import ionizationmodel

from ..... import pypicongpu

import enum
import typeguard

Expand All @@ -33,17 +32,17 @@ class BSI(FieldIonization):
BSI_extensions: tuple[BSIExtension]
"""extension to the BSI model"""

def get_as_pypicongpu(self) -> pypicongpu.species.constant.ionizationmodel.IonizationModel:
def get_as_pypicongpu(self) -> ionizationmodel.IonizationModel:
self.check()

if self.BSI_extensions == []:
return ionizationmodel.BSI(ionization_current=None_())

if len(self.BSI_extensions) > 1:
pypicongpu.util.unsupported("more than one BSI_extension")
else:
pypicongpu.util.unsupported(f"unknown BSI_extension {self.BSI_extensions[0]}")
pypicongpu.util.unsupported("more than one BSI_extension, will use first entry only")

if self.BSI_extensions[0] is BSIExtension.StarkShift:
return ionizationmodel.BSIStarkShifted(ionization_current=None_())
if self.BSI_extensions[0] is BSIExtension.EffectiveZ:
return ionizationmodel.BSIEffectiveZ(ionization_current=None_())
raise ValueError("unknown BSI extension")
raise ValueError(f"unknown BSI_extension {self.BSI_extensions[0]}")
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .....pypicongpu.species.constant.ionizationcurrent import None_
from .....pypicongpu.species.constant import ionizationmodel

from ..... import pypicongpu
import typeguard


Expand All @@ -20,5 +19,7 @@ class Keldysh(FieldIonization):

MODEL_NAME: str = "Keldysh"

def get_as_pypicongpu(self) -> pypicongpu.species.constant.ionizationmodel.IonizationModel:
def get_as_pypicongpu(self) -> ionizationmodel.IonizationModel:
self.check()

return ionizationmodel.Keldysh(ionization_current=None_())
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
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"""
self.check()

Z = self.ion_species.picongpu_element.get_atomic_number()
assert self.ion_species.charge_state <= Z, f"charge_state must be <= atomic number ({Z})"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
License: GPLv3+
"""

from ...species import Species
from .... import pypicongpu

import pydantic
import typeguard
import typing


@typeguard.typechecked
Expand All @@ -23,10 +23,10 @@ class IonizationModel(pydantic.BaseModel):
MODEL_NAME: str
"""ionization model"""

ion_species: Species
ion_species: typing.Any
"""PICMI ion species to apply ionization model for"""

ionization_electron_species: Species
ionization_electron_species: typing.Any
"""PICMI electron species of which to create macro particle upon ionization"""

def __hash__(self):
Expand All @@ -43,6 +43,15 @@ def __hash__(self):
raise TypeError
return hash_value

def check(self):
# import here to avoid circular import
from ... import Species

assert isinstance(self.ion_species, Species), "ion_species must be an instance of the species object"
assert isinstance(
self.ionization_electron_species, Species
), "ionization_electron_species must be an instance of species object"

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

Expand Down
Loading

0 comments on commit 1bbfe4b

Please sign in to comment.