Skip to content

Commit

Permalink
got Ben & idaes tests running
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahaki Leach committed Dec 2, 2024
1 parent bc53b0f commit 901c232
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
4 changes: 2 additions & 2 deletions property_packages/tests/test_asu_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_build(self):
model.params.config.state_bounds,
{
"flow_mol": (0, 100, 1000, pyunits.mol / pyunits.s),
"temperature": (54.361, 150, 350, pyunits.K),
"temperature": (54.361, 150, 500, pyunits.K),
"pressure": (5e4, 1e5, 1e6, pyunits.Pa),
},
item_callback=_as_quantity,
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_build(self, model):

assert isinstance(model.props[1].temperature, Var)
assert value(model.props[1].temperature) == 150
assert model.props[1].temperature.ub == 350
assert model.props[1].temperature.ub == 500
assert model.props[1].temperature.lb == 54.361

assert isinstance(model.props[1].mole_frac_comp, Var)
Expand Down
80 changes: 80 additions & 0 deletions property_packages/tests/test_compressor_pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Build and solve a heater block.
from ..build_package import build_package
from pytest import approx

# Import objects from pyomo package
from pyomo.environ import ConcreteModel, SolverFactory, value, units

# Import the main FlowsheetBlock from IDAES. The flowsheet block will contain the unit model
from idaes.core import FlowsheetBlock
from idaes.core.util.model_statistics import degrees_of_freedom
from idaes.models.unit_models.heater import Heater
from idaes.models.unit_models.pressure_changer import Pump
from idaes.core.util.tables import _get_state_from_port
from idaes.models.unit_models.pressure_changer import PressureChanger, ThermodynamicAssumption

def assert_approx(value, expected_value, error_margin):
percent_error = error_margin / 100
tolerance = abs(percent_error * expected_value)
assert approx(value, abs=tolerance) == expected_value

def test_compressor_asu():
m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)
m.fs.properties = build_package("peng-robinson", ["argon", "oxygen", "nitrogen"], ["Liq", "Vap"])

m.fs.compressor = PressureChanger(
property_package=m.fs.properties,
thermodynamic_assumption=ThermodynamicAssumption.isentropic,
compressor=True)

m.fs.compressor.inlet.flow_mol[0].fix(1*units.kilomol/units.hour)
m.fs.compressor.inlet.pressure.fix(200000 * units.Pa) # doesn't work from 100,000
m.fs.compressor.inlet.temperature.fix((273.15+25) * units.K)
m.fs.compressor.inlet.mole_frac_comp[0, "argon"].fix(0.33)
m.fs.compressor.inlet.mole_frac_comp[0, "oxygen"].fix(0.33)
m.fs.compressor.inlet.mole_frac_comp[0, "nitrogen"].fix(0.33)

m.fs.compressor.outlet.pressure.fix(500000*units.Pa)
m.fs.compressor.efficiency_isentropic.fix(0.75)

assert degrees_of_freedom(m) == 0

m.fs.compressor.initialize()

assert degrees_of_freedom(m) == 0

solver = SolverFactory('ipopt')
solver.solve(m, tee=True)

assert_approx(value(m.fs.compressor.outlet.temperature[0]), 466.12, 0.1)

def test_expander_asu():
m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)
m.fs.properties = build_package("peng-robinson", ["argon", "oxygen", "nitrogen"], ["Liq", "Vap"])

m.fs.compressor = PressureChanger(
property_package=m.fs.properties,
thermodynamic_assumption=ThermodynamicAssumption.adiabatic,
compressor=False)

m.fs.compressor.inlet.flow_mol[0].fix(1*units.kilomol/units.hour)
m.fs.compressor.inlet.pressure.fix(1000000 * units.Pa)
m.fs.compressor.inlet.temperature.fix((273.15+25) * units.K)
m.fs.compressor.inlet.mole_frac_comp[0, "argon"].fix(0.33)
m.fs.compressor.inlet.mole_frac_comp[0, "oxygen"].fix(0.33)
m.fs.compressor.inlet.mole_frac_comp[0, "nitrogen"].fix(0.33)

m.fs.compressor.outlet.pressure.fix(100000*units.Pa)

assert degrees_of_freedom(m) == 0

m.fs.compressor.initialize()

assert degrees_of_freedom(m) == 0

solver = SolverFactory('ipopt')
solver.solve(m, tee=True)

assert_approx(int(value(m.fs.compressor.deltaP[0])), -900000, 0)

0 comments on commit 901c232

Please sign in to comment.