diff --git a/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/plant_pfd_result.svg b/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/plant_pfd_result.svg index e405022d0e..4afb1476ca 100644 --- a/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/plant_pfd_result.svg +++ b/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/plant_pfd_result.svg @@ -500,156 +500,156 @@ - 810 K K - 3,421 kJ/kg J/kg - 14,400 kPa Pa - 268.6 kg/s kg/s + 810 K + 3,421,228 J/kg + 14,400,000 Pa + 268.6 kg/s 1.000 FTPHx - 803 K K - 3,421 kJ/kg J/kg - 12,710 kPa Pa - 268.6 kg/s kg/s + 803 K + 3,421,228 J/kg + 12,710,285 Pa + 268.6 kg/s 1.000 FTPHx - 809 K K - 3,535 kJ/kg J/kg - 3,326 kPa Pa - 241.7 kg/s kg/s + 809 K + 3,535,071 J/kg + 3,325,993 Pa + 241.7 kg/s 1.000 FTPHx - 612 K K - 3,074 kJ/kg J/kg - 3,666 kPa Pa - 241.7 kg/s kg/s + 612 K + 3,074,455 J/kg + 3,666,249 Pa + 241.7 kg/s 1.000 FTPHx - 330 K K - 238 kJ/kg J/kg - 17.23 kPa Pa - 9.12 kg/s kg/s + 330 K + 238,085 J/kg + 17,230 Pa + 9.12 kg/s 0.000 FTPHx - 318 K K - 188 kJ/kg J/kg - 9.53 kPa Pa - 176.5 kg/s kg/s + 318 K + 187,884 J/kg + 9,530 Pa + 176.5 kg/s 0.000 FTPHx - 318 K K - 2,440 kJ/kg J/kg - 9.53 kPa Pa - 176.5 kg/s kg/s + 318 K + 2,440,483 J/kg + 9,530 Pa + 176.5 kg/s 0.941 FTPHx - 1,426 K K - 100 kPa Pa - 344.0 kg/s kg/s + 1,425 K + 100,325 Pa + 344.0 kg/s FTP - 892 K K - 100 kPa Pa - 344.0 kg/s kg/s + 892 K + 100,075 Pa + 344.0 kg/s FTP - 571 K K - 1,328 kJ/kg J/kg - 15,038 kPa Pa - 272.6 kg/s kg/s + 571 K + 1,328,391 J/kg + 15,037,744 Pa + 272.6 kg/s 0.000 FTPHx - 517 K K - 1,058 kJ/kg J/kg - 15,401 kPa Pa - 272.6 kg/s kg/s + 517 K + 1,057,982 J/kg + 15,400,712 Pa + 272.6 kg/s 0.000 FTPHx - 446 K K - 741 kJ/kg J/kg - 15,401 kPa Pa - 1.41 kg/s kg/s + 446 K + 741,042 J/kg + 15,400,712 Pa + 1.42 kg/s 0.000 FTPHx - 458 K K - 98.61 kPa Pa - 344.0 kg/s kg/s + 458 K + 98,610 Pa + 344.0 kg/s FTP - 612 K K - 3,074 kJ/kg J/kg - 3,666 kPa Pa - 26.9 kg/s kg/s + 612 K + 3,074,455 J/kg + 3,666,249 Pa + 26.9 kg/s 1.000 FTPHx - 682 K K - 3,277 kJ/kg J/kg - 1,442 kPa Pa - 9.71 kg/s kg/s + 682 K + 3,276,580 J/kg + 1,442,238 Pa + 9.71 kg/s 1.000 FTPHx - 604 K K - 3,120 kJ/kg J/kg - 825 kPa Pa - 12.8 kg/s kg/s + 604 K + 3,120,425 J/kg + 824,653 Pa + 12.8 kg/s 1.000 FTPHx - 507 K K - 2,934 kJ/kg J/kg - 348 kPa Pa - 9.70 kg/s kg/s + 507 K + 2,933,961 J/kg + 348,416 Pa + 9.70 kg/s 1.000 FTPHx - 604 K K - 3,120 kJ/kg J/kg - 825 kPa Pa - 9.12 kg/s kg/s + 604 K + 3,120,425 J/kg + 824,653 Pa + 9.12 kg/s 1.000 FTPHx - 439 K K - 2,804 kJ/kg J/kg - 171 kPa Pa - 11.2 kg/s kg/s + 439 K + 2,803,515 J/kg + 170,724 Pa + 11.2 kg/s 1.000 FTPHx - 359 K K - 2,648 kJ/kg J/kg - 59.75 kPa Pa - 12.7 kg/s kg/s + 359 K + 2,647,688 J/kg + 59,753 Pa + 12.7 kg/s 0.998 diff --git a/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/subcritical_power_plant.py b/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/subcritical_power_plant.py index fd54b7ebac..e593af8e94 100644 --- a/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/subcritical_power_plant.py +++ b/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/subcritical_power_plant.py @@ -2167,6 +2167,54 @@ def write_data_to_txt_file(plot_data): fout.write("\n") +def _build_pfd_tag_group(sd): + """ + Build tags/tag_formats/ModelTagGroup from stream state dict `sd`. + Split out for unit-testing. + """ + tags = {} + tag_formats = {} + + for i, s in sd.items(): + tags[i + "_Fmass"] = s.flow_mass + tag_formats[i + "_Fmass"] = lambda x: ("{:.1f}" if x >= 10 else "{:.2f}") + + tags[i + "_F"] = s.flow_mol + tag_formats[i + "_F"] = "{:,.0f}" + + tags[i + "_T"] = s.temperature + tag_formats[i + "_T"] = "{:,.0f}" + + tags[i + "_P_kPa"] = s.pressure + tag_formats[i + "_P_kPa"] = lambda x: ("{:,.0f}" if x >= 100 else "{:.2f}") + + try: + tags[i + "_hmass"] = s.enth_mass + tag_formats[i + "_hmass"] = "{:,.0f}" + tags[i + "_h"] = s.enth_mol + tag_formats[i + "_h"] = "{:,.0f}" + except AttributeError: + pass + + try: + tags[i + "_x"] = s.vapor_frac + tag_formats[i + "_x"] = "{:.3f}" + except AttributeError: + pass + + if hasattr(s, "mole_frac_comp"): + for comp in ("N2", "O2", "NO", "CO2", "H2O", "SO2"): + if comp in s.mole_frac_comp: + tags[i + f"_y{comp}"] = s.mole_frac_comp[comp] + + tag_group = ModelTagGroup() + for t, v in tags.items(): + formatter = tag_formats.get(t, "{:.3f}") + tag_group.add(t, v, format_string=formatter) + + return tags, tag_formats, tag_group + + def print_pfd_results(m): streams = tables.arcs_to_stream_dict( m.fs_main, @@ -2208,52 +2256,8 @@ def print_pfd_results(m): ) sdf.sort_index(inplace=True) sdf.to_csv("streams.csv") - tags = {} - tag_formats = {} - for i, s in sd.items(): - tags[i + "_Fmass"] = s.flow_mass - tag_formats[i + "_Fmass"] = lambda x: ( - "{:.1f} kg/s" if x >= 10 else "{:.2f} kg/s" - ) - tags[i + "_F"] = s.flow_mol - tag_formats[i + "_F"] = "{:,.0f} mol/s" - tags[i + "_T"] = s.temperature - tag_formats[i + "_T"] = "{:,.0f} K" - tags[i + "_P_kPa"] = s.pressure / 1000 - tag_formats[i + "_P_kPa"] = lambda x: ( - "{:,.0f} kPa" if x >= 100 else "{:.2f} kPa" - ) - tags[i + "_P"] = s.pressure / 1000 - tag_formats[i + "_P"] = "{:,.0f} Pa" - try: - tags[i + "_hmass"] = s.enth_mass / 1000.0 - tag_formats[i + "_hmass"] = "{:,.0f} kJ/kg" - tags[i + "_h"] = s.enth_mol - tag_formats[i + "_h"] = "{:,.0f} J/mol" - except AttributeError: - pass - try: - tags[i + "_x"] = s.vapor_frac - tag_formats[i + "_x"] = "{:.3f}" - except AttributeError: - pass - try: - tags[i + "_yN2"] = s.mole_frac_comp["N2"] - tags[i + "_yO2"] = s.mole_frac_comp["O2"] - tags[i + "_yNO"] = s.mole_frac_comp["NO"] - tags[i + "_yCO2"] = s.mole_frac_comp["CO2"] - tags[i + "_yH2O"] = s.mole_frac_comp["H2O"] - tags[i + "_ySO2"] = s.mole_frac_comp["SO2"] - except AttributeError: - pass - tag_group = ModelTagGroup() - for t, v in tags.items(): - try: - formatter = tag_formats[t] - except KeyError: - formatter = "{:.3f}" - tag_group.add(t, v, format_string=formatter) + _, _, tag_group = _build_pfd_tag_group(sd) # first two unused dirpath = os.path.dirname(__file__) svgpath = os.path.join(dirpath, "plant_pfd.svg") diff --git a/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/tests/test_subcritical_flowsheets.py b/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/tests/test_subcritical_flowsheets.py index 6203cf8977..1b26b768e4 100644 --- a/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/tests/test_subcritical_flowsheets.py +++ b/idaes/models_extra/power_generation/flowsheets/subcritical_power_plant/tests/test_subcritical_flowsheets.py @@ -20,6 +20,7 @@ import idaes.models_extra.power_generation.flowsheets.subcritical_power_plant.subcritical_boiler as recyrc from idaes.models.properties.general_helmholtz import helmholtz_available +import types import pytest @@ -91,6 +92,42 @@ def test_subcritical_boiler_dynamic(): ) +@pytest.mark.skipif(not helmholtz_available(), reason="General Helmholtz not available") +@pytest.mark.component +def test_build_pfd_tag_group_smoke(): + sd = { + "S1": types.SimpleNamespace( + flow_mass=9.5, + flow_mol=1000, + temperature=450, + pressure=95, + enth_mass=1.0, + enth_mol=2.0, + vapor_frac=0.1, + mole_frac_comp={"N2": 0.7, "O2": 0.2}, + ), + "S2": types.SimpleNamespace( + flow_mass=12.0, + flow_mol=200, + temperature=300, + pressure=250, + mole_frac_comp={"CO2": 0.15}, + ), + } + + tags, fmts, tg = subcrit_plant._build_pfd_tag_group(sd) + + assert {"S1_F", "S1_x", "S1_yN2", "S2_yCO2"} <= set(tags) + assert tags["S1_T"] == 450.0 + assert tags["S1_P_kPa"] == 95.0 + assert tags["S1_hmass"] == 1.0 + assert fmts["S1_F"] == "{:,.0f}" + assert fmts["S1_Fmass"](9.5) == "{:.2f}" and fmts["S2_Fmass"](12.0) == "{:.1f}" + assert fmts["S1_T"] == "{:,.0f}" + assert fmts["S1_P_kPa"](95.0) == "{:.2f}" and fmts["S1_P_kPa"](250.0) == "{:,.0f}" + assert fmts["S1_h"] == "{:,.0f}" and fmts["S1_hmass"] == "{:,.0f}" + + @pytest.mark.skipif(not helmholtz_available(), reason="General Helmholtz not available") @pytest.mark.integration def test_steam_cycle():