Ejemplo n.º 1
0
    def calculate_matrix_data(self, list_name, reset=False):
        """
        Calculates binary coefficients for all composition lists and stores them
        :param list_name: str, Name of component list
        :param reset: bool, If True, existing matrix data will be overloaded by thermopack's default values
        """
        init_thermopack(self.thermopack, self.component_lists[list_name], list_name, self.settings)

        coeff_matrices = self.settings["Parameters"][list_name]["Coefficient matrices"]
        if "PC-SAFT K" in coeff_matrices.keys() and not reset:
            # Loaded data should not be replaced
            return

        # Creating 2D array to be stored in self.data
        component_list = self.component_lists[list_name]["Names"]
        size = len(component_list)
        matrix_data = np.zeros(shape=(size, size))

        for row in range(size):
            for col in range(size):
                identity1 = self.component_lists[list_name]["Identities"][row]
                identity2 = self.component_lists[list_name]["Identities"][col]
                index1 = self.thermopack.getcompindex(identity1)
                index2 = self.thermopack.getcompindex(identity2)
                coeff = self.thermopack.get_kij(index1, index2)
                matrix_data[row][col] = coeff

        for row in range(size):
            matrix_data[row][row] = 0.0

        matrix_data = matrix_data.tolist()
        coeff_matrices["PC-SAFT K"] = matrix_data
Ejemplo n.º 2
0
    def calculate_matrix_data(self, list_name):
        """
        Calculates binary coefficients for all composition lists and stores them in the session data.
        :param list_name: str, Name of component list
        """
        # Creating 2D arrays to be stored in self.data
        component_list = self.component_lists[list_name]["Names"]
        size = len(component_list)
        alpha_matrix_data = np.zeros(shape=(size, size))
        a_matrix_data = np.zeros(shape=(size, size))
        b_matrix_data = np.zeros(shape=(size, size))
        c_matrix_data = np.zeros(shape=(size, size))

        init_thermopack(self.thermopack, self.component_lists[list_name], list_name, self.settings)

        for row in range(size - 1):
            for col in range(row + 1, size):
                identity1 = self.component_lists[list_name]["Identities"][row]
                identity2 = self.component_lists[list_name]["Identities"][col]
                index1 = self.thermopack.getcompindex(identity1)
                index2 = self.thermopack.getcompindex(identity2)

                hv_param = self.thermopack.get_hv_param(index1, index2)
                alpha_ij, alpha_ji, a_ij, a_ji, b_ij, b_ji, c_ij, c_ji = hv_param

                alpha_matrix_data[row][col] = alpha_ij
                alpha_matrix_data[col][row] = alpha_ji
                a_matrix_data[row][col] = a_ij
                a_matrix_data[col][row] = a_ji
                b_matrix_data[row][col] = b_ij
                b_matrix_data[col][row] = b_ji
                c_matrix_data[row][col] = c_ij
                c_matrix_data[col][row] = c_ji

        for row in range(size):
            alpha_matrix_data[row][row] = 0.0
            a_matrix_data[row][row] = 0.0
            b_matrix_data[row][row] = 0.0
            c_matrix_data[row][row] = 0.0

        alpha_matrix_data = alpha_matrix_data.tolist()
        a_matrix_data = a_matrix_data.tolist()
        b_matrix_data = b_matrix_data.tolist()
        c_matrix_data = c_matrix_data.tolist()

        coeff_matrices = self.settings["Parameters"][list_name]["Coefficient matrices"]

        coeff_matrices["HV1 Alpha"] = alpha_matrix_data
        coeff_matrices["HV1 A"] = a_matrix_data
        coeff_matrices["HV1 B"] = b_matrix_data
        coeff_matrices["HV1 C"] = c_matrix_data
