pylbo.gimli.legolas
Classes
Class for generating user-defined Legolas modules and parfiles. |
Functions
|
Writes the use of user-defined physics functions to the Legolas user module. |
|
Writes a sympy expression to the user module as a Fortran function. |
|
Iterates over all Legolas equilibrium quantities and writes them to the user module. |
|
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_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”.
- user_module(filename='smod_user_defined', loc=None)
Writes the user module for the Legolas run.
- Parameters:
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:
- Returns:
parfiles – A list containing the paths to the parameter files.
- Return type:
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()