Struphy model base class#
- class struphy.models.base.StruphyModel[source]#
Bases:
objectAbstract base class for all Struphy models.
This class defines the interface for plasma simulation models in Struphy. Concrete implementations must specify the model type (Fluid, Kinetic, Hybrid, or Toy), define propagators for time integration, and configure species (field, fluid, particle, and diagnostic). The class provides core functionality for managing species, scalar quantities, time integration, and particle diagnostics.
- Variables:
species (dict) – Dictionary of all species (field, fluid, and particle) in the model.
field_species (dict) – Dictionary of field species in the model.
fluid_species (dict) – Dictionary of fluid species in the model.
particle_species (dict) – Dictionary of particle species in the model.
diagnostic_species (dict) – Dictionary of diagnostic species in the model.
scalars (Scalars or None) – Scalar quantities to be tracked and saved during simulation.
prop_list (list) – List of propagator objects controlling time integration.
clone_config (CloneConfig or None) – Configuration for domain clones if used in parallelization.
subclasses) (Abstract Methods (must be implemented by)
----------------------------------------------------
model_type (classmethod) – Must return one of “Fluid”, “Kinetic”, “Hybrid”, or “Toy”.
bulk_species (property) – Must specify the dominant plasma species.
velocity_scale (property) – Must return velocity scale: “alfvén”, “cyclotron”, “light”, or “thermal”.
post_allocate (method) – Must perform operations after main allocation and before time stepping.
Propagators (class) – Must define the propagators used for time integration.
__init__ (method) – Must perform a light-weight initialization of the model.
Notes
All Struphy models must be subclasses of
StruphyModeland should be added tostruphy/models/in one of the modules:fluid.py,kinetic.py,hybrid.py, ortoy.py.Time integration is performed by calling the
integrate()method with a time step and splitting algorithm (Lie-Trotter or Strang). The model manages the execution of all propagators in sequence to advance the simulation state.Species management is handled automatically through property caching. Species attributes are discovered at runtime and categorized by type.
Examples
Subclasses should implement:
class MyFluidModel(StruphyModel): @classmethod def model_type(cls): return "Fluid" @property def bulk_species(self): return self.electrons @property def velocity_scale(self): return "thermal" def post_allocate(self): # Perform operations after main allocation and before time stepping pass class Propagators: # Define propagators pass
- abstract classmethod model_type() Literal['Toy', 'Kinetic', 'Fluid', 'Hybrid'][source]#
Model type (Fluid, Kinetic, Hybrid, or Toy)
- abstract property bulk_species: Species#
Bulk species of the plasma. Must be an attribute of species_static().
- abstract property velocity_scale: str#
Velocity unit scale of the model. Must be one of “alfvén”, “cyclotron”, “light” or “thermal”.
- abstract post_allocate()[source]#
Perform operations after main allocation and before time stepping.
- property is_default#
- forced_heading_level = 5#
- property scalars: Scalars | None#
Scalars to be updated and saved during the simulation.
- update_scalar_quantities()[source]#
Update scalar quantities by calling their .update() method. This should be called at the end of each time step in the simulation loop.
- setup_equation_params(base_units: BaseUnits)[source]#
Compute units and set equation parameters for each fluid and kinetic species.
- integrate(dt, split_algo='LieTrotter')[source]#
Advance the model by a time step
dtby sequentially calling its Propagators.- Parameters:
dt (float) – Time step of time integration.
split_algo (str) – Splitting algorithm. Currently available: “LieTrotter” and “Strang”.
- update_markers_to_be_saved()[source]#
Writes markers with IDs that are supposed to be saved into corresponding array.
- update_distr_functions()[source]#
Writes distribution functions slices that are supposed to be saved into corresponding array.
- generate_default_parameter_file(path: str | None = None, prompt: bool = True)[source]#
Generate a parameter file with default options for each species, and save it to the current input path.
The default name is params_<model_name>.yml.
- Parameters:
path (str) – Alternative path to getcwd()/params_MODEL.py.
prompt (bool) – Whether to prompt for overwriting the specified .yml file.
- Returns:
params_path – The path of the parameter file.
- Return type:
str
- to_dict(*, initial_condition_serializer=None) dict[source]#
Serialize the model constructor, variables and propagator options.
Pass an initial-condition serializer to include each variable’s definitions in run metadata. The plain configuration omits them.
- classmethod from_dict(dct) StruphyModel[source]#
Deserialize a model from
to_dict().
- classmethod from_name(name: str) StruphyModel[source]#
Instantiate a model from its name.
- property field_species: dict#
- property fluid_species: dict#
- property particle_species: dict#
- property diagnostic_species: dict#
- property species#
- property clone_config#
Config in case domain clones are used.
- property prop_list#
List of Propagator objects.
- property params: dict#
Model parameters passed to __init__() of the class, as dictionary.