Beispiel #1
0
    def post_process(self):
        try:
            import matplotlib
            matplotlib.use('Agg')
            from matplotlib import pyplot as plt
        except ImportError:
            print("Post processing requires matplotlib.")
            return
        if self.rank > 0 or len(self.output_files) == 0:
            return

        last_output = self.output_files[-1]
        from pysph.solver.utils import load
        data = load(last_output)
        pa = data['arrays']['fluid']
        gamma = self.options.gamma if self.options.gamma else 1.4
        riemann_solver.set_gamma(gamma)

        rho_e, u_e, p_e, e_e, x_e = riemann_solver.solve(x_min=self.xmin,
                                                         x_max=self.xmax,
                                                         x_0=self.x0,
                                                         t=self.tf,
                                                         p_l=self.pl,
                                                         p_r=self.pr,
                                                         rho_l=self.rhol,
                                                         rho_r=self.rhor,
                                                         u_l=self.ul,
                                                         u_r=self.ur,
                                                         N=101)
        x = pa.x
        rho = pa.rho
        e = pa.e
        cs = pa.cs
        u = pa.u
        p = pa.p
        h = pa.h

        plt.plot(x, rho, label='pysph (' + str(self.options.scheme) + ')')
        plt.plot(x_e, rho_e, label='exact')
        plt.xlabel('x')
        plt.ylabel('rho')
        plt.legend()
        fig = os.path.join(self.output_dir, "density.png")
        plt.savefig(fig, dpi=300)
        plt.clf()
        plt.plot(x, e, label='pysph (' + str(self.options.scheme) + ')')
        plt.plot(x_e, e_e, label='exact')
        plt.xlabel('x')
        plt.ylabel('e')
        plt.legend()
        fig = os.path.join(self.output_dir, "energy.png")
        plt.savefig(fig, dpi=300)
        plt.clf()

        plt.plot(x, rho * u, label='pysph (' + str(self.options.scheme) + ')')
        plt.plot(x_e, rho_e * u_e, label='exact')
        plt.xlabel('x')
        plt.ylabel('M')
        plt.legend()
        fig = os.path.join(self.output_dir, "Machno.png")
        plt.savefig(fig, dpi=300)
        plt.clf()

        plt.plot(x, p, label='pysph (' + str(self.options.scheme) + ')')
        plt.plot(x_e, p_e, label='exact')
        plt.xlabel('x')
        plt.ylabel('p')
        plt.legend()
        fig = os.path.join(self.output_dir, "pressure.png")
        plt.savefig(fig, dpi=300)
        plt.clf()

        fname = os.path.join(self.output_dir, 'results.npz')
        numpy.savez(fname, x=x, u=u, e=e, cs=cs, rho=rho, p=p, h=h)

        fname = os.path.join(self.output_dir, 'exact.npz')
        numpy.savez(fname, x=x_e, u=u_e, e=e_e, p=p_e, rho=rho_e)
Beispiel #2
0
    def post_process(self):
        try:
            import matplotlib
            matplotlib.use('Agg')
            from matplotlib import pyplot
        except ImportError:
            print("Post processing requires matplotlib.")
            return

        if self.rank > 0 or len(self.output_files) == 0:
            return

        import os
        from pysph.solver.utils import load
        from pysph.examples.gas_dynamics import riemann_solver
        outfile = self.output_files[-1]
        data = load(outfile)
        pa = data['arrays']['fluid']

        try:
            gamma = self.options.gamma or 1.4
        except AttributeError:
            gamma = 1.4
        print(gamma)
        riemann_solver.set_gamma(gamma)
        rho_e, u_e, p_e, e_e, x_e = riemann_solver.solve(x_min=0,
                                                         x_max=1,
                                                         x_0=0.5,
                                                         t=self.tf,
                                                         p_l=self.pl,
                                                         p_r=self.pr,
                                                         rho_l=self.rhol,
                                                         rho_r=self.rhor,
                                                         u_l=self.ul,
                                                         u_r=self.ur,
                                                         N=101)

        x = pa.x
        u = pa.u
        e = pa.e
        p = pa.p
        rho = pa.rho
        cs = pa.cs

        pyplot.scatter(x,
                       rho,
                       label='pysph (' + str(self.options.scheme) + ')',
                       s=1,
                       color='k')
        pyplot.plot(x_e, rho_e, label='exact')
        pyplot.xlim((0.2, 0.8))
        pyplot.xlabel('x')
        pyplot.ylabel('rho')
        pyplot.legend()
        fig = os.path.join(self.output_dir, "density.png")
        pyplot.savefig(fig, dpi=300)
        pyplot.clf()

        pyplot.scatter(x,
                       e,
                       label='pysph (' + str(self.options.scheme) + ')',
                       s=1,
                       color='k')
        pyplot.plot(x_e, e_e, label='exact')
        pyplot.xlim((0.2, 0.8))
        pyplot.xlabel('x')
        pyplot.ylabel('e')
        pyplot.legend()
        fig = os.path.join(self.output_dir, "energy.png")
        pyplot.savefig(fig, dpi=300)
        pyplot.clf()

        pyplot.scatter(x,
                       rho * u,
                       label='pysph (' + str(self.options.scheme) + ')',
                       s=1,
                       color='k')
        pyplot.plot(x_e, rho_e * u_e, label='exact')
        pyplot.xlim((0.2, 0.8))
        pyplot.xlabel('x')
        pyplot.ylabel('M')
        pyplot.legend()
        fig = os.path.join(self.output_dir, "Machno.png")
        pyplot.savefig(fig, dpi=300)
        pyplot.clf()

        pyplot.scatter(x,
                       p,
                       label='pysph (' + str(self.options.scheme) + ')',
                       s=1,
                       color='k')
        pyplot.plot(x_e, p_e, label='exact')
        pyplot.xlim((0.2, 0.8))
        pyplot.xlabel('x')
        pyplot.ylabel('p')
        pyplot.legend()
        fig = os.path.join(self.output_dir, "pressure.png")
        pyplot.savefig(fig, dpi=300)
        pyplot.clf()

        fname = os.path.join(self.output_dir, 'results.npz')
        numpy.savez(fname, x=x, u=u, e=e, cs=cs, rho=rho, p=p)

        fname = os.path.join(self.output_dir, 'exact.npz')
        numpy.savez(fname, x=x_e, u=u_e, e=e_e, rho=rho_e, p=p_e)