def calc(self, solution, bcs): error_value = -1. if ham_not_none(self.domain): ham_error('HAM_ERROR_CRITICAL', 'CRITICAL__NOT_IMPLEMENTED_YET') elif len(self.eval_points) > 0: error_value = 0. the_vars = self._consistent_points() if ham_not_none(the_vars): expr_to_eval = self._subs_solution(solution) expr_eval_l = lambdify(the_vars, expr_to_eval, modules=['math', 'sympy']) if len(self.eval_points) > 0: for pnt in self.eval_points: # type: HamPoint get_back_vars = pnt.p_list(the_vars) error_value += expr_eval_l(get_back_vars[0], get_back_vars[1], get_back_vars[2]) error_value /= len(self.eval_points) else: error_value = 'N/A' else: ham_error('HAM_ERROR_CRITICAL', 'CRITICAL__ASSERT_NOT_REACHED') else: ham_error('HAM_ERROR_CRITICAL', 'CRITICAL__ASSERT_NOT_REACHED') return error_value
def _consistent_points(self): ret_vars = None x_absent = False y_absent = False t_absent = False falsy = False for pnt in self.eval_points: if not ham_not_none(pnt.x): if x_absent: falsy = True break else: x_absent = True if not ham_not_none(pnt.y): if y_absent: falsy = True break if not ham_not_none(pnt.t): if t_absent: falsy = True break if not falsy: ret_vars = [] if not x_absent: ret_vars.append(x) if not y_absent: ret_vars.append(y) if not t_absent: ret_vars.append(t) return ret_vars
def do_the_plot(self, u_fun, points, parametric=None, style=None): if ham_not_none(parametric): ham_error('HAM_ERROR_CRITICAL', 'CRITICAL__NOT_IMPLEMENTED_YET') if ham_not_none(style): self.style = style self._reset() self._set_fun(u_fun) self._set_points(points) self._set_parametric(parametric) self._preliminary_checks() self._build_data() self._plot()
def _build_ani_data(self): all_t_data = [] for point in self.points: # type: HamPoint t_data = TimeData() t_data.time = point.t t_data.data = [point.x] if ham_not_none(point.y): t_data.data.append(point.y) all_t_data.append(t_data) all_t_data.sort() curr_time = None curr_list = None for curr_t_data in all_t_data: if curr_t_data.time == curr_time: curr_list.append(curr_t_data) else: curr_time = curr_t_data.time curr_list = [curr_t_data] self.ani_data.append(curr_list) for curr_ani_data in self.ani_data: self.computed_ani_data.append( self._compute_ani_data(curr_ani_data))
def _build_static_data(self): for point in self.points: # type: HamPoint a_list = [point.x] if ham_not_none(point.y): a_list.append(point.y) self.data.append(a_list)