uclchem.makerates.io_functions#
Functions to read in the species and reaction files and write output files
Module Contents#
Functions#
|
Write an array to fortran source code |
|
A long, complex function that does the messy work of creating the actual ODE |
|
Checks a row parsed from a reaction file and checks it only contains acceptable things. |
|
Try to find a reactant in the species list |
Every desorption has a corresponding freeze out eg desorption of #CO and freeze of CO. |
|
|
KIDA used a fixed format file so we read each line in the chunks they specify |
|
Writes the reactions that are dropped to disk/logs |
|
Reads in a reaction file of any kind (user, UMIST, KIDA) |
|
Reads in a Makerates species file |
|
Build the string of Fortran code for a species once it's loss and gains |
|
Take a string and adds line endings at regular intervals |
|
Two phase networks mimic episodic thermal desorption seen in lab (see Viti et al. 2004) |
|
Write the physical reactions to the f2py_constants.f90 file after every run of |
|
Write jacobian in Modern Fortran. This has never improved UCLCHEM's speed |
|
Write the Fortran code file that contains all network information for UCLCHEM. |
|
Write the ODEs in Modern Fortran. This is an actual code file. |
|
Write the ODE and Network fortran source files to the fortran source. |
|
Function to write the python constants to the constants.py file after every run, |
|
Write the human readable reaction file. |
|
Write the human readable species file. Note UCLCHEM doesn't use this file. |
- uclchem.makerates.io_functions.array_to_string(name: str, array: numpy.array, type: str = 'int', parameter: bool = True) str[source]#
Write an array to fortran source code
- Parameters:
- Raises:
ValueError – Raises an error if type isn’t “int”,”float”, or “string”
- Returns:
String containing the Fortran code to declare this array.
- Return type:
- uclchem.makerates.io_functions.build_ode_string(species_list: list[uclchem.makerates.species.Species], reaction_list: list[uclchem.makerates.reaction.Reaction], rates_to_disk: bool = False) str[source]#
A long, complex function that does the messy work of creating the actual ODE code to calculate the rate of change of each species. Test any change to this code thoroughly because ODE mistakes are very hard to spot.
- uclchem.makerates.io_functions.check_reaction(reaction_row, keep_list) bool[source]#
Checks a row parsed from a reaction file and checks it only contains acceptable things. It checks if all species in the reaction are present, and adds the temperature range is none is specified.
- uclchem.makerates.io_functions.find_reactant(species_list: list[str], reactant: str) int[source]#
Try to find a reactant in the species list
- uclchem.makerates.io_functions.get_desorption_freeze_partners(reaction_list: list[uclchem.makerates.reaction.Reaction]) list[uclchem.makerates.reaction.Reaction][source]#
Every desorption has a corresponding freeze out eg desorption of #CO and freeze of CO. This find the corresponding freeze out for every desorb so that when desorb>>freeze we can turn off freeze out in UCLCHEM.
- uclchem.makerates.io_functions.kida_parser(kida_file)[source]#
KIDA used a fixed format file so we read each line in the chunks they specify and use python built in classes to convert to the necessary types. NOTE KIDA defines some of the same reaction types to UMIST but with different names and coefficients. We fix that by converting them here.
- uclchem.makerates.io_functions.output_drops(dropped_reactions: list[uclchem.makerates.reaction.Reaction], output_dir: str = None, write_files: bool = True)[source]#
Writes the reactions that are dropped to disk/logs
- uclchem.makerates.io_functions.read_grain_assisted_recombination_file(file_name: pathlib.Path) dict[source]#
- uclchem.makerates.io_functions.read_reaction_file(file_name: pathlib.Path, species_list: list[uclchem.makerates.species.Species], ftype: str) tuple[list[uclchem.makerates.reaction.Reaction], list[uclchem.makerates.reaction.Reaction]][source]#
Reads in a reaction file of any kind (user, UMIST, KIDA) produces a list of reactions for the network, filtered by species_list
- uclchem.makerates.io_functions.read_species_file(file_name: pathlib.Path) list[uclchem.makerates.species.Species][source]#
Reads in a Makerates species file
- uclchem.makerates.io_functions.species_ode_string(n: int, species: uclchem.makerates.species.Species) str[source]#
Build the string of Fortran code for a species once it’s loss and gains strings have been produced.
- uclchem.makerates.io_functions.truncate_line(input_string: str, lineLength: int = 72) str[source]#
Take a string and adds line endings at regular intervals keeps us from overshooting fortran’s line limits and, frankly, makes for nicer ode.f90 even if human readability isn’t very important
- uclchem.makerates.io_functions.write_evap_lists(network_file, species_list: list[uclchem.makerates.species.Species]) int[source]#
Two phase networks mimic episodic thermal desorption seen in lab (see Viti et al. 2004) by desorbing fixed fractions of material at specific temperatures. Three phase networks just use binding energy and that fact we set binding energies in bulk to water by default. This function writes all necessary arrays to the network file so these processes work.
- uclchem.makerates.io_functions.write_f90_constants(replace_dict: Dict[str, int], output_file_name: pathlib.Path, template_file_path: pathlib.Path = 'fortran_templates') None[source]#
Write the physical reactions to the f2py_constants.f90 file after every run of makerates, this ensures the Fortran and Python bits are compatible with one another.
- uclchem.makerates.io_functions.write_jacobian(file_name: pathlib.Path, species_list: list[uclchem.makerates.species.Species]) None[source]#
Write jacobian in Modern Fortran. This has never improved UCLCHEM’s speed and so is not used in the code as it stands. Current only works for three phase model.
- Parameters:
file_name (str) – Path to jacobian file
species_list (species_list) – List of species AFTER being processed by build_ode_string
- uclchem.makerates.io_functions.write_network_file(file_name: pathlib.Path, network: uclchem.makerates.network.Network, rates_to_disk: bool = False, gar_database=None)[source]#
Write the Fortran code file that contains all network information for UCLCHEM. This includes lists of reactants, products, binding energies, formationEnthalpies and so on.
- uclchem.makerates.io_functions.write_odes_f90(file_name: pathlib.Path, species_list: list[uclchem.makerates.species.Species], reaction_list: list[uclchem.makerates.reaction.Reaction], rates_to_disk: bool = False) None[source]#
Write the ODEs in Modern Fortran. This is an actual code file.
- uclchem.makerates.io_functions.write_outputs(network: uclchem.makerates.network.Network, output_dir: str = None, rates_to_disk: bool = False, gar_database: dict[str, numpy.array] = None) None[source]#
Write the ODE and Network fortran source files to the fortran source.
- Parameters:
network (network) – The makerates Network class
output_dir (bool) – The directory to write to.
- uclchem.makerates.io_functions.write_python_constants(replace_dict: Dict[str, int], python_constants_file: pathlib.Path) None[source]#
Function to write the python constants to the constants.py file after every run, this ensure the Python and Fortran bits are compatible with one another.
- uclchem.makerates.io_functions.write_reactions(fileName, reaction_list) None[source]#
Write the human readable reaction file.
- uclchem.makerates.io_functions.write_species(file_name: pathlib.Path, species_list: list[uclchem.makerates.species.Species]) None[source]#
Write the human readable species file. Note UCLCHEM doesn’t use this file.