コード例 #1
0
def pfd_result(m, df, svg):
    """Insert model results into the PFD and return a new SVG string, which
    can be displayed, further edited, or saved to a file.

    Args:
        m (ConcreteModel): A steam cycle model
        df (Pandas DataFrame): Stream table
        svg (FILE*, str, bytes): Origianl svg svg as either a file-like object,
            a string, or a byte array.

    Returns:
        (str): SVG content.
    """
    tags = {}  # dict of tags and data to insert into SVG
    for i in df.index:  # Create entires for streams
        tags[i + "_F"] = df.loc[i, "Molar Flow (mol/s)"]
        tags[i + "_T"] = df.loc[i, "T (K)"]
        tags[i + "_P"] = df.loc[i, "P (Pa)"]
        tags[i + "_X"] = df.loc[i, "Vapor Fraction"]
    # Add some addtional quntities from the model to report
    tags["gross_power"] = -pyo.value(m.fs.turb.power[0])
    tags["gross_power_mw"] = -pyo.value(m.fs.turb.power[0]) * 1e-6
    tags["steam_mass_flow"] = df.loc["STEAM_MAIN", "Mass Flow (kg/s)"]
    tags["sc_eff"] = pyo.value(m.fs.steam_cycle_eff[0])
    tags["boiler_heat"] = pyo.value(m.fs.boiler_heat[0]) * 1e-6
    tags["steam_pressure"] = df.loc["STEAM_MAIN", "P (Pa)"] / 1000.0
    tags["cond_pressure"] = df.loc["EXHST_MAIN", "P (Pa)"] / 1000.0
    tags["bfp_power"] = pyo.value(m.fs.bfp.work_mechanical[0])
    tags["bfp_eff"] = pyo.value(m.fs.bfp.efficiency_isentropic[0]) * 100
    tags["bfpt_power"] = pyo.value(m.fs.bfpt.work_mechanical[0])
    tags["bfpt_eff"] = pyo.value(m.fs.bfpt.efficiency_isentropic[0]) * 100

    return svg_tag(tags, svg=svg)
コード例 #2
0
def test_tag_reference():
    m = ConcreteModel()
    m.x = Var([0,1], initialize={0:2.22,1:3.33})
    m.y = Var([0,1], initialize={0:4.44,1:5.55})
    m.f = Var([0,1], initialize={0:6.66,1:7.77})
    test_tag = {}
    test_tag["[email protected]"] = TagReference(m.x[:], description="x tag")
    test_tag["[email protected]"] = TagReference(m.y[:], description="y tag")
    test_tag["[email protected]"] = TagReference(m.f[:], description="z tag")
    m.tag = test_tag

    xml_str = svg_tag(m.tag, svg_test_str, idx=0)
    # lazy testing
    assert("2.22" in xml_str)
    assert("4.44" in xml_str)
    assert("6.66" in xml_str)

    xml_str = svg_tag(m.tag, svg_test_str, idx=1)
    # lazy testing
    assert("3.33" in xml_str)
    assert("5.55" in xml_str)
    assert("7.77" in xml_str)

    xml_str = svg_tag(m.tag, svg_test_str, show_tags=True)
    # lazy testing
    assert("[email protected]" in xml_str)
    assert("[email protected]" in xml_str)
    assert("[email protected]" in xml_str)

    tag_data_like = {}
    tag_data_like["[email protected]"] = 1.1212
    tag_data_like["[email protected]"] = 2.1212
    tag_data_like["[email protected]"] = "3.1212 Hello"
    xml_str = svg_tag(tag_data_like, svg_test_str, idx=None)
    assert("1.1212" in xml_str)
    assert("2.1212" in xml_str)
    assert("3.1212 Hello" in xml_str)