Ejemplo n.º 3
0
    def calculate_matrix_data(self, list_name):
        """
        Calculates binary coefficients for all composition lists and stores them in the session data.
        :param list_name: str, Name of component list
        """
        component_list = self.component_lists[list_name]["Names"]
        size = len(component_list)
        epsilon_matrix_data = np.zeros(shape=(size, size))
        sigma_matrix_data = np.zeros(shape=(size, size))
        gamma_matrix_data = np.zeros(shape=(size, size))

        init_thermopack(self.thermopack, self.component_lists[list_name], list_name, self.settings)

        for row in range(size - 1):
            for col in range(row + 1, size):
                identity1 = self.component_lists[list_name]["Identities"][row]
                identity2 = self.component_lists[list_name]["Identities"][col]
                index1 = self.thermopack.getcompindex(identity1)
                index2 = self.thermopack.getcompindex(identity2)

                epsilon_kij = self.thermopack.get_eps_kij(index1, index2)
                sigma_lij = self.thermopack.get_sigma_lij(index1, index2)
                lr_gammaij = self.thermopack.get_lr_gammaij(index1, index2)

                # Symmetric matrices
                epsilon_matrix_data[row][col] = epsilon_kij
                epsilon_matrix_data[col][row] = epsilon_kij
                sigma_matrix_data[row][col] = sigma_lij
                sigma_matrix_data[col][row] = sigma_lij
                gamma_matrix_data[row][col] = lr_gammaij
                gamma_matrix_data[col][row] = lr_gammaij

        for row in range(size):
            epsilon_matrix_data[row][row] = 0.0
            sigma_matrix_data[row][row] = 0.0
            gamma_matrix_data[row][row] = 0.0

        epsilon_matrix_data = epsilon_matrix_data.tolist()
        sigma_matrix_data = sigma_matrix_data.tolist()
        gamma_matrix_data = gamma_matrix_data.tolist()

        coeff_matrices = self.settings["Parameters"][list_name]["Coefficient matrices"]

        coeff_matrices["SAFT-VR Mie Epsilon"] = epsilon_matrix_data
        coeff_matrices["SAFT-VR Mie Sigma"] = sigma_matrix_data
        coeff_matrices["SAFT-VR Mie Gamma"] = gamma_matrix_data
Ejemplo n.º 4
0
    def show_component_pure_params(self, button):
        """
        When a component is chosen, the corresponding pure fluid parameters are displayed
        :param button: Clicked radio button giving the chosen component
        """
        comp_name = button.text()
        list_name = self.composition_list.currentItem().text()

        self.pure_params_frame.show()

        init_thermopack(self.thermopack, self.component_lists[list_name], list_name, self.settings)

        self.component_id = get_comp_id(self.component_lists[list_name], comp_name)
        comp_index = self.thermopack.getcompindex(self.component_id)

        m, sigma, eps_div_k, lambda_a, lambda_r = self.thermopack.get_pure_fluid_param(comp_index)

        self.pure_param_m_edit.setText(str(m))
        self.pure_param_sigma_edit.setText(str(sigma))
        self.pure_param_epsilon_edit.setText(str(eps_div_k))
        self.pure_param_lambda_a_edit.setText(str(lambda_a))
        self.pure_param_lambda_r_edit.setText(str(lambda_r))
Ejemplo n.º 5
0
    def calculate_matrix_data(self, list_name):
        """
        Calculates binary coefficients for all composition lists and stores them
        :param list_name: str, Name of component list
        """
        component_list = self.component_lists[list_name]["Names"]
        size = len(component_list)
        k_matrix_data = np.zeros(shape=(size, size))
        eps_matrix_data = np.zeros(shape=(size, size))

        init_thermopack(self.thermopack, self.component_lists[list_name], list_name, self.settings)

        for row in range(size - 1):
            for col in range(row + 1, size):
                id1 = self.component_lists[list_name]["Identities"][row]
                id2 = self.component_lists[list_name]["Identities"][col]
                index1 = self.thermopack.getcompindex(id1)
                index2 = self.thermopack.getcompindex(id2)

                vals = self.thermopack.get_kij(index1, index2)
                k_ij, eps_kij = vals

                # Symmetric matrices
                k_matrix_data[row][col] = k_ij
                k_matrix_data[col][row] = k_ij
                eps_matrix_data[row][col] = eps_kij
                eps_matrix_data[col][row] = eps_kij

        for row in range(size):
            k_matrix_data[row][row] = 0.0
            eps_matrix_data[row][row] = 0.0

        k_matrix_data = k_matrix_data.tolist()
        eps_matrix_data = eps_matrix_data.tolist()

        coeff_matrices = self.settings["Parameters"][list_name]["Coefficient matrices"]
        coeff_matrices["CPA K"] = k_matrix_data
        coeff_matrices["CPA Epsilon"] = eps_matrix_data
