示例#1
0
        custom_lines = [
            Line2D([0], [0], color='k', lw=2),
            Line2D([0], [0], color='r', ls='--', lw=2)
        ]
        axs[count].legend(custom_lines, ['$u$', '$Fu$'])
        if coarse:
            custom_lines = [Line2D([0], [0], color='b', lw=2)]
            axs[count + 1].legend(custom_lines, ['$u - Fu$'])
        axs[count].set_xlim(domain)
        axs[count].set_xlabel('$x$')
        axs[count].set_title(f'PD={pd}, $N$={n}')

        count = count + 1

        #%%
        errL2, errKL2 = getErr1D(uh, pde.exactu, mesh, fem, ng, 0)
        errH1, errKH2 = getErr1D(uh, pde.Du, mesh, fem, ng, 1)

        error_list.append([pd, n, errL2, errH1])

        print('#----------------------------------------#')
        print('n = %d' % (n))
        print('L2 error:  %5.3e' % errL2)
        print('H1 error:  %5.3e' % errH1)
        if i >= 1:
            rateL2 = np.log(errL2_0 / errL2) / np.log(2.0)
            rateH1 = np.log(errH1_0 / errH1) / np.log(2.0)
            print('L2 order:  %5.3f' % rateL2)
            print('H1 order:  %5.3f' % rateH1)

        errL2_0 = errL2
示例#2
0
            axs[pd - 1, i].plot(x, u, 'r', lw=1)

        axs[pd - 1, i].grid()
        custom_lines = [
            Line2D([0], [0], color='k', lw=2),
            Line2D([0], [0], color='r', lw=1)
        ]
        axs[pd - 1, i].legend(custom_lines, ['$u$', '$Iu$'])
        axs[pd - 1, i].set_xlim(domain)
        axs[pd - 1, i].set_title(f'$p$={pd}, $h$=1/{n}')
        if pd == 4:
            axs[pd - 1, i].set_xlabel('$x$')
        if i == 0:
            axs[pd - 1, i].set_ylabel('$u(x)$')

        errL2, errKL2 = getErr1D(uh, fun, mesh, fem, ng, 0)
        errH1, errKH2 = getErr1D(uh, dfun, mesh, fem, ng, 1)

        error_list.append([pd, n, errL2, errH1])

        print('#----------------------------------------#')
        print('n = %d' % (n))
        print('L2 error:  %5.3e' % errL2)
        print('H1 error:  %5.3e' % errH1)
        if i >= 1:
            rateL2 = np.log(errL2_0 / errL2) / np.log(2.0)
            rateH1 = np.log(errH1_0 / errH1) / np.log(2.0)
            print('L2 order:  %5.3f' % rateL2)
            print('H1 order:  %5.3f' % rateH1)

        errL2_0 = errL2