Skip to content

Commit

Permalink
Merge pull request #2 from waikato-ahuora-smart-energy-systems/fix/te…
Browse files Browse the repository at this point in the history
…st_asu_pr

Fix/test asu pr
  • Loading branch information
Mahaki-Leach authored Nov 13, 2024
2 parents 392477f + 2dae08f commit c9bb4c3
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 1,219 deletions.
4 changes: 1 addition & 3 deletions compounds/Compound.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from pprint import pprint
import xml.etree.ElementTree as ET
from pydantic import BaseModel
from typing import Dict
import os
import json
from pydantic import BaseModel

def convert_string_to_float(string: str) -> float | str:
try:
Expand Down
67 changes: 52 additions & 15 deletions property_packages/modular/builder/common_parsers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from math import floor
from typing import Any, Dict, List
from .base_parser import BuildBase
from compounds.Compound import Compound
Expand All @@ -10,14 +11,8 @@
from idaes.models.properties.modular_properties.eos.ceos import Cubic, CubicType
from idaes.models.properties.modular_properties.pure import RPP4, RPP3, Perrys
from property_packages.modular.builder.data.chem_sep import ChemSep

"""
TODO: Need to double check all equation numbers
to throw errors if mis-matched or not found
"""

from pyomo.common.fileutils import this_file_dir
import csv

class base_units_parser(BuildBase):
@staticmethod
Expand Down Expand Up @@ -188,7 +183,7 @@ def serialise_component(compound: Compound) -> Dict[str, Any]:
class phase_equilibrium_state_parser(BuildBase):
@staticmethod
def serialise(compounds: List[Compound]) -> Dict[str, Any]:
return {("Vap", "Liq"): SmoothVLE} # TODO: Update to Smooth VLE_v2 https://github.com/IDAES/idaes-pse/blob/main/idaes/models/properties/modular_properties/phase_equil/smooth_VLE_2.py
return {("Vap", "Liq"): SmoothVLE}

class phases_parser(BuildBase):
@staticmethod
Expand Down Expand Up @@ -217,13 +212,27 @@ def serialise(compounds: List[Compound]) -> Dict[str, Any]:
return (101325, pyunits.Pa)

class state_bounds_parser(BuildBase):
"""
State bounds are used to find optimal solution
TODO: need to find a way to dynamically determine these
"""
@staticmethod
def serialise(compounds: List[Compound]) -> Dict[str, Any]:
return {
"flow_mol": (0, 100, 1000, pyunits.mol / pyunits.s),
"temperature": (273.15, 300, 500, pyunits.K),
"pressure": (5e4, 1e5, 1e6, pyunits.Pa),
}
min_melting_point = min([compound["NormalMeltingPointTemperature"].value for compound in compounds])
min_critical_temperature = min([compound["CriticalTemperature"].value for compound in compounds])

if(min_critical_temperature > 500):
return {
"flow_mol": (0, 100, 1000, pyunits.mol / pyunits.s),
"temperature": (min_melting_point, 300, 500, pyunits.K),
"pressure": (5e4, 1e5, 1e6, pyunits.Pa),
}
else:
return {
"flow_mol": (0, 100, 1000, pyunits.mol / pyunits.s),
"temperature": (min_melting_point, 150, 350, pyunits.K),
"pressure": (5e4, 1e5, 1e6, pyunits.Pa),
}

class state_definition_parser(BuildBase):
@staticmethod
Expand All @@ -239,9 +248,37 @@ class pr_kappa_parser(BuildBase):
@staticmethod
def serialise(compounds: List[Compound]) -> Dict[str, Any]:
kappa_parameters = {}
compound_id_map = {}

for i, compound1 in enumerate(compounds):
compound_id_map[str(floor(compound1["LibraryIndex"].value))] = compound1
for j, compound2 in enumerate(compounds):
kappa_parameters[(compound1["CompoundID"].value, compound2["CompoundID"].value)] = 0.000
# Setting all interactions initially to zero
# TODO: Pass over the correct values

# TODO: Adjust method so the multiple kappa values for single pair are supported
# Open and read the interaction data file
file = open(this_file_dir() + "/data/pr.dat", 'r')
reader = csv.reader(file, delimiter=';')
for row in reader:

# Skip invalid rows
if len(row) < 4:
continue

# Extract ID1, ID2, kappa (k12) and comment
id1, id2, kappa, _ = row

try:
kappa_value = float(kappa)
except ValueError:
continue

# Check if the compound IDs exist in the compound list
if id1 in compound_id_map and id2 in compound_id_map:
compound1 = compound_id_map[id1]
compound2 = compound_id_map[id2]
kappa_parameters[(compound1["CompoundID"].value, compound2["CompoundID"].value)] = kappa_value
kappa_parameters[(compound2["CompoundID"].value, compound1["CompoundID"].value)] = kappa_value

return {"PR_kappa": kappa_parameters}
4 changes: 0 additions & 4 deletions property_packages/modular/builder/data/chem_sep.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ def build_parameters(cobj):

@staticmethod
def return_expression(b, cobj, T, dT=False):

print("Calculating pressure saturation pressure")
print("at the specified temperature", value(T), u.get_units(T))

psat = (
exp(
cobj.pressure_sat_comp_coeff_A - cobj.pressure_sat_comp_coeff_B /
Expand Down
Loading

0 comments on commit c9bb4c3

Please sign in to comment.