Ejemplo n.º 6
0
    def calculate(self):
        """
        Calls thermopack's flash functions, and populates the table with the results
        """
        fractions = np.array(self.component_data["Fractions"])
        mole_fraction_sum = np.sum(fractions)

        if abs(mole_fraction_sum - 1.00) > 1e-8:
            msg_title = "Molar fractions error"
            msg_text = "Molar fractions have to add up to 1.00. Currently the sum is %s." % mole_fraction_sum
            msg = MessageBox(msg_title, msg_text)
            msg.exec_()
            return
        else:
            # Setting the last mol fraction to 1 - the rest of them, to ensure that the total sum is exactly 1
            fractions[-1] = 1 - np.sum(fractions[:-1])

        self.table.clearContents()
        self.set_table_units()

        init_thermopack(self.tp, self.component_data, self.comp_list_name,
                        self.settings)

        flash_mode = self.flash_mode_selection.currentText()
        self.tp.set_ph_tolerance(float(self.ph_tol.text()))

        if flash_mode == "TP":
            T = float(self.tp_t_input.text())
            P = float(self.tp_p_input.text())

            # Conversion to standard SI to be used in functions
            T = self.ureg.Quantity(
                T, self.units["Temperature"]).to("degK").magnitude
            P = self.ureg.Quantity(P,
                                   self.units["Pressure"]).to("Pa").magnitude

            # TODO: Need an exception thrown in two_phase_tpflash() to be caught in case calculation fails
            x, y, beta_vap, beta_liq, phase = self.tp.two_phase_tpflash(
                T, P, fractions)

        elif flash_mode == "PS":
            P = float(self.ps_p_input.text())
            S = float(self.ps_s_input.text())

            # Unit conversion
            P = self.ureg.Quantity(P,
                                   self.units["Pressure"]).to("Pa").magnitude
            S = self.ureg.Quantity(
                S, self.units["Entropy"]).to("J / (degK * mol)").magnitude

            if self.ps_initial_guess.isChecked():
                T = float(self.ps_t_guess.text())
                T = self.ureg.Quantity(
                    T, self.units["Temperature"]).to("degK").magnitude
            else:
                T = None

            try:
                T, x, y, beta_vap, beta_liq, phase = self.tp.two_phase_psflash(
                    press=P, z=fractions, entropy=S, temp=T)
            except Exception as error:
                msg = MessageBox("Error", str(error))
                msg.exec_()
                return

        elif flash_mode == "PH":
            P = float(self.ph_p_input.text())
            H = float(self.ph_h_input.text())

            # Convert units
            P = self.ureg.Quantity(P,
                                   self.units["Pressure"]).to("Pa").magnitude
            H = self.ureg.Quantity(
                H, self.units["Enthalpy"]).to("J / mol").magnitude

            if self.ph_initial_guess.isChecked():
                T = float(self.ph_t_guess.text())
                T = self.ureg.Quantity(
                    T, self.units["Temperature"]).to("degK").magnitude
            else:
                T = None

            try:
                T, x, y, beta_vap, beta_liq, phase = self.tp.two_phase_phflash(
                    press=P, z=fractions, enthalpy=H, temp=T)
            except Exception as error:
                msg = MessageBox("Error", str(error))
                msg.exec_()
                return

        elif flash_mode == "UV":
            U = float(self.uv_u_input.text())
            V = float(self.uv_v_input.text())

            # Unit conversion
            U = self.ureg.Quantity(
                U, self.units["Internal energy"]).to("J / mol").magnitude
            V = self.ureg.Quantity(
                V, self.units["Specific volume"]).to("m ** 3 / mol").magnitude

            if self.uv_t_initial_guess.isChecked():
                T = float(self.uv_t_guess.text())
                T = self.ureg(T,
                              self.units["Temperature"]).to("degK").magnitude
            else:
                T = None

            if self.uv_p_initial_guess.isChecked():
                P = float(self.uv_p_guess.text())
                P = self.ureg.Quantity(
                    P, self.units["Pressure"]).to("Pa").magnitude
            else:
                P = None

            # TODO: Need an exception thrown in two_phase_uvflash() to be caught in case calculation fails
            T, P, x, y, beta_vap, beta_liq, phase = self.tp.two_phase_uvflash(
                z=fractions,
                specific_energy=U,
                specific_volume=V,
                temp=T,
                press=P)

        else:
            return

        phase_type = self.tp.get_phase_type(phase)
        LIQUID, VAPOR = 1, 2

        is_liq, is_vap = True, True

        if phase_type == "TWO_PHASE":
            self.table.horizontalHeaderItem(1).setText("Vapor")
            self.table.horizontalHeaderItem(2).setText("Liquid")
            pass

        elif phase_type == "LIQUID":
            is_vap = False
            self.table.horizontalHeaderItem(1).setText("Vapor")
            self.table.horizontalHeaderItem(2).setText("Liquid")

        elif phase_type == "VAPOR":
            is_liq = False
            self.table.horizontalHeaderItem(1).setText("Vapor")
            self.table.horizontalHeaderItem(2).setText("Liquid")

        elif phase_type == "SINGLE":
            self.table.horizontalHeaderItem(1).setText("Single")
            self.table.horizontalHeaderItem(2).setText("Single")
            pass

        elif phase_type == "MINIMUM_GIBBS":
            self.table.horizontalHeaderItem(1).setText("Minimum Gibbs")
            self.table.horizontalHeaderItem(2).setText("Minimum Gibbs")
            pass

        elif phase_type == "FAKE":
            msg = MessageBox(
                "Error", "Currently no functionality for phase " + phase_type)
            msg.exec_()

        elif phase_type == "SOLID":
            msg = MessageBox(
                "Error", "Currently no functionality for phase " + phase_type)
            msg.exec_()

        else:
            return

        component_indices = [
            self.tp.getcompindex(comp)
            for comp in self.component_data["Identities"]
        ]
        molecular_weights = [
            self.tp.compmoleweight(index) for index in component_indices
        ]

        if is_liq:
            V_liq, dVdT_liq, dVdn_liq = self.tp.specific_volume(T,
                                                                P,
                                                                x,
                                                                phase=LIQUID,
                                                                dvdt=True,
                                                                dvdn=True)
            H_liq, dHdT_liq, dHdP_liq, dHdn_liq = self.tp.enthalpy(
                T, P, x, phase=LIQUID, dhdt=True, dhdp=True, dhdn=True)
            S_liq, dSdT_liq, dSdP_liq, dSdn_liq = self.tp.entropy(T,
                                                                  P,
                                                                  x,
                                                                  phase=LIQUID,
                                                                  dsdt=True,
                                                                  dsdp=True,
                                                                  dsdn=True)
            U_liq, dUdT_liq, dUdV_liq = self.tp.internal_energy_tv(T,
                                                                   V_liq,
                                                                   x,
                                                                   dedt=True,
                                                                   dedv=True)

            sos_liq = self.tp.speed_of_sound(T,
                                             P,
                                             x,
                                             y,
                                             fractions,
                                             beta_vap,
                                             beta_liq,
                                             phase=LIQUID)

            U_liq = H_liq - P * V_liq
            G_liq = H_liq - T * S_liq

            Cp_liq = dHdT_liq
            Cv_liq = dUdT_liq

            mol_weight_liq = sum([
                x[i] * molecular_weights[i]
                for i in range(len(molecular_weights))
            ])

            self.set_table_value("Temperature", "Liq", "degK",
                                 self.units["Temperature"], T)
            self.set_table_value("Pressure", "Liq", "Pa",
                                 self.units["Pressure"], P)
            self.set_table_value("Specific volume", "Liq", "m ** 3 / mol",
                                 self.units["Specific volume"], V_liq)
            self.set_table_value("Internal energy", "Liq", "J / mol",
                                 self.units["Internal energy"], U_liq)
            self.set_table_value("Enthalpy", "Liq", "J / mol",
                                 self.units["Enthalpy"], H_liq)
            self.set_table_value("Entropy", "Liq", "J / (K * mol)",
                                 self.units["Entropy"], S_liq)
            self.set_table_value("Gibbs energy", "Liq", "J / mol",
                                 self.units["Gibbs energy"], G_liq)
            self.set_table_value("Isobar heat capacity", "Liq",
                                 "J / (K * mol)",
                                 self.units["Isobar heat capacity"], Cp_liq)
            self.set_table_value("Isochor heat capacity", "Liq",
                                 "J / (K * mol)",
                                 self.units["Isochor heat capacity"], Cv_liq)
            self.set_table_value("Speed of sound", "Liq", "m / s",
                                 self.units["Speed of sound"], sos_liq)
            self.set_table_value("Phase fraction", "Liq", "mol / mol",
                                 self.units["Phase fraction"], beta_liq)
            self.set_table_value("Molecular weight", "Liq", "kg / mol",
                                 self.units["Molecular weight"],
                                 mol_weight_liq)

        if is_vap:
            V_vap, dVdT_vap, dVdP_vap, dVdn_vap = self.tp.specific_volume(
                T, P, x, phase=VAPOR, dvdt=True, dvdp=True, dvdn=True)
            H_vap, dHdT_vap, dHdP_vap, dHdn_vap = self.tp.enthalpy(T,
                                                                   P,
                                                                   x,
                                                                   phase=VAPOR,
                                                                   dhdt=True,
                                                                   dhdp=True,
                                                                   dhdn=True)
            S_vap, dSdT_vap, dSdP_vap, dSdn_vap = self.tp.entropy(T,
                                                                  P,
                                                                  x,
                                                                  phase=VAPOR,
                                                                  dsdt=True,
                                                                  dsdp=True,
                                                                  dsdn=True)
            U_vap, dUdT_vap, dUdV_vap = self.tp.internal_energy_tv(T,
                                                                   V_vap,
                                                                   x,
                                                                   dedt=True,
                                                                   dedv=True)
            sos_vap = self.tp.speed_of_sound(T,
                                             P,
                                             x,
                                             y,
                                             fractions,
                                             beta_vap,
                                             beta_liq,
                                             phase=VAPOR)

            U_vap = H_vap - P * V_vap
            G_vap = H_vap - T * S_vap

            Cp_vap = dHdT_vap
            Cv_vap = dUdT_vap

            mol_weight_vap = sum([
                y[i] * molecular_weights[i]
                for i in range(len(molecular_weights))
            ])

            self.set_table_value("Temperature", "Vap", "degK",
                                 self.units["Temperature"], T)
            self.set_table_value("Pressure", "Vap", "Pa",
                                 self.units["Pressure"], P)
            self.set_table_value("Specific volume", "Vap", "m**3 / mol",
                                 self.units["Specific volume"], V_vap)
            self.set_table_value("Internal energy", "Vap", "J / mol",
                                 self.units["Internal energy"], U_vap)
            self.set_table_value("Enthalpy", "Vap", "J / mol",
                                 self.units["Enthalpy"], H_vap)
            self.set_table_value("Entropy", "Vap", "J / (K * mol)",
                                 self.units["Entropy"], S_vap)
            self.set_table_value("Gibbs energy", "Vap", "J / mol",
                                 self.units["Gibbs energy"], G_vap)
            self.set_table_value("Isobar heat capacity", "Vap",
                                 "J / (K * mol)",
                                 self.units["Isobar heat capacity"], Cp_vap)
            self.set_table_value("Isochor heat capacity", "Vap",
                                 "J / (K * mol)",
                                 self.units["Isochor heat capacity"], Cv_vap)
            self.set_table_value("Speed of sound", "Vap", "m / s",
                                 self.units["Speed of sound"], sos_vap)
            self.set_table_value("Phase fraction", "Vap", "mol / mol",
                                 self.units["Phase fraction"], beta_vap)
            self.set_table_value("Molecular weight", "Vap", "kg / mol",
                                 self.units["Molecular weight"],
                                 mol_weight_vap)

        if is_liq and is_vap:

            if beta_vap == -1 and beta_liq == -1:
                beta_vap, beta_liq = 0.5, 0.5

            V_overall = V_vap * beta_vap + V_liq * beta_liq
            U_overall = U_vap * beta_vap + U_liq * beta_liq
            H_overall = H_vap * beta_vap + H_liq * beta_liq
            S_overall = S_vap * beta_vap + S_liq * beta_liq
            G_overall = G_vap * beta_vap + G_liq * beta_liq
            Cp_overall = Cp_vap * beta_vap + Cp_liq * beta_liq
            Cv_overall = Cv_vap * beta_vap + Cv_liq * beta_liq
            sos_overall = sos_vap * beta_vap + sos_liq * beta_liq
            frac_overall = beta_vap + beta_liq

            if mol_weight_liq == 0:
                mol_weight_overall = mol_weight_vap
            elif mol_weight_vap == 0:
                mol_weight_overall = mol_weight_liq
            else:
                mol_weight_overall = mol_weight_vap * beta_vap + mol_weight_liq * beta_liq

        elif is_liq:
            V_overall = V_liq
            U_overall = U_liq
            H_overall = H_liq
            S_overall = S_liq
            G_overall = G_liq
            Cp_overall = Cp_liq
            Cv_overall = Cv_liq
            sos_overall = sos_liq
            frac_overall = beta_liq
            mol_weight_overall = mol_weight_liq

        elif is_vap:
            V_overall = V_vap
            U_overall = U_vap
            H_overall = H_vap
            S_overall = S_vap
            G_overall = G_vap
            Cp_overall = Cp_vap
            Cv_overall = Cv_vap
            sos_overall = sos_vap
            frac_overall = beta_vap
            mol_weight_overall = mol_weight_vap

        if is_liq or is_vap:
            self.set_table_value("Temperature", "Overall", "degK",
                                 self.units["Temperature"], T)
            self.set_table_value("Pressure", "Overall", "Pa",
                                 self.units["Pressure"], P)
            self.set_table_value("Specific volume", "Overall", "m**3 / mol",
                                 self.units["Specific volume"], V_overall)
            self.set_table_value("Internal energy", "Overall", "J / mol",
                                 self.units["Internal energy"], U_overall)
            self.set_table_value("Enthalpy", "Overall", "J / mol",
                                 self.units["Enthalpy"], H_overall)
            self.set_table_value("Entropy", "Overall", "J / (K * mol)",
                                 self.units["Entropy"], S_overall)
            self.set_table_value("Gibbs energy", "Overall", "J / mol",
                                 self.units["Gibbs energy"], G_overall)
            self.set_table_value("Isobar heat capacity", "Overall",
                                 "J / (K * mol)",
                                 self.units["Isobar heat capacity"],
                                 Cp_overall)
            self.set_table_value("Isochor heat capacity", "Overall",
                                 "J / (K * mol)",
                                 self.units["Isochor heat capacity"],
                                 Cv_overall)
            self.set_table_value("Speed of sound", "Overall", "m / s",
                                 self.units["Speed of sound"], sos_overall)
            self.set_table_value("Phase fraction", "Overall", "mol / mol",
                                 self.units["Phase fraction"], frac_overall)
            self.set_table_value("Molecular weight", "Overall", "kg / mol",
                                 self.units["Molecular weight"],
                                 mol_weight_overall)

        self.table.resizeColumnsToContents()
        self.table.resizeRowsToContents()

        self.download_csv_btn.setEnabled(True)
