Releases: sinagilassi/PyThermoModels
π PyThermoModels v1.6.0 Release Notes
π§ͺ New Feature: UNIFAC Example
Added a comprehensive example for the UNIFAC activity model in examples/activity-models/activity-unifac-1.py. This script demonstrates:
# Load UNIFAC parameters
group_parameters_dict, group_interaction_dict = load_unifac_data()
activity_unifac.load_data(
group_data=group_parameters_dict,
interaction_data=group_interaction_dict
)
# Assign component group structures
components_group_data = {
"acetone": {"CH3": 1.0, "CH3CO": 1.0},
"n_heptane": {"CH3": 2.0, "CH2": 3.0}
}
activity_unifac.set_component_groups(component_groups=components_group_data)
# Calculate activity coefficients
model_inputs = {
"mole_fraction": {"acetone": 0.047, "n_heptane": 0.953},
"temperature": [307, "K"]
}
res_, other_values = activity_unifac.cal(model_inputs=model_inputs)
print(res_)
# Compute excess Gibbs free energy
gibbs_energy = activity.general_excess_molar_gibbs_free_energy(
mole_fraction=model_inputs["mole_fraction"],
activity_coefficients=res_["value"]
)
print(f"general excess gibbs free energy: {gibbs_energy}")π οΈ Improvements
Enhanced modularity and usability. Example:
# Modular activity model configuration
activity = ptm.activity(
components=["acetone", "n_heptane"],
model_name="UNIFAC"
)
print(activity)Improved data loading and assignment:
# group_parameters_dict, group_interaction_dict already constructed from external sources such as:
# The Properties of Gases and Liquids, Sixth Edition
# Vapor-Liquid Equilibria Using Unifac: A Group-Contribution Method By Aage Fredenslund
activity_unifac.load_data(
group_data=group_parameters_dict,
interaction_data=group_interaction_dict
)Structure of UNIFAC Data:
group_parameters_dict (from UNIFAC Data CSV):
CSV format:
main-group,sub-group,group-id,volume,surface-area
m,k,-,R[k],Q[k]
1,1,CH3,0.9011,0.848
1,2,CH2,0.6744,0.54
# ...
Python dict example:
{
"CH3": {
"main_group": 1,
"sub_group": 1,
"group_id": "CH3",
"volume": 0.9011,
"surface_area": 0.848
},
"CH2": {
"main_group": 1,
"sub_group": 2,
"group_id": "CH2",
"volume": 0.6744,
"surface_area": 0.54
},
# ...
}group_interaction_dict (from unifac_with_na.csv):
CSV format (excerpt):
"[m,n]",1,2,3,...
1,0,86.02,61.13,...
2,-35.36,0,38.81,...
# ...
Python dict example:
{
"1": {'': 1.0, '1': 0.0, '2': 86.02, ...}
# ...
}These structures allow the UNIFAC model to compute activity coefficients based on group contributions and their interactions.
π Documentation
Updated docs and examples for activity models. Example:
# Step-by-step comments in example
# 1. Load parameters
# 2. Assign groups
# 3. Calculate coefficients
# 4. Compute Gibbs energyπ Bug Fixes
Minor fixes in activity model initialization and data assignment. Example:
# Fixed: Proper initialization and assignment
activity = ptm.activity(components=["acetone", "n_heptane"], model_name="UNIFAC")
activity_unifac = activity.unifac
activity_unifac.set_component_groups(component_groups=components_group_data)π‘ How to Use
See the new UNIFAC example to learn how to:
# 1. Load and set UNIFAC parameters with respect to the valid structure
# group_parameters_dict, group_interaction_dict
# 2. Assign component group data
activity_unifac.set_component_groups(component_groups=components_group_data)
# 3. Calculate activity coefficients and excess Gibbs energy
res_, other_values = activity_unifac.cal(model_inputs=model_inputs)
gibbs_energy = activity.general_excess_molar_gibbs_free_energy(
mole_fraction=model_inputs["mole_fraction"],
activity_coefficients=res_["value"]
)Thank you for using PyThermoModels! For more details, check the README and docs.
# π PyThermoModels v1.5.0
This update introduces comprehensive example scripts for thermodynamic modeling, focusing on activity coefficient calculations and equation of state (EOS) fugacity computations.
π New Examples in the Examples Folder
π Activity Models (examples/activity-models/)
We've added extensive examples for activity coefficient models, including NRTL and UNIQUAC, with various approaches for parameter handling and calculations.
Key Scripts
- Basic Activity Calculations:
activity-1.py,activity-2.py,activity-3.pyand variants (activity-1-2.py, etc.) - Demonstrate activity coefficient calculations for binary mixtures like ethanol-butyl-methyl-ether using NRTL model. - Parameter Calculation:
calc-parameters-nrtl.py,calc-parameters-uniquac.py- Show how to fit model parameters to experimental data. - Inline and Build Model Sources: Scripts like
calc activity using nrtl inline source-1.py,calc activity using uniquac inline source and build model source-1.py- Illustrate different ways to provide model parameters and equations.
Example: Activity Coefficient Calculation with NRTL
import pyThermoModels as ptm
import pyThermoDB as ptdb
# Load thermodb data
thermodb = ptdb.load_thermodb('thermodb_nrtl_ethanol_butyl-methyl-ether.pkl')
# Initialize activity model
activity = ptm.activity(components=['ethanol', 'butyl-methyl-ether'], model_name='NRTL')
# Model input
model_input = {
"mole_fraction": {'ethanol': 0.4, 'butyl-methyl-ether': 0.6},
"tau_ij": [[0.0, 1.21670526], [0.65831047, 0.0]],
"alpha_ij": {'ethanol | ethanol': 0.0, 'ethanol | butyl-methyl-ether': 0.680715, 'butyl-methyl-ether | ethanol': 0.680715, 'butyl-methyl-ether | butyl-methyl-ether': 0.0}
}
# Calculate activity coefficients
res, others = activity.nrtl.cal(model_input=model_input)
activity_coefficients = others['AcCo_i_comp']
print(f"Activity coefficients: {activity_coefficients}")π§ͺ Equation of State Models (examples/eos-models/)
New examples showcase fugacity calculations for pure components and mixtures using Peng-Robinson (PR) and Redlich-Kwong (RK) equations of state.
EOS Key Scripts
- Pure Component Fugacity:
fugacity-gas.py,fugacity-liquid.py- Calculate fugacity for single components in vapor and liquid phases. - Mixture Fugacity:
fugacity-mixture.py- Demonstrate fugacity calculations for multi-component mixtures. - Build Model Sources: Variants like
fugacity-gas using build model source.py- Show how to use pre-built model sources for EOS calculations.
Example: Fugacity Calculation for Pure Component (Gas Phase)
import pyThermoModels as ptm
# Initialize EOS
eos = ptm.eos()
# Model input for propane
model_input = {
"component": "propane",
"temperature": [300.1, 'K'],
"pressure": [9.99, 'bar']
}
# Calculate fugacity using PR EOS
res = eos.cal_fugacity(model_name='PR', model_input=model_input, model_source=model_source)
print(f"Fugacity: {res}")Example: Fugacity Calculation for Mixture
# For a CO2-n-butane mixture
model_input = {
"feed-specification": {'CO2': 0.15, 'n-butane': 0.85},
"pressure": [10, 'bar'],
"temperature": [444, 'K']
}
# Calculate mixture fugacity using RK EOS
res = eos.cal_fugacity_mixture(model_name='RK', model_input=model_input, model_source=model_source)
print(f"Mixture fugacities: {res}")π§ Key Features Demonstrated
- ThermoDB Integration: All examples show how to load and use thermodynamic databases for component properties.
- Multiple Model Approaches: Examples cover inline parameter specification, build model sources, and parameter fitting.
- Phase Equilibria: Calculations for vapor-liquid equilibria using activity models and EOS.
- Parameter Estimation: Scripts for calculating interaction parameters from experimental data.
π How to Use
- Navigate to the
examples/folder - Choose the relevant subfolder (
activity-models/oreos-models/) - Run the Python scripts to see calculations in action
- Modify input parameters to fit your specific systems
π― What's Changed
- Added 20+ new example scripts across activity and EOS modeling
- Enhanced documentation through practical code examples
- Improved integration with pyThermoDB for data handling