""":mod:`mirgecom.mechanisms`: Utilities for managing thermochemistry mechanisms... autofunction:: get_mechanisms_pkgname.. autofunction:: get_mechanism_file_name.. autofunction:: get_mechanism_input.. autofunction:: import_mechdata"""__copyright__="""Copyright (C) 2020 University of Illinois Board of Trustees"""__license__="""Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE."""importsysifsys.version_info<(3,9):# importlib.resources either doesn't exist or lacks the files()# function, so use the PyPI version:importimportlib_resources# pylint: disable=import-errorelse:# importlib.resources has files(), so use that:importimportlib.resourcesasimportlib_resources
[docs]defget_mechanisms_pkgname()->str:"""Get a qualified package name for the location of mechanism data."""return"mirgecom.mechanisms"
[docs]defget_mechanism_file_name(mechanism_name:str)->str:"""Form the YAML file name for a mechanism."""returnf"{mechanism_name}.yaml"
[docs]defimport_mechdata():"""Import the mechanism data as a mechanism data resource. Returns ------- :class:`importlib.resources.abc.Traversable` Object of type :class:`importlib.resources.abc.Traversable` representing the container (think directory) of the thermochemistry mechanism data (think YAML files). """returnimportlib_resources.files(get_mechanisms_pkgname())
[docs]defget_mechanism_input(mechanism_name:str)->str:"""Get the contents of a mechanism YAML input file."""importosfrompathlibimportPathmech_data=import_mechdata()mech_file=mech_data/get_mechanism_file_name(mechanism_name)ifnotos.path.isfile(mech_file):fromwarningsimportwarnwarn("Mechanism not found in default location.",stacklevel=2)current_path=os.path.abspath(os.getcwd())+"/"mech_file=Path(current_path+get_mechanism_file_name(mechanism_name))warn("Trying "+current_path,stacklevel=2)returnmech_file.read_text()