trapp = 0.5*(ep[:-1] + ep[1:]) errp = (dtvec*trapp).sum() trapc = 0.5*(ec[:-1] + ec[1:]) resc = (dtvec*trapc).sum() print 'Nts = {0}, v_error = {1}, p_error = {2}, contres={3}'.\ format(Nts, errv, errp, resc) errvl.append(errv) errpl.append(errp) rescl.append(resc) print errvl print errpl print rescl topgfplot = True if topgfplot: ltpl = [errvl, errpl, rescl] for ltp in ltpl: for (i, Nts) in enumerate(Ntslist): print '({0}, {1})'.format(1./Nts, ltp[i]) cpu.conv_plot(Ntslist, [errvl], logscale=2, markerl=['o'], fignum=1, leglist=['velerror']) cpu.conv_plot(Ntslist, [rescl], logscale=2, markerl=['o'], fignum=2, leglist=['cres']) cpu.conv_plot(Ntslist, [errpl], logscale=2, markerl=['o'], fignum=3, leglist=['perror'])
def jsd_calc_l2errs(JsDict, plot=False, ptikzfile=None): jsd = load_json_dicts(JsDict) timelength = jsd['TimeInterval'][1] - jsd['TimeInterval'][0] contresl, velerrl, perrl = [], [], [] for i in range(len(jsd['TimeDiscs'])): dx = timelength / jsd['TimeDiscs'][i] contresl.append(np.sqrt(np.trapz(np.square(jsd['ContiRes'][i]), dx=dx))) velerrl.append(np.sqrt(np.trapz(np.square(jsd['VelEr'][i]), dx=dx))) perrl.append(np.sqrt(np.trapz(np.square(jsd['PEr'][i]), dx=dx))) try: dconresl, momresl, tolcorl = [], [], [] for i in range(len(jsd['TimeDiscs'])): dx = timelength / jsd['TimeDiscs'][i] dconresl.append(np.sqrt(np.trapz(np.square(jsd['DContiRes'][i]), dx=dx))) momresl.append(np.sqrt(np.trapz(np.square(jsd['MomRes'][i]), dx=dx))) tolcorl.append(np.sqrt(np.trapz(np.square(jsd['TolCor'][i]), dx=dx))) allres = True except: allres = False print 'not all residuals were recorded' Ntsl = jsd['TimeDiscs'] print 'L2 errors for method ' + jsd['TimeIntMeth'] print 'N = ', jsd['SpaceDiscParam'] print 'Nts = ', jsd['TimeDiscs'] print 'Velocity Errors: ', velerrl print 'Pressure Errors: ', perrl print 'Conti Residuals: ', contresl if allres: print 'DConti Residuals: ', dconresl print 'Momenteq Residuals: ', momresl print 'TolCor: ', tolcorl if plot: plt.figure() plt.loglog(Ntsl, dconresl, 'o') plt.title('dconres') plt.figure() plt.loglog(Ntsl, momresl, 'v') plt.title('momres') plt.figure() plt.loglog(Ntsl, tolcorl, '^') plt.title('tolcors') if plot: plt.figure() plt.loglog(Ntsl, velerrl, 'o') plt.title('velerror') plt.figure() plt.loglog(Ntsl, perrl, 'v') plt.title('perror') plt.figure() plt.loglog(Ntsl, contresl, '^') plt.title('contres') if ptikzfile is None: plt.show(block=False) if ptikzfile is not None: import matlibplots.conv_plot_utils as cpu # see [email protected]:highlando/mat-lib-plots.git cpu.conv_plot(1./np.array(Ntsl[:-1]), [perrl[:-1]], leglist=['perr'], markerl=['*'], fit=[-1], logscale=True, tikzfile=ptikzfile)
errv, errp, crr, mrr = errvl[k], errpl[k], crrsl[k], mrrsl[k] print('{0}: {1}; {2}; {3}; {4}'.format(Nts, errv, errp, crr, mrr)) vel.append(errvl) pel.append(errpl) crl.append(crrsl) mrl.append(mrrsl) import matlibplots.conv_plot_utils as cpu tkzprfx = 'tikzs/' + curmethnm markers = ['x', 'o', 'v', '^'] leglist = ['{0:.2e}'.format(ltol) for ltol in linatollist] abscissa = 1./np.array(Ntslist) markerl = markers[:len(vel)] pltdct = dict(logscale=True, markerl=markerl, logbase=10, leglist=leglist, legloc=4) cpu.conv_plot(abscissa, vel, fignum=1, tikzfile=tkzprfx+'velerrs.tikz', title='vel apprx', **pltdct) cpu.conv_plot(abscissa, pel, fignum=2, tikzfile=tkzprfx+'pelerrs.tikz', title='pres apprx', **pltdct) # don't need the residuals for the exact solves crpcrl = crl[1:] crpmrl = mrl[1:] markerl = markers[1:len(crl)+1] leglistc = leglist[1:len(crl)+1] pltdct.update(dict(markerl=markerl, leglist=leglistc)) cpu.conv_plot(abscissa, crpcrl, fignum=3, tikzfile=tkzprfx+'cres.tikz', title='conti residual', **pltdct) cpu.conv_plot(abscissa, crpmrl, fignum=4, tikzfile=tkzprfx+'meqres.tikz', title='momeq residual', **pltdct)