def main(): start_time = datetime.now() #y0_sode_p1 = np.array([1.,0.,0.]) y0 = np.array([2.,1.]) # problem1 = rhs.Rhs(func01, 0.0, 2 , y0 , 30) #y0_sode_p1 = np.array([1.,0.,0.]) #y0_sode_p2 = np.array([1.,0.]) #y0 = np.array([0.15]) problem1 = rhs.Rhs(func0, 0.0, 0.01 , y0, 20, anal0) x,y = problem1.analiticalSolution(save=True) #------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------ # fwdeuler_p1 = euler.Explicit(problem1,'fwe.dat') # fet,feu = fwdeuler_p1.solve() bwdeuler = impliciteuler.BWDEuler(problem1, 'bwe.dat') bet,beu = bwdeuler.solve() # sieuler_p1 = euler.SemiImplicit(problem1, 'bwe.dat') # siet,sieu = sieuler_p1.solve() beuler = euler.Backward(problem1, 'bwe.dat') bt,bu = beuler.solve() # midpoint = centdiff.MidPointSolver(problem1 , 'mp.dat') # cdt,cdu = midpoint.solve() #sieuler_p4 = euler.Implicit(problem1, 'bwe.dat') #siet,sieu = bwdeuler_p4.solve() implicitmidpoint = centdiff.ImplicitMidPoint(problem1 , 'Imp_mp.dat') impt,impu = implicitmidpoint.solve() impcn = rungekutta.ImplicitCrankNicholson(problem1, 'cn.dat') cnt,cnu = impcn.solve() # # rk_p1 = implicitrungekutta.ImpRK2(problem1, 'rk.dat') # rkt,rku = rk_p1.solve() rk_p1 = implicitrungekutta.ImpRK4(problem1, 'rk.dat') rkt,rku = rk_p1.solve() radau = RadauIIA(problem1,'radIIA.dat') rdt,rdu = radau.solve() radau5 = RadauIIA5th(problem1,'radIIA.dat') rd5t,rd5u = radau5.solve() bdf = MEBDF(problem1,'bdf.dat') bdft,bdfu = bdf.solve(1,0.5) end_time = datetime.now() print('Duration: {}'.format(end_time - start_time)) fig,axs = qualityplot.Fonts()(1,1) #mkplot.PlotBase('Solution of Differential Equations','p1.pdf') # axs.plot(fet,feu,label='Exp Euler') #axs.plot(iet,ieu,label='Imp Euler') #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':') axs.plot(bt,bu,label='NR-BWDEuler',color='C1') #, linestyle=':') #axs.plot(bet,beu,label='Imp Euler') #, linestyle=':') axs.plot(rdt,rdu,label='Radau IIA 3rd',color='C3') axs.plot(rd5t,rd5u,label='Radau IIA 5th',color='C2') axs.plot(bdft,bdfu,label='BDF',color='C4')#,linestyle='--') axs.plot(rkt,rku,label='Implicit RK4',color='C0') #,linestyle=':') #axs.plot(rk3t,rk3u,label='Imp RK') #,linestyle=':') #axs.plot(am4t,am4u,label='Adams Moulton 4th') #,linestyle=':') #axs.plot(cd2t,cd2u,label='Cent diff 2nd') # axs.plot(impt,impu,label='Implicit Mid-Point Method')#,linestyle='-.') axs.plot(x,1.5*np.exp(-x) + 0.5* np.exp(-1000*x) ,label='Analitical', marker='o',markersize=7,linestyle='',alpha=0.7, color= 'C0' ) #, linestyle=':') axs.plot(x,1.5*np.exp(-x) - 0.5* np.exp(-1000*x), marker='o',markersize=7,linestyle='',alpha=0.7 , color= 'C0') #, linestyle=':') legend = leg = axs.legend() legend.get_frame().set_linewidth(0.7) plt.setp(legend.get_texts(), color='#555555') axs.set(xlabel = 'time' ,ylabel='y(t)') axs.set_title('dy$_1$/dt=-10(t-1)y$_1$',y=1.05) #plt.savefig('system02.pdf') chartBox = axs.get_position() legend = leg = axs.legend() legend.get_frame().set_linewidth(0.7) axs.set_position([chartBox.x0, chartBox.y0, chartBox.width*0.8, chartBox.height]) plt.setp(legend.get_texts(), color='#2E3436') plt.legend(bbox_to_anchor=(1.03, 0.85), loc=2, borderaxespad=0.) plt.show()
def main(): start_time = datetime.now() y0 = np.array([0.15]) problem1 = rhs.Rhs(func0, 0.0, 2.0 , y0, 20) #x,y = problem1.analiticalSolution(save=True) #------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------ # fwdeuler = euler.Explicit(problem1,'fwe.dat') # fet,feu = fwdeuler.solve() # bwdeuler = euler.Implicit(problem1, 'bwe.dat') # bet,beu = bwdeuler.solve() impeuler = impliciteuler.BWDEuler(problem1,'impeul.dat') iet,ieu = impeuler.solve() # sieuler_p1 = euler.SemiImplicit(problem1, 'bwe.dat') # siet,sieu = sieuler_p1.solve() # beuler_p1 = euler.Backward(problem1, 'bwe.dat') # bt,bu = beuler_p1.solve() # midpoint = centdiff.MidPointSolver(problem1 , 'mp.dat') # cdt,cdu = midpoint.solve() #sieuler_p4 = euler.Implicit(problem1, 'bwe.dat') #siet,sieu = bwdeuler_p4.solve() implicitmidpoint = centdiff.ImplicitMidPoint(problem1 , 'Imp_mp.dat') impt,impu = implicitmidpoint.solve() # impCN = rungekutta.ImplicitCrankNicholson(problem1, 'cn.dat') # cnt,cnu = impCN.solve() # impCN = rungekutta.ImplicitCrankNicholson(problem1, 'cn.dat') # cnt,cnu = impCN.solve() # # rk4ord = implicitrungekutta.ImpRK2(problem1, 'rk.dat') # rkt,rku = rk4ord.solve() # rk4ord = implicitrungekutta.ImpRK4(problem1, 'rk.dat') rkt,rku = rk4ord.solve() radau = RadauIIA(problem1, 'radau.dat') rdt,rdu = radau.solve() radau5 = RadauIIA5th(problem1, 'radau.dat') rd5t,rd5u = radau5.solve() # #fwdeuler_p1 = euler.Explicit(problem1, True, True, 'lorentz_fwe.dat') # #fet,feu = fwdeuler_p1.solve() # #leapfrog_p1 = multistep.LeapFrog(problem1, 'lorentz_lf.dat') #lft,lfu = leapfrog_p1.solve() # # leapfrog_p2 = euler.Explicit(problem2, 'oscillator_lf.dat') # lf2,lf2 = leapfrog_p2.solve() am5_p1 = adamsmoulton.AdamsMoulton5th(problem1, 'am5_1.dat') #ab2_p = ab2_p1._2nd(problem1,'ab2_1.dat') am5t,am5u = am5_p1.solve() bdf = MEBDF(problem1 , 'bdf.dat') bdft , bdfu = bdf.solve(1,0) #fwdeuler_p1.plot() #ab2_p1 = euler.Implicit(problem3,True,True,filename='lorentz_bwe.dat') #bet,beu = bwdeuler_p1.solve() #bwdeuler_p1.plot() end_time = datetime.now() print('Duration: {}'.format(end_time - start_time)) fig,axs = qualityplot.Fonts()(1,1) #mkplot.PlotBase('Solution of Differential Equations','p1.pdf') # axs.plot(fet,feu,label='Exp Euler') #axs.plot(iet,ieu,label='Imp Euler') #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':') axs.plot(iet,ieu,label='NR-BWDEuler')#, linestyle=':') # axs.plot(bet,beu,label='Imp Euler') #, linestyle=':') #axs.plot(iet,ieu,label='NR-Imp Euler') #, linestyle=':') #axs.plot(lft,lfu,label='Leap Frog') #axs.plot(cnt,cnu,label='Implicit Crank Nicholson')#,linestyle='--') axs.plot(rkt,rku,label='Runge Kutta 4th',linestyle='-') axs.plot(rdt,rdu,label='RadauIIA') #,linestyle=':') axs.plot(rd5t,rd5u,label='RadauIIA') #,linestyle=':') #axs.plot(am5t,am5u,label='Adams Moulton 5th',linestyle=':') axs.plot(bdft,bdfu,label='BDF') #axs.plot(impt,impu,label='Implicit Mid-Point Method',linestyle='-.') #axs.plot(x,y,label='Analitical', marker='o',linestyle='',color='C0',alpha=0.7 ) #, linestyle=':') legend = leg = axs.legend() legend.get_frame().set_linewidth(0.7) plt.setp(legend.get_texts(), color='#555555') axs.set(xlabel = 'time' ,ylabel='y(t)') axs.set_title('dy$_1$/dt=-10(t-1)y$_1$',y=1.05) plt.savefig('../Results/StiffEq1.pdf') plt.show()
def main(): start_time = datetime.now() y0 = np.array([2. / 3. * np.exp(2), 1]) problem1 = rhs.Rhs(func0, 0.0, 3.0, y0, 30) #x,y = problem1.analiticalSolution(save=True) ##------------------------------------------------------------------------------------------------------------ ##------------------------------------------------------------------------------------------------------------ ##------------------------------------------------------------------------------------------------------------ fwdeuler_p1 = euler.Explicit(problem1, 'fwe.dat') fet, feu = fwdeuler_p1.solve() bwdeuler_p1 = euler.Implicit(problem1, 'bwe.dat') bet, beu = bwdeuler_p1.solve() # sieuler_p1 = euler.SemiImplicit(problem1, 'bwe.dat') # siet,sieu = sieuler_p1.solve() beuler_p1 = euler.Backward(problem1, 'bwe.dat') bt, bu = beuler_p1.solve() # midpoint = centdiff.MidPointSolver(problem1 , 'mp.dat') # cdt,cdu = midpoint.solve() #sieuler_p4 = euler.Implicit(problem1, 'bwe.dat') #siet,sieu = bwdeuler_p4.solve() implicitmidpoint = centdiff.ImplicitMidPoint(problem1, 'Imp_mp.dat') impt, impu = implicitmidpoint.solve() am5_p1 = adamsmoulton.AdamsMoulton5th(problem1, 'am5_1.dat') #ab2_p = ab2_p1._2nd(problem1,'ab2_1.dat') am5t, am5u = am5_p1.solve() impcn = implicitrungekutta.ImpRK4(problem1, 'cn.dat') rkt, rku = impcn.solve() radau = RadauIIA(problem1, 'radIIA.dat') radt, radu = radau.solve() radau5 = RadauIIA5th(problem1, 'radIIA.dat') rad5t, rad5u = radau5.solve() # rk_p1 = rungekutta.RK4(problem1, 'rk.dat') # rkt,rku = rk_p1.solve() # #rk3 = implicitrungekutta.ImpRK4(problem1, 'rk.dat') #rk3t,rk3u = rk3.solve() # #fwdeuler_p1 = euler.Explicit(problem1, True, True, 'lorentz_fwe.dat') # #fet,feu = fwdeuler_p1.solve() # #leapfrog_p1 = multistep.LeapFrog(problem1, 'lorentz_lf.dat') #lft,lfu = leapfrog_p1.solve() # # leapfrog_p2 = euler.Explicit(problem2, 'oscillator_lf.dat') # lf2,lf2 = leapfrog_p2.solve() #fwdeuler_p1.plot() #ab2_p1 = euler.Implicit(problem3,True,True,filename='lorentz_bwe.dat') #bet,beu = bwdeuler_p1.solve() #bwdeuler_p1.plot() end_time = datetime.now() print('Duration: {}'.format(end_time - start_time)) fig, axs = qualityplot.Fonts()( 1, 1) #mkplot.PlotBase('Solution of Differential Equations','p1.pdf') # axs.plot(fet,feu,label='Exp Euler') #axs.plot(iet,ieu,label='Imp Euler') #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':') axs.plot(bt, bu, label='NR-BWDEuler') #, linestyle=':') # axs.plot(bet,beu,label='Imp Euler') #, linestyle=':') axs.plot(radt, radu, label='RadauIIA 3th', linewidth=3) axs.plot(rad5t, rad5u, label='RadauIIA 5th', linewidth=3) axs.plot(rkt, rku, label='Imp RK4', linewidth=2) #axs.plot(am5t,am5u,label='Adams Moulton') #,linestyle=':') #axs.plot(am3t,am3u,label='Adams Moulton 3rd') #,linestyle=':') #axs.plot(am4t,am4u,label='Adams Moulton 4th') #,linestyle=':') #axs.plot(cd2t,cd2u,label='Cent diff 2nd') #axs.plot(impt,impu,label='Implicit Mid-Point Method',linestyle='-.') #axs.plot(x,y,label='Analitical', marker='o',linestyle='',color='C0',alpha=0.7 ) #, linestyle=':') legend = leg = axs.legend() legend.get_frame().set_linewidth(0.7) plt.setp(legend.get_texts(), color='#555555') axs.set(xlabel='time', ylabel='y(t)') axs.set_title('dy$_1$/dt=-10(t-1)y$_1$', y=1.05) plt.savefig('../Results/StiffSys1.pdf') plt.show()
def main(): start_time = datetime.now() y0 = np.array([1., 1.]) problem1 = rhs.Rhs(func0, 0.0, 20, y0, 60, anal0, dt=0.1) x, y = problem1.analiticalSolution(save=True) ##---------------------------------------------------------------------------------------------------- ##---------------------------------------------------------------------------------------------------- ##---------------------------------------------------------------------------------------------------- # fwdeuler_p1 = euler.Explicit(problem1,'fwe.dat') # fet,feu = fwdeuler_p1.solve() bwdeuler = impliciteuler.BWDEuler(problem1, 'bwe.dat') iet, ieu = bwdeuler.solve() # sieuler_p1 = euler.SemiImplicit(problem1, 'bwe.dat') # siet,sieu = sieuler_p1.solve() #beuler = euler.Backward(problem1, 'bwe.dat') #bt,bu = beuler.solve() # midpoint = centdiff.MidPointSolver(problem1 , 'mp.dat') # cdt,cdu = midpoint.solve() #sieuler_p4 = euler.Implicit(problem1, 'bwe.dat') #siet,sieu = bwdeuler_p4.solve() #implicitmidpoint = centdiff.ImplicitMidPoint(problem1 , 'Imp_mp.dat') #impt,impu = implicitmidpoint.solve() #am5_p1 = adamsmoulton.AdamsMoulton5th(problem1, 'am5_1.dat') #ab2_p = ab2_p1._2nd(problem1,'ab2_1.dat') #am5t,am5u = am5_p1.solve() cn_p2 = rungekutta.ImplicitCrankNicholson(problem1, 'cn.dat') cnt, cnu = cn_p2.solve() # # rk_p1 = implicitrungekutta.ImpRK2(problem1, 'rk.dat') # rkt,rku = rk_p1.solve() rk_p = implicitrungekutta.ImpRK4(problem1, 'rk.dat') rkt, rku = rk_p.solve() radau = RadauIIA(problem1, 'radau3.dat') rt, ru = radau.solve() radau5 = RadauIIA5th(problem1, 'radau5.dat') r5t, r5u = radau5.solve() bdf = MEBDF(problem1, 'bdf.dat') bdft, bdfu = bdf.solve(0.6, 0.2) end_time = datetime.now() print('Duration: {}'.format(end_time - start_time)) fig, axs = qualityplot.Fonts(**{'scheme': 'nbd'})( 1, 1) #mkplot.PlotBase('Solution of Differential Equations','p1.pdf') # axs.plot(fet,feu,label='Exp Euler') #axs.plot(iet,ieu,label='Imp Euler') #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':') #axs.plot(bt,bu,label='NR-BWDEuler') #, linestyle=':') # axs.plot(iet,ieu,label='NR-BWDEuler') #, linestyle=':') #axs.plot(bet,beu,label='Imp Euler') #, linestyle=':') # axs.plot(rt,ru,label='RadauIIA') axs.plot(r5t, r5u, label='RadauIIA 5th') #axs.plot(cnt,cnu,label='Imp Crank Nicholson',linestyle='-') # axs.plot(rkt,rku,label='Imp RK4') #,linestyle=':') # axs.plot(am5t,am5u,label='Adams Moulton 5th') #,linestyle=':') # axs.plot(am4t,am4u,label='Adams Moulton 4th') #,linestyle=':') axs.plot(bdft, bdfu, label='BDF') # axs.plot(impt,impu,label='Implicit Mid-Point Method',linestyle='-.') #axs.plot(x,y,label='Analitical', marker='o',markersize=7,linestyle='',alpha=0.7, color= 'C0' ) #, linestyle=':') #axs.plot(x,1.5*np.exp(-x) - 0.5* np.exp(-1000*x), marker='o',markersize=7,linestyle='',alpha=0.7 , color= 'C0') #, linestyle=':') legend = leg = axs.legend() legend.get_frame().set_linewidth(0.7) plt.setp(legend.get_texts(), color='#555555') axs.set(xlabel='time', ylabel='y(t)') axs.set_title('Van Der Pol Problem (Stiff system diff eq)', y=1.05) #plt.savefig('system02.pdf') plt.show()
def main(): start_time = datetime.now() y0 = np.array([0.]) problem1 = rhs.Rhs(func0, 0.0, 2.0, y0, 30, anal01) x, y = problem1.analiticalSolution(save=True) #------------------------------------------------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------------------------------------------------ bwdeuler = euler.Implicit(problem1, 'bwe.dat') bet, beu = bwdeuler.solve() # sieuler_p1 = euler.SemiImplicit(problem1, 'bwe.dat') # siet,sieu = sieuler_p1.solve() beuler = euler.Backward(problem1, 'bwe.dat') bt, bu = beuler.solve() ieuler = impliciteuler.BWDEuler(problem1, 'bwe.dat') iet, ieu = ieuler.solve() # midpoint = centdiff.MidPointSolver(problem1 , 'mp.dat') # cdt,cdu = midpoint.solve() #sieuler_p4 = euler.Implicit(problem1, 'bwe.dat') #siet,sieu = bwdeuler_p4.solve() implicitmidpoint = centdiff.ImplicitMidPoint(problem1, 'Imp_mp.dat') impt, impu = implicitmidpoint.solve() # impmidpoint = centdiff.ImpMidPoint(problem1 , 'Imp_mp.dat') # it,iu = impmidpoint.solve() cn_p2 = rungekutta.ImplicitCrankNicholson(problem1, 'cn.dat') cnt, cnu = cn_p2.solve() # rk_p1 = implicitrungekutta.ImpRK2(problem1, 'rk.dat') rkt, rku = rk_p1.solve() # # #fwdeuler_p1 = euler.Explicit(problem1, True, True, 'lorentz_fwe.dat') # #fet,feu = fwdeuler_p1.solve() # #leapfrog_p1 = multistep.LeapFrog(problem1, 'lorentz_lf.dat') #lft,lfu = leapfrog_p1.solve() # # leapfrog_p2 = euler.Explicit(problem2, 'oscillator_lf.dat') # lf2,lf2 = leapfrog_p2.solve() rk = implicitrungekutta.ImpRK4(problem1, 'rk.dat') rk3t, rk3u = rk.solve() bdf = MEBDF(problem1, 'bdf.dat') bdft, bdfu = bdf.solve(1, 0.5) radau = RadauIIA(problem1, 'radau.dat') rdt, rdu = radau.solve() radau = RadauIIA5th(problem1, 'radau.dat') rd5t, rd5u = radau.solve() end_time = datetime.now() print('Duration: {}'.format(end_time - start_time)) fig, axs = qualityplot.Fonts()( 1, 1) #mkplot.PlotBase('Solution of Differential Equations','p1.pdf') # axs.plot(fet,feu,label='Exp Euler') axs.plot(iet, ieu, label='Imp Euler') #axs.plot(siet,sieu,label='Sem.Imp Euler') #, linestyle=':') #axs.plot(bt,bu,label='NR-BWDEuler') #, linestyle=':') # axs.plot(bet,beu,label='Imp Euler') #, linestyle=':') axs.plot(rdt, rdu, label='RadauIIA') axs.plot(rd5t, rd5u, label='RadauIIA 5th') #axs.plot(cnt,cnu,label='Implicit Crank Nicholson',linestyle='-') #axs.plot(rkt,rku,label='Runge Kutta 4th') #,linestyle=':') #axs.plot(am3t,am3u,label='Adams Moulton 3rd') #,linestyle=':') #axs.plot(am4t,am4u,label='Adams Moulton 4th') #,linestyle=':') axs.plot(bdft, bdfu, label='BDF') # axs.plot(rkt,rku,label='Imp. Runge Kutta') #axs.plot(impt,impu,label='Implicit Mid-Point Method',linestyle='--') #axs.plot(iet,ieu,label='NR Implicit Euler') #,linestyle='-.') axs.plot(rk3t, rk3u, label='Imp. RK4') #,linestyle='-.') axs.plot(x, y, label='Analitical', marker='o', markersize='7', linestyle='', color='C0', alpha=0.7) #, linestyle=':') legend = leg = axs.legend() legend.get_frame().set_linewidth(0.7) plt.setp(legend.get_texts(), color='#555555') axs.set(xlabel='time', ylabel='y(t)') axs.set_title('dy$_1$/dt=-10(t-1)y$_1$', y=1.05) #plt.savefig('system02.pdf') plt.show()