Beispiel #1
0
def solve_RO(base="TDS", level="simple"):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    property_models.build_prop(m, base="TDS")

    build_RO(m, base=base, level=level)

    # specify feed
    property_models.specify_feed(m.fs.RO.feed_side.properties[0, 0],
                                 base="TDS")
    m.fs.RO.feed_side.properties[0, 0].pressure.fix(50e5)

    # scaling
    calculate_scaling_factors(m)

    # initialize
    m.fs.RO.initialize(optarg={"nlp_scaling_method": "user-scaling"})

    m.fs.RO.display()
    check_dof(m)
    solve_block(m)

    m.fs.RO.report()

    return m
Beispiel #2
0
def simulate_enrtl_FpcTP(state_var_args):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    m.fs.params = GenericParameterBlock(
        default=entrl_config_FpcTP.configuration)

    m.fs.state = m.fs.params.build_state_block(m.fs.time,
                                               default={"defined_state": True})

    for (v_name, ind), val in state_var_args.items():
        var = getattr(m.fs.state[0], v_name)
        var[ind].fix(val)

    # scale model
    calculate_scaling_factors(m)
    for (ind, c) in m.fs.state[0].true_to_appr_species.items():
        sf = get_scaling_factor(
            m.fs.state[0].flow_mol_phase_comp_apparent[ind])
        constraint_scaling_transform(c, sf)
    for (ind, c) in m.fs.state[0].appr_mole_frac_constraint.items():
        sf = get_scaling_factor(
            m.fs.state[0].mole_frac_phase_comp_apparent[ind])
        constraint_scaling_transform(c, sf)

    check_scaling(m)

    solve_block(m)

    ksp = 3.2e-9  # Gibbs energy gives 3.9e-8, but this fits expectations better
    saturation_index = value(m.fs.state[0].act_phase_comp["Liq", "Ca_2+"] *
                             m.fs.state[0].act_phase_comp["Liq", "SO4_2-"] *
                             m.fs.state[0].act_phase_comp["Liq", "H2O"]**2 /
                             ksp)
    return saturation_index
def solve_flowsheet(**desal_kwargs):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    build(m, **desal_kwargs)
    TransformationFactory("network.expand_arcs").apply_to(m)

    # scale
    calculate_scaling_factors(m.fs.tb_pretrt_to_desal)
    scale(m, **desal_kwargs)
    calculate_scaling_factors(m)

    # initialize
    m.fs.feed.initialize()
    propagate_state(m.fs.s_pretrt_tb)
    optarg = {'nlp_scaling_method': 'user-scaling'}
    m.fs.tb_pretrt_to_desal.initialize(optarg=optarg)
    initialize(m, **desal_kwargs)

    check_dof(m)
    solve_block(m, tee=False, fail_flag=True)

    # report
    report(m, **desal_kwargs)

    return m
def solve_flowsheet(**desal_kwargs):
    if desal_kwargs == {}:
        desal_kwargs = flowsheet_two_stage.desal_kwargs

    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    build(m, **desal_kwargs)
    TransformationFactory("network.expand_arcs").apply_to(m)

    # scale
    scale(m, **desal_kwargs)
    calculate_scaling_factors(m)

    # initialize
    initialize(m, **desal_kwargs)

    check_dof(m)
    solve_block(m, tee=False, fail_flag=True)

    # report
    print("==================================="
          "\n          Simulation          ")
    report(m, **desal_kwargs)

    return m
Beispiel #5
0
def run_ideal_naocl_mixer_example(fixed_dosage=False):
    model = ConcreteModel()
    model.fs = FlowsheetBlock(default={"dynamic": False})

    # Add properties to model
    build_ideal_naocl_prop(model)

    # Add mixer to the model
    build_ideal_naocl_mixer_unit(model)

    # Set some inlet values
    set_ideal_naocl_mixer_inlets(model)

    # Fix the inlets for a solve
    fix_ideal_naocl_mixer_inlets(model)

    # unfix the flow_mol for the naocl_stream and fix dosing rate (alt form)
    if fixed_dosage == True:
        model.fs.ideal_naocl_mixer_unit.naocl_stream.flow_mol[0].unfix()
        model.fs.ideal_naocl_mixer_unit.dosing_rate.fix()

    check_dof(model)

    # initializer mixer
    initialize_ideal_naocl_mixer(model.fs.ideal_naocl_mixer_unit)

    solve_block(model, tee=True)

    display_results_of_ideal_naocl_mixer(model.fs.ideal_naocl_mixer_unit)

    return model
def solve_pretreatment_NF(**kwargs):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    property_models.build_prop(m, base=kwargs["NF_base"])
    build_pretreatment_NF(m, **kwargs)
    TransformationFactory("network.expand_arcs").apply_to(m)

    scale_pretreatment_NF(m, **kwargs)

    initialize_pretreatment_NF(m, **kwargs)

    check_dof(m)
    solve_block(m, tee=True, fail_flag=True)

    display_pretreatment_NF(m, **kwargs)
