# Path: auxi/tools/materialphysicalproperties/core.py
# class Model(Object):
#     """
#     Base class of models that describe the variation of a specific material
#     physical property.
# 
#     :param material: the name of the material being described, e.g. "Air"
#     :param property: the name of the property being described, e.g. "density"
#     :param symbol: the symbol of the property being described, e.g. "rho"
#     :param display symbol: the display symbol of the property being described,\
#     e.g. "\rho"
#     :param units: the units used to express the property, e.g. "kg/m3"
#     :param references: a list of literature references on which this model\
#     implementation is based, e.g. ['lienhard2015', 'smith2006']
#     :param datasets: a list of data sets on which this model implementation is\
#     based, e.g. ['dataset-air-lienhard2015.csv']
#     """
# 
#     def __init__(self, material, property, symbol, display_symbol, units,
#                  state_schema, references, datasets):
#         self.material = material
#         self.property = property
#         self.symbol = symbol
#         self.display_symbol = display_symbol
#         self.units = units
#         self.references = references
#         self.datasets = datasets
#         self.state_schema = state_schema
#         self._create_validator(self.state_schema)
# 
#     def __call__(self, **state):
#         """
#         For details about this method, please refer to the calculate method.
#         """
#         return self.calculate(**state)
# 
#     def _create_validator(self, state_schema):
#         self.state_schema = state_schema
#         self.state_validator = Validator(self.state_schema)
# 
#     def calculate(self, **state):
#         """
#         Base calculate method for models.
#         Validates the material state parameter(s).
# 
#         :param **state: The material state
#         """
#         if not self.state_validator.validate(state):
#             msg = f"{self.material} {self.property} model. The state "
#             msg += f"description ({state}) contains errors:"
#             for key, value in self.state_validator.errors.items():
#                 msg += ' %s: %s;' % (key, value)
#             msg = msg[0:-1]+'.'
#             raise ValidationError(msg)
# 
# Path: auxi/tools/physicalconstants.py
# R = 8.314462618
# 
# Path: auxi/tools/chemistry/stoichiometry.py
# def molar_mass(self):
#     return sum(_element_dictionary_[element].molar_mass*count
#                for element, count in self.count().items())


from matplotlib.backends.backend_pdf import PdfPages
from auxi.tools.materialphysicalproperties.core import Model
from auxi.tools.physicalconstants import R
from auxi.tools.chemistry.stoichiometry import molar_mass as mm
    from idealgas_test import *
import webbrowser
import matplotlib.pyplot as plt
import numpy as np
    import unittest
class RhoTP(Model):
    """
    A model that describes the variation in density of an ideal gas as a
    function of temperature and pressure.

    :param molar_mass: [g/mol] average molar mass of the gas
    """

    def __init__(self, molar_mass):
        state_schema = {"T": {"required": True, "type": "float", "min": 0.0},
                        "P": {"required": True, "type": "float", "min": 0.0}}
        super().__init__("Ideal Gas", "Density", "rho", "\\rho", "kg/m3",
                         state_schema, None, None)

        self.mm = molar_mass / 1000.0
        """[kg/mol] average molar mass of the gas"""

    def calculate(self, **state):
        """
        Calculate the density at the specified temperature and pressure.

        :param T: [K] temperature
        :param P: [Pa] pressure

        :returns: [kg/m3] density

        The **state parameter contains the keyword argument(s) specified above\
        that are used to describe the state of the material.
        """
        super().calculate(**state)

# Path: auxi/tools/materialphysicalproperties/core.py
# class Model(Object):
#     """
#     Base class of models that describe the variation of a specific material
#     physical property.
# 
#     :param material: the name of the material being described, e.g. "Air"
#     :param property: the name of the property being described, e.g. "density"
#     :param symbol: the symbol of the property being described, e.g. "rho"
#     :param display symbol: the display symbol of the property being described,\
#     e.g. "\rho"
#     :param units: the units used to express the property, e.g. "kg/m3"
#     :param references: a list of literature references on which this model\
#     implementation is based, e.g. ['lienhard2015', 'smith2006']
#     :param datasets: a list of data sets on which this model implementation is\
#     based, e.g. ['dataset-air-lienhard2015.csv']
#     """
# 
#     def __init__(self, material, property, symbol, display_symbol, units,
#                  state_schema, references, datasets):
#         self.material = material
#         self.property = property
#         self.symbol = symbol
#         self.display_symbol = display_symbol
#         self.units = units
#         self.references = references
#         self.datasets = datasets
#         self.state_schema = state_schema
#         self._create_validator(self.state_schema)
# 
#     def __call__(self, **state):
#         """
#         For details about this method, please refer to the calculate method.
#         """
#         return self.calculate(**state)
# 
#     def _create_validator(self, state_schema):
#         self.state_schema = state_schema
#         self.state_validator = Validator(self.state_schema)
# 
#     def calculate(self, **state):
#         """
#         Base calculate method for models.
#         Validates the material state parameter(s).
# 
#         :param **state: The material state
#         """
#         if not self.state_validator.validate(state):
#             msg = f"{self.material} {self.property} model. The state "
#             msg += f"description ({state}) contains errors:"
#             for key, value in self.state_validator.errors.items():
#                 msg += ' %s: %s;' % (key, value)
#             msg = msg[0:-1]+'.'
#             raise ValidationError(msg)
# 
# Path: auxi/tools/physicalconstants.py
# R = 8.314462618
# 
# Path: auxi/tools/chemistry/stoichiometry.py
# def molar_mass(self):
#     return sum(_element_dictionary_[element].molar_mass*count
#                for element, count in self.count().items())


# Path: auxi/tools/materialphysicalproperties/idealgas.py
from matplotlib.backends.backend_pdf import PdfPages
from auxi.tools.materialphysicalproperties.core import Model
from auxi.tools.physicalconstants import R
from auxi.tools.chemistry.stoichiometry import molar_mass as mm
    from idealgas_test import *
import webbrowser
import matplotlib.pyplot as plt
import numpy as np
    import unittest

class RhoTP(Model):
    """
    A model that describes the variation in density of an ideal gas as a
    function of temperature and pressure.

    :param molar_mass: [g/mol] average molar mass of the gas
    """

    def __init__(self, molar_mass):
        state_schema = {"T": {"required": True, "type": "float", "min": 0.0},
                        "P": {"required": True, "type": "float", "min": 0.0}}
        super().__init__("Ideal Gas", "Density", "rho", "\\rho", "kg/m3",
                         state_schema, None, None)

        self.mm = molar_mass / 1000.0
        """[kg/mol] average molar mass of the gas"""

    def calculate(self, **state):
        """
        Calculate the density at the specified temperature and pressure.

        :param T: [K] temperature
        :param P: [Pa] pressure

        :returns: [kg/m3] density

        The **state parameter contains the keyword argument(s) specified above\
        that are used to describe the state of the material.
        """
        super().calculate(**state)

        return self.mm * state["P"] / R / state["T"]