pyjac.utils module

Module containing utility functions.

pyjac.utils.comment = {'c': '//', 'cuda': '//', 'fortran': '!', 'matlab': '%'}

dict – comment characters for each language

pyjac.utils.langs = ['c', 'cuda', 'fortran', 'matlab']

list(str) – list of supported languages

pyjac.utils.file_ext = {'c': '.c', 'cuda': '.cu', 'fortran': '.f90', 'matlab': '.m'}

dict – source code file extensions based on language

pyjac.utils.restrict = {'c': '__restrict__', 'cuda': '__restrict__'}

dict – language-dependent keyword for restrict

pyjac.utils.header_ext = {'c': '.h', 'cuda': '.cuh'}

dict – header extensions based on language

pyjac.utils.line_end = {'c': ';\n', 'cuda': ';\n', 'fortran': '\n', 'matlab': ';\n'}

dict – line endings dependent on language

pyjac.utils.exp_10_fun = {'c': 'pow(10.0, ', 'cuda': 'exp10(', 'fortran': 'exp(log(10) * ', 'matlab': 'exp(log(10.0) * '}

dict – exp10 functions for various languages

pyjac.utils.array_chars = {'c': '[{}]', 'cuda': '[INDEX({})]', 'fortran': '({})', 'matlab': '({})'}

dict – the characters to format an index into an array per language

pyjac.utils.get_species_mappings(num_specs, last_species)[source]

Maps species indices around species moved to last position.

Parameters:
  • num_specs (int) – Number of species.
  • last_species (int) – Index of species being moved to end of system.
Returns:

  • fwd_species_map (list of int) – List of original indices in new order
  • back_species_map (list of int) – List of new indicies in original order

pyjac.utils.get_nu(isp, rxn)[source]

Returns the net nu of species isp for the reaction rxn

Parameters:
  • isp (int) – Species index
  • rxn (ReacInfo) – Reaction
Returns:

nu – Overall stoichiometric coefficient of species isp in reaction rxn

Return type:

int

pyjac.utils.read_str_num(string, sep=None)[source]

Returns a list of floats pulled from a string.

Delimiter is optional; if not specified, uses whitespace.

Parameters:
  • string (str) – String to be parsed.
  • sep (str, optional) – Delimiter (default is None, which means consecutive whitespace).
Returns:

Floats separated by sep in string.

Return type:

list of float

pyjac.utils.split_str(seq, length)[source]

Separate a string seq into length-sized pieces.

Parameters:
  • seq (str) – String containing sequence of smaller strings of constant length.
  • length (int) – Length of individual sequences.
Returns:

List of strings of length length from seq.

Return type:

list of str

pyjac.utils.create_dir(path)[source]

Creates a new directory based on input path.

No error if path already exists, but other error is reported.

Parameters:path (str) – Path of directory to be created
Returns:
Return type:None
pyjac.utils.get_array(lang, name, index, twod=None)[source]

Given a language and an index, returns the proper string index formatted into the appropriate array characters (e.g., [] or ()).

Parameters:
  • lang (str) – One of the accepted languages
  • name (str) – The name of the array
  • index (int) – The index to format
  • twod (int, optional) – If not None and the lang is ‘fortan’ or ‘matlab’ this will be formatted as a second index in the array.
Returns:

name – String with indexed array.

Return type:

str

pyjac.utils.get_index(lang, index)[source]

Given an integer index this function will return the proper string version of the index based on the language and other considerations

Parameters:
  • lang (str) – One of the supported languages, {‘c’, ‘cuda’, ‘fortran’, ‘matlab’}
  • index (int) –
Returns:

The string corresponding to the correct index to be formatted into the code

Return type:

str

pyjac.utils.reassign_species_lists(reacs, specs)[source]

Given a list of ReacInfo, and SpecInfo, this method will update the ReacInfo reactants / products / third body list to integers representing the species’ index in the list.

Parameters:
  • reacs (list of ReacInfo) – List of reactions to be updated.
  • specs (list of SpecInfo) – List of species
Returns:

Return type:

None

pyjac.utils.is_integer(val)[source]

Returns True if argument is an integer or whole number.

Parameters:val (int, float) – Value to be checked.
Returns:True if val is int or whole number (if float).
Return type:bool
pyjac.utils.get_parser()[source]
Parameters:None
Returns:args – Command line arguments for running pyJac.
Return type:argparse.Namespace