Skip to content

Commit

Permalink
working implementation in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterbarber committed Mar 4, 2024
1 parent 43d3655 commit 6c80edd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
5 changes: 2 additions & 3 deletions watertap/examples/flowsheets/gac/gac.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():

# example usage
m = build(
material_flow_basis="mass",
material_flow_basis="molar",
film_transfer_coefficient_type="calculated",
surface_diffusion_coefficient_type="calculated",
diffusivity_calculation="HaydukLaudie",
Expand All @@ -59,8 +59,7 @@ def build(
diffusivity_calculation="none",
cost_contactor_type="pressure",
):
# TODO: mass or mole basis
# surrogates to replace empirical parameters
# TODO: surrogates to replace empirical parameters
# autoscaling, check robustness of solve over sweeps
# build only supports string (Option.value.name) and not Option.value from import

Expand Down
39 changes: 36 additions & 3 deletions watertap/examples/flowsheets/gac/gac_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def export_to_ui():
"MaterialFlowBasis": {
"name": "FilmTransferCoefficientType",
"display_name": "Material Flow Basis",
"values_allowed": [x.name for x in MaterialFlowBasis],
"values_allowed": [
x.name for x in [MaterialFlowBasis.molar, MaterialFlowBasis.mass]
],
"value": MaterialFlowBasis.molar.name,
},
"FilmTransferCoefficientType": {
Expand Down Expand Up @@ -177,14 +179,20 @@ def export_variables(flowsheet=None, exports=None, build_options=None, **kwargs)
is_output=True,
output_category=category,
)
if build_options["MaterialFlowBasis"].value == "molar":
fix_molar = True
fix_mass = False
else:
fix_molar = False
fix_mass = True

Check warning on line 187 in watertap/examples/flowsheets/gac/gac_ui.py

View check run for this annotation

Codecov / codecov/patch

watertap/examples/flowsheets/gac/gac_ui.py#L186-L187

Added lines #L186 - L187 were not covered by tests
exports.add(
obj=fs.feed.properties[0].flow_mol_phase_comp["Liq", "H2O"],
name="Molar flow rate water",
ui_units=pyunits.mol / pyunits.s,
display_units="mol/s",
rounding=rounding,
description="Feed molar flow rate of water",
is_input=True,
is_input=fix_molar,
input_category=category,
is_output=True,
output_category=category,
Expand All @@ -196,7 +204,31 @@ def export_variables(flowsheet=None, exports=None, build_options=None, **kwargs)
display_units="mol/s",
rounding=rounding,
description="Feed molar flow rate of solute",
is_input=True,
is_input=fix_molar,
input_category=category,
is_output=True,
output_category=category,
)
exports.add(
obj=fs.feed.properties[0].flow_mass_phase_comp["Liq", "H2O"],
name="Mass flow rate water",
ui_units=pyunits.kg / pyunits.s,
display_units="kg/s",
rounding=rounding,
description="Feed mass flow rate of water",
is_input=fix_mass,
input_category=category,
is_output=True,
output_category=category,
)
exports.add(
obj=fs.feed.properties[0].flow_mass_phase_comp["Liq", solute_name],
name="Mass flow rate solute",
ui_units=pyunits.kg / pyunits.s,
display_units="kg/s",
rounding=rounding,
description="Feed mass flow rate of solute",
is_input=fix_mass,
input_category=category,
is_output=True,
output_category=category,
Expand Down Expand Up @@ -795,6 +827,7 @@ def build_flowsheet(build_options=None, **kwargs):

if build_options is not None:
m = gac_fs.build(
material_flow_basis=build_options["MaterialFlowBasis"].value,
film_transfer_coefficient_type=build_options[
"FilmTransferCoefficientType"
].value,
Expand Down
5 changes: 1 addition & 4 deletions watertap/examples/flowsheets/gac/tests/test_gac.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def test_solve(self, gac_frame):
def test_build_solve_options(self):

# test build and solve at initial conditions for all config options
for flow_basis in MaterialFlowBasis:
print(flow_basis.name)
for flow_basis in [MaterialFlowBasis.molar, MaterialFlowBasis.mass]:
for film_option in FilmTransferCoefficientType:
for surface_option in SurfaceDiffusionCoefficientType:
for diffus_option in DiffusivityCalculation:
Expand All @@ -92,8 +91,6 @@ def test_build_solve_options(self):
gac_fs.initialize(m)
res = gac_fs.optimize(m)

m.fs.gac.operational_time.display()

assert_units_consistent(m)
assert degrees_of_freedom(m) == 0
assert_optimal_termination(res)

0 comments on commit 6c80edd

Please sign in to comment.