コード例 #3
0
def pfd_result(outfile, m, df):
    tags = {}
    for i in df.index:
        tags[i + "_F"] = df.loc[i, "Molar Flow (mol/s)"]
        tags[i + "_T"] = df.loc[i, "T (K)"]
        tags[i + "_P"] = df.loc[i, "P (Pa)"]
        tags[i + "_X"] = df.loc[i, "Vapor Fraction"]

    tags['FG_2_RH_Fm'] = value(m.fs.RH.side_2.properties_in[0].flow_mass)
    tags['FG_2_RH_T'] = value(m.fs.RH.side_2.properties_in[0].temperature)
    tags['FG_2_RH_P'] = value(m.fs.RH.side_2.properties_in[0].pressure)

    tags['FG_RH_2_Mix_Fm'] = value(m.fs.RH.side_2.properties_out[0].flow_mass)
    tags['FG_RH_2_Mix_T'] = value(m.fs.RH.side_2.properties_out[0].temperature)
    tags['FG_RH_2_Mix_P'] = value(m.fs.RH.side_2.properties_out[0].pressure)

    tags['FG_2_FSH_Fm'] = value(m.fs.FSH.side_2.properties_in[0].flow_mass)
    tags['FG_2_FSH_T'] = value(m.fs.FSH.side_2.properties_in[0].temperature)
    tags['FG_2_FSH_P'] = value(m.fs.FSH.side_2.properties_in[0].pressure)

    tags['FG_2_PrSH_Fm'] = value(m.fs.PrSH.side_2.properties_in[0].flow_mass)
    tags['FG_2_PrSH_T'] = value(m.fs.PrSH.side_2.properties_in[0].temperature)
    tags['FG_2_PrSH_P'] = value(m.fs.PrSH.side_2.properties_in[0].pressure)

    tags['FG_PrSH_2_Mix_Fm'] = value(
        m.fs.PrSH.side_2.properties_out[0].flow_mass)
    tags['FG_PrSH_2_Mix_T'] = value(
        m.fs.PrSH.side_2.properties_out[0].temperature)
    tags['FG_PrSH_2_Mix_P'] = value(
        m.fs.PrSH.side_2.properties_out[0].pressure)

    tags['FG_2_ECON_Fm'] = value(m.fs.ECON.side_2.properties_in[0].flow_mass)
    tags['FG_2_ECON_T'] = value(m.fs.ECON.side_2.properties_in[0].temperature)
    tags['FG_2_ECON_P'] = value(m.fs.ECON.side_2.properties_in[0].pressure)

    tags['FG_2_AIRPH_Fm'] = value(m.fs.ECON.side_2.properties_out[0].flow_mass)
    tags['FG_2_AIRPH_T'] = value(
        m.fs.ECON.side_2.properties_out[0].temperature)
    tags['FG_2_AIRPH_P'] = value(m.fs.ECON.side_2.properties_out[0].pressure)

    tags['FG_2_STACK_Fm'] = value(m.fs.ECON.side_2.properties_out[0].flow_mass)
    tags['FG_2_STACK_T'] = value(
        m.fs.ECON.side_2.properties_out[0].temperature)
    tags['FG_2_STACK_P'] = value(m.fs.ECON.side_2.properties_out[0].pressure)

    original_svg_file = os.path.join(this_file_dir(), "Boiler_scpc_PFD.svg")
    with open(original_svg_file, "r") as f:
        s = svg_tag(tags, f, outfile=outfile)
コード例 #4
0
def test_tag_reference_tag_format():
    m = ConcreteModel()
    m.x = Var([0,1], initialize={0:2.22,1:3.33})
    m.y = Var([0,1], initialize={0:4.44,1:5.55})
    m.f = Var([0,1], initialize={0:6.66,1:7.77})
    test_tag = {}
    test_tag["[email protected]"] = TagReference(m.x[:], description="x tag")
    test_tag["[email protected]"] = TagReference(m.y[:], description="y tag")
    test_tag["[email protected]"] = TagReference(m.f[:], description="z tag")
    m.tag = test_tag

    xml_str = svg_tag(m.tag, svg_test_str, idx=0, tag_format={"[email protected]":"{:.5e}"})
    # lazy testing
    assert("2.2200e" in xml_str)
    assert("4.44000e" in xml_str)
    assert("6.6600e" in xml_str)
コード例 #5
0
ファイル: report_steady.py プロジェクト: IDAES/publications
def svg_output(tags, tag_format, n=""):
    with open("pfd/plant_template.svg", "r") as f:
        svg_tag(svg=f,
                tags=tags,
                outfile=f"results/plant_pfd{n}.svg",
                tag_format=tag_format)
    with open("pfd/boiler_template.svg", "r") as f:
        svg_tag(svg=f,
                tags=tags,
                outfile=f"results/boiler_pfd{n}.svg",
                tag_format=tag_format)
    with open("pfd/fwh_hp_template.svg", "r") as f:
        svg_tag(svg=f,
                tags=tags,
                outfile=f"results/fwh_hp_pfd{n}.svg",
                tag_format=tag_format)
    with open("pfd/fwh_lp_template.svg", "r") as f:
        svg_tag(svg=f,
                tags=tags,
                outfile=f"results/fwh_lp_pfd{n}.svg",
                tag_format=tag_format)
コード例 #6
0
def test_tag_reference_tag_format_conditional():
    m = ConcreteModel()
    m.x = Var([0,1], initialize={0:10000,1:3.33})
    m.y = Var([0,1], initialize={0:1.1,1:5.55})
    m.f = Var([0,1], initialize={0:4.5,1:7.77})
    test_tag = {}
    test_tag["[email protected]"] = TagReference(m.x[:], description="x tag")
    test_tag["[email protected]"] = TagReference(m.y[:], description="y tag")
    test_tag["[email protected]"] = TagReference(m.f[:], description="z tag")
    m.tag = test_tag

    xml_str = svg_tag(
        m.tag,
        svg_test_str,
        idx=0,
        tag_format_default=lambda x: "{:,.0f} kPa" if x >= 100 else "{:.2f} kPa")
    # lazy testing
    assert("10,000 kPa" in xml_str)
    assert("1.10 kPa" in xml_str)
    assert("4.50 kPa" in xml_str)