Skip to content

Commit

Permalink
Reporting methods for MSContactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlee94 committed Nov 3, 2023
1 parent 47ae9d8 commit 4d0410a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 85 deletions.
13 changes: 7 additions & 6 deletions idaes/models/unit_models/mscontactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,21 +905,22 @@ def initialize(self, **kwargs):
)

def _get_performance_contents(self, time_point=0):
assert False
return {"vars": {"Liquid Recovery": self.liquid_recovery[time_point]}}
# Due to the flexibility of the MSContactor and the number of possible terms
# that could be included here, we will leave this up to the user to define.
return {}

def _get_stream_table_contents(self, time_point=0):
stream_attributes = {}
stream_attributes["Units"] = {}

sblocks = {}
for stream, pconfig in self.config.streams.keys():
for stream, pconfig in self.config.streams.items():
sblock = getattr(self, stream)
flow_dir = pconfig.flow_direction

if pconfig.has_feed:
inlet_state = getattr(self, stream + "_inlet_state")
sblocks[stream + " Inlet"] = inlet_state
sblocks[stream + " Inlet"] = inlet_state[time_point]

if flow_dir == FlowDirection.forward:
outlet = self.elements.last()
Expand All @@ -928,10 +929,10 @@ def _get_stream_table_contents(self, time_point=0):
else:
raise BurntToast("If/else overrun when constructing stream table")

sblocks[stream + " Outlet"] = sblock[outlet]
sblocks[stream + " Outlet"] = sblock[time_point, outlet]

for n, v in sblocks.items():
dvars = v[time_point].define_display_vars()
dvars = v.define_display_vars()

stream_attributes[n] = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def test_get_performance_contents(self, model):
}

@pytest.mark.ui
@pytest.mark.unit
@pytest.mark.component
def test_get_stream_table_contents(self, model):
stable = model.fs.unit._get_stream_table_contents()

Expand Down
151 changes: 73 additions & 78 deletions idaes/models/unit_models/tests/test_mscontactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,79 @@ def test_MSInitializer(self, model):
assert not model.fs.contactor.s2_inlet.temperature[0].fixed
assert not model.fs.contactor.s2_inlet.pressure[0].fixed

@pytest.mark.ui
@pytest.mark.unit
def test_get_performance_contents(self, model):
perf_dict = model.fs.contactor._get_performance_contents()

assert perf_dict == {}

@pytest.mark.ui
@pytest.mark.unit
def test_get_stream_table_contents(self, model):
stable = model.fs.contactor._get_stream_table_contents()

expected = {
"Units": {
"Volumetric Flowrate": getattr(units.pint_registry, "m**3/second"),
"Molar Concentration H2O": getattr(units.pint_registry, "mole/m**3"),
"Molar Concentration NaOH": getattr(units.pint_registry, "mole/m**3"),
"Molar Concentration EthylAcetate": getattr(
units.pint_registry, "mole/m**3"
),
"Molar Concentration SodiumAcetate": getattr(
units.pint_registry, "mole/m**3"
),
"Molar Concentration Ethanol": getattr(
units.pint_registry, "mole/m**3"
),
"Temperature": getattr(units.pint_registry, "K"),
"Pressure": getattr(units.pint_registry, "Pa"),
},
"s1 Inlet": {
"Volumetric Flowrate": pytest.approx(0.001, rel=1e-4),
"Molar Concentration H2O": pytest.approx(5.5388e4, rel=1e-4),
"Molar Concentration NaOH": pytest.approx(100, rel=1e-4),
"Molar Concentration EthylAcetate": pytest.approx(100, rel=1e-4),
"Molar Concentration SodiumAcetate": pytest.approx(0, abs=1e-6),
"Molar Concentration Ethanol": pytest.approx(0, abs=1e-6),
"Temperature": pytest.approx(303.15, rel=1e-4),
"Pressure": pytest.approx(101325, rel=1e-4),
},
"s1 Outlet": {
"Volumetric Flowrate": pytest.approx(1, rel=1e-4),
"Molar Concentration H2O": pytest.approx(100, rel=1e-4),
"Molar Concentration NaOH": pytest.approx(100, rel=1e-4),
"Molar Concentration EthylAcetate": pytest.approx(100, rel=1e-4),
"Molar Concentration SodiumAcetate": pytest.approx(100, rel=1e-4),
"Molar Concentration Ethanol": pytest.approx(100, rel=1e-4),
"Temperature": pytest.approx(298.15, rel=1e-4),
"Pressure": pytest.approx(101325, rel=1e-4),
},
"s2 Inlet": {
"Volumetric Flowrate": pytest.approx(0.002, rel=1e-4),
"Molar Concentration H2O": pytest.approx(5.5388e4, rel=1e-4),
"Molar Concentration NaOH": pytest.approx(50, rel=1e-4),
"Molar Concentration EthylAcetate": pytest.approx(50, rel=1e-4),
"Molar Concentration SodiumAcetate": pytest.approx(50, rel=1e-4),
"Molar Concentration Ethanol": pytest.approx(50, rel=1e-4),
"Temperature": pytest.approx(323.15, rel=1e-4),
"Pressure": pytest.approx(2e5, rel=1e-4),
},
"s2 Outlet": {
"Volumetric Flowrate": pytest.approx(1, rel=1e-4),
"Molar Concentration H2O": pytest.approx(100, rel=1e-4),
"Molar Concentration NaOH": pytest.approx(100, rel=1e-4),
"Molar Concentration EthylAcetate": pytest.approx(100, rel=1e-4),
"Molar Concentration SodiumAcetate": pytest.approx(100, rel=1e-4),
"Molar Concentration Ethanol": pytest.approx(100, rel=1e-4),
"Temperature": pytest.approx(298.15, rel=1e-4),
"Pressure": pytest.approx(101325, rel=1e-4),
},
}

