mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 13:53:40 +01:00
gf: imfreq. general case, fix python interface
- Fix constructor, now taking n_points like the positive_only case - Fix python, h5read, for general case (i.e. all frequencies).
This commit is contained in:
parent
2200e2680f
commit
b644b38a6a
@ -18,6 +18,7 @@ class GfImFreq ( GfGeneric, GfImFreq_cython ) :
|
||||
* ``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
|
||||
@ -40,9 +41,10 @@ class GfImFreq ( GfGeneric, GfImFreq_cython ) :
|
||||
if mesh is None :
|
||||
if 'beta' not in d : raise ValueError, "beta not provided"
|
||||
beta = float(d.pop('beta'))
|
||||
n_max = d.pop('n_points',1025)
|
||||
n_points = d.pop('n_points',1025)
|
||||
stat = d.pop('statistic','F')
|
||||
mesh = MeshImFreq(beta,stat,n_max)
|
||||
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)
|
||||
|
@ -11,9 +11,10 @@ cdef extern from "triqs/gfs/imfreq.hpp" namespace "triqs::gfs" :
|
||||
imfreq_domain & domain()
|
||||
double x_min()
|
||||
long size()
|
||||
bint positive_only()
|
||||
bint operator ==( mesh_imfreq &)
|
||||
|
||||
cdef mesh_imfreq make_mesh_imfreq "triqs::gfs::gf_mesh<triqs::gfs::imfreq>" (double beta, statistic_enum S, size_t n_max)
|
||||
cdef mesh_imfreq make_mesh_imfreq "triqs::gfs::gf_mesh<triqs::gfs::imfreq>" (double beta, statistic_enum S, size_t n_max, bint positive_only)
|
||||
#cdef mesh_imfreq make_mesh_imfreq "triqs::gfs::gf_implementation::gf_factories<triqs::gfs::imfreq,triqs::gfs::matrix>::make_mesh" (double beta, statistic_enum S, size_t n_max)
|
||||
|
||||
cdef cppclass gf_imfreq "triqs::python_tools::cython_proxy<triqs::gfs::gf_view<triqs::gfs::imfreq> >" :
|
||||
|
@ -1,8 +1,8 @@
|
||||
cdef class MeshImFreq:
|
||||
cdef mesh_imfreq _c
|
||||
|
||||
def __init__(self, beta, stat, int n_max):
|
||||
self._c = make_mesh_imfreq(beta,{'F' :Fermion, 'B' : Boson}[stat], n_max)
|
||||
def __init__(self, beta, stat, int n_pts, bint positive_only=True):
|
||||
self._c = make_mesh_imfreq(beta,{'F' :Fermion, 'B' : Boson}[stat], n_pts, positive_only)
|
||||
|
||||
def __len__ (self) : return self._c.size()
|
||||
|
||||
@ -28,6 +28,6 @@ cdef class MeshImFreq:
|
||||
|
||||
# C -> Python
|
||||
cdef inline make_MeshImFreq (mesh_imfreq x) :
|
||||
return MeshImFreq( x.domain().beta, 'F' if x.domain().statistic==Fermion else 'B', x.size() )
|
||||
return MeshImFreq( x.domain().beta, 'F' if x.domain().statistic==Fermion else 'B', x.size(), x.positive_only() )
|
||||
|
||||
|
||||
|
@ -48,6 +48,8 @@ namespace gfs {
|
||||
}
|
||||
};
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &out, matsubara_freq const &y) { return out << std::complex<double>(y); }
|
||||
|
||||
inline matsubara_freq operator+(matsubara_freq const &x, matsubara_freq const &y) {
|
||||
return {x.n + y.n + (x.statistic & y.statistic), x.beta, ((x.statistic ^ y.statistic) == 1 ? Fermion : Boson)};
|
||||
}
|
||||
|
@ -35,15 +35,15 @@ namespace gfs {
|
||||
using domain_pt_t = typename domain_t::point_t;
|
||||
|
||||
/// Constructor
|
||||
matsubara_freq_mesh() : _dom(), n_max(0), _positive_only(true) {}
|
||||
matsubara_freq_mesh() : _dom(), _n_pts(0), _positive_only(true) {}
|
||||
|
||||
/// Constructor
|
||||
matsubara_freq_mesh(domain_t dom, int n_pts=1025, bool positive_only = true)
|
||||
: _dom(std::move(dom)), n_max(n_pts), _positive_only(positive_only) {}
|
||||
: _dom(std::move(dom)), _n_pts(n_pts), _positive_only(positive_only) {}
|
||||
|
||||
/// Constructor
|
||||
matsubara_freq_mesh(double beta, statistic_enum S, int Nmax = 1025, bool positive_only = true)
|
||||
: matsubara_freq_mesh({beta, S}, Nmax, positive_only) {}
|
||||
matsubara_freq_mesh(double beta, statistic_enum S, int n_pts = 1025, bool positive_only = true)
|
||||
: matsubara_freq_mesh({beta, S}, n_pts, positive_only) {}
|
||||
|
||||
/// Copy constructor
|
||||
matsubara_freq_mesh(matsubara_freq_mesh const &) = default;
|
||||
@ -55,13 +55,13 @@ namespace gfs {
|
||||
*
|
||||
* 0 if positive_only is true
|
||||
* else :
|
||||
* For fermions : -Nmax +1
|
||||
* For fermions : -Nmax - 1
|
||||
* For Bosons : -Nmax
|
||||
**/
|
||||
int index_start() const { return -(_positive_only ? 0 : n_max + (_dom.statistic == Fermion)); }
|
||||
int index_start() const { return -(_positive_only ? 0 : n_max() + (_dom.statistic == Fermion)); }
|
||||
|
||||
/// Size (linear) of the mesh
|
||||
long size() const { return (_positive_only ? n_max : 2 * n_max + (_dom.statistic == Boson ? 1 : 2)); }
|
||||
long size() const { return _n_pts;}
|
||||
|
||||
/// From an index of a point in the mesh, returns the corresponding point in the domain
|
||||
domain_pt_t index_to_point(index_t ind) const { return 1_j * M_PI * (2 * ind + (_dom.statistic == Fermion)) / _dom.beta; }
|
||||
@ -107,7 +107,7 @@ namespace gfs {
|
||||
const_iterator cend() const { return const_iterator(this, true); }
|
||||
|
||||
bool operator==(matsubara_freq_mesh const &M) const {
|
||||
return (std::make_tuple(_dom, n_max, _positive_only, n_max) == std::make_tuple(M._dom, M.n_max, M._positive_only, n_max));
|
||||
return (std::make_tuple(_dom, _n_pts, _positive_only) == std::make_tuple(M._dom, M._n_pts, M._positive_only));
|
||||
}
|
||||
bool operator!=(matsubara_freq_mesh const &M) const { return !(operator==(M)); }
|
||||
|
||||
@ -143,7 +143,7 @@ namespace gfs {
|
||||
/// BOOST Serialization
|
||||
template <class Archive> void serialize(Archive &ar, const unsigned int version) {
|
||||
ar &boost::serialization::make_nvp("domain", _dom);
|
||||
ar &boost::serialization::make_nvp("size", n_max);
|
||||
ar &boost::serialization::make_nvp("size", _n_pts);
|
||||
ar &boost::serialization::make_nvp("kind", _positive_only);
|
||||
}
|
||||
|
||||
@ -154,7 +154,8 @@ namespace gfs {
|
||||
|
||||
private:
|
||||
domain_t _dom;
|
||||
int n_max;
|
||||
int _n_pts;
|
||||
long n_max() const { return (_positive_only ? _n_pts : (_n_pts - (_dom.statistic == Boson ? 1 : 2))/2);}
|
||||
bool _positive_only;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user