Ejemplo n.º 1
0
def calculate(eD, F):
    fanning = Preferences.getboolean("Moody", "fanning")
    method = Preferences.getint("Moody", "method")

    dat = {}
    dat["fanning"] = fanning
    dat["method"] = method
    # laminar
    if fanning:
        dat["laminar"] = [16.0 / R for R in Re_laminar]
        x = 4
    else:
        dat["laminar"] = [64.0 / R for R in Re_laminar]
        x = 1

    # turbulent
    turb = {}
    for e in eD:
        turb[e] = [F(Rei, e) / x for Rei in Re_turbulent]
        dat["turbulent"] = turb

    # Line to define the fully desarrolled turbulent flux
    # dat["fully"] = [(1/(1.14-2*log10(3500/R)))**2 for R in Re_fully]

    # Save to file
    with open(conf_dir + "moody.dat", "w") as file:
        json.dump(dat, file, indent=4)
Ejemplo n.º 2
0
    def __plot(self):
        """Plot the Moody chart using the indicate method """
        fanning = Preferences.getboolean("Moody", "fanning")
        method = Preferences.getint("Moody", "method")

        if fanning:
            x = 4
        else:
            x = 1

        self.diagrama.ax.clear()
        self.diagrama.ax.set_autoscale_on(False)
        xlabel = QtWidgets.QApplication.translate("pychemqt", "Reynolds number") + ", " + r"$Re=\frac{V\rho D}{\mu}$"
        self.diagrama.ax.set_xlabel(xlabel, ha="center", size="10")
        if fanning:
            ylabel = QtWidgets.QApplication.translate("pychemqt", "Fanning Friction factor")
            formula = r"$f_f=\frac{2hDg}{LV^2}$"
        else:
            ylabel = QtWidgets.QApplication.translate("pychemqt", "Darcy Friction factor")
            formula = r"$f_d=\frac{2hDg}{LV^2}$"
        self.diagrama.ax.set_ylabel(ylabel + ",  " + formula, size="10")
        txt = QtWidgets.QApplication.translate("pychemqt", "Relative roughness") + ", " + r"$r=\frac{\epsilon}{D}$"
        self.diagrama.fig.text(0.97, 0.5, txt, rotation=90, size="10", va="center", ha="center")
        self.diagrama.ax.grid(True)
        self.diagrama.ax.set_xlim(600, 1e8)
        self.diagrama.ax.set_ylim(0.008 / x, 0.11 / x)
        self.diagrama.ax.set_xscale("log")
        self.diagrama.ax.set_yscale("log")
        xticks = [
            7e2,
            8e2,
            9e2,
            1e3,
            2e3,
            3e3,
            4e3,
            5e3,
            6e3,
            7e3,
            8e3,
            9e3,
            1e4,
            2e4,
            3e4,
            4e4,
            5e4,
            6e4,
            7e4,
            8e4,
            9e4,
            1e5,
            2e5,
            3e5,
            4e5,
            5e5,
            6e5,
            7e5,
            8e5,
            9e5,
            1e6,
            2e6,
            3e6,
            4e6,
            5e6,
            6e6,
            7e6,
            8e6,
            9e6,
            1e7,
            2e7,
            3e7,
            4e7,
            5e7,
            6e7,
            7e7,
            8e7,
            9e7,
        ]
        self.diagrama.ax.set_xticks(xticks, minor=False)
        self.diagrama.ax.set_yticks([], minor=True)
        if fanning:
            yticks = [
                2e-3,
                2.5e-3,
                3e-3,
                3.5e-3,
                4e-3,
                5e-3,
                6e-3,
                7e-3,
                8e-3,
                9e-3,
                1e-2,
                1.1e-2,
                1.2e-2,
                1.3e-2,
                1.4e-2,
                1.5e-2,
                1.6e-2,
                1.7e-2,
                1.8e-2,
                1.9e-2,
                2e-2,
                2.1e-2,
                2.2e-2,
                2.3e-2,
                2.4e-2,
                2.5e-2,
            ]
            ytickslabel = [
                2,
                2.5,
                3,
                3.5,
                4,
                5,
                6,
                7,
                8,
                9,
                r"$10^{-2}$",
                "",
                1.2,
                "",
                1.4,
                "",
                1.6,
                "",
                1.8,
                "",
                2,
                "",
                "",
                "",
                "",
                2.5,
            ]
        else:
            yticks = [
                9e-3,
                1e-2,
                1.1e-2,
                1.2e-2,
                1.3e-2,
                1.4e-2,
                1.5e-2,
                1.6e-2,
                1.7e-2,
                1.8e-2,
                1.9e-2,
                2e-2,
                2.1e-2,
                2.2e-2,
                2.3e-2,
                2.4e-2,
                2.5e-2,
                2.6e-2,
                2.7e-2,
                2.8e-2,
                2.9e-2,
                3e-2,
                3.2e-2,
                3.4e-2,
                3.6e-2,
                3.8e-2,
                4e-2,
                4.2e-2,
                4.4e-2,
                4.6e-2,
                4.8e-2,
                5e-2,
                5.2e-2,
                5.4e-2,
                5.6e-2,
                5.8e-2,
                6e-2,
                6.2e-2,
                6.4e-2,
                6.6e-2,
                6.8e-2,
                7e-2,
                7.5e-2,
                8e-2,
                8.5e-2,
                9e-2,
                9.5e-2,
                1e-1,
            ]
            ytickslabel = [
                9,
                r"$10^{-2}$",
                "",
                1.2,
                "",
                1.4,
                "",
                1.6,
                "",
                1.8,
                "",
                2,
                "",
                "",
                "",
                "",
                2.5,
                "",
                "",
                "",
                "",
                3,
                "",
                "",
                "",
                "",
                4,
                "",
                "",
                "",
                "",
                5,
                "",
                "",
                "",
                "",
                6,
                "",
                "",
                "",
                "",
                7,
                "",
                8,
                "",
                9,
                "",
                r"$10^{-1}$",
            ]
        self.diagrama.ax.set_yticks(yticks)
        self.diagrama.ax.set_yticklabels(ytickslabel)

        eD = [
            0,
            1e-6,
            5e-6,
            1e-5,
            2e-5,
            5e-5,
            1e-4,
            2e-4,
            4e-4,
            6e-4,
            8e-4,
            0.001,
            0.0015,
            0.002,
            0.003,
            0.004,
            0.006,
            0.008,
            0.01,
            0.0125,
            0.015,
            0.0175,
            0.02,
            0.025,
            0.03,
            0.035,
            0.04,
            0.045,
            0.05,
            0.06,
            0.07,
        ]
        F = f_list[method]

        if not os.path.isfile(conf_dir + "moody.dat"):
            calculate(eD, F)

        load = False
        with open(conf_dir + "moody.dat", "r") as file:
            try:
                dat = json.load(file)
            except ValueError:
                calculate(eD, F)
                load = True

            if dat["fanning"] != fanning or dat["method"] != method:
                calculate(eD, F)
                load = True

        # Reload file if is create in las with statement
        if load:
            with open(conf_dir + "moody.dat", "r") as file:
                dat = json.load(file)

        # Plot data
        self.diagrama.ax.plot(Re_laminar, dat["laminar"], "k")
        for eD, f in dat["turbulent"].items():
            self.diagrama.ax.plot(Re_turbulent, f, "k")
            title = " " + representacion(eD, tol=4.5)
            if f[-1] > 0.008 / x:
                self.diagrama.ax.text(1e8, f[-1], title, size="x-small", ha="left", va="center")
        # self.diagrama.ax.plot(Re_fully, dat["fully"], "k", lw=0.5, ls=":")

        # Add explicative legend
        # Laminar zone
        self.diagrama.ax.add_artist(
            ConnectionPatch(
                (600, 0.009 / x), (2400, 0.009 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w"
            )
        )
        txt = QtWidgets.QApplication.translate("pychemqt", "Laminar flux")
        self.diagrama.ax.text(1200, 0.0091 / x, txt, size="small", va="bottom", ha="center")

        # Critic zone
        self.diagrama.ax.add_artist(
            ConnectionPatch(
                (2400, 0.009 / x), (4000, 0.009 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w"
            )
        )
        txt = QtWidgets.QApplication.translate("pychemqt", "Critic\nzone")
        self.diagrama.ax.text(3200, 0.0091 / x, txt, size="small", va="bottom", ha="center")

        # Transition zone
        self.diagrama.ax.add_artist(
            ConnectionPatch(
                (4000, 0.095 / x), (10000, 0.095 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w"
            )
        )
        txt = QtWidgets.QApplication.translate("pychemqt", "Transition Zone")
        self.diagrama.ax.text(7000, 0.104 / x, txt, size="small", va="top", ha="center")

        # Turbulent zone
        self.diagrama.ax.add_artist(
            ConnectionPatch(
                (10000, 0.095 / x), (9.9e7, 0.095 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w"
            )
        )
        txt = QtWidgets.QApplication.translate("pychemqt", "Turbulent flux fully developed")
        self.diagrama.ax.text(1e6, 0.104 / x, txt, size="small", va="top", ha="center")

        # Smooth tubes
        self.diagrama.ax.add_artist(
            ConnectionPatch(
                (1e6, 0.009 / x), (1.5e6, 0.011 / x), "data", "data", arrowstyle="<|-|>", mutation_scale=20, fc="w"
            )
        )
        txt = QtWidgets.QApplication.translate("pychemqt", "Smooth tubes")
        self.diagrama.ax.text(1e6, 0.009 / x, txt, size="small", va="top", ha="right")

        # Laminar equation
        if fanning:
            txt = r"$f=\frac{16}{Re}$"
        else:
            txt = r"$f=\frac{64}{Re}$"
        self.diagrama.ax.text(1.4e3, 0.042 / x, txt, size="12", va="top", ha="center", rotation=-66)