def test_iteration(self): Constants.n = 10 Constants.tau = 0.1 t = 1.8 print "----------------------------------------------" print "pradedama nuo: " print "----------------------------------------------" u_now = Functions.u_exact_range(t) Helpers.pretty_print_complex(u_now) u_new_expected = Functions.u_exact_range(t + Constants.tau) u_new_actual = Algorithm._iteration_block(u_now, t) print "----------------------------------------------" print "lauktas rezultatas: " print "----------------------------------------------" Helpers.pretty_print_complex(u_new_expected) print "----------------------------------------------" print "gautas rezultatas: " print "----------------------------------------------" Helpers.pretty_print_complex(u_new_actual) print "Max netiktis: ", Functions.u_error(u_new_actual, t) self.assertTrue(True)
def test_iteration_precision(self): t = 0.8 Constants.n = 10 Constants.tau = 1.0 errors = [] for i in range(0, 5): u_now = Functions.u_exact_range(t) # tikslios reiksmes dabartiniu laiko momentu u_next = Algorithm._iteration_block(u_now, t) # isskaiciuotos reikmes sekanciu laiko momentu errors.append(Functions.u_error(u_next, t + Constants.tau)) # netiktis Constants.n *= 3 Constants.tau /= 3 Helpers.pretty_print_complex(errors) self.assertTrue(True)
def test_solve(self): t = 2.7 # koks nors laiko momentas u = Functions.u_exact_range(t) # laukiamos tikslios reiksmes # sufabrikuotos desines lygybes puses reiksmes (F) fake_f_prime = [] for i in range(1, len(u) - 1): f = u[i+1] - (Constants.u_const() * u[i]) + u[i-1] # butinai reikia padauginti is -1, nes algoritmas tikisi F reiksmiu, bet desinese lygybiu pusese yra -F f *= -1 fake_f_prime.append(f) # testas actual = ThomasAlgorithm.solve(Constants.u_const(), fake_f_prime, Constants.kappa, Constants.gamma) equal = Helpers.almost_equal_complex(u, actual) self.assertTrue(equal)
def test_algorithm(self): print "-------------------------------------" print "-- Viso algoritmo testas" print "-------------------------------------" Constants.n = 4 Constants.tau = 0.1 errors = [] for i in range(0, 5): u_initial = Functions.u_exact_range(0.0) # tikslios reiksmes pradiniu laiko momentu func_points, time_points = Algorithm.run(u_initial) max_error = Functions.u_error_total(func_points, time_points) errors.append(max_error) Constants.n *= 2 # Constants.tau /= 2 Helpers.pretty_print_complex(errors) self.assertTrue(True)
#!/usr/bin/python import sys from src.algorithm import Algorithm from src.constants import Constants from src.functions import Functions runs = int(sys.argv[1]) # skaiciavimai Constants.n = 5 Constants.tau = 0.1 # penkis kartus mazinami zingsniai for i in range(0, runs): u_initial = Functions.u_exact_range(0) func_points, time_points = Algorithm.run(u_initial) error_total = Functions.u_error_total(func_points, time_points) print "h = %.5f, tau = %.5f, netiktis: %.10f" % (Constants.h(), Constants.tau, error_total) Constants.n *= 2 Constants.tau /= 2.0