Struphy model base class#
- class struphy.models.base.StruphyModel[source]#
Bases:
objectBase class for all Struphy models.
Note
All Struphy models are subclasses of
StruphyModeland should be added tostruphy/models/in one of the modulesfluid.py,kinetic.py,hybrid.pyortoy.py.- 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 update_scalar_quantities()[source]#
Specify an update rule for each item in
scalar_quantitiesusingupdate_scalar().
- setup_equation_params(units: Units, verbose=False)[source]#
Set euqation parameters for each fluid and kinetic species.
- setup_domain_and_equil(domain: Domain, equil: FluidEquilibrium)[source]#
If a numerical equilibirum is used, the domain is taken from this equilibirum.
- property field_species: dict#
- property fluid_species: dict#
- property particle_species: dict#
- property diagnostic_species: dict#
- property species#
- allocate_feec(grid: TensorProductGrid, derham_opts: DerhamOptions)[source]#
- static diagnostics_dct()[source]#
Diagnostics dictionary. Model specific variables (FemField) which is going to be saved during the simulation.
- property params#
Model parameters from
parameters.yml.
- property pparams#
Plasma parameters for each species.
- property equation_params#
Parameters appearing in model equation due to Struphy normalization.
- property clone_config#
Config in case domain clones are used.
- property equil#
Fluid equilibrium object, see Fluid equilibria.
- property derham#
3d Derham sequence, see derham.
- property projected_equil#
Fluid equilibrium projected on 3d Derham sequence with commuting projectors.
- property mass_ops#
WeighteMassOperators object, see mass_ops.
- property basis_ops#
Basis projection operators.
- property prop_list#
List of Propagator objects.
- property prop_fields#
- property prop_coupling#
- property prop_markers#
- property kwargs#
Dictionary holding the keyword arguments for each propagator specified in
propagators_cls. Keys must be the same as inpropagators_cls, values are dictionaries holding the keyword arguments.
- property scalar_quantities#
A dictionary of scalar quantities to be saved during the simulation.
- property time_state#
A pointer to the time variable of the dynamics (‘t’).
- property verbose#
show model info on screen.
- Type:
Bool
- classmethod options()[source]#
Dictionary for available species options of the form {‘em_fields’: {}, ‘fluid’: {}, ‘kinetic’: {}}.
- classmethod add_option(species: str | list, option, dct: dict, *, key=None)[source]#
Add an option to the dictionary of parameters under [species][options].
Test with “struphy params MODEL”.
- Parameters:
species (str or list) – path in the dict before the ‘options’ key
option (any) – value which should be added in the dict
dct (dict) – dictionary to which the value should be added at the corresponding position
key (str or list) – path in the dict after the ‘options’ key
- add_scalar(name: str, variable: PICVariable | SPHVariable | None = None, compute=None, summands=None)[source]#
Add a scalar to be saved during the simulation.
- Parameters:
name (str) – Dictionary key for the scalar.
variable (PICVariable | SPHVariable, optional) – The variable associated with the scalar. Required if compute is ‘from_particles’.
compute (str, optional) – Type of scalar, determines the compute operations. Options: ‘from_particles’ or ‘from_field’. Default is None.
summands (list, optional) – List of other scalar names whose values should be summed to compute the value of this scalar. Default is None.
- update_scalar(name, value=None)[source]#
Add a scalar that should be saved during the simulation.
- Parameters:
name (str) – Dictionary key of the scalar.
value (float, optional) – Value to be saved. Required if there are no summands.
- add_time_state(time_state)[source]#
Add a pointer to the time variable of the dynamics (‘t’) to the model and to all propagators of the model.
- Parameters:
time_state (ndarray) – Of size 1, holds the current physical time ‘t’.
- allocate_variables(verbose: bool = False)[source]#
Allocate memory for model variables and set initial conditions.
- 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.
- initialize_from_restart(data)[source]#
Set initial conditions for FE coefficients (electromagnetic and fluid) and markers from restart group in hdf5 files.
- Parameters:
data (struphy.io.output_handling.DataContainer) – The data object that links to the hdf5 files.
- initialize_data_output(data: DataContainer, size)[source]#
Create datasets in hdf5 files according to model unknowns and diagnostics data.
- Parameters:
data (struphy.io.output_handling.DataContainer) – The data object that links to the hdf5 files.
size (int) – Number of MPI processes of the model run.
- Returns:
save_keys_all (list) – Keys of datasets which are saved during the simulation.
save_keys_end (list) – Keys of datasets which are saved at the end of a simulation to enable restarts.
- 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
- compute_plasma_params(verbose=True)[source]#
Compute and print volume averaged plasma parameters for each species of the model.
Global parameters: - plasma volume - transit length - magnetic field
Species dependent parameters: - mass - charge - density - pressure - thermal energy kBT - Alfvén speed v_A - thermal speed v_th - thermal frequency Omega_th - cyclotron frequency Omega_c - plasma frequency Omega_p - Alfvèn frequency Omega_A - thermal Larmor radius rho_th - MHD length scale v_a/Omega_c - rho/L - alpha = Omega_p/Omega_c - epsilon = 1/(t*Omega_c)