示例#1
0
    def __init__(self, **d):
        """
        The constructor have two variants : you can either provide the mesh in
        Matsubara frequencies yourself, or give the parameters to build it.
        All parameters must be given with keyword arguments.

        GfImFreq(indices, beta, statistic, n_points, data, tail, name)

              * ``indices``:  a list of indices names of the block
              * ``beta``:  Inverse Temperature
              * ``statistic``:  'F' or 'B'
              * ``positive_only``:  True or False
              * ``n_points``:  Number of Matsubara frequencies
              * ``data``:   A numpy array of dimensions (len(indices),len(indices),n_points) representing the value of the Green function on the mesh.
              * ``tail``:  the tail
              * ``name``:  a name of the GF

        GfImFreq(indices, mesh, data, tail, name)

              * ``indices``:  a list of indices names of the block
              * ``mesh``:  a MeshGf object, such that mesh.TypeGF== GF_Type.Imaginary_Frequency
              * ``data``:   A numpy array of dimensions (len(indices),len(indices),:) representing the value of the Green function on the mesh.
              * ``tail``:  the tail
              * ``name``:  a name of the GF

        .. warning::

          The Green function take a **view** of the array data, and a **reference** to the tail.

        """
        mesh = d.pop('mesh', None)
        if mesh is None:
            if 'beta' not in d: raise ValueError, "beta not provided"
            beta = float(d.pop('beta'))
            n_points = d.pop('n_points', 1025)
            stat = d.pop('statistic', 'F')
            positive_only = d.pop('positive_only', True)
            mesh = MeshImFreq(beta, stat, n_points, positive_only)

        self.dtype = numpy.complex_
        indices_pack = get_indices_in_dict(d)
        indicesL, indicesR = indices_pack
        N1, N2 = len(indicesL), len(indicesR)
        data = d.pop('data') if 'data' in d else numpy.zeros(
            (len(mesh), N1, N2), self.dtype)
        tail = d.pop('tail') if 'tail' in d else TailGf(shape=(N1, N2))
        symmetry = d.pop('symmetry', Nothing())
        name = d.pop('name', 'g')
        assert len(
            d
        ) == 0, "Unknown parameters in GFBloc constructions %s" % d.keys()

        GfGeneric.__init__(self, mesh, data, tail, symmetry, indices_pack,
                           name, GfImFreq)
        GfImFreq_cython.__init__(self, mesh, data, tail)
示例#2
0
    def __init__(self, **d):
        """
        The constructor have two variants : you can either provide the mesh in
        Matsubara frequencies yourself, or give the parameters to build it.
        All parameters must be given with keyword arguments.

        GfReTime(indices, window, n_points, data, tail, name)

              * ``indices``:  a list of indices names of the block
              * ``window``:  a tuple (t_min, t_max)
              * ``n_points``  : Number of time points in the mesh
              * ``data``:   A numpy array of dimensions (len(indices),len(indices),n_points) representing the value of the Green function on the mesh.
              * ``tail``:  the tail
              * ``name``:  a name of the GF

        GfReTime (indices, mesh, data, tail, name)

              * ``indices``:  a list of indices names of the block
              * ``mesh``:  a MeshGf object, such that mesh.TypeGF== GF_Type.Imaginary_Time
              * ``data``:   A numpy array of dimensions (len(indices),len(indices),n_points) representing the value of the Green function on the mesh.
              * ``tail``:  the tail
              * ``name``:  a name of the GF

        .. warning::

          The Green function take a **view** of the array data, and a **reference** to the tail.

        """
        mesh = d.pop('mesh', None)
        if mesh is None:
            window = d.pop('window')
            t_min = window[0]
            t_max = window[1]
            n_max = d.pop('n_points', 10000)
            kind = d.pop('kind', 'F')
            mesh = MeshReTime(t_min, t_max, n_max, kind)

        self.dtype = numpy.complex_
        indices_pack = get_indices_in_dict(d)
        indicesL, indicesR = indices_pack
        N1, N2 = len(indicesL), len(indicesR)
        data = d.pop('data') if 'data' in d else numpy.zeros(
            (len(mesh), N1, N2), self.dtype)
        tail = d.pop('tail') if 'tail' in d else TailGf(shape=(N1, N2))
        symmetry = d.pop('symmetry', None)
        name = d.pop('name', 'g')
        assert len(
            d
        ) == 0, "Unknown parameters in GFBloc constructions %s" % d.keys()

        GfGeneric.__init__(self, mesh, data, tail, symmetry, indices_pack,
                           name, GfReTime)
        GfReTime_cython.__init__(self, mesh, data, tail)