assert stable.to_dict() == expected


class TestLiCODiafiltration:
"""
Expand Down Expand Up @@ -3055,81 +3128,3 @@ def test_initialize_and_solve(self, model):
)
assert R_Li == pytest.approx(0.9451, rel=1e-4)
assert R_Co == pytest.approx(0.6378, rel=1e-4)

@pytest.mark.ui
@pytest.mark.unit
def test_get_stream_table_contents(self, model):
stable = model.fs.unit._get_stream_table_contents()

print(stable)

expected = {
"Units": {
"Volumetric Flowrate": getattr(units.pint_registry, "m**3/second"),
"Molar Concentration H2O": getattr(units.pint_registry, "mole/m**3"),
"Molar Concentration NaOH": getattr(units.pint_registry, "mole/m**3"),
"Molar Concentration EthylAcetate": getattr(
units.pint_registry, "mole/m**3"
),
"Molar Concentration SodiumAcetate": getattr(
units.pint_registry, "mole/m**3"
),
"Molar Concentration Ethanol": getattr(
units.pint_registry, "mole/m**3"
),
"Temperature": getattr(units.pint_registry, "K"),
"Pressure": getattr(units.pint_registry, "Pa"),
},
"Solid Inlet": {
"Volumetric Flowrate": pytest.approx(10, rel=1e-4),
"Molar Concentration H2O": pytest.approx(5.5388e4, rel=1e-4),
"Molar Concentration NaOH": pytest.approx(100, rel=1e-4),
"Molar Concentration EthylAcetate": pytest.approx(100, rel=1e-4),
"Molar Concentration SodiumAcetate": pytest.approx(1e-6, abs=1e-4),
"Molar Concentration Ethanol": pytest.approx(1e-6, rel=1e-4),
"Temperature": pytest.approx(303.15, rel=1e-4),
"Pressure": pytest.approx(101325, rel=1e-4),
},
"Liquid Inlet": {
"Volumetric Flowrate": pytest.approx(20, rel=1e-4),
"Molar Concentration H2O": pytest.approx(5.5388e4, rel=1e-4),
"Molar Concentration NaOH": pytest.approx(1e-6, rel=1e-4),
"Molar Concentration EthylAcetate": pytest.approx(1e-6, rel=1e-4),
"Molar Concentration SodiumAcetate": pytest.approx(50, rel=1e-4),
"Molar Concentration Ethanol": pytest.approx(50, rel=1e-4),
"Temperature": pytest.approx(320, rel=1e-4),
"Pressure": pytest.approx(2e5, rel=1e-4),
},
"Solid Outlet": {
"Volumetric Flowrate": pytest.approx(10, rel=1e-4),
"Molar Concentration H2O": pytest.approx(5.5388e4, rel=1e-4),
"Molar Concentration NaOH": pytest.approx(100, rel=1e-4),
"Molar Concentration EthylAcetate": pytest.approx(100, rel=1e-4),
"Molar Concentration SodiumAcetate": pytest.approx(1e-6, rel=1e-4),
"Molar Concentration Ethanol": pytest.approx(1e-6, rel=1e-4),
"Temperature": pytest.approx(303.15, rel=1e-4),
"Pressure": pytest.approx(101325, rel=1e-4),
},
"Liquid in Solids Outlet": {
"Volumetric Flowrate": pytest.approx(20 * 0.3, rel=1e-4),
"Molar Concentration H2O": pytest.approx(5.5388e4, rel=1e-4),
"Molar Concentration NaOH": pytest.approx(1e-6, rel=1e-4),
"Molar Concentration EthylAcetate": pytest.approx(1e-6, rel=1e-4),
"Molar Concentration SodiumAcetate": pytest.approx(50, rel=1e-4),
"Molar Concentration Ethanol": pytest.approx(50, rel=1e-4),
"Temperature": pytest.approx(320, rel=1e-4),
"Pressure": pytest.approx(2e5, rel=1e-4),
},
"Recovered Liquid Outlet": {
"Volumetric Flowrate": pytest.approx(20 * 0.7, rel=1e-4),
"Molar Concentration H2O": pytest.approx(5.5388e4, rel=1e-4),
"Molar Concentration NaOH": pytest.approx(1e-6, rel=1e-4),
"Molar Concentration EthylAcetate": pytest.approx(1e-6, rel=1e-4),
"Molar Concentration SodiumAcetate": pytest.approx(50, rel=1e-4),
"Molar Concentration Ethanol": pytest.approx(50, rel=1e-4),
"Temperature": pytest.approx(320, rel=1e-4),
"Pressure": pytest.approx(2e5, rel=1e-4),
},
}

assert stable.to_dict() == expected

0 comments on commit 4d0410a

Please sign in to comment.