def test_benchmark_solvers_for_constant_diagonal_case(self): ode = Ode(coeff_matrix=self.COEFF_MATRIX_CONSTANT_DIAGONAL, init_condition=self.INIT_CONDITION_GENERAL) numerical = ode.calculate_numerical_solution(self.STEPS) analytical = ode.calculate_analytical_solution(self.STEPS) self.assertEqual(numerical.size, self.EXPECTED_SIZE_200) self.assertEqual(analytical.size, self.EXPECTED_SIZE_200) npt.assert_almost_equal(numerical, analytical, self.DECIMALS_6)
def test_calculate_numerical_solution_for_constant_nondiagonal_case(self): ode = Ode(coeff_matrix=self.COEFF_MATRIX_CONSTANT_NONDIAGONAL, init_condition=self.INIT_CONDITION_CONSTANT_NONDIAGONAL) actual = ode.calculate_numerical_solution(self.STEPS) self.assertEqual(actual.size, self.STEP_NUMBER * self.INIT_CONDITION_CONSTANT_NONDIAGONAL.size) self.assertEqual(actual.shape, (self.STEP_NUMBER, self.INIT_CONDITION_CONSTANT_NONDIAGONAL.size)) for index in range(self.INIT_CONDITION_CONSTANT_NONDIAGONAL.size): self.assertIn(type(actual[-1, index]), self.ACCEPTED_TYPES) self.assertAlmostEqual(actual[-1, index], self.EXPECTED_RESULT_CONSTANT_NONDIAGONAL[index], self.DECIMALS_6)
def test_calculate_numerical_solution_for_constant_diagonal_case(self): ode = Ode(coeff_matrix=self.COEFF_MATRIX_CONSTANT_DIAGONAL, init_condition=self.INIT_CONDITION_GENERAL) actual = ode.calculate_numerical_solution(self.STEPS) self.assertEqual(type(actual), numpy.ndarray) self.assertEqual(actual.size, self.EXPECTED_SIZE_200) for i in range(self.STEP_NUMBER): for j in range(self.INIT_CONDITION_GENERAL.size): expected = ode.calculate_exp_solution(self.INIT_CONDITION_GENERAL[j], self.COEFF_MATRIX_CONSTANT_DIAGONAL[j, j], self.STEPS[i]) self.assertIn(type(actual[i, j]), self.ACCEPTED_TYPES) self.assertAlmostEqual(actual[i, j], expected, self.DECIMALS_6)
def __solve_numerically(self): if self.coefficient_matrix is None or self.initial_condition is None: self.__initialize_ode() ode = Ode(coeff_matrix=self.coefficient_matrix.matrix, init_condition=self.initial_condition) numerical = ode.calculate_numerical_solution( self.profiles['beamlet grid']['distance']['m']) for level in range(self.atomic_db.atomic_ceiling): label = 'level ' + self.atomic_db.inv_atomic_dict[level] self.profiles[label] = numerical[:, level] return
def test_calculate_numerical_solution_for_varying_nondiagonal_case(self): ode = Ode(coeff_matrix=self.COEFF_MATRIX_VARYING_NONDIAGONAL, init_condition=self.INIT_CONDITION_VARYING_NONDIAGONAL) actual = ode.calculate_numerical_solution(self.STEPS_VARYING_NONDIAGONAL) self.assertEqual(type(actual), numpy.ndarray) self.assertEqual(actual.size, self.STEPS_VARYING_NONDIAGONAL.size * self.INIT_CONDITION_VARYING_NONDIAGONAL.size) self.assertEqual(actual.shape, (self.STEPS_VARYING_NONDIAGONAL.size, self.INIT_CONDITION_VARYING_NONDIAGONAL.size)) npt.assert_almost_equal(actual, self.EXPECTED_RESULT_VARYING_NONDIAGONAL, self.DECIMALS_6) for i in range(self.STEPS_VARYING_NONDIAGONAL.size): for j in range(self.INIT_CONDITION_VARYING_NONDIAGONAL.size): self.assertIn(type(actual[i, j]), self.ACCEPTED_TYPES)
def test_benchmark_solvers_for_varying_nondiagonal_case(self): ode = Ode(coeff_matrix=self.COEFF_MATRIX_VARYING_NONDIAGONAL, init_condition=self.INIT_CONDITION_VARYING_NONDIAGONAL) numerical = ode.calculate_numerical_solution(self.STEPS_VARYING_NONDIAGONAL) analytical = ode.calculate_numerical_solution(self.STEPS_VARYING_NONDIAGONAL) npt.assert_almost_equal(numerical, analytical, self.DECIMALS_6)