Beispiel #7
0
def solve_SepRO(base="TDS"):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    property_models.build_prop(m, base=base)
    build_SepRO(m, base=base)
    property_models.specify_feed(m.fs.RO.mixed_state[0], base=base)

    check_dof(m)
    calculate_scaling_factors(m)
    solve_block(m)

    m.fs.RO.inlet.display()
    m.fs.RO.permeate.display()
    m.fs.RO.retentate.display()

    return m
Beispiel #8
0
def solve_SepNF(base="ion"):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    property_models.build_prop(m, base=base)
    build_SepNF(m, base=base)
    property_models.specify_feed(m.fs.NF.mixed_state[0], base=base)

    m.fs.NF.mixed_state[0].mass_frac_phase_comp  # touching for tests
    check_dof(m)
    calculate_scaling_factors(m)
    solve_block(m)

    m.fs.NF.inlet.display()
    m.fs.NF.permeate.display()
    m.fs.NF.retentate.display()

    return m
Beispiel #9
0
def solve_ZONF(base="ion"):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})

    property_models.build_prop(m, base=base)
    build_ZONF(m, base=base)
    property_models.specify_feed(m.fs.NF.feed_side.properties_in[0], base="ion")

    check_dof(m)
    calculate_scaling_factors(m)
    solve_block(m)

    m.fs.NF.inlet.display()
    m.fs.NF.permeate.display()
    m.fs.NF.retentate.display()

    return m
Beispiel #10
0
def solve_desalination(**kwargs):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    property_models.build_prop(m, base="TDS")
    build_desalination(m, **kwargs)
    TransformationFactory("network.expand_arcs").apply_to(m)

    scale_desalination(m, **kwargs)

    initialize_desalination(m, **kwargs)

    check_dof(m)

    solve_block(m)

    display_desalination(m, **kwargs)

    return m
Beispiel #11
0
def solve_flowsheet_mvp_NF(**kwargs):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    build_flowsheet_mvp_NF(m, **kwargs)
    TransformationFactory("network.expand_arcs").apply_to(m)

    # scale
    pretreatment_NF.scale_pretreatment_NF(m, **kwargs)
    calculate_scaling_factors(m.fs.tb_pretrt_to_desal)
    desalination.scale_desalination(m, **kwargs)
    calculate_scaling_factors(m)

    # initialize
    optarg = {"nlp_scaling_method": "user-scaling"}
    pretreatment_NF.initialize_pretreatment_NF(m, **kwargs)
    m.fs.pretrt_saturation.properties.initialize(optarg=optarg)
    propagate_state(m.fs.s_pretrt_tb)
    m.fs.tb_pretrt_to_desal.initialize(optarg=optarg)
    propagate_state(m.fs.s_tb_desal)
    desalination.initialize_desalination(m, **kwargs)
    m.fs.desal_saturation.properties.initialize()

    m.fs.costing.initialize()

    # check_build(m)
    # check_scaling(m)

    check_dof(m)
    solve_block(m, tee=False, fail_flag=True)

    pretreatment_NF.display_pretreatment_NF(m, **kwargs)
    m.fs.tb_pretrt_to_desal.report()
    desalination.display_desalination(m, **kwargs)
    print(
        "desalination solubility index:", value(m.fs.desal_saturation.saturation_index)
    )
    print(
        "pretreatment solubility index:", value(m.fs.pretrt_saturation.saturation_index)
    )
    print("water recovery:", value(m.fs.system_recovery))
    print("LCOW:", value(m.fs.costing.LCOW))
    print("CP modulus:", value(m.fs.desal_saturation.cp_modulus))

    return m
Beispiel #12
0
def solve():
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    build(m)
    TransformationFactory("network.expand_arcs").apply_to(m)

    scale(m)

    initialize(m)

    check_dof(m)

    # solve
    solve_block(m)

    # display
    display(m)

    return m
Beispiel #13
0
def solve_flowsheet(has_bypass=True):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    build(m, has_bypass=has_bypass)
    TransformationFactory("network.expand_arcs").apply_to(m)

    # scale
    scale(m, has_bypass=has_bypass)
    calculate_scaling_factors(m)

    # initialize
    initialize(m, has_bypass=has_bypass)

    check_dof(m)
    solve_block(m, tee=True, fail_flag=True)

    # report
    report(m, has_bypass=has_bypass)

    return m
Beispiel #14
0
def solve_flowsheet(**desal_kwargs):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    build(m, **desal_kwargs)
    TransformationFactory("network.expand_arcs").apply_to(m)

    # scale
    scale(m, **desal_kwargs)
    calculate_scaling_factors(m)

    # initialize
    m.fs.feed.initialize()
    propagate_state(m.fs.s_pretrt_tb)
    initialize(m, **desal_kwargs)

    check_dof(m)
    solve_block(m, tee=False, fail_flag=True)

    # report
    print('==================================='
          '\n          Simulation          ')
    report(m, **desal_kwargs)

    return m
