Exemplo n.º 1
0
def laguerre_integral(f, x_scale, degree=LAGDEGREE):
    lag_x, lag_w = laggauss(degree)
    if np.isscalar(x_scale):
        scaled_x = lag_x / x_scale
    elif len(x_scale.shape) == 1:
        scaled_x = lag_x[:,None] / x_scale[None,:]
    return lag_w @ f(scaled_x)
Exemplo n.º 2
0
    def laguerre(self, nb, ifsort=True):
        assert nb <= 100

        omega_value, w = la.laggauss(nb)
        omega_value *= self.omega_c
        c_j2 = w * self.alpha * self.omega_c * omega_value**2

        return self.post_process(omega_value, c_j2, ifsort)
Exemplo n.º 3
0
def laguerre_double_integral(f, x_scale, degree=LAGDEGREE):
    lag_x, lag_w = laggauss(degree)
    if np.isscalar(x_scale):
        scaled_x = lag_x / x_scale
        F = f(scaled_x[:,None], scaled_x[None,:])
        print(F)
    else:
        scaled_x = lag_x[None,:] / x_scale[:,None]
        F = f(scaled_x[:,:,None,None], scaled_x[None,None,:,:])
    return lag_w @ (F @ lag_w)
Exemplo n.º 4
0
    def points_and_weights(self, N=None, map_true_domain=False):
        if N is None:
            N = self.N
        if self.quad == "LG":
            points, weights = lag.laggauss(N)
            weights *= np.exp(points)
        else:
            raise NotImplementedError

        return points, weights
Exemplo n.º 5
0
    def __init__(self, alpha, npts):

        warn("This class is deprecated")
        if alpha <= 0:
            raise Exception("negative alpha")

        self.npts = npts
        self.alpha = alpha

        # transform the ordinary GL quad
        lagg_pts, lagg_wts = laguerre.laggauss(npts)

        self.pts = np.sqrt(lagg_pts / alpha)
        self.wts = 0.5 * lagg_wts / alpha
Exemplo n.º 6
0
    def test_100(self):
        x, w = lag.laggauss(100)

        # test orthogonality. Note that the results need to be normalized,
        # otherwise the huge values that can arise from fast growing
        # functions like Laguerre can be very confusing.
        v = lag.lagvander(x, 99)
        vv = np.dot(v.T * w, v)
        vd = 1/np.sqrt(vv.diagonal())
        vv = vd[:, None] * vv * vd
        assert_almost_equal(vv, np.eye(100))

        # check that the integral of 1 is correct
        tgt = 1.0
        assert_almost_equal(w.sum(), tgt)
Exemplo n.º 7
0
    def test_100(self):
        x, w = lag.laggauss(100)

        # test orthogonality. Note that the results need to be normalized,
        # otherwise the huge values that can arise from fast growing
        # functions like Laguerre can be very confusing.
        v = lag.lagvander(x, 99)
        vv = np.dot(v.T * w, v)
        vd = 1 / np.sqrt(vv.diagonal())
        vv = vd[:, None] * vv * vd
        assert_almost_equal(vv, np.eye(100))

        # check that the integral of 1 is correct
        tgt = 1.0
        assert_almost_equal(w.sum(), tgt)
Exemplo n.º 8
0
  #K=int(raw_input("Enter sparsity value: "))

  N = 200
  K = 10

  mp.dps = 30   # set high precision to 30 

  avg_x = np.vectorize(avg_x)
  avg_x2 = np.vectorize(avg_x2)


  Leg = leg.leggauss(100)
  roots_leg = Leg[0]
  weights_leg = Leg[1]

  Lag = lag.laggauss(100)
  roots_lag = Lag[0]
  weights_lag = Lag[1]  


  mu = 0
  sigma2 = .001           # \sigma parameter I vary sigma2 rather than lamda as I found making smaller lambda doesnt lead to a convergent result
  sigmax02 =1.
  lamda = 1.               #\lambda parameter

  M = K
  while(M<=N):


      ##############
      #producing sample sparse array
Exemplo n.º 9
0
def int_lag_gauss(func, args=(), deg=100):
    x, w = laggauss(deg)
    res = 0
    for i in range(deg):
        res += func(x[i], *args) * w[i]
    return res
Exemplo n.º 10
0
def sommerfeld_parameter(
        T: Union[float, np.ndarray],
        Z: int,
        m_eff: float,
        eps0: float,
        method: str = 'Integrate') -> Union[float, np.ndarray]:
    """Compute the sommerfeld parameter.

    Computes the sommerfeld parameter at a given temperature using the
    definitions in R. Pässler et al., phys. stat. sol. (b) 78, 625 (1976). We
    assume that theta_{b,i}(T) ~ T.

    Parameters
    ----------
    T : float, np.array(dtype=float)
        temperature in K
    Z : int
        Z = Q / q where Q is the charge of the defect and q is the charge of
        the carrier. Z < 0 corresponds to attractive centers and Z > 0
        corresponds to repulsive centers
    m_eff : float
        effective mass of the carrier in units of m_e (electron mass)
    eps0 : float
        static dielectric constant
    method : str
        specify method for evaluating sommerfeld parameter ('Integrate' or
        'Analytic'). The default is recommended as the analytic equation may
        introduce significant errors for the repulsive case at high T.

    Returns
    -------
    float, np.array(dtype=float)
        sommerfeld factor evaluated at the given temperature
    """
    if Z == 0:
        return 1.

    if method.lower()[0] == 'i':
        kT = const.k * T
        m = m_eff * const.m_e
        eps = (4 * np.pi * const.epsilon_0) * eps0
        f = -2 * np.pi * Z * m * const.e**2 / const.hbar**2 / eps

        def s_k(k):
            return f / k / (1 - np.exp(-f / k))

        t = 0.
        x, w = laggauss(64)
        for ix, iw in zip(x, w):
            t += iw * np.sqrt(ix) * s_k(np.sqrt(2 * m * kT * ix) / const.hbar)
        return t / np.sum(w * np.sqrt(x))

    # that 4*pi from Gaussian units....
    theta_b = np.pi**2 * (m_eff * const.m_e) * const.e**4 / \
        (2 * const.k * const.hbar**2 * (eps0 * 4*np.pi*const.epsilon_0)**2)
    zthetaT = Z**2 * theta_b / T

    if Z < 0:
        return 4 * np.sqrt(zthetaT / np.pi)
    return (8 / np.sqrt(3)) * \
        zthetaT**(2/3) * np.exp(-3 * zthetaT**(1/3))
Exemplo n.º 11
0
N = 15  # gaussian nodes
M = 50  # Grid points
L = 12.0  # range of grid
p0 = 2.3
Lambda = 1.0
pi = 3.14159265358979323846


def sort_list(list1, list2):
    zipped_pairs = zip(list2, list1)
    z = [x for _, x in sorted(zipped_pairs)]
    return z


root = lag.laggauss(N)[0]

node = np.array(
    [i * L / (M - 1) + p0 for i in range(M)]
)  # np.array([L/2*cos(pi*i/(M-1)) + p0 + L/2 for i in range(M)]) #np.array([i*L/(M-1) + p0 for i in range(M)])

x = np.concatenate((root, node), axis=None)

function = np.loadtxt("data_cpd.txt")
sigma = function[2 * (N + M):3 * (N + M)]
pii = function[(5 * (N + M) + 1):(6 * (N + M) + 1)]
sigma1 = sort_list(sigma, x)
pii1 = sort_list(pii, x)
x = np.sort(x)
#print(function)
print(sigma)