pylbo.gimli.amrvac ================== .. py:module:: pylbo.gimli.amrvac Classes ------- .. autoapisummary:: pylbo.gimli.amrvac.Amrvac Functions --------- .. autoapisummary:: pylbo.gimli.amrvac.write_equilibrium_functions pylbo.gimli.amrvac.write_split_equilibrium_functions pylbo.gimli.amrvac.write_physics_pointers pylbo.gimli.amrvac.write_physics_subroutines pylbo.gimli.amrvac.get_code_expression Module Contents --------------- .. py:function:: write_equilibrium_functions(file, eq, to_fetch_total, to_fetch_split) Writes a subroutine where all equilibrium functions are defined for reuse in other routines. `get_equilibrium' then returns the total equilibrium functions plus the current if needed (if not, this part of the array is zero). :param file: The file object to write to. :type file: file :param eq: The equilibrium object containing the user-defined equilibria. :type eq: Equilibrium :param to_fetch_total: The list of equilibrium functions to write to the file. :type to_fetch_total: list :param to_fetch_split: The list of split equilibrium functions to write to the file. :type to_fetch_split: list .. !! processed by numpydoc !! .. py:function:: write_split_equilibrium_functions(file, to_fetch, field) .. py:function:: write_physics_pointers(file, eq) .. py:function:: write_physics_subroutines(file, eq) .. py:function:: get_code_expression(expr, translation, assign) .. py:class:: Amrvac(config) Class to prepare Legolas data for use in MPI-AMRVAC (https://amrvac.org). :param config: The configuration dictionary detailing everything needed for the desired functionalities. :type config: dict .. !! processed by numpydoc !! .. py:attribute:: config .. py:method:: _validate_config() Validates the presence and value of `physics_type` in the configuration dictionary. :raises KeyError: If `physics_type` is missing. :raises ValueError: If `physics_type` is invalid. .. !! processed by numpydoc !! .. py:method:: _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. :raises KeyError: If no datfile is specified; if no initial guess for the eigenvalue is specified. :raises TypeError: If `ev_guess` is not a single float/complex number or a list/NumPy array of float/complex numbers; 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. :raises ValueError: If `quantity` is not in the list of equilibrium quantities. :raises Exception: If the datfile is invalid. .. !! processed by numpydoc !! .. py:method:: _validate_config_for_mod_usr() Validates whether the configuration dictionary contains all the arguments to generate a mod_usr.t file for use with MPI-AMRVAC. .. !! processed by numpydoc !! .. py:method:: _validate_simulation_dict() .. py:method:: _get_combined_perturbation(ef, clean=True) Takes Legolas's perturbations of different eigenvalues and adds them up to a single perturbation. :param ef: The eigenfunction to combine. :type ef: str :returns: The combined perturbation. :rtype: np.ndarray .. !! processed by numpydoc !! .. py:method:: _get_total_perturbation(ef_type, clean=True) Combines the perturbations of different eigenvalues into a single perturbation. Derives the pressure perturbation from the density and temperature perturbations. :param ef_type: The eigenfunction to calculate. :type ef_type: str :returns: The total perturbation. :rtype: np.ndarray .. !! processed by numpydoc !! .. py:method:: _integrate_energy_term(array, order) .. py:method:: _get_ef_normalisation(clean=True) Normalises the perturbation of the specified quantity by the maximum background value. :returns: The normalisation factor. :rtype: float .. !! processed by numpydoc !! .. py:method:: _get_energy_normalisation(clean=True) Normalises the perturbation eigenfunctions by the energy. :returns: The normalisation factor. :rtype: float .. !! processed by numpydoc !! .. py:method:: _get_normalisation(clean=True) Selects which procedure to follow for the normalisation. :returns: The normalisation factor. :rtype: float .. !! processed by numpydoc !! .. py:method:: _check_physical_perturbation(ef_name, pert) .. py:method:: prepare_legolas_data(name=None, loc=None, clean=True) Prepares a file (.ldat) from the Legolas data for use with MPI-AMRVAC. :param name: Name of the .ldat file :type name: str :param loc: Path to the directory where the .ldat file will be stored. Default is the current directory. :type loc: str, ~os.PathLike :raises ValueError: If the datfile is invalid. .. rubric:: Examples >>> from pylbo.gimli import Amrvac >>> amrvac_config = { >>> "datfile": "./datfile.dat", >>> "physics_type": "mhd", >>> "ev_guess": [-0.1, 0.1], >>> "percentage": 0.01, >>> "quantity": "rho0" >>> } >>> amrvac = gimli.Amrvac(amrvac_config) >>> amrvac.prepare_legolas_data() .. !! processed by numpydoc !! .. py:method:: user_module(filename='mod_usr', loc=None) Writes the user module for MPI-AMRVAC. :param filename: Name of the user module file, defaults to mod_usr :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 .. !! processed by numpydoc !! .. py:method:: parfile(basename='amrvac_config', loc=None, subdir=True, prefix_numbers=False, nb_prefix_digits=4) Generates parfiles based on the `parfile` dictionary. The separate namelists do not have to be taken into account, and a normal dictionary should be supplied where the keys correspond to the namelist items that are required. Typechecking is done automatically during parfile generation. :param basename: The basename for the parfile, the `.par` suffix is added automatically and is not needed. If multiple parfiles are generated, these will be prepended by a 4-digit number (e.g. 0003myparfile.par). If not provided, the basename will default to `amrvac_config`. :type basename: str :param output_dir: Output directory where the parfiles are saved, defaults to the current working directory if not specified. A subdirectory called `parfiles` will be created in which the parfiles will be saved. :type output_dir: str, ~os.PathLike :param subdir: If `True` (default), creates a subdirectory `parfiles` in the output folder. :type subdir: boolean :param prefix_numbers: If `True` prepends the `basename` by a n-digit number (e.g. xxxxmyparfile.par). The number of digits is specified by `nb_prefix_digits`. :type prefix_numbers: boolean :param nb_prefix_digits: Number of digits to prepend to the `basename` if `prefix_numbers` is `True`. Defaults to 4. :type nb_prefix_digits: int :returns: **parfiles** -- A list with the paths to the parfiles that were generated. :rtype: list .. !! processed by numpydoc !!