Beispiel #15
0
def solve_RO(base='TDS', level='simple'):
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    property_models.build_prop(m, base='TDS')

    build_RO(m, base=base, level=level)

    # specify feed
    property_models.specify_feed(m.fs.RO.feed_side.properties_in[0],
                                 base='TDS')
    m.fs.RO.feed_side.properties_in[0].pressure.fix(50e5)

    # scaling
    calculate_scaling_factors(m)

    # initialize
    m.fs.RO.initialize(optarg={'nlp_scaling_method': 'user-scaling'})

    check_dof(m)
    solve_block(m)

    m.fs.RO.report()

    return m
Beispiel #16
0
def solve_specify_feed(base):
    # build state block
    m = ConcreteModel()
    m.fs = FlowsheetBlock(default={"dynamic": False})
    build_prop(m, base=base)
    if base == "TDS":
        m.fs.stream = m.fs.prop_TDS.build_state_block([0], default={})
    elif base == "ion":
        m.fs.stream = m.fs.prop_ion.build_state_block([0], default={})
    elif base == "salt":
        m.fs.stream = m.fs.prop_salt.build_state_block([0], default={})
    specify_feed(m.fs.stream[0], base=base)

    m.fs.stream[
        0].mass_frac_phase_comp  # touch a variable to have a model with at least one constraint

    # scale
    calculate_scaling_factors(m.fs)
    # solve
    solve_block(m)
    # display
    m.fs.stream.display()

    return m
Beispiel #17
0
def test_property_seawater_ions():
    m = ConcreteModel()

    m.fs = FlowsheetBlock(default={"dynamic": False})
    m.fs.properties = property_seawater_ions.PropParameterBlock()
    m.fs.stream = m.fs.properties.build_state_block([0], default={})

    # specify
    feed_flow_mass = 1
    feed_mass_frac = {
        "Na": 11122e-6,
        "Ca": 382e-6,
        "Mg": 1394e-6,
        "SO4": 2136e-6,
        "Cl": 20300e-6,
    }
    m.fs.stream[0].flow_mass_phase_comp["Liq", "H2O"].fix(
        feed_flow_mass * (1 - sum(x for x in feed_mass_frac.values())))
    for s in feed_mass_frac:
        m.fs.stream[0].flow_mass_phase_comp["Liq", s].fix(feed_flow_mass *
                                                          feed_mass_frac[s])
    m.fs.stream[0].temperature.fix(273.15 + 25)
    m.fs.stream[0].pressure.fix(101325)

    m.fs.stream[0].mass_frac_phase_comp
    m.fs.stream[0].flow_mol_phase_comp

    # scaling
    m.fs.properties.set_default_scaling("flow_mass_phase_comp",
                                        1,
                                        index=("Liq", "H2O"))
    m.fs.properties.set_default_scaling("flow_mass_phase_comp",
                                        1e2,
                                        index=("Liq", "Na"))
    m.fs.properties.set_default_scaling("flow_mass_phase_comp",
                                        1e4,
                                        index=("Liq", "Ca"))
    m.fs.properties.set_default_scaling("flow_mass_phase_comp",
                                        1e3,
                                        index=("Liq", "Mg"))
    m.fs.properties.set_default_scaling("flow_mass_phase_comp",
                                        1e3,
                                        index=("Liq", "SO4"))
    m.fs.properties.set_default_scaling("flow_mass_phase_comp",
                                        1e2,
                                        index=("Liq", "Cl"))
    iscale.calculate_scaling_factors(m.fs)

    # checking state block
    assert_units_consistent(m)
    check_dof(m)

    # initialize
    m.fs.stream.initialize(optarg={"nlp_scaling_method": "user-scaling"})

    # solve
    solve_block(m)

    # check values
    assert value(m.fs.stream[0].mass_frac_phase_comp["Liq",
                                                     "H2O"]) == pytest.approx(
                                                         0.9647, rel=1e-3)
    assert value(m.fs.stream[0].flow_mol_phase_comp["Liq",
                                                    "Na"]) == pytest.approx(
                                                        0.4838, rel=1e-3)
    assert value(m.fs.stream[0].flow_mol_phase_comp["Liq",
                                                    "Ca"]) == pytest.approx(
                                                        9.531e-3, rel=1e-3)
def optimize(m, check_termination=True):
    return solve_block(m, tee=False, fail_flag=check_termination)
Beispiel #19
0
def optimize(m):
    solve_block(m, tee=False, fail_flag=True)
Beispiel #20
0
def simulate(m, check_termination=True):
    return solve_block(m, tee=False, fail_flag=check_termination)