Skip to content

Commit

Permalink
Refactor code for improved readability and formatting in KBHDP case s…
Browse files Browse the repository at this point in the history
…tudies
  • Loading branch information
zacharybinger committed Dec 10, 2024
1 parent f37e893 commit ccafe10
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def build_treatment(m):
has_phase_equilibrium=False,
outlet_state_defined=True,
)

treatment.NaCl_to_TDS_translator = Translator_NaCl_to_TDS(
inlet_property_package=m.fs.RO_properties,
outlet_property_package=m.fs.MD_properties,
Expand Down Expand Up @@ -177,7 +177,7 @@ def build_treatment(m):
m.fs.RO_properties.set_default_scaling(
"flow_mass_phase_comp", 1e2, index=("Liq", "NaCl")
)

m.fs.MD_properties.set_default_scaling(
"flow_mass_phase_comp", 1, index=("Liq", "H2O")
)
Expand Down Expand Up @@ -238,12 +238,12 @@ def add_connections(m):
source=treatment.RO.product.outlet,
destination=treatment.product.inlet,
)

treatment.ro_to_translator = Arc(
source=treatment.RO.disposal.outlet,
destination=treatment.NaCl_to_TDS_translator.inlet,
)

treatment.translator_to_md = Arc(
source=treatment.NaCl_to_TDS_translator.outlet,
destination=treatment.MD.feed.inlet,
Expand Down Expand Up @@ -521,7 +521,7 @@ def init_treatment(m, verbose=True, solver=None):
propagate_state(treatment.translator_to_md)

init_md(treatment.MD)
#TODO: Continue from here
# TODO: Continue from here
# treatment.product.initialize(optarg=optarg)
# # init_DWI(m, treatment.DWI)
# display_system_stream_table(m)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ def get_concentrate_flow(b):
* blk.model_options["initial_batch_volume"]
* pyunits.L
* (1 - b.unit.get_active_process_blocks()[-1].fs.acc_recovery_ratio)
/ (b.unit.get_active_process_blocks()[-1].fs.dt * (blk.n_time_points - 1))
/ (
b.unit.get_active_process_blocks()[-1].fs.dt
* (blk.n_time_points - 1)
)
),
to_units=pyunits.m**3 / pyunits.s,
)
Expand Down Expand Up @@ -363,19 +366,19 @@ def set_md_op_conditions(blk):
# feed_temp = pyunits.convert_temp_K_to_C(blk.feed.properties[0].temperature())

print("\n--------- MD TIME PERIOD 1 INPUTS ---------\n")
print("Feed flow rate in L/h:", blk.model_options["feed_flow_rate"])
print("Feed salinity in g/l:", blk.model_options["feed_salinity"])
print("Feed temperature in C:", blk.model_options["feed_temp"])
print("Feed flow rate in L/h:", blk.model_options["feed_flow_rate"])
print("Feed salinity in g/l:", blk.model_options["feed_salinity"])
print("Feed temperature in C:", blk.model_options["feed_temp"])
print("\n")

active_blks[0].fs.vagmd.feed_props[0].conc_mass_phase_comp["Liq", "TDS"].fix(
blk.model_options["feed_salinity"]
blk.model_options["feed_salinity"]
)
active_blks[0].fs.vagmd.feed_props[0].temperature.fix(
blk.model_options["feed_temp"] + 273.15
blk.model_options["feed_temp"] + 273.15
)
active_blks[0].fs.acc_distillate_volume.fix(0)
active_blks[0].fs.pre_feed_temperature.fix( blk.model_options["feed_temp"] + 273.15)
active_blks[0].fs.pre_feed_temperature.fix(blk.model_options["feed_temp"] + 273.15)
active_blks[0].fs.pre_permeate_flow_rate.fix(0)
active_blks[0].fs.acc_thermal_energy.fix(0)
active_blks[0].fs.pre_thermal_power.fix(0)
Expand Down Expand Up @@ -720,23 +723,29 @@ def report_md_costing(m, blk):
m.fs.md.unit.get_active_process_blocks()[0].fs.acc_distillate_volume.display()
m.fs.md.unit.get_active_process_blocks()[0].fs.pre_evap_out_temp.display()
m.fs.md.unit.get_active_process_blocks()[0].fs.vagmd.thermal_power.display()
m.fs.md.unit.get_active_process_blocks()[0].fs.specific_energy_consumption_thermal.display()
m.fs.md.unit.get_active_process_blocks()[
0
].fs.specific_energy_consumption_thermal.display()

