2013-11-05 08:56:42 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 by O. Parcollet
|
|
|
|
*
|
|
|
|
* TRIQS is free software: you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* TRIQS. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include "./mesh_tools.hpp"
|
|
|
|
#include "../domains/matsubara.hpp"
|
|
|
|
|
|
|
|
namespace triqs {
|
|
|
|
namespace gfs {
|
|
|
|
|
|
|
|
struct matsubara_freq_mesh {
|
|
|
|
|
2013-12-30 22:31:36 +01:00
|
|
|
///
|
2013-11-05 08:56:42 +01:00
|
|
|
using domain_t = matsubara_domain<true>;
|
2013-12-30 22:31:36 +01:00
|
|
|
///
|
|
|
|
using index_t = long;
|
|
|
|
///
|
2013-11-05 08:56:42 +01:00
|
|
|
using domain_pt_t = typename domain_t::point_t;
|
|
|
|
|
2013-12-30 22:31:36 +01:00
|
|
|
/// Constructor
|
2013-11-05 08:56:42 +01:00
|
|
|
matsubara_freq_mesh() : _dom(), n_max(0), _positive_only(true) {}
|
|
|
|
|
2013-12-30 22:31:36 +01:00
|
|
|
/// Constructor
|
|
|
|
matsubara_freq_mesh(domain_t dom, int n_pts=1025, bool positive_only = true)
|
2013-11-05 08:56:42 +01:00
|
|
|
: _dom(std::move(dom)), n_max(n_pts), _positive_only(positive_only) {}
|
|
|
|
|
2013-12-30 22:31:36 +01:00
|
|
|
/// Constructor
|
|
|
|
matsubara_freq_mesh(double beta, statistic_enum S, int Nmax = 1025, bool positive_only = true)
|
|
|
|
: matsubara_freq_mesh({beta, S}, Nmax, positive_only) {}
|
|
|
|
|
|
|
|
/// Copy constructor
|
|
|
|
matsubara_freq_mesh(matsubara_freq_mesh const &) = default;
|
|
|
|
|
|
|
|
/// The corresponding domain
|
2013-11-05 08:56:42 +01:00
|
|
|
domain_t const &domain() const { return _dom; }
|
2013-12-30 22:31:36 +01:00
|
|
|
|
|
|
|
/** \brief First value of the index
|
|
|
|
*
|
|
|
|
* 0 if positive_only is true
|
|
|
|
* else :
|
|
|
|
* For fermions : -Nmax +1
|
|
|
|
* For Bosons : -Nmax
|
|
|
|
**/
|
2013-12-17 15:09:34 +01:00
|
|
|
int index_start() const { return -(_positive_only ? 0 : n_max + (_dom.statistic == Fermion)); }
|
2013-11-05 08:56:42 +01:00
|
|
|
|
2013-12-30 22:31:36 +01:00
|
|
|
/// Size (linear) of the mesh
|
|
|
|
long size() const { return (_positive_only ? n_max : 2 * n_max + (_dom.statistic == Boson ? 1 : 2)); }
|
|
|
|
|
|
|
|
/// From an index of a point in the mesh, returns the corresponding point in the domain
|
2014-01-05 16:56:41 +01:00
|
|
|
domain_pt_t index_to_point(index_t ind) const { return 1_j * M_PI * (2 * ind + (_dom.statistic == Fermion)) / _dom.beta; }
|
2013-11-05 08:56:42 +01:00
|
|
|
|
2013-12-30 22:31:36 +01:00
|
|
|
/// Flatten the index in the positive linear index for memory storage (almost trivial here).
|
2014-01-05 20:10:33 +01:00
|
|
|
long index_to_linear(index_t ind) const { return ind - index_start(); }
|
2013-11-05 08:56:42 +01:00
|
|
|
|
2014-01-06 17:46:09 +01:00
|
|
|
/// Is the mesh only for positive omega_n (G(tau) real))
|
|
|
|
bool positive_only() const { return _positive_only;}
|
|
|
|
|
2013-12-30 22:31:36 +01:00
|
|
|
/**
|
|
|
|
* The mesh point
|
|
|
|
*
|
|
|
|
* * NB : the mesh point is also in this case a matsubara_freq.
|
|
|
|
**/
|
2013-11-20 15:11:29 +01:00
|
|
|
struct mesh_point_t : tag::mesh_point, matsubara_freq {
|
|
|
|
mesh_point_t() = default;
|
2013-11-05 08:56:42 +01:00
|
|
|
mesh_point_t(matsubara_freq_mesh const &mesh, index_t const &index_)
|
2013-12-17 15:09:34 +01:00
|
|
|
: matsubara_freq(index_, mesh.domain().beta, mesh.domain().statistic),
|
|
|
|
index_start(mesh.index_start()),
|
|
|
|
index_stop(mesh.index_start() + mesh.size() - 1) {}
|
2014-01-05 20:10:33 +01:00
|
|
|
mesh_point_t(matsubara_freq_mesh const &mesh) : mesh_point_t(mesh, mesh.index_start()) {}
|
2013-11-05 08:56:42 +01:00
|
|
|
void advance() { ++n; }
|
2014-01-05 20:10:33 +01:00
|
|
|
long linear_index() const { return n - index_start; }
|
2013-12-30 22:31:36 +01:00
|
|
|
long index() const { return n; }
|
2013-12-17 15:09:34 +01:00
|
|
|
bool at_end() const { return (n == index_stop); }
|
|
|
|
void reset() { n = index_start; }
|
2013-12-30 22:31:36 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
index_t index_start, index_stop;
|
2013-11-05 08:56:42 +01:00
|
|
|
};
|
|
|
|
|
2013-12-30 22:31:36 +01:00
|
|
|
/// Accessing a point of the mesh from its index
|
|
|
|
mesh_point_t operator[](index_t i) const {
|
|
|
|
return {*this, i};
|
|
|
|
}
|
2013-11-05 08:56:42 +01:00
|
|
|
|
|
|
|
/// Iterating on all the points...
|
|
|
|
using const_iterator = mesh_pt_generator<matsubara_freq_mesh>;
|
|
|
|
const_iterator begin() const { return const_iterator(this); }
|
|
|
|
const_iterator end() const { return const_iterator(this, true); }
|
|
|
|
const_iterator cbegin() const { return const_iterator(this); }
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
bool operator!=(matsubara_freq_mesh const &M) const { return !(operator==(M)); }
|
|
|
|
|
|
|
|
/// Write into HDF5
|
|
|
|
friend void h5_write(h5::group fg, std::string subgroup_name, matsubara_freq_mesh const &m) {
|
|
|
|
h5::group gr = fg.create_group(subgroup_name);
|
|
|
|
h5_write(gr, "domain", m.domain());
|
|
|
|
h5_write(gr, "size", m.size());
|
2013-12-17 15:09:34 +01:00
|
|
|
if (m._positive_only) {
|
2013-12-30 22:31:36 +01:00
|
|
|
// kept ONLY for backward compatibility of archives
|
2013-12-17 15:09:34 +01:00
|
|
|
auto beta = m.domain().beta;
|
|
|
|
h5_write(gr, "min", Fermion ? M_PI / beta : 0);
|
|
|
|
h5_write(gr, "max", ((Fermion ? 1 : 0) + 2 * m.size()) * M_PI / beta);
|
|
|
|
h5_write(gr, "kind", 2);
|
|
|
|
} else { // A strange way : to preserve backward compatibility for old archive.
|
|
|
|
h5_write(gr, "start_at_0", m._positive_only);
|
|
|
|
}
|
2013-11-05 08:56:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Read from HDF5
|
|
|
|
friend void h5_read(h5::group fg, std::string subgroup_name, matsubara_freq_mesh &m) {
|
|
|
|
h5::group gr = fg.open_group(subgroup_name);
|
|
|
|
typename matsubara_freq_mesh::domain_t dom;
|
|
|
|
int L;
|
|
|
|
bool s = true;
|
|
|
|
h5_read(gr, "domain", dom);
|
|
|
|
h5_read(gr, "size", L);
|
2013-12-17 15:09:34 +01:00
|
|
|
if (gr.has_key("start_at_0")) h5_read(gr, "start_at_0", s);
|
2013-11-05 08:56:42 +01:00
|
|
|
m = matsubara_freq_mesh{std::move(dom), L, s};
|
|
|
|
}
|
|
|
|
|
|
|
|
friend class boost::serialization::access;
|
2013-12-30 22:31:36 +01:00
|
|
|
/// BOOST Serialization
|
2013-11-05 08:56:42 +01:00
|
|
|
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("kind", _positive_only);
|
|
|
|
}
|
|
|
|
|
2013-12-30 22:31:36 +01:00
|
|
|
/// Simple print (just blabla and the size)
|
2013-11-05 08:56:42 +01:00
|
|
|
friend std::ostream &operator<<(std::ostream &sout, matsubara_freq_mesh const &m) {
|
|
|
|
return sout << "Matsubara Freq Mesh of size " << m.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
domain_t _dom;
|
|
|
|
int n_max;
|
|
|
|
bool _positive_only;
|
|
|
|
};
|
2013-12-30 22:31:36 +01:00
|
|
|
|
|
|
|
//-------------------------------------------------------
|
|
|
|
|
|
|
|
/** \brief foreach for this mesh
|
|
|
|
*
|
|
|
|
* @param m : a mesh
|
|
|
|
* @param F : a function of synopsis auto F (matsubara_freq_mesh::mesh_point_t)
|
|
|
|
*
|
|
|
|
* Calls F on each point of the mesh, in arbitrary order.
|
|
|
|
**/
|
|
|
|
template <typename Lambda> void foreach(matsubara_freq_mesh const &m, Lambda F) {
|
|
|
|
for (auto const &w : m) F(w);
|
|
|
|
}
|
2013-11-20 15:11:29 +01:00
|
|
|
}
|
2013-11-05 08:56:42 +01:00
|
|
|
}
|
|
|
|
|