Ejemplo n.º 7
0
    def plot(self):
        """
        Checks type of plot selected, gets the correct parameters, inits thermopack,
        and calls the correct plot function in MplCanvas
        """
        category = self.settings["Model category"]
        plot_type = self.plot_type_btn_group.checkedButton().text()
        prim_vars = self.prim_vars_dropdown.currentText()

        if category in ["Cubic", "CPA"]:
            eos = self.model_btn_group.checkedButton().text()
            if self.settings["EOS"] != eos:
                self.settings["EOS"] = eos

        elif category == "SAFT-VR Mie":
            self.settings["Model options"]["A1"] = self.a1_checkbox.isChecked()
            self.settings["Model options"]["A2"] = self.a2_checkbox.isChecked()
            self.settings["Model options"]["A3"] = self.a3_checkbox.isChecked()
            self.settings["Model options"][
                "Hard sphere"] = self.hard_sphere_checkbox.isChecked()
            self.settings["Model options"][
                "Chain"] = self.chain_checkbox.isChecked()

        init_thermopack(self.tp, self.component_data, self.comp_list_name,
                        self.settings)

        fractions = np.array(self.component_data["Fractions"])

        if self.canvas.empty:
            self.canvas.axes = self.canvas.fig.add_subplot(111)
            self.canvas.empty = False

        if self.redraw:
            self.canvas.axes.cla()

        self.isopleth_btn_stack.hide()
        self.download_csv_btn.setEnabled(True)

        if plot_type in ["Phase envelope", "Pressure density"]:
            mole_fraction_sum = np.sum(fractions)

            if abs(mole_fraction_sum - 1.00) > 1e-8:
                msg_title = "Molar fractions error"
                msg_text = "Molar fractions have to add up to 1.00. Currently the sum is %s." % mole_fraction_sum
                msg = MessageBox(msg_title, msg_text)
                msg.exec_()
                return
            else:
                # Setting the last mol fraction to 1 - the rest of them, to ensure that the total sum is exactly 1
                fractions[-1] = 1 - np.sum(fractions[:-1])

        if plot_type == "Phase envelope":
            self.canvas.plot_envelope(self.tp, prim_vars, fractions)
            self.canvas.show()
            self.mpl_toolbar.show()
            if self.plotting_preferences["Phase envelope"]["Isopleths"][
                    "Number of isopleths"] > 0:
                self.isopleth_btn_stack.show()

        elif plot_type == "Binary pxy":
            self.canvas.plot_binary_pxy(self.tp)
            self.canvas.show()
            self.mpl_toolbar.show()

        elif plot_type == "Pressure density":
            self.canvas.plot_pressure_density(self.tp, fractions)
            self.canvas.show()
            self.mpl_toolbar.show()

        elif plot_type == "Global binary":
            self.canvas.plot_global_binary(self.tp)
            self.canvas.show()
            self.mpl_toolbar.show()

        else:
            pass
