# This file is part of BurnMan - a thermoelastic and thermodynamic toolkit for the Earth and Planetary Sciences# Copyright (C) 2012 - 2017 by the BurnMan team, released under the GNU# GPL v2 or later.from__future__importabsolute_importimportnumpyasnpfrom..importconstants# Try to import the jit from numba. If it is# not available, just go with the standard# python interpretertry:importosif"NUMBA_DISABLE_JIT"inos.environandint(os.environ["NUMBA_DISABLE_JIT"])==1:raiseImportError("NOOOO!")fromnumbaimportjitexceptImportError:defjit(fn):returnfn"""Functions for the Einstein model of a solid."""eps=np.finfo(float).eps
[docs]@jit(nopython=True)defthermal_energy(T,einstein_T,n):""" calculate the thermal energy of a substance. Takes the temperature, the Einstein temperature, and n, the number of atoms per molecule. Returns thermal energy in J/mol """ifT<=eps:return0.0x=einstein_T/TE_th=3.0*n*constants.gas_constant*einstein_T*(1.0/(np.exp(x)-1.0))returnE_th
[docs]@jit(nopython=True)defmolar_heat_capacity_v(T,einstein_T,n):""" Heat capacity at constant volume. In J/K/mol """ifT<=eps:return0.0x=einstein_T/TC_v=(3.0*n*constants.gas_constant*(x*x*np.exp(x)/np.power(np.exp(x)-1.0,2.0)))returnC_v
[docs]@jit(nopython=True)defhelmholtz_free_energy(T,einstein_T,n):""" Helmholtz free energy of lattice vibrations in the Einstein model [J]. It is important to note that this does NOT include the zero point energy for the lattice. As long as you are calculating relative differences in F, this should cancel anyway. """E=thermal_energy(T,einstein_T,n)S=entropy(T,einstein_T,n)returnE-T*S
[docs]@jit(nopython=True)defentropy(T,einstein_T,n):""" Entropy due to lattice vibrations in the Einstein model [J/K] """ifT<=eps:return0.0x=einstein_T/TS=(3.0*n*constants.gas_constant*(-x*np.exp(-x)/(np.exp(-x)-1.0)-np.log(1.0-np.exp(-x))))returnS
[docs]@jit(nopython=True)defdmolar_heat_capacity_v_dT(T,einstein_T,n):""" First temperature derivative of the heat capacity at constant volume according to the Einstein model [J/K^2/mol]. """ifT<=eps:return0.0x=einstein_T/TdCvdT=(3.0*n*constants.gas_constant*x*x*np.exp(x)*((x-2.0)*np.exp(x)+(x+2.0))/(T*np.power(np.exp(x)-1.0,3.0)))returndCvdT