pylbo.gimli.legolas

Classes

Legolas

Class for generating user-defined Legolas modules and parfiles.

Functions

write_physics_calls(file, equilibrium)

Writes the use of user-defined physics functions to the Legolas user module.

fortran_function(file, expr, varname, translation[, ...])

Writes a sympy expression to the user module as a Fortran function.

write_grid_functions(file, equilibrium)

Writes the Legolas grid spacing function, if present, to the user module.

write_equilibrium_functions(file, equilibrium)

Iterates over all Legolas equilibrium quantities and writes them to the user module.

write_physics_functions(file, equilibrium)

Iterates over all Legolas physics expressions and writes them to the user module.

Module Contents

pylbo.gimli.legolas.write_physics_calls(file, equilibrium)

Writes the use of user-defined physics functions to the Legolas user module.

Parameters:
  • file (file) – The file object to write to.

  • equilibrium (Equilibrium) – The equilibrium object containing the user-defined equilibrium and physics functions.

pylbo.gimli.legolas.fortran_function(file, expr, varname, translation, constant=False, level=0)

Writes a sympy expression to the user module as a Fortran function.

Parameters:
  • file (file) – The file object to write to.

  • expr (sympy expression) – The expression to write.

  • varname (str) – The name of the function.

  • translation (dict) – A dictionary containing any substitution rules for sympy to Fortran expressions.

  • constant (bool) – Set to True if the function is a constant.

  • level (int) – The indentation level.

pylbo.gimli.legolas.write_grid_functions(file, equilibrium)

Writes the Legolas grid spacing function, if present, to the user module.

Parameters:
  • file (file) – The file object to write to.

  • equilibrium (Equilibrium) – The equilibrium object containing the user-defined grid function.

pylbo.gimli.legolas.write_equilibrium_functions(file, equilibrium)

Iterates over all Legolas equilibrium quantities and writes them to the user module.

Parameters:
  • file (file) – The file object to write to.

  • equilibrium (Equilibrium) – The equilibrium object containing the user-defined equilibrium functions.

pylbo.gimli.legolas.write_physics_functions(file, equilibrium)

Iterates over all Legolas physics expressions and writes them to the user module.

Parameters:
  • file (file) – The file object to write to.

  • equilibrium (Equilibrium) – The equilibrium object containing the user-defined physics functions.

class pylbo.gimli.legolas.Legolas(equilibrium, config)

Class for generating user-defined Legolas modules and parfiles.

Parameters:
  • equilibrium (Equilibrium) – The equilibrium object containing the user-defined equilibrium and physics functions.

  • config (dict) – A dictionary containing the configuration for the Legolas run (both equilibrium parameter values and technical settings).

equilibrium
config
_validate_config()

Validates the validity of the configuration dictionary.

Raises:
  • KeyError – If the configuration dictionary is missing the physics_type key.

  • ValueError – If physics_type is not “hd” or “mhd”.

_compare_heatcool()

Compares the presence of ‘heatcool’ in the equilibrium with the radiative cooling settings in the config. ‘heatcool’ overrides config settings, but if ‘heatcool’ is not present, config settings are added to the equilibrium.

_check_resistivity()

Makes sure that resistivity is enabled if needed.

user_module(filename='smod_user_defined', loc=None)

Writes the user module for the Legolas run.

Parameters:
  • filename (str) – The name of the user module file.

  • loc (str, PathLike) – Path to the directory where the user module will be stored. Default is the current directory.

Examples

The example below defines a homogeneous hydrodynamic equilibrium with constant density and temperature. The values of the equilibrium parameters are set in the configuration dictionary.

>>> from pylbo.gimli import Variables, Equilibrium, Legolas
>>> var = Variables()
>>> eq = Equilibrium(var, rho0=var.rhoc, v02=0, v03=0, T0=var.Tc)
>>> config = {
>>>     "geometry": "Cartesian",
>>>     "x_start": 0,
>>>     "x_end": 1,
>>>     "gridpoints": 51,
>>>     "parameters": {
>>>         "k2": 0.5,
>>>         "k3": 0,
>>>         "cte_rho0": 1,
>>>         "cte_T0": 1
>>>     },
>>>     "equilibrium_type": "user_defined",
>>>     "boundary_type": "wall_weak",
>>>     "physics_type": "mhd"
>>> }
>>> legolas = Legolas(eq, config)
>>> legolas.user_module()
parfile(filename='legolas_config', loc=None)

Writes the parameter file for the Legolas run.

Parameters:
  • filename (str) – The name of the parameter file.

  • make_dir (bool) – If True, creates a directory for the parameter file.

Returns:

parfiles – A list containing the paths to the parameter files.

Return type:

list

Examples

The example below defines a homogeneous hydrodynamic equilibrium with constant density and temperature. The values of the equilibrium parameters are set in the configuration dictionary and written to the parameter file.

>>> from pylbo.gimli import Variables, Equilibrium, Legolas
>>> var = Variables()
>>> eq = Equilibrium(var, rho0=var.rhoc, v02=0, v03=0, T0=var.Tc)
>>> config = {
>>>     "geometry": "Cartesian",
>>>     "x_start": 0,
>>>     "x_end": 1,
>>>     "gridpoints": 51,
>>>     "parameters": {
>>>         "k2": 0.5,
>>>         "k3": 0,
>>>         "cte_rho0": 1,
>>>         "cte_T0": 1
>>>     },
>>>     "equilibrium_type": "user_defined",
>>>     "boundary_type": "wall_weak",
>>>     "physics_type": "mhd"
>>> }
>>> legolas = Legolas(eq, config)
>>> legolas.parfile()