Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Costing Model Test Harness #1324

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
318 changes: 185 additions & 133 deletions watertap/costing/unit_models/tests/test_gac.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,153 +10,205 @@
# "https://github.com/watertap-org/watertap/"
#################################################################################

import pytest
import pyomo.environ as pyo
import idaes.core.util.model_statistics as istat

from pyomo.util.check_units import assert_units_consistent
from pyomo.environ import (
value,
ConcreteModel,
Var,
units as pyunits,
)
from idaes.core import (
FlowsheetBlock,
UnitModelCostingBlock,
)
from idaes.core.solvers import get_solver
from idaes.core.util.testing import initialization_tester
from watertap.costing import WaterTAPCosting
from watertap.unit_models.tests.test_gac import build_crittenden

from watertap.costing.unit_models.gac import cost_gac
from watertap.costing.unit_models.tests.unit_costing_test_harness import (
UnitCostingTestHarness,
DummyUnitModel,
)

__author__ = "Hunter Barber"

solver = get_solver()
zero = 1e-8
relative_tolerance = 1e-3


def build_pressure():
m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)

m.fs.unit = DummyUnitModel()
m.fs.unit.default_costing_method = cost_gac

m.fs.unit.bed_volume = Var(units=pyunits.meter**3)
m.fs.unit.bed_volume.fix(8.900)
m.fs.unit.bed_mass_gac = Var(units=pyunits.kg)
m.fs.unit.bed_mass_gac.fix(4004)
m.fs.unit.gac_usage_rate = Var(units=pyunits.kg / pyunits.second)
m.fs.unit.gac_usage_rate.fix(0.0002925)

class TestGACCosting:
@pytest.fixture(scope="class")
def build(self):
m = build_crittenden()
initialization_tester(m)
solver.solve(m)
m.fs.costing = WaterTAPCosting()
m.fs.costing.base_currency = pyunits.USD_2020

m.fs.unit.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
m.fs.costing.cost_process()

return m


class TestGACPressureCosting(UnitCostingTestHarness):
def configure(self):
m = build_pressure()

# arguments for UnitTestHarness
self.default_zero = zero
self.default_relative_tolerance = relative_tolerance

cost_blk = m.fs.unit.costing
self.cost_solutions[cost_blk.contactor_cost] = 56900
self.cost_solutions[cost_blk.adsorbent_unit_cost] = 4.359
self.cost_solutions[cost_blk.adsorbent_cost] = 17450
self.cost_solutions[cost_blk.other_process_cost] = 81690
self.cost_solutions[cost_blk.capital_cost] = 2 * 156000
self.cost_solutions[cost_blk.gac_makeup_cost] = 12680
self.cost_solutions[cost_blk.gac_regen_cost] = 27660
self.cost_solutions[cost_blk.energy_consumption] = 0.01631
self.cost_solutions[cost_blk.fixed_operating_cost] = 40370

return m

@pytest.mark.component
def test_robust_costing_pressure(self, build):
m = build

m.fs.costing = WaterTAPCosting()
m.fs.costing.base_currency = pyo.units.USD_2020

m.fs.unit.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
m.fs.costing.cost_process()

# testing gac costing block dof and initialization
assert assert_units_consistent(m) is None
assert istat.degrees_of_freedom(m) == 0
m.fs.unit.costing.initialize()

# solve
results = solver.solve(m)

# Check for optimal solution
assert pyo.check_optimal_termination(results)

cost = m.fs.unit.costing
# Check for known cost solution of default twin alternating contactors
assert pyo.value(m.fs.costing.gac_pressure.num_contactors_op) == 1
assert pyo.value(m.fs.costing.gac_pressure.num_contactors_redundant) == 1
assert pytest.approx(56900, rel=1e-3) == pyo.value(cost.contactor_cost)
assert pytest.approx(4.359, rel=1e-3) == pyo.value(cost.adsorbent_unit_cost)
assert pytest.approx(17450, rel=1e-3) == pyo.value(cost.adsorbent_cost)
assert pytest.approx(81690, rel=1e-3) == pyo.value(cost.other_process_cost)
assert pytest.approx(2.0 * 156000, rel=1e-3) == pyo.value(cost.capital_cost)
assert pytest.approx(12680, rel=1e-3) == pyo.value(cost.gac_makeup_cost)
assert pytest.approx(27660, rel=1e-3) == pyo.value(cost.gac_regen_cost)
assert pytest.approx(0.01631, rel=1e-3) == pyo.value(cost.energy_consumption)
assert pytest.approx(40370, rel=1e-3) == pyo.value(cost.fixed_operating_cost)

