pylbo.gimli.legolas =================== .. py:module:: pylbo.gimli.legolas Classes ------- .. autoapisummary:: pylbo.gimli.legolas.Legolas Functions --------- .. autoapisummary:: pylbo.gimli.legolas.write_physics_calls pylbo.gimli.legolas.fortran_function pylbo.gimli.legolas.write_grid_functions pylbo.gimli.legolas.write_equilibrium_functions pylbo.gimli.legolas.write_physics_functions Module Contents --------------- .. py:function:: write_physics_calls(file, equilibrium) Writes the use of user-defined physics functions to the Legolas user module. :param file: The file object to write to. :type file: file :param equilibrium: The equilibrium object containing the user-defined equilibrium and physics functions. :type equilibrium: Equilibrium .. !! processed by numpydoc !! .. py:function:: fortran_function(file, expr, varname, translation, constant=False, level=0) Writes a sympy expression to the user module as a Fortran function. :param file: The file object to write to. :type file: file :param expr: The expression to write. :type expr: sympy expression :param varname: The name of the function. :type varname: str :param translation: A dictionary containing any substitution rules for sympy to Fortran expressions. :type translation: dict :param constant: Set to `True` if the function is a constant. :type constant: bool :param level: The indentation level. :type level: int .. !! processed by numpydoc !! .. py:function:: write_grid_functions(file, equilibrium) Writes the Legolas grid spacing function, if present, to the user module. :param file: The file object to write to. :type file: file :param equilibrium: The equilibrium object containing the user-defined grid function. :type equilibrium: Equilibrium .. !! processed by numpydoc !! .. py:function:: write_equilibrium_functions(file, equilibrium) Iterates over all Legolas equilibrium quantities and writes them to the user module. :param file: The file object to write to. :type file: file :param equilibrium: The equilibrium object containing the user-defined equilibrium functions. :type equilibrium: Equilibrium .. !! processed by numpydoc !! .. py:function:: write_physics_functions(file, equilibrium) Iterates over all Legolas physics expressions and writes them to the user module. :param file: The file object to write to. :type file: file :param equilibrium: The equilibrium object containing the user-defined physics functions. :type equilibrium: Equilibrium .. !! processed by numpydoc !! .. py:class:: Legolas(equilibrium, config) Class for generating user-defined Legolas modules and parfiles. :param equilibrium: The equilibrium object containing the user-defined equilibrium and physics functions. :type equilibrium: Equilibrium :param config: A dictionary containing the configuration for the Legolas run (both equilibrium parameter values and technical settings). :type config: dict .. !! processed by numpydoc !! .. py:attribute:: equilibrium .. py:attribute:: config .. py:method:: _validate_config() Validates the validity of the configuration dictionary. :raises KeyError: If the configuration dictionary is missing the `physics_type` key. :raises ValueError: If `physics_type` is not "hd" or "mhd". .. !! processed by numpydoc !! .. py:method:: _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. .. !! processed by numpydoc !! .. py:method:: _check_resistivity() Makes sure that resistivity is enabled if needed. .. !! processed by numpydoc !! .. py:method:: user_module(filename='smod_user_defined', loc=None) Writes the user module for the Legolas run. :param filename: The name of the user module file. :type filename: str :param loc: Path to the directory where the user module will be stored. Default is the current directory. :type loc: str, ~os.PathLike .. rubric:: 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() .. !! processed by numpydoc !! .. py:method:: parfile(filename='legolas_config', loc=None) Writes the parameter file for the Legolas run. :param filename: The name of the parameter file. :type filename: str :param make_dir: If `True`, creates a directory for the parameter file. :type make_dir: bool :returns: **parfiles** -- A list containing the paths to the parameter files. :rtype: list .. rubric:: 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() .. !! processed by numpydoc !!