Пример #1
0
def test_sample_with_one_intervall():
    """
    Test the position and handling of the 21 sampling points.
    """
    e_test = 0.1
    a_test = 2.0
    a = -10
    b = 10

    x_exp = (kronrod21 + 1.0) / 2.0 * (b - a) + a
    lorentz_exp, lorentz_normed_exp = lorentz_approx(x_exp, e_test, a_test)

    sampler = MVFSampler(
        lorentz_approx,
        (e_test, a_test),
        (np.float64, np.float64),
        epsrel=1e-4,
        epsabs=1e-8,
        n_intervalls_max=1,
        do_sort=False,
    )
    xs, [lorentz, lorentz_normed] = sampler.eval_interval(a, b)

    print("n_intrvalls = {0}".format(sampler.n_intervalls))
    print("n_eval = {0}".format(sampler.n_samples))
    print("integral_value = {0}".format(sampler.integral_value))

    np.testing.assert_allclose(lorentz, lorentz_exp, rtol=3e-10, atol=1e-10)
    np.testing.assert_allclose(xs, x_exp, rtol=3e-10, atol=1e-10)
    np.testing.assert_allclose(lorentz_normed, lorentz_normed_exp, rtol=3e-10, atol=1e-10)
    assert_equal(sampler.n_intervalls, 1)
    assert_equal(sampler.n_samples, 21)
Пример #2
0
def test_sorting_sample():
    """
    Test the sorting of the sample.
    """
    e_test = 0.1
    a_test = 2.0
    a = -10
    b = 10

    x_exp = (kronrod21_sorted + 1.0) / 2.0 * (b - a) + a
    lorentz_exp, lorentz_normed_exp = lorentz_approx(x_exp, e_test, a_test)

    sampler = MVFSampler(
        lorentz_approx,
        (e_test, a_test),
        (np.float64, np.float64),
        epsrel=1e-4,
        epsabs=1e-8,
        n_intervalls_max=1,
        do_sort=True,
    )
    xs, [lorentz, lorentz_normed] = sampler.eval_interval(a, b)

    np.testing.assert_allclose(xs, x_exp)
    np.testing.assert_allclose(lorentz, lorentz_exp)
Пример #3
0
    def calc(self):

        k_vac = 2.*np.pi/self.wl
        n_e = self.N_top[0].real

        ow_h = self.stack.emitter.orientation_weights[0]
        ow_v = self.stack.emitter.orientation_weights[1]
        iqe = self.stack.emitter.iqe
        pfunc_args = (
            k_vac, n_e,
            self.stack.top.L, self.stack.bot.L,
            self.N_top, self.N_bot,
            self.mu_top, self.mu_bot,
            self.hs_top, self.hs_bot,
            ow_h, ow_v, self.radiationborder_cheatshift)
        try:
            u_points = (self.angular_range.get_array()).data
        except TypeError:
            # do adaptive sampling
            sampler = MVFSampler(
                self._get_p_func(), pfunc_args,
                (np.float32, np.complex64, np.float32, np.float32, np.float32),
                epsabs=0, epsrel=1e-7, n_intervalls_max=50, do_sort=True
            )
            sampler_result = sampler.eval_interval(
                self.angular_range.begin, self.angular_range.end)
        else:
            # do fixed sampling
            sampler = MVFFixedSampler(
                self._get_p_func(), pfunc_args,
                (np.float32, np.complex64, np.float32, np.float32, np.float32),
            )
            sampler_result = sampler.eval_points(u_points)

        self.us = sampler_result[0]
        self.p_u = sampler_result[1][0]
        self.we_u = sampler_result[1][1]
        self.p_hTE_u = sampler_result[1][2]
        self.p_hTM_u = sampler_result[1][3]
        self.p_vTM_u = sampler_result[1][4]
        self.P = sampler.integral_value

        self.f_u = self.p_u / ((1. - iqe) / iqe + self.P)
        self.f_hTE_u = self.p_hTE_u / ((1. - iqe) / iqe + self.P)
        self.f_hTM_u = self.p_hTM_u / ((1. - iqe) / iqe + self.P)
        self.f_vTM_u = self.p_vTM_u / ((1. - iqe) / iqe + self.P)
Пример #4
0
def test_integration_of_lorentz_delta():
    """
    Test the integration of the lorentz delta approximation.
    """
    e_test = 0.001
    a_test = 2.0
    a = -100
    b = 100

    i_exp = a_test * (np.arctan(b / e_test) - np.arctan(a / e_test)) / np.pi

    sampler = MVFSampler(
        lorentz_approx, (e_test, a_test), (np.float64, np.float64), epsrel=1e-6, epsabs=1e-6, do_sort=False
    )
    xs, [lorentz, lorentz_normed] = sampler.eval_interval(a, b)

    np.testing.assert_allclose(sampler.integral_value, i_exp, rtol=1e-6, atol=1e-6)