@pytest.mark.component
def test_robust_costing_gravity(self, build):
mr_grav = build

mr_grav.fs.costing = WaterTAPCosting()
mr_grav.fs.costing.base_currency = pyo.units.USD_2020

mr_grav.fs.unit.costing = UnitModelCostingBlock(
flowsheet_costing_block=mr_grav.fs.costing,
costing_method_arguments={"contactor_type": "gravity"},
)
mr_grav.fs.costing.cost_process()

# testing gac costing block dof and initialization
assert assert_units_consistent(mr_grav) is None
assert istat.degrees_of_freedom(mr_grav) == 0
mr_grav.fs.unit.costing.initialize()

# solve
results = solver.solve(mr_grav)

# Check for optimal solution
assert pyo.check_optimal_termination(results)

cost = mr_grav.fs.unit.costing
# Check for known cost solution of default twin alternating contactors
assert pyo.value(mr_grav.fs.costing.gac_gravity.num_contactors_op) == 1
assert pyo.value(mr_grav.fs.costing.gac_gravity.num_contactors_redundant) == 1
assert pytest.approx(163200, rel=1e-3) == pyo.value(cost.contactor_cost)
assert pytest.approx(4.359, rel=1e-3) == pyo.value(cost.adsorbent_unit_cost)
assert pytest.approx(17450, rel=1e-3) == pyo.value(cost.adsorbent_cost)
assert pytest.approx(159500, rel=1e-3) == pyo.value(cost.other_process_cost)
assert pytest.approx(2.0 * 340200, rel=1e-3) == pyo.value(cost.capital_cost)
assert pytest.approx(12680, rel=1e-3) == pyo.value(cost.gac_makeup_cost)
assert pytest.approx(27660, rel=1e-3) == pyo.value(cost.gac_regen_cost)
assert pytest.approx(2.476, rel=1e-3) == pyo.value(cost.energy_consumption)
assert pytest.approx(40370, rel=1e-3) == pyo.value(cost.fixed_operating_cost)

@pytest.mark.component
def test_robust_costing_modular_contactors(self, build):
m = build

m.fs.costing = WaterTAPCosting()
m.fs.costing.base_currency = pyo.units.USD_2020

m.fs.unit.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
m.fs.costing.cost_process()

m.fs.costing.gac_pressure.num_contactors_op.fix(4)
m.fs.costing.gac_pressure.num_contactors_redundant.fix(2)

results = solver.solve(m)

cost = m.fs.unit.costing
# Check for known cost solution when changing volume scale of vessels in parallel
assert pyo.value(m.fs.costing.gac_pressure.num_contactors_op) == 4
assert pyo.value(m.fs.costing.gac_pressure.num_contactors_redundant) == 2
assert pytest.approx(89040, rel=1e-3) == pyo.value(cost.contactor_cost)
assert pytest.approx(69690, rel=1e-3) == pyo.value(cost.other_process_cost)
assert pytest.approx(2.0 * 176200, rel=1e-3) == pyo.value(cost.capital_cost)

@pytest.mark.component
def test_robust_costing_max_gac_ref(self, build):
m = build

# scale flow up 10x
unit_feed = m.fs.unit.process_flow.properties_in[0]
unit_feed.flow_mol_phase_comp["Liq", "H2O"].fix(10 * 824.0736620370348)
unit_feed.flow_mol_phase_comp["Liq", "TCE"].fix(10 * 5.644342973110135e-05)

m.fs.costing = WaterTAPCosting()
m.fs.costing.base_currency = pyo.units.USD_2020

m.fs.unit.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
m.fs.costing.cost_process()
# not necessarily an optimum solution because poor scaling
# but just checking the conditional
results = solver.solve(m)

# Check for bed_mass_gac_cost_ref to be overwritten
# if bed_mass_gac is greater than bed_mass_gac_cost_max_ref
assert pyo.value(m.fs.unit.bed_mass_gac) > pyo.value(

def build_gravity():
m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)

m.fs.unit = DummyUnitModel()
m.fs.unit.default_costing_method = cost_gac

m.fs.unit.bed_volume = Var(units=pyunits.meter**3)
m.fs.unit.bed_volume.fix(8.900)
m.fs.unit.bed_mass_gac = Var(units=pyunits.kg)
m.fs.unit.bed_mass_gac.fix(4004)
m.fs.unit.gac_usage_rate = Var(units=pyunits.kg / pyunits.second)
m.fs.unit.gac_usage_rate.fix(0.0002925)

