Example #1
0
    def test_equilibrium_partial_pressure(self, frame):
        frame.params.config.equilibrium_reactions["e1"] = rxn_config
        frame.params.config.equilibrium_reactions["e1"].concentration_form = \
            ConcentrationForm.partialPressure

        assert get_concentration_term(frame, "e1") is frame.pressure_phase_comp
        assert get_concentration_term(frame, "e1", log=True) is \
            frame.log_pressure_phase_comp
Example #2
0
    def test_inherent_activity(self, frame2):
        frame2.params.config.inherent_reactions["i1"] = rxn_config
        frame2.params.config.inherent_reactions["i1"].concentration_form = \
            ConcentrationForm.activity

        assert get_concentration_term(frame2, "i1") is frame2.act_phase_comp
        assert get_concentration_term(frame2, "i1", log=True) is \
            frame2.log_act_phase_comp
Example #3
0
    def test_equilibrium_molality(self, frame):
        frame.params.config.equilibrium_reactions["e1"] = rxn_config
        frame.params.config.equilibrium_reactions["e1"].concentration_form = \
            ConcentrationForm.molality

        assert get_concentration_term(frame, "e1") is frame.molality_phase_comp
        assert get_concentration_term(frame, "e1", log=True) is \
            frame.log_molality_phase_comp
Example #4
0
    def test_rate_activity(self, frame):
        frame.params.config.rate_reactions["r1"] = rxn_config
        frame.params.config.rate_reactions["r1"].concentration_form = \
            ConcentrationForm.activity

        assert get_concentration_term(frame, "r1") is frame.act_phase_comp
        assert get_concentration_term(frame, "r1", log=True) is \
            frame.log_act_phase_comp
Example #5
0
    def test_inherent_partial_pressure(self, frame2):
        frame2.params.config.inherent_reactions["i1"] = rxn_config
        frame2.params.config.inherent_reactions["i1"].concentration_form = \
            ConcentrationForm.partialPressure

        assert get_concentration_term(frame2, "i1") is \
            frame2.pressure_phase_comp
        assert get_concentration_term(frame2, "i1", log=True) is \
            frame2.log_pressure_phase_comp
Example #6
0
    def test_inherent_mass_frac(self, frame2):
        frame2.params.config.inherent_reactions["i1"] = rxn_config
        frame2.params.config.inherent_reactions["i1"].concentration_form = \
            ConcentrationForm.massFraction

        assert get_concentration_term(frame2, "i1") is \
            frame2.mass_frac_phase_comp
        assert get_concentration_term(frame2, "i1", log=True) is \
            frame2.log_mass_frac_phase_comp
Example #7
0
    def test_rate_mass_frac(self, frame):
        frame.params.config.rate_reactions["r1"] = rxn_config
        frame.params.config.rate_reactions["r1"].concentration_form = \
            ConcentrationForm.massFraction

        assert get_concentration_term(frame, "r1") is \
            frame.mass_frac_phase_comp
        assert get_concentration_term(frame, "r1", log=True) is \
            frame.log_mass_frac_phase_comp
Example #8
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))
        else:
            # Need to remove units as complementarity is not consistent
            sunits = pyunits.get_units(s)

            if sunits is not None:
                s = s / sunits

        Q = b.k_eq[r_idx] - e

        # Need to remove units again
        Qunits = pyunits.get_units(b.k_eq[r_idx])

        if Qunits is not None:
            Q = Q / Qunits

        return s - smooth_max(0, s - Q, rblock.eps) == 0
Example #9
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 #10
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.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_eq[r_idx] == e