m.fs.md.unit.get_active_process_blocks()[1].fs.vagmd.permeate_flux.display()
m.fs.md.unit.get_active_process_blocks()[1].fs.pre_permeate_flow_rate.display()
m.fs.md.unit.get_active_process_blocks()[1].fs.pre_acc_distillate_volume.display()
m.fs.md.unit.get_active_process_blocks()[1].fs.acc_distillate_volume.display()
m.fs.md.unit.get_active_process_blocks()[1].fs.pre_evap_out_temp.display()
m.fs.md.unit.get_active_process_blocks()[1].fs.vagmd.thermal_power.display()
m.fs.md.unit.get_active_process_blocks()[1].fs.specific_energy_consumption_thermal.display()
m.fs.md.unit.get_active_process_blocks()[
1
].fs.specific_energy_consumption_thermal.display()

m.fs.md.unit.get_active_process_blocks()[-1].fs.vagmd.permeate_flux.display()
m.fs.md.unit.get_active_process_blocks()[-1].fs.pre_permeate_flow_rate.display()
m.fs.md.unit.get_active_process_blocks()[-1].fs.pre_acc_distillate_volume.display()
m.fs.md.unit.get_active_process_blocks()[-1].fs.acc_distillate_volume.display()
m.fs.md.unit.get_active_process_blocks()[-1].fs.pre_evap_out_temp.display()
m.fs.md.unit.get_active_process_blocks()[-1].fs.vagmd.thermal_power.display()
m.fs.md.unit.get_active_process_blocks()[-1].fs.specific_energy_consumption_thermal.display()
m.fs.md.unit.get_active_process_blocks()[
-1
].fs.specific_energy_consumption_thermal.display()

m.fs.disposal.properties[0].flow_vol_phase

Expand All @@ -754,7 +763,15 @@ def report_md_costing(m, blk):
results = solve(m)
print("\n--------- Cost solve Completed ---------\n")

print("Inlet flow rate in m3/day:", value(pyunits.convert(m.fs.feed.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)))
print(
"Inlet flow rate in m3/day:",
value(
pyunits.convert(
m.fs.feed.properties[0].flow_vol_phase["Liq"],
pyunits.m**3 / pyunits.day,
)
),
)
report_MD(m, m.fs.md)
report_md_costing(m, m.fs)

Expand All @@ -770,12 +787,26 @@ def report_md_costing(m, blk):
# heat_in = [value(active_blks[i].fs.pre_thermal_power) for i in range(n_time_points)]

# m.fs.water_recovery.display()
print('\n')
print(f'Sys Feed Flow Rate: {value(pyunits.convert(m.fs.feed.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day')
print(f'MD Feed Flow Rate: {value(pyunits.convert(m.fs.md.feed.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day')
print(f'Sys Perm Flow Rate: {value(pyunits.convert(m.fs.product.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day')
print(f'MD Perm Flow Rate: {value(pyunits.convert(m.fs.md.permeate.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day')
print(f'Sys Conc Flow Rate: {value(pyunits.convert(m.fs.disposal.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day')
print(f'MD Conc Flow Rate: {value(pyunits.convert(m.fs.md.concentrate.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day')
print(f'System Var Recovery: {value(m.fs.water_recovery):<10.2f}')
print(f'Calculated Recovery: {value(m.fs.md.permeate.properties[0].flow_vol_phase["Liq"] / (m.fs.md.permeate.properties[0].flow_vol_phase["Liq"] + m.fs.md.concentrate.properties[0].flow_vol_phase["Liq"])):<10.2f}')
print("\n")
print(
f'Sys Feed Flow Rate: {value(pyunits.convert(m.fs.feed.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day'
)
print(
f'MD Feed Flow Rate: {value(pyunits.convert(m.fs.md.feed.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day'
)
print(
f'Sys Perm Flow Rate: {value(pyunits.convert(m.fs.product.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day'
)
print(
f'MD Perm Flow Rate: {value(pyunits.convert(m.fs.md.permeate.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day'
)
print(
f'Sys Conc Flow Rate: {value(pyunits.convert(m.fs.disposal.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day'
)
print(
f'MD Conc Flow Rate: {value(pyunits.convert(m.fs.md.concentrate.properties[0].flow_vol_phase["Liq"], pyunits.m ** 3 / pyunits.day)):<10.2f} m3/day'
)
print(f"System Var Recovery: {value(m.fs.water_recovery):<10.2f}")
print(
f'Calculated Recovery: {value(m.fs.md.permeate.properties[0].flow_vol_phase["Liq"] / (m.fs.md.permeate.properties[0].flow_vol_phase["Liq"] + m.fs.md.concentrate.properties[0].flow_vol_phase["Liq"])):<10.2f}'
)
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ def eq_pressure_rule(blk, t):
doc="Equality solute equation",
)
def eq_solute_mass_flow(blk, t):
return blk.properties_out[t].flow_mass_phase_comp["Liq", "TDS"] == blk.properties_in[t].flow_mass_phase_comp["Liq", "NaCl"]

return (
blk.properties_out[t].flow_mass_phase_comp["Liq", "TDS"]
== blk.properties_in[t].flow_mass_phase_comp["Liq", "NaCl"]
)

def initialize_build(
self,
Expand Down

0 comments on commit ccafe10

Please sign in to comment.