def _thermo_wrapper(self, eos): """ Generate thermodynamic predictions from eos object Parameters ---------- eos : obj EOS object with updated parameters Returns ------- phase_list : float A list of the predicted thermodynamic values estimated from thermo calculation. This list can be composed of lists or floats """ if self.calctype == "phase_xiT": try: output_dict = thermo(eos, self._thermodict) output = [output_dict['P'], output_dict["yi"]] except: raise ValueError("Calculation of calc_xT_phase failed") elif self.calctype == "phase_yiT": try: output_dict = thermo(eos, self._thermodict) output = [output_dict['P'], output_dict["xi"]] except: raise ValueError("Calculation of calc_yT_phase failed") return output
def _thermo_wrapper(self): """ Generate thermodynamic predictions from Eos object Returns ------- phase_list : float A list of the predicted thermodynamic values estimated from thermo calculation. This list can be composed of lists or floats """ # Remove results opts = self.thermodict.copy() tmp = self.result_keys + ["name", "parameters_guess"] for key in tmp: if key in opts: del opts[key] if self.thermodict["calculation_type"] == "bubble_pressure": try: output_dict = thermo(self.Eos, **opts) output = [output_dict["P"], output_dict["yi"]] except Exception: raise ValueError("Calculation of calc_bubble_pressure failed") elif self.thermodict["calculation_type"] == "dew_pressure": try: output_dict = thermo(self.Eos, **opts) output = [output_dict["P"], output_dict["xi"]] except Exception: raise ValueError("Calculation of calc_dew_pressure failed") return output
def _thermo_wrapper(self, eos): """ Generate thermodynamic predictions from eos object Parameters ---------- eos : obj EOS object with updated parameters Returns ------- phase_list : float A list of the predicted thermodynamic values estimated from thermo calculation. This list can be composed of lists or floats """ # Check bead type if 'xilist' not in self._thermodict: if len(eos._nui) > 1: raise ValueError( "Ambiguous instructions. Include xi to define intended component to obtain saturation properties" ) else: self._thermodict['xilist'] = np.array( [[1.0] for x in range(len(self._thermodict['Tlist']))]) # Run thermo calculations try: output_dict = thermo(eos, self._thermodict) output = [ output_dict["Psat"], output_dict["rhol"], output_dict["rhov"] ] except: raise ValueError("Calculation of calc_Psat failed") return output
def _thermo_wrapper(self): """ Generate thermodynamic predictions from Eos object Returns ------- phase_list : float A list of the predicted thermodynamic values estimated from thermo calculation. This list can be composed of lists or floats """ # Remove results opts = self.thermodict.copy() tmp = self.result_keys + ["name", "parameters_guess"] for key in tmp: if key in opts: del opts[key] # Run thermo calculations try: output_dict = thermo(self.Eos, **opts) output = [output_dict["delta"], output_dict["rhol"]] except Exception: raise ValueError("Calculation of solubility_parameter failed") return output
def test_phase_xiT(eos=eos_co2_h2o, Tlist=Tlist, xilist=xilist): output = thermo.thermo(eos, { "calculation_type": "phase_xiT", "Tlist": Tlist, "xilist": xilist }) # assert output["P"][0]==pytest.approx(1223211.573700886,abs=1e+1) and output["yi"][0]==pytest.approx([0.94880358, 0.05119642],abs=1e-4) assert output["P"][0] == pytest.approx( 3042623.2, abs=1e+1) and output["yi"][0] == pytest.approx( [0.97701902, 0.02298098], abs=1e-4)
def test_bubble_pressure(Eos=Eos_co2_h2o, Tlist=Tlist, xilist=xilist): output = thermo.thermo(Eos, calculation_type="bubble_pressure", **{ "Tlist": Tlist, "xilist": xilist, "Pmin": [6900000], "Pmax": [7100000] }) assert output["P"][0] == pytest.approx( 7005198.6, abs=5e1) and output["yi"][0] == pytest.approx( [0.98779049, 0.01220951], abs=1e-4)
def test_sat_props(eos=eos_co2_h2o, Tlist=Tlist): output = thermo.thermo( eos, { "calculation_type": "sat_props", "Tlist": Tlist, "xilist": [np.array([0.0, 1.0])] }) assert output["Psat"][0] == pytest.approx( 12314.30, abs=1e+1) and output["rhol"][0] == pytest.approx( 54700.25, abs=1e-1), output["rhol"][0] == pytest.approx( 2371.38970066, abs=1e-1)
def test_saturation_properties(Eos=Eos_co2_h2o, Tlist=Tlist): output = thermo.thermo(Eos, calculation_type="saturation_properties", **{ "Tlist": Tlist, "xilist": [np.array([0.0, 1.0])] }) assert output["Psat"][0] == pytest.approx( 46266.2, abs=1e1) and output["rhol"][0] == pytest.approx( 53883.63, abs=1e-1), output["rhol"][0] == pytest.approx( 2371.38970066, abs=1e-1)
def test_vapor_properties(Eos=Eos_co2_h2o, Tlist=Tlist, yilist=yilist, Plist=Plist): output = thermo.thermo(Eos, calculation_type="vapor_properties", **{ "Tlist": Tlist, "Plist": Plist, "yilist": yilist }) assert output["rhov"][0] == pytest.approx( 2938.3, abs=1e-1) and output["phiv"][0] == pytest.approx( np.array([0.865397, 0.63848]), abs=1e-1)
def test_liquid_properties(Eos=Eos_co2_h2o, Tlist=Tlist, xilist=xilist, Plist=Plist): output = thermo.thermo(Eos, calculation_type="liquid_properties", **{ "Tlist": Tlist, "Plist": Plist, "xilist": xilist }) assert output["rhol"][0] == pytest.approx( 53831.6, abs=1e-1) and output["phil"][0] == pytest.approx( np.array([403.98, 6.8846e-03]), abs=1e-1)
def test_vapor_properties(eos=eos_co2_h2o, Tlist=Tlist, yilist=yilist, Plist=Plist): output = thermo.thermo( eos, { "calculation_type": "vapor_properties", "Tlist": Tlist, "Plist": Plist, "yilist": yilist }) # assert output["rhov"][0]==pytest.approx(37.85937201,abs=1e-1) and output["phiv"][0]==pytest.approx(np.array([2.45619145, 0.37836741]),abs=1e-1) assert output["rhov"][0] == pytest.approx( 2156.81, abs=1e-1) and output["phiv"][0] == pytest.approx( np.array([0.90729601, 0.13974291]), abs=1e-1)
def test_liquid_properties(eos=eos_co2_h2o, Tlist=Tlist, xilist=xilist, Plist=Plist): output = thermo.thermo( eos, { "calculation_type": "liquid_properties", "Tlist": Tlist, "Plist": Plist, "xilist": xilist }) # assert output["rhol"][0]==pytest.approx(54072.87630577754,abs=1e-1) and output["phil"][0]==pytest.approx(np.array([2646.44010, 0.120295122]),abs=1e-1) assert output["rhol"][0] == pytest.approx( 54156.297, abs=1e-1) and output["phil"][0] == pytest.approx( np.array([6.04140887e+01, 2.79514245e-03]), abs=1e-1)
def test_activity_coefficient(Eos=Eos_h2o_hexane, Tlist=Tlist, xilist=xilist, yilist=yilist, Plist=Plist): output = thermo.thermo(Eos, calculation_type="activity_coefficient", **{ "Tlist": Tlist, "Plist": Plist, "yilist": yilist, "xilist": xilist }) print(output["gamma"]) assert output["gamma"][0] == pytest.approx(np.array( [7.23733364e04, 6.30243983e-01]), abs=1e-2)
import despasito import despasito.input_output.read_input as io import despasito.thermodynamics as thermo import despasito.equations_of_state despasito.initiate_logger(console=True, verbose=10) Eos = despasito.equations_of_state.initiate_eos( eos="saft.gamma_mie", beads=["CH3", "CH2"], molecular_composition=np.array([[2.0, 4.0], [2.0, 5.0]]), bead_library=io.json_to_dict("../../library/SAFTgroup.json"), cross_library=io.json_to_dict("../../library/SAFTcross.json"), ) output = thermo.thermo( Eos, calculation_type="liquid_properties", Tlist=320.0, Plist=1e+5, xilist=np.array([0.4, 0.6]), ) print("Thermo Output", output) args = (output["rhol"][0], 320.0, [0.4, 0.6]) print("Helmholtz Contributions:") print(" Ideal: ", Eos.Aideal(*args)) print(" Monomer: ", Eos.saft_source.Amonomer(*args)) print(" Chain: ", Eos.saft_source.Achain(*args)) print(" Aassoc: ", Eos.Aassoc(*args))
import despasito import despasito.input_output as io import despasito.thermodynamics as thermo import despasito.equations_of_state despasito.initiate_logger(console=True, verbose=10) beadlibrary = io.json_to_dict("../../library/SAFTgroup.json") crosslibrary = io.json_to_dict("../../library/SAFTcross.json") T = 320.0 P = 1e5 xi = np.array([0.4, 0.6]) beads = ["CH3", "CH2"] nui = np.array([[2.0, 4.0], [2.0, 5.0]]) eos = despasito.equations_of_state.initiate_eos( eos="saft.gamma_mie", beads=beads, molecular_composition=nui, bead_library=beadlibrary, cross_library=crosslibrary, ) output = thermo.thermo(eos, calculation_type="activity_coefficient", Tlist=T, Plist=P, xilist=xi)