Example #1
0
 def test_set_derivative_vector_for_constant_nondiagonal_case(self):
     ode = Ode(coeff_matrix=self.COEFF_MATRIX_CONSTANT_NONDIAGONAL,
               init_condition=self.INIT_CONDITION_CONSTANT_NONDIAGONAL)
     actual = ode.set_derivative_vector(variable_vector=self.INIT_CONDITION_CONSTANT_NONDIAGONAL, actual_position=0,
                                        coeff_matrix=self.COEFF_MATRIX_CONSTANT_NONDIAGONAL, steps=self.STEPS)
     self.assertEqual(actual.size, self.EXPECTED_SIZE_3)
     npt.assert_almost_equal(actual, self.EXPECTED_DERIVATIVE_CONSTANT_NONDIAGONAL, self.DECIMALS_6)
Example #2
0
 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)
Example #3
0
 def solve_numerically(inputs):
     inp = inputs
     coeffmatrix = coefficientmatrix.CoefficientMatrix(inputs=inp)
     ode_init = Ode(coefficient_matrix=coeffmatrix.matrix,
                    initial_condition=inp.initial_condition,
                    steps=inp.steps)
     numerical = ode_init.calculate_solution()
     return numerical
Example #4
0
 def test_set_derivative_vector_for_varying_nondiagonal(self):
     ode = Ode(coeff_matrix=self.COEFF_MATRIX_VARYING_NONDIAGONAL,
               init_condition=self.INIT_CONDITION_VARYING_NONDIAGONAL)
     actual = ode.set_derivative_vector(variable_vector=self.INIT_CONDITION_VARYING_NONDIAGONAL,
                                        actual_position=self.STEPS_VARYING_NONDIAGONAL[1],
                                        coeff_matrix=self.COEFF_MATRIX_VARYING_NONDIAGONAL,
                                        steps=self.STEPS_VARYING_NONDIAGONAL)
     self.assertEqual(actual.size, self.EXPECTED_SIZE_2)
     npt.assert_almost_equal(actual, self.EXPECTED_DERIVATIVE_VARYING_NONDIAGONAL, self.DECIMALS_6)
Example #5
0
 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)
Example #6
0
 def test_calculate_analytical_solution_1d(self):
     for init in self.INIT_CONDITION_1D:
         for coefficient in self.COEFF_MATRIX_1D:
             ode = Ode(coeff_matrix=coefficient, init_condition=init)
             actual = ode.calculate_analytical_solution(self.STEPS)
             self.assertEqual(type(actual), numpy.ndarray)
             self.assertEqual(actual.size, self.EXPECTED_SIZE_100)
             for index, variable in enumerate(self.STEPS):
                 expected = ode.calculate_exp_solution(init, coefficient, variable)
                 self.assertIn(type(actual[index]), self.ACCEPTED_TYPES)
                 self.assertEqual(actual[index], expected)
Example #7
0
 def test_calculate_analytical_solution_for_constant_diagonal_case(self):
     ode = Ode(coeff_matrix=self.COEFF_MATRIX_CONSTANT_DIAGONAL, init_condition=self.INIT_CONDITION_GENERAL)
     actual = ode.calculate_analytical_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)
Example #8
0
    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
Example #9
0
 def test_calculate_analytical_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_analytical_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)
Example #10
0
 def test_set_derivative_vector_for_dimension_error(self):
     with self.assertRaises(ValueError):
         ode = Ode(coeff_matrix=self.COEFF_MATRIX_DIM_ERROR, init_condition=self.INIT_CONDITION_GENERAL)
         ode.set_derivative_vector(variable_vector=self.INIT_CONDITION_GENERAL, actual_position=self.START_POSITION,
                                   coeff_matrix=self.COEFF_MATRIX_DIM_ERROR, steps=self.STEPS)
Example #11
0
 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)