Example #1
0
# # 6. Plot Thermodynamic Quantities
# Use [`pmutt.plot_1D`](https://vlachosgroup.github.io/pMuTT/visual.html#plot-1d) and [`pmutt.plot_2D`](https://vlachosgroup.github.io/pMuTT/visual.html#plot-2d) to plot any function with respect to 1 or 2 variables.

# In[7]:

import numpy as np
from matplotlib import pyplot as plt
from pmutt import plot_1D, plot_2D

T = np.linspace(300., 500.)

f1, ax1 = plot_1D(H2_statmech,
                  x_name='T',
                  x_values=T,
                  methods=('get_H', 'get_S', 'get_G'),
                  get_H_kwargs={'units': 'kcal/mol'},
                  get_S_kwargs={'units': 'cal/mol/K'},
                  get_G_kwargs={'units': 'kcal/mol'})
f1.set_size_inches(6, 6)
f1.set_dpi(200)
plt.show()

# <a id='section_7'></a>

# # 7. Exercise 2
#
# 1. Create a ``StatMech`` object for ideal gas-phase H2O. The necessary inputs are given below.
#
# |            Parameter           |             Value            |
# |--------------------------------|------------------------------|
Example #2
0
    def plot_empirical(self, T_low=None, T_high=None, Cp_units=None,
                       H_units=None, S_units=None, G_units=None):
        """Plots the thermodynamic profiles between ``T_low`` and ``T_high``
        using empirical relationship

        Parameters
        ----------
            T_low : float
                Lower temperature in K. If not specified,
                ``T_low`` attribute used.
            T_high : float
                Upper temperature in K. If not specified,
                ``T_high`` attribute used.
            Cp_units : str
                Units to plot heat capacity. See :func:`~pmutt.constants.R`
                for accepted units. If not specified, dimensionless units used.
            H_units : str
                Units to plot enthalpy. See :func:`~pmutt.constants.R` for
                accepted units but omit the '/K' (e.g. J/mol). If not
                specified, dimensionless units used.
            S_units : str
                Units to plot entropy. See :func:`~pmutt.constants.R` for
                accepted units. If not specified, dimensionless units used.
            G_units : str
                Units to plot Gibbs free energy. See :func:`~pmutt.constants.R`
                for accepted units but omit the '/K' (e.g. J/mol). If not
                specified, dimensionless units used.
        Returns
        -------
            figure : `matplotlib.figure.Figure`_
                Figure
            axes : tuple of `matplotlib.axes.Axes.axis`_
                Axes of the plots.
                0. Cp
                1. H
                2. S
                3. G

        .. _`matplotlib.figure.Figure`: https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html
        .. _`matplotlib.axes.Axes.axis`: https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.axis.html
        """
        # Process temperatures
        if T_low is None:
            T_low = self.T_low
        if T_high is None:
            T_high = self.T_high
        T = np.linspace(T_low, T_high)

        # Process the method names, units, and y labels
        units = (Cp_units, H_units, S_units, G_units)
        methods = ['get_Cp', 'get_H', 'get_S', 'get_G']
        y_labels = []
        kwargs = {}
        for i, (units, method) in enumerate(zip(units, methods)):
            if units is None:
                if method == 'get_Cp' or method == 'get_S':
                    methods[i] = '{}oR'.format(method)
                else:
                    methods[i] = '{}oRT'.format(method)
                y_labels.append(method.replace('o', '/').replace('get_', ''))
            else:
                kwargs['{}_kwargs'.format(method)] = {'units': units}
                y_labels.append('{} ({})'.format(method.replace('get_', ''),
                                                 units))

        fig, ax = plot_1D(self, x_name='T', x_values=T, methods=methods,
                          **kwargs)
        
        # Add titles and labels
        ax[0].set_title('Species: {}'.format(self.name))
        for i, y_label in enumerate(y_labels):
            ax[i].set_xlabel('Temperature (K)')            
            ax[i].set_ylabel(y_label)
        return fig, ax
Example #3
0
               a_high=[
                   3.33727920E+00, -4.94024731E-05, 4.99456778E-07,
                   -1.79566394E-10, 2.00255376E-14, -9.50158922E+02,
                   -3.20502331E+00
               ])

# Calculate thermodynamic quantities using the same syntax as StatMech
H_H2 = H2_nasa.get_H(units='kcal/mol', T=298.)
print('H_H2(T=298 K) = {} kcal/mol'.format(H_H2))

# Show thermodynamic quantities vs. T
T = np.linspace(200., 3500.)
f2, ax2 = plot_1D(H2_nasa,
                  x_name='T',
                  x_values=T,
                  methods=('get_H', 'get_S', 'get_G'),
                  get_H_kwargs={'units': 'kcal/mol'},
                  get_S_kwargs={'units': 'cal/mol/K'},
                  get_G_kwargs={'units': 'kcal/mol'})

# Modifying figure
ax2[0].set_ylabel('H (kcal/mol)')
ax2[1].set_ylabel('S (cal/mol/K)')
ax2[2].set_ylabel('G (kcal/mol)')
ax2[2].set_xlabel('T (K)')
f2.set_size_inches(5, 5)
f2.set_dpi(200)
plt.show()

# <a id='section_4_2'></a>