def test_f_prime(self): print "-------------------------------------" print "-- F testas" print "-------------------------------------" x, t = 0.7, 1.7 Constants.beta = 1 Constants.n = 5 # pradinis intervalu skaicius Constants.tau = 0.2 # pradinis laiko zingsnis error = [] # netiktys for i in range(0, 15): # tikrinamos reiksmes is tiksliu funkciju u_now0 = Functions.u_exact(x - Constants.h(), t) u_now1 = Functions.u_exact(x, t) u_now2 = Functions.u_exact(x + Constants.h(), t) u_next0 = Functions.u_exact(x - Constants.h(), t + Constants.tau) u_next1 = Functions.u_exact(x, t + Constants.tau) u_next2 = Functions.u_exact(x + Constants.h(), t + Constants.tau) f_now = Functions.f(x,t) f_next = Functions.f(x, t + Constants.tau) # print "F testo f_now, f_next:", f_now, f_next f_prime_val = Functions.f_prime(u_now0, u_now1, u_now2, u_next0, u_next1, u_next2, f_now, f_next) # print "F reiksme:", Constants.h(), f_prime_val result = u_now2 - (Constants.u_const() * u_now1) + u_now0 + f_prime_val error.append(abs(result)) # print "h, tau = ", Constants.h(), ",", Constants.tau # print result # print "-------------------------------------" Constants.n *= 2 Constants.tau /= 2.0 Helpers.pretty_print_complex(error) self.assertTrue(True)
def test_f(self): print "-------------------------------------" print "-- f(x,t) testas" print "-------------------------------------" x, t = 0.42, 0.8 Constants.beta = 3 Constants.n = 10 # pradinis intervalu skaicius Constants.tau = 0.1 # pradinis laiko zingsnis errors = [] for i in range(0, 7): print Constants.h(), Constants.tau # print x, t # tikrinamos reiksmes is tiksliu funkciju u_now0 = Functions.u_exact(x - Constants.h(), t) u_now1 = Functions.u_exact(x, t) u_now2 = Functions.u_exact(x + Constants.h(), t) u_next0 = Functions.u_exact(x - Constants.h(), t + Constants.tau) u_next1 = Functions.u_exact(x, t + Constants.tau) u_next2 = Functions.u_exact(x + Constants.h(), t + Constants.tau) f_now = Functions.f(x,t) f_next = Functions.f(x, t + Constants.tau) # kaire algoritmo lygybes puse left = (u_next1 - u_now1) / Constants.tau # desine algoritmo lygybes puse right11 = (u_next2 - 2.0 * u_next1 + u_next0) / pow(Constants.h(), 2) right12 = (u_now2 - 2.0 * u_now1 + u_now0) / pow(Constants.h(), 2) right1 = 1j * 0.5 * (right11 + right12) right21 = (pow(abs(u_next2), 2) * u_next2 - pow(abs(u_next0), 2) * u_next0) / (Constants.h() * 2.0) right22 = (pow(abs(u_now2), 2) * u_now2 - pow(abs(u_now0), 2) * u_now0) / (Constants.h() * 2.0) right2 = Constants.beta * 0.5 * (right21 + right22) right3 = (f_next + f_now) / 2.0 right = right1 + right2 + right3 errors.append(abs(left - right)) Constants.n *= 10 Constants.tau /= 10.0 Helpers.pretty_print_complex(errors) # self.assertTrue(Helpers.sequence_descending(errors)) self.assertTrue(True)