예제 #1
0
    def save_snapshot(self):

        if self.fast_run:
            return

        fig = plt.figure()
        ax = fig.add_subplot(111)
        y = self.u_n

        ax.plot(self.mesh, y, 'ko', linewidth=2, label='Approx.')

        auc = srule(y, self.mesh)

        eps = 1e-2

        txt = 't = ' + '{:0.3f}'.\
                format(self.current_time-self.initial_time) +\
                ', AUC: ' + '{:0.3f}'.format(auc)
        ax.text(0.1, 0.1, txt, fontsize=16)

        ax.legend(loc=1)

        fname = 'solution_' + str(self.counter) + self.figure_format
        fname = os.path.join(self.fem_solution_storage_dir, fname)
        self.counter += 1
        ax.set_ylim([-2 - eps, 1 + eps])
        fig.savefig(fname, dpi=150)
        plt.close('all')
예제 #2
0
    def save_snapshot(self):

        if self.fast_run:
            return

        if self.dimension == 2:
            self.vtkfile << (self.u_n, self.current_time)
            self.counter += 1
            return

        fig = plt.figure()
        ax = fig.add_subplot(111)
        y = self.u_n.vector().get_local()[self.dof_map]

        ax.plot(self.ordered_mesh, y, 'ko', linewidth=2, label='Approx.')

        auc = srule(y, self.ordered_mesh)

        if self.plot_symmetric:

            reflected_mesh = -self.ordered_mesh[::-1]
            ax.plot(reflected_mesh, y[::-1], 'ko', linewidth=2)
            auc *= 2

        eps = 1e-2

        if self.plot_true_solution:

            y_true = self.U(self.ordered_mesh, self.current_time)

            ax.plot(self.ordered_mesh, y_true,\
                    'b-', linewidth=2, label='Exact')

            if self.plot_symmetric:
                ax.plot(reflected_mesh, y_true[::-1],\
                        'b-', linewidth=2)

            ax.set_ylim([-0 - eps, 1 + eps])
            ax.set_xlim([self.x_left - eps, self.x_right + eps])

            if self.plot_symmetric:
                ax.set_xlim([-self.x_right - eps, self.x_right + eps])


        txt = 't = ' + '{:0.3f}'.\
                format(self.current_time-self.initial_time) +\
                ', AUC: ' + '{:0.3f}'.format(auc)
        ax.text(0.1, 0.1, txt, fontsize=16)

        ax.legend(loc=1)

        fname = 'solution_' + str(self.counter) + self.figure_format
        fname = os.path.join(self.fem_solution_storage_dir, fname)
        self.counter += 1
        fig.savefig(fname, dpi=150)
        plt.close('all')
예제 #3
0
 def IC(self, m):
     norm_sq = self.L
     if 0 < m:
         norm_sq /= 2
     x = np.linspace(0, self.L, 5000)
     y = self.initial_condition(x) - self.shift(x)
     y *= self.X(m, x)
     auc = srule(y, x)
     auc /= norm_sq
     return auc