m.fs.costing = WaterTAPCosting()
m.fs.costing.base_currency = pyunits.USD_2020

m.fs.unit.costing = UnitModelCostingBlock(
flowsheet_costing_block=m.fs.costing,
costing_method_arguments={"contactor_type": "gravity"},
)
m.fs.costing.cost_process()

return m


class TestGACGravityCosting(UnitCostingTestHarness):
def configure(self):
m = build_gravity()

# arguments for UnitTestHarness
self.default_zero = zero
self.default_relative_tolerance = relative_tolerance

cost_blk = m.fs.unit.costing
self.cost_solutions[cost_blk.contactor_cost] = 163200
self.cost_solutions[cost_blk.adsorbent_unit_cost] = 4.359
self.cost_solutions[cost_blk.adsorbent_cost] = 17450
self.cost_solutions[cost_blk.other_process_cost] = 159500
self.cost_solutions[cost_blk.capital_cost] = 2 * 340200
self.cost_solutions[cost_blk.gac_makeup_cost] = 12680
self.cost_solutions[cost_blk.gac_regen_cost] = 27660
self.cost_solutions[cost_blk.energy_consumption] = 2.476
self.cost_solutions[cost_blk.fixed_operating_cost] = 40370

return m


def build_modular():
m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)

m.fs.unit = DummyUnitModel()
m.fs.unit.default_costing_method = cost_gac

m.fs.unit.bed_volume = Var(units=pyunits.meter**3)
m.fs.unit.bed_volume.fix(8.900)
m.fs.unit.bed_mass_gac = Var(units=pyunits.kg)
m.fs.unit.bed_mass_gac.fix(4004)
m.fs.unit.gac_usage_rate = Var(units=pyunits.kg / pyunits.second)
m.fs.unit.gac_usage_rate.fix(0.0002925)

m.fs.costing = WaterTAPCosting()
m.fs.costing.base_currency = pyunits.USD_2020

m.fs.unit.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
m.fs.costing.cost_process()

m.fs.costing.gac_pressure.num_contactors_op.fix(4)
m.fs.costing.gac_pressure.num_contactors_redundant.fix(2)

return m


class TestGACModularCosting(UnitCostingTestHarness):
def configure(self):
m = build_modular()

# arguments for UnitTestHarness
self.default_zero = zero
self.default_relative_tolerance = relative_tolerance

cost_blk = m.fs.unit.costing
self.cost_solutions[cost_blk.contactor_cost] = 89040
self.cost_solutions[cost_blk.other_process_cost] = 69690
self.cost_solutions[cost_blk.capital_cost] = 2 * 176200

return m


def build_max():
m = ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)

m.fs.unit = DummyUnitModel()
m.fs.unit.default_costing_method = cost_gac

m.fs.unit.bed_volume = Var(units=pyunits.meter**3)
m.fs.unit.bed_volume.fix(10 * 8.900)
m.fs.unit.bed_mass_gac = Var(units=pyunits.kg)
m.fs.unit.bed_mass_gac.fix(10 * 4004)
m.fs.unit.gac_usage_rate = Var(units=pyunits.kg / pyunits.second)
m.fs.unit.gac_usage_rate.fix(10 * 0.0002925)

m.fs.costing = WaterTAPCosting()
m.fs.costing.base_currency = pyunits.USD_2020

m.fs.unit.costing = UnitModelCostingBlock(flowsheet_costing_block=m.fs.costing)
m.fs.costing.cost_process()

return m


class TestGACMaxCosting(UnitCostingTestHarness):
def configure(self):
m = build_max()

# arguments for UnitTestHarness
self.default_zero = zero
self.default_relative_tolerance = relative_tolerance

cost_blk = m.fs.unit.costing
assert value(m.fs.unit.bed_mass_gac) > value(
m.fs.costing.gac_pressure.bed_mass_max_ref
)
assert pyo.value(m.fs.unit.costing.bed_mass_gac_ref) == (
pytest.approx(pyo.value(m.fs.costing.gac_pressure.bed_mass_max_ref), 1e-5)
self.cost_solutions[cost_blk.bed_mass_gac_ref] = value(
m.fs.costing.gac_pressure.bed_mass_max_ref
)
self.cost_solutions[cost_blk.adsorbent_unit_cost] = 3.651
self.cost_solutions[cost_blk.adsorbent_cost] = 146200

return m
Loading
Loading