From ccafe107f1d13dd3c226bc0826c7a2bb01625de7 Mon Sep 17 00:00:00 2001 From: zacharybinger Date: Tue, 10 Dec 2024 16:15:00 -0700 Subject: [PATCH] Refactor code for improved readability and formatting in KBHDP case studies --- .../analysis/case_studies/KBHDP/KBHDP_ZLD.py | 10 +-- .../case_studies/KBHDP/components/MD.py | 71 +++++++++++++------ .../KBHDP/components/translator_6.py | 6 +- 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/KBHDP_ZLD.py b/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/KBHDP_ZLD.py index 37ce57e5..cb299954 100644 --- a/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/KBHDP_ZLD.py +++ b/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/KBHDP_ZLD.py @@ -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, @@ -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") ) @@ -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, @@ -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) diff --git a/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/components/MD.py b/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/components/MD.py index d7503560..194ba71f 100644 --- a/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/components/MD.py +++ b/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/components/MD.py @@ -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, ) @@ -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) @@ -720,7 +723,9 @@ 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() @@ -728,7 +733,9 @@ def report_md_costing(m, blk): 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() @@ -736,7 +743,9 @@ def report_md_costing(m, blk): 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 @@ -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) @@ -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}') \ No newline at end of file + 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}' + ) diff --git a/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/components/translator_6.py b/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/components/translator_6.py index cd290bc7..c08c1359 100644 --- a/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/components/translator_6.py +++ b/src/watertap_contrib/reflo/analysis/case_studies/KBHDP/components/translator_6.py @@ -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,