Ejemplo n.º 8
0
    def __init__(self,
                 data,
                 json_file,
                 component_list_name,
                 model_settings_name,
                 parent=None):
        super().__init__(parent=parent)

        loadUi("gui/layouts/plot_mode.ui", self)
        self.setWindowTitle("Thermopack - Plot Mode")
        self.showMaximized()

        self.data = data
        self.json_file = json_file

        self.component_data = self.data["Component lists"][component_list_name]
        self.comp_list_name = component_list_name
        self.settings = self.data["Model setups"][model_settings_name]
        self.units = self.data["Units"]

        self.set_toolbar()

        if self.data["Plotting preferences"]:
            self.plotting_preferences = self.data["Plotting preferences"]
        else:
            self.plotting_preferences = self.init_plotting_preferences()
            self.data["Plotting preferences"] = self.plotting_preferences

        # In case the user wants to reset settings
        self.default_plotting_preferences = self.init_plotting_preferences()

        self.redraw = True
        self.redraw_checkbox.setChecked(self.redraw)

        self.init_plot_modes()

        self.model_btn_group = QButtonGroup(parent=self.model_box)
        self.init_model_options()

        self.init_fractions()

        # Initiating thermopack
        self.tp = get_thermopack(category=self.settings["Model category"])

        # Init function depends on settings
        init_thermopack(self.tp, self.component_data, self.comp_list_name,
                        self.settings)

        self.ph_env_toolbtn.clicked.connect(self.show_ph_env_options)
        self.bin_pxy_toolbtn.clicked.connect(self.show_bin_pxy_options)
        self.p_rho_toolbtn.clicked.connect(self.show_p_rho_options)
        self.global_binary_toolbtn.clicked.connect(
            self.show_global_binary_options)

        self.plot_type_btn_group.buttonClicked.connect(self.change_plot_type)

        # Setup for plot window
        self.canvas = MplCanvas(self.component_data["Names"],
                                self.plotting_preferences)
        self.mpl_toolbar = NavigationToolbar2QT(self.canvas, self)
        self.mpl_toolbar.hide()
        self.canvas.hide()
        self.plot_layout.addWidget(self.mpl_toolbar)
        self.plot_layout.addWidget(self.canvas)

        self.init_isopleth_btns()
        self.redraw_checkbox.clicked.connect(self.toggle_redraw)
        self.plot_button.clicked.connect(self.plot)
        self.download_csv_btn.clicked.connect(self.export_csv)