示例#3
0
 def __sub_isub_impl (self, lhs,  arg, is_sub):
     d, t, rhs = lhs.data, lhs.tail,None
     if type(lhs) == type(arg):
         d[:,:,:] -= arg.data
         t -= arg.tail
     elif isinstance(arg, numpy.ndarray): # an array considered as a constant function
         MatrixStack(lhs.data).sub(arg)
         rhs = arg
     elif descriptors.is_scalar(arg): # just a scalar
         arg = arg*numpy.identity(lhs.N1,dtype = lhs.data.dtype )
         MatrixStack(lhs.data).sub(arg)
         assert lhs.tail.shape[0] == lhs.tail.shape[1], "tail - scalar only valid in diagonal case"
         rhs = numpy.identity(lhs.tail.shape[0]) *arg
     else:
         raise RuntimeError, " argument type not recognized in -= for %s"%arg
     if rhs !=None :
         new_tail = TailGf(shape=lhs.tail.shape)
         new_tail[0][:,:] = rhs
         if is_sub : lhs._singularity = lhs.tail - new_tail
         else : lhs.tail = lhs.tail - new_tail
     return lhs
示例#4
0
def tail_fit(Sigma_iw,
             G0_iw=None,
             G_iw=None,
             fit_min_n=None,
             fit_max_n=None,
             fit_min_w=None,
             fit_max_w=None,
             fit_max_moment=None,
             fit_known_moments=None):
    """
    Fit the tails of Sigma_iw and optionally G_iw.

    Parameters
    ----------
    Sigma_iw : Gf
               Self-energy.
    G0_iw : Gf, optional
            Non-interacting Green's function.
    G_iw : Gf, optional
           Interacting Green's function.
           If G0_iw and G_iw are provided, the tails of G_iw will also be fitted.
    fit_min_n : int, optional, default=int(0.8*len(Sigma_iw.mesh))
                Matsubara frequency index from which tail fitting should start.
    fit_max_n : int, optional, default=int(len(Sigma_iw.mesh))
                Matsubara frequency index at which tail fitting should end.
    fit_min_w : float, optional
                Matsubara frequency from which tail fitting should start.
    fit_max_w : float, optional
                Matsubara frequency at which tail fitting should end.
    fit_max_moment : int, optional
                     Highest moment to fit in the tail of Sigma_iw.
    fit_known_moments : dict{str:TailGf object}, optional, default = {block_name: TailGf(dim1, dim2, max_moment=0, order_min=0)}
                        Known moments of Sigma_iw, given as a TailGf object.

    Returns
    -------
    Sigma_iw : Gf
               Self-energy.
    G_iw : Gf, optional
           Interacting Green's function.
    """

    # Define default tail quantities
    if fit_known_moments is None:
        fit_known_moments = {
            name: TailGf(sig.N1, sig.N2, 0, 0)
            for name, sig in Sigma_iw
        }
    if fit_min_w is not None:
        fit_min_n = int(0.5 * (fit_min_w * Sigma_iw.mesh.beta / np.pi - 1.0))
    if fit_max_w is not None:
        fit_max_n = int(0.5 * (fit_max_w * Sigma_iw.mesh.beta / np.pi - 1.0))
    if fit_min_n is None: fit_min_n = int(0.8 * len(Sigma_iw.mesh) / 2)
    if fit_max_n is None: fit_max_n = int(len(Sigma_iw.mesh) / 2)
    if fit_max_moment is None: fit_max_moment = 3

    # Now fit the tails of Sigma_iw and G_iw
    for name, sig in Sigma_iw:
        sig.fit_tail(fit_known_moments[name], fit_max_moment, fit_min_n,
                     fit_max_n)
    if (G_iw is not None) and (G0_iw is not None):
        for name, g in G_iw:
            g.tail = inverse(inverse(G0_iw[name].tail) - Sigma_iw[name].tail)

    return Sigma_iw, G_iw