def calc_a_coef(self): a = self.a nu = self.nu k = self.k arc_R = self.arc_R M = self.M fft_a_coef = self.get_expected_a_coef() if self.acheat: self.a_coef = fft_a_coef else: eval_phi0 = self.problem.eval_phi0 def eval_bc0(th): r = self.boundary.eval_r(th) return eval_phi0(th) - self.v_interp(r, th) a_coef, singvals = abcoef.calc_a_coef(self.problem, self.boundary, eval_bc0, self.M, self.problem.get_m1()) self.a_coef = a_coef np.set_printoptions(precision=4) if self.boundary.name == 'arc': error = np.abs(self.a_coef - fft_a_coef) print('a_coef error:', error) print() elif self.problem.name == 'iz-bessel': print('a_coef:', scipy.real(a_coef)) print()
def do_test(m1): a_coef = calc_a_coef(problem, boundary, eval_phi0, M, m1) errors = np.abs(problem.fft_a_coef[:M] - a_coef) error7 = np.max(errors) print("a_coef(expected):") print_array(problem.fft_a_coef[:M]) print() print("a_coef(actual):") print_array(a_coef) print() print("errors:") print_array(errors) print() print("max_error(a1-a7)={}".format(error7)) """print('-'*20)
def go(problem_name, boundary_name): global n_done output = {} def to_basic_list(array): assert np.linalg.norm(scipy.imag(array)) == 0 return list(scipy.real(array)) def eval_phi0(th): r = boundary.eval_r(th) return problem.eval_expected_polar(r, th) problem = problems.problem_dict[problem_name]() boundary = problems.boundary.boundaries[boundary_name](problem.R) problem.boundary = boundary output = { "problem": problem_name, "m_max": problem.m_max, "boundary": boundary_name, "k": problem.k, "a": problem.a, "bet": boundary.bet, "m1_data": [], "error": [], "singular_vals": [], } for m1 in m1_list: a_coef, singular_vals = calc_a_coef(problem, boundary, eval_phi0, M, m1) error = a_coef - problem.fft_a_coef[:M] output["m1_data"].append(m1) output["error"].append(to_basic_list(np.abs(error))) output["singular_vals"].append(to_basic_list(singular_vals)) n_done += 1 progress = n_done / n_tests print("\r{}%".format(int(100 * progress)), end="") fname = "m1trend_{}_{}_{}.dat".format(problem_name, boundary_name, problem.k) outfile = open(sys.path[0] + "/" + fname, "w") json.dump(output, outfile)
def test_many(m1_list=None): min_error7 = float("inf") if m1_list is None: m1_list = range(10, 250, 2) for m1 in m1_list: print("\n----- m1={} -----".format(m1)) a_coef, singular_vals = calc_a_coef(problem, boundary, eval_phi0, M, m1) error7 = np.max(np.abs(a_coef - problem.fft_a_coef[:7])) print("a_coef=") print_array(a_coef) print("max_error(a1-a7)={}".format(error7), end=" ") if error7 < min_error7: min_error7 = error7 print("!!!") else: print()
def test_many(): global m1, boundary bet = .5 max_i = 100 for i in range(max_i): result_dict = {} result_dict['bet'] = bet boundary = boundary_cls(R, bet) problem.boundary = boundary if m1 is None: m1 = problem.get_m1() output['m1'] = m1 a_coef, singular_vals = calc_a_coef(problem, boundary, eval_phi0, M, m1) result_dict['a_error'] = list(np.abs(a_coef - problem.fft_a_coef[:7])) result_dict['singular_vals'] = list(singular_vals) bet *= .95 output['results'].append(result_dict) print('\r{}%'.format(int(100*i/max_i)), end='')
problem_results[boundary_name] = boundary_results if boundary.name == 'arc': max_series_error = 0 for th in np.linspace(problem.a, 2*np.pi, 1024): series_error = abs(problem.eval_bc(th, 0) - problem.eval_phi0(th)) if series_error > max_series_error: max_series_error = series_error problem_results['series_error'] = max_series_error min_error7 = float('inf') for m1 in m1_list: a_coef, singular_vals = calc_a_coef(problem, boundary, eval_phi0, M, m1) error7 = np.max(np.abs(a_coef - problem.fft_a_coef[:M])) if error7 < min_error7: min_error7 = error7 boundary_results['m1'] = m1 boundary_results['a_coef'] = to_basic_list(a_coef) boundary_results['fft_a_coef'] = to_basic_list(problem.fft_a_coef[:M]) boundary_results['error'] = to_basic_list(a_coef - problem.fft_a_coef[:M]) boundary_results['error7'] = error7 n_done += 1 progress = n_done / n_tests print('\r{}%'.format(int(100*progress)), end='') print('\n')