pylbo.gimli

Submodules

Classes

Equilibrium

Variables

Defines a set of variables and constants to be used in defining an Equilibrium

Legolas

Class for generating user-defined Legolas modules and parfiles.

Amrvac

Class to prepare Legolas data for use in MPI-AMRVAC (https://amrvac.org).

Package Contents

class pylbo.gimli.Equilibrium(var, rho0, v02, v03, T0, B02=None, B03=None, resistivity=None, gravity=None, condpara=None, condperp=None, cooling=None, heating=None)

” Class containing all equilibrium expressions and initialisation functions. This object is a required argument when generating user files with the Legolas and Amrvac classes.

Parameters:
  • var (Variables) – The Variables object containing the symbols to be used in the equilibrium expressions.

  • rho0 (sympy expression) – The equilibrium density expression.

  • v02 (sympy expressions) – The equilibrium velocity expressions.

  • v03 (sympy expressions) – The equilibrium velocity expressions.

  • T0 (sympy expression) – The equilibrium temperature expression.

  • B02 (sympy expressions) – The equilibrium magnetic field expressions.

  • B03 (sympy expressions) – The equilibrium magnetic field expressions.

  • resistivity (sympy expression) – The resistivity expression.

  • gravity (constant) – The gravitational acceleration.

  • condpara (sympy expression) – The parallel conduction prescription.

  • condperp (sympy expression) – The perpendicular conduction prescription.

  • cooling (sympy expression) – The cooling prescription.

  • heating (sympy expression) – The heating prescription.

variables

Variables object from which all expressions are constructed.

Type:

Variables object

rho0

The equilibrium density expression.

Type:

sympy expression

v02, v03

The equilibrium velocity expressions.

Type:

sympy expressions

T0

The equilibrium temperature expression.

Type:

sympy expression

B02, B03

The equilibrium magnetic field expressions.

Type:

sympy expressions

Examples

The example below defines a homogeneous hydrodynamic equilibrium with constant density and temperature. Their values can be set later when passing this equilibrium to the Legolas or Amrvac class along with a dictionary.

>>> from pylbo.gimli import Equilibrium, Variables
>>> var = Variables()
>>> eq = Equilibrium(var, rho0=var.rhoc, v02=0, v03=0, T0=var.Tc)
variables
rho0
T0
_dict_phys
get_physics()

Returns a dictionary containing the physics expressions and the dependencies to check for.

get_dependencies()

Checks for dependencies on other equilibrium quantities. Returns a dictionary with the replacement expressions for use in Fortran files.

class pylbo.gimli.Variables

Defines a set of variables and constants to be used in defining an Equilibrium object.

x, y, z

Coordinates.

Type:

sympy symbols

rho0, T0, B0sq

Density, temperature, and magnetic field squared for use in expressions depending on these quantities.

Type:

sympy symbols

k2, k3

Wavenumbers.

Type:

sympy symbols

rhoc, Tc, B2c, B3c, v2c, v3c, pc

Constants typically used for amplitudes or uniform terms in their corresponding equilibrium quantities.

Type:

sympy symbols

p1, p2, p3, p4, p5, p6, p7, p8

Additional free-use constants.

Type:

sympy symbols

alpha, beta, delta, theta, tau, lamda, nu

Additional free-use constants.

Type:

sympy symbols

r0, rc, rj, Bth0, V, j0, g

Additional constants, originally use in cylindrical coordinates.

Type:

sympy symbols

fkey

Dictionary translating LaTeX notation to Legolas variable names.

Type:

dict

Examples

>>> from pylbo.gimli import Variables
>>> var = Variables()
fkey
class pylbo.gimli.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”.

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', make_dir=False)

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()
class pylbo.gimli.Amrvac(config)

Class to prepare Legolas data for use in MPI-AMRVAC (https://amrvac.org).

Parameters:

config (dict) – The configuration dictionary detailing which Legolas file and selection of eigenmodes to use.

config
_validate_config()

Validates the presence and value of physics_type in the configuration dictionary.

Raises:
_validate_datfile()

Validates whether a valid Legolas data file was specified in the configuration. Further checks whether all necessary parameters are present in the configuration to prepare Legolas data for use with MPI-AMRVAC.

Raises:
  • AssertionError – If the length of weights is not equal to the number of eigenvalues or if the elements of the weights do not add up to 1; if ef_factor does not have modulus 1; if norm_range does not have length 2; if norm_range’s first element is larger than the second.

  • KeyError – If no datfile is specified; if no initial guess for the eigenvalue is specified.

  • TypeError – If ev_guess is not a single float/complex number or a list/NumPy array of float/complex numbers; if ev_time for the eigenvalue is not a float or an integer; if weights is not a list or NumPy array; if ef_factor is not a list with length equal to the number of eigenvalues, or an integer, float, or complex number; if quantity is not a string; if percentage is not a float; if norm_range is not a NumPy array.

  • ValueError – If quantity is not in the list of equilibrium quantities.

  • Exception – If the datfile is invalid.

_get_combined_perturbation(ef)

Takes Legolas’s perturbations of different eigenvalues and adds them up to a single perturbation.

Parameters:

ef (str) – The eigenfunction to combine.

Returns:

The combined perturbation.

Return type:

np.ndarray

_get_total_perturbation(ef_type)

Combines the perturbations of different eigenvalues into a single perturbation. Derives the pressure perturbation from the density and temperature perturbations.

Parameters:

ef_type (str) – The eigenfunction to calculate.

Returns:

The total perturbation.

Return type:

np.ndarray

_get_normalisation()

Normalises the perturbation of the specified quantity by the maximum background value.

Returns:

The normalisation factor.

Return type:

float

prepare_legolas_data(loc=None)

Prepares a file (.ldat) from the Legolas data for use with MPI-AMRVAC.

Parameters:

loc (str, PathLike) – Path to the directory where the .ldat file will be stored. Default is the current directory.

Raises:

ValueError – If the datfile is invalid.

Examples

>>> from pylbo.gimli import Amrvac
>>> amrvac_config = {
>>>     "datfile": "./datfile.dat",
>>>     "physics_type": "mhd",
>>>     "ev_guess": [-0.1, 0.1],
>>>     "ev_time": 0,
>>>     "percentage": 0.01,
>>>     "quantity": "rho0"
>>> }
>>> amrvac = gimli.Amrvac(amrvac_config)
>>> amrvac.prepare_legolas_data()