Example #1
0
    def return_expression(b, rblock, r_idx, T):
        e = None
        # Get reaction orders and construct power law expression
        for p, j in b.state_ref.params._phase_component_set:
            o = rblock.reaction_order[p, j]

            if e is None and o != 0:
                e = get_concentration_term(b, r_idx)[p, j]**o
            elif e is not None and o != 0:
                e = e * get_concentration_term(b, r_idx)[p, j]**o

        return b.k_eq[r_idx] == e
Example #2
0
    def return_expression(b, rblock, r_idx, T):
        e = None
        # Get reaction orders and construct power law expression
        for p, j in b.phase_component_set:
            o = rblock.reaction_order[p, j]

            if e is None and o.value != 0:
                e = get_concentration_term(b, r_idx)[p, j]**o
            elif e is not None and o.value != 0:
                e = e * get_concentration_term(b, r_idx)[p, j]**o

        return b.k_rxn[r_idx] * e
Example #3
0
    def return_expression(b, rblock, r_idx, T):
        e = None

        if hasattr(b.params, "_electrolyte") and b.params._electrolyte:
            pc_set = b.params.true_phase_component_set
        else:
            pc_set = b.phase_component_set

        # Get reaction orders and construct power law expression
        for p, j in pc_set:
            o = rblock.reaction_order[p, j]

            if e is None and o != 0:
                # Need to strip units from concentration term (if applicable)
                c = get_concentration_term(b, r_idx)[p, j]
                u = pyunits.get_units(c)
                if u is not None:
                    # Has units, so divide conc by units
                    expr = c / u
                else:
                    # Units is None, so just use conc
                    expr = c
                e = o * safe_log(expr, eps=rblock.eps)
            elif e is not None and o != 0:
                # Need to strip units from concentration term (if applicable)
                c = get_concentration_term(b, r_idx)[p, j]
                u = pyunits.get_units(c)
                if u is not None:
                    # Has units, so divide conc by units
                    expr = c / u
                else:
                    # Units is None, so just use conc
                    expr = c
                e = e + o * safe_log(expr, eps=rblock.eps)

        # Need to check units on k_eq as well
        u = pyunits.get_units(b.k_eq[r_idx])
        if u is not None:
            # Has units, so divide k_eq by units
            expr = b.k_eq[r_idx] / u
        else:
            # Units is None, so just use k_eq
            expr = b.k_eq[r_idx]

        return safe_log(expr, eps=rblock.eps) == e
Example #4
0
    def return_expression(b, rblock, r_idx, T):
        e = None

        if hasattr(b.params, "_electrolyte") and b.params._electrolyte:
            pc_set = b.params.true_phase_component_set
        else:
            pc_set = b.phase_component_set

        # Get reaction orders and construct power law expression
        for p, j in pc_set:
            o = rblock.reaction_order[p, j]

            if e is None and o != 0:
                e = get_concentration_term(b, r_idx)[p, j]**o
            elif e is not None and o != 0:
                e = e * get_concentration_term(b, r_idx)[p, j]**o

        return b.k_eq[r_idx] == e
Example #5
0
    def return_expression(b, rblock, r_idx, T):
        e = None
        s = None

        if hasattr(b.params, "_electrolyte") and b.params._electrolyte:
            pc_set = b.params.true_phase_component_set
        else:
            pc_set = b.phase_component_set

        # Get reaction orders and construct power law expression
        for p, j in pc_set:
            p_obj = b.state_ref.params.get_phase(p)

            # First, build E
            o = rblock.reaction_order[p, j]

            if e is None and o.value != 0:
                e = get_concentration_term(b, r_idx)[p, j]**o
            elif e is not None and o.value != 0:
                e = e * get_concentration_term(b, r_idx)[p, j]**o

            if p_obj.is_solid_phase():
                # If solid phase, identify S
                r_config = b.params.config.equilibrium_reactions[r_idx]

                try:
                    stoic = r_config.stoichiometry[p, j]
                    if s is None and stoic != 0:
                        s = b.state_ref.flow_mol_phase_comp[p, j]
                    elif s is not None and stoic != 0:
                        s += b.state_ref.flow_mol_phase_comp[p, j]
                except KeyError:
                    pass

        if s is None:
            # Catch for not finding a solid phase
            raise ConfigurationError(
                "{} did not find a solid phase component for precipitation "
                "reaction {}. This is likely due to the reaction "
                "configuration.".format(b.name, r_idx))

        Q = b.k_eq[r_idx] - e

        return s - smooth_max(0, s - Q, rblock.eps) == 0