Skip to content

πŸš€ PyThermoModels v1.6.0 Release Notes

Latest

Choose a tag to compare

@sinagilassi sinagilassi released this 19 Dec 02:20
· 5 commits to main since this release

πŸ§ͺ 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.