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

working version of KBH MD #159

Open
wants to merge 4 commits into
base: kbhdp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def build_sweep(
):
m = build_system(water_recovery=water_recovery)
add_connections(m)
add_constraints(m)
# add_constraints(m)
set_operating_conditions(m)
apply_scaling(m)
init_system(m, m.fs)
Expand Down Expand Up @@ -317,7 +317,7 @@ def init_system(m, blk, verbose=True, solver=None):

treatment.feed.initialize()

init_md(treatment.md)
init_md(m, treatment.md)

propagate_state(treatment.md_to_product)
treatment.product.initialize()
Expand Down Expand Up @@ -629,10 +629,11 @@ def save_results(m):

if __name__ == "__main__":

# main(water_recovery=0.8)
m = build_sweep(water_recovery=0.8, heat_price=0.01)

m = build_sweep(water_recovery=0.90, heat_price=0.01)
m.fs.costing.LCOT.display()
m.fs.energy.FPC.heat_load.display()

results = solve(m)
m.fs.costing.LCOT.display()
m.fs.energy.FPC.heat_load.display()
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def set_md_model_options(m, blk, n_time_points=None):
"module_type": "AS26C7.2L",
"cooling_system_type": "closed",
"cooling_inlet_temp": 25,
"recovery_ratio": m.water_recovery
"recovery_ratio": m.water_recovery,
}

if n_time_points == None:
Expand Down Expand Up @@ -208,36 +208,36 @@ def build_md(m, blk, prop_package=None) -> None:
# assert False


def init_md(blk, verbose=True, solver=None):
def init_md(m, blk, verbose=True, solver=None):
# blk = m.fs.md

blk.feed.initialize()

# blk.mp.build_multi_period_model(
# model_data_kwargs={t: blk.model_options for t in range(blk.n_time_points)},
# flowsheet_options=blk.model_options,
# unfix_dof_options={"feed_flow_rate": blk.model_options["feed_flow_rate"]},
# )

# add_performance_constraints(blk)

# blk.unit.system_capacity.fix(blk.model_options["system_capacity"])

# solver = get_solver()
# active_blks = blk.unit.mp.get_active_process_blocks()
# active_blks[0].fs.vagmd.feed_props.display()
# active_blks[0].fs.vagmd.feed_props.initialize()
# print(f"dof = {degrees_of_freedom(active_blks[0].fs.vagmd)}")
# assert False
# for active in active_blks:
# fix_dof_and_initialize(
# m=active,
# feed_temp=blk.model_input["feed_temp"],
# )
# _ = solver.solve(active)
# unfix_dof(m=active, feed_flow_rate=blk.model_input["feed_flow_rate"])

# Build connection to permeate state junction
# # blk.mp.build_multi_period_model(
# # model_data_kwargs={t: blk.model_options for t in range(blk.n_time_points)},
# # flowsheet_options=blk.model_options,
# # unfix_dof_options={"feed_flow_rate": blk.model_options["feed_flow_rate"]},
# # )

# # add_performance_constraints(blk)

# # blk.unit.system_capacity.fix(blk.model_options["system_capacity"])

# # solver = get_solver()
# # active_blks = blk.unit.mp.get_active_process_blocks()
# # active_blks[0].fs.vagmd.feed_props.display()
# # active_blks[0].fs.vagmd.feed_props.initialize()
# # print(f"dof = {degrees_of_freedom(active_blks[0].fs.vagmd)}")
# # assert False
# # for active in active_blks:
# # fix_dof_and_initialize(
# # m=active,
# # feed_temp=blk.model_input["feed_temp"],
# # )
# # _ = solver.solve(active)
# # unfix_dof(m=active, feed_flow_rate=blk.model_input["feed_flow_rate"])

# # Build connection to permeate state junction
blk.permeate.properties[0]._flow_vol_phase

@blk.Constraint(
Expand Down Expand Up @@ -267,7 +267,7 @@ def get_permeate_flow(b):
blk.permeate.properties[0].pressure.fix(101325)
blk.permeate.properties[0].temperature.fix(298.15)

# Build connection to concentrate state junction
# # Build connection to concentrate state junction

blk.concentrate.properties[0]._flow_vol_phase
blk.concentrate.properties[0]._conc_mass_phase_comp
Expand All @@ -280,11 +280,13 @@ def get_concentrate_flow(b):

return b.concentrate.properties[0].flow_vol_phase["Liq"] == pyunits.convert(
(
num_modules
* blk.model_input["initial_batch_volume"]
* pyunits.L
* (1 - b.unit.mp.get_active_process_blocks()[-1].fs.acc_recovery_ratio)
/ (b.unit.mp.get_active_process_blocks()[-1].fs.dt * (blk.n_time_points - 1))
b.unit.mp.get_active_process_blocks()[-1].fs.vagmd.system_capacity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checking on this. Is system capacity the volume of water (total feed) being treated or the volume of treated water produced (total permeate)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks for spotting that, you're definitely correct (capacity = total permeate).
I just committed the correct equation, so that concentrate_volume = system_capacity * (1-recovery) / recovery

* (1 - m.water_recovery)
# num_modules
# * blk.model_input["initial_batch_volume"]
# * pyunits.L
# * (1 - b.unit.mp.get_active_process_blocks()[-1].fs.acc_recovery_ratio)
# / (b.unit.mp.get_active_process_blocks()[-1].fs.dt * (blk.n_time_points - 1))
),
to_units=pyunits.m**3 / pyunits.s,
)
Expand All @@ -305,7 +307,7 @@ def get_concentrate_conc(b):
blk.concentrate.properties[0].pressure.fix(101325)
blk.concentrate.properties[0].temperature.fix(298.15)

# set_md_initial_conditions(blk)
# # set_md_initial_conditions(blk)


def init_system(m, verbose=True, solver=None):
Expand All @@ -323,7 +325,7 @@ def init_system(m, verbose=True, solver=None):
m.fs.feed.initialize()
propagate_state(m.fs.feed_to_md)

init_md(m.fs.md, verbose=True, solver=None)
init_md(m, m.fs.md, verbose=True, solver=None)

propagate_state(m.fs.md_to_product)
m.fs.product.initialize()
Expand Down