def compute_error(self, state, **kwargs): super(SdcSolverCore, self).compute_error(state, **kwargs) assert_named_argument('problem', kwargs, types=IProblem, descriptor="Problem", checking_obj=self) _problem = kwargs['problem'] if problem_has_exact_solution(_problem, self): # LOG.debug("Error for t={:.3f}: {} - {}".format(state.current_step.time_point, # state.current_step.value, # _problem.exact(state.current_step.time_point))) state.current_step.solution.error = Error( abs(state.current_step.value - _problem.exact(state.current_step.time_point)) ) else: # we need the exact solution for that # (unless we find an error approximation method) pass
def test_problem_has_exact_solution_introspection(self): self.assertTrue(problem_has_exact_solution(self._default)) self.assertFalse(problem_has_exact_solution(IProblem()))