コード例 #1
0
ファイル: ode.py プロジェクト: srmagura/potential
def calc_z1_fourier(initial_func, d_initial_func, eval_f1, a, nu, k, R0, R, M):
    arc_dst = lambda func: fourier.arc_dst(a, func, N=fourier_N)

    my_print('R0: {}'.format(R0))
    my_print('tol: {}'.format(atol))
    my_print('mxstep: {}'.format(mxstep))

    # Estimate the accuracy of the DFT
    r = R
    d1 = arc_dst(lambda th: eval_f1(r, th))[:M]
    d2 = fourier.arc_dst(a, lambda th: eval_f1(r, th), N=8192)[:M]
    my_print('Fourier discretization error: {}'.format(np.max(np.abs(d1-d2))))

    global n_dst
    n_dst = 0

    def eval_deriv(Y, r):
        global n_dst
        assert r != 0

        n_dst += 1

        f_fourier = arc_dst(lambda th: eval_f1(r, th))[:M]

        derivs = np.zeros(2*M)
        for i in range(0, 2*M, 2):
            m = i//2+1
            z1 = Y[i]
            z2 = Y[i+1]

            derivs[i] = z2
            derivs[i+1] = -z2/r - (k**2 - (m*nu/r)**2) * z1 + f_fourier[m-1]

        return np.array(derivs)

    initial_fourier = arc_dst(lambda th: initial_func(R0, th))[:M]
    d_initial_fourier = arc_dst(lambda th: d_initial_func(R0, th))[:M]

    ic = np.zeros(2*M)
    for i in range(0, 2*M, 2):
        m = i//2+1
        ic[i] = initial_fourier[m-1]
        ic[i+1] = d_initial_fourier[m-1]

    sol = odeint(eval_deriv, ic, [R0, R], atol=atol, rtol=rtol, mxstep=mxstep)
    my_print('Number of dst: {}'.format(n_dst))

    # Fourier coefficients at r=R
    return sol[1, 0::2]
コード例 #2
0
ファイル: zmethod.py プロジェクト: srmagura/potential
    def get_expected_a_coef(self):
        if self.problem.name == 'iz-bessel':
            return np.zeros(self.M)

        # Arc only
        r = self.problem.R

        def eval_bc0(th):
            return self.problem.eval_phi0(th) - self.problem.eval_v(r, th)

        def eval_diff(th):
            return self.problem.eval_v(r, th) - self.v_interp(r, th)

        interp_error = arc_dst(self.a, eval_diff)[:self.M]
        print('b interp error:')
        print(interp_error)
        print()

        b_coef = arc_dst(self.a, eval_bc0)[:self.M]
        return abcoef.b_to_a(b_coef, self.k, self.problem.R, self.nu)
コード例 #3
0
ファイル: singular.py プロジェクト: srmagura/potential
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        if 'to_dst' in kwargs:
            self.to_dst = kwargs.pop('to_dst')
        else:
            self.to_dst = lambda th: 0

        self.fft_b_coef = fourier.arc_dst(self.a, self.to_dst)[:self.m_max]
        self.fft_a_coef = abcoef.b_to_a(self.fft_b_coef, self.k,
            self.R, self.nu)
コード例 #4
0
ファイル: zmethod.py プロジェクト: srmagura/potential
    def get_expected_z1_fourier(self):
        """
        Compute the expected Fourier coefficients of z1 from
        z1 = v - (v_asympt g + q)

        For checking the accuracy of the ODE method or
        skipping the ODE method during testing
        """
        R = self.arc_R

        def z1_expected(th):
            return self.problem.eval_v(R, th) - self.eval_gq(R, th)

        # This should be close to 0
        return arc_dst(self.a, z1_expected)[:self.M]