2013-07-17 19:24:07 +02:00
|
|
|
/*******************************************************************************
|
2013-09-06 18:12:50 +02:00
|
|
|
*
|
2013-07-17 19:24:07 +02:00
|
|
|
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 by M. Ferrero, 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/>.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
#ifndef TRIQS_GF_TWO_TIMES_H
|
|
|
|
#define TRIQS_GF_TWO_TIMES_H
|
|
|
|
#include "./tools.hpp"
|
|
|
|
#include "./gf.hpp"
|
|
|
|
#include "./retime.hpp"
|
|
|
|
#include "./meshes/product.hpp"
|
|
|
|
|
2013-07-28 13:28:19 +02:00
|
|
|
namespace triqs { namespace gfs {
|
2013-09-06 18:12:50 +02:00
|
|
|
|
2013-07-17 19:24:07 +02:00
|
|
|
struct two_real_times {};
|
|
|
|
|
2013-08-24 14:47:47 +02:00
|
|
|
// the mesh
|
2013-08-27 14:20:50 +02:00
|
|
|
template<typename Opt> struct gf_mesh<two_real_times,Opt> :mesh_product<gf_mesh<retime,Opt> ,gf_mesh<retime,Opt> > {
|
|
|
|
typedef mesh_product<gf_mesh<retime,Opt> ,gf_mesh<retime,Opt> > B;
|
|
|
|
gf_mesh() = default;
|
|
|
|
gf_mesh (double tmax, double n_time_slices) :
|
|
|
|
B(gf_mesh<retime,Opt> ( 0, tmax,n_time_slices, full_bins),
|
|
|
|
gf_mesh<retime,Opt> ( 0, tmax,n_time_slices, full_bins) ) {}
|
2013-08-24 14:47:47 +02:00
|
|
|
};
|
|
|
|
|
2013-07-28 13:28:19 +02:00
|
|
|
namespace gfs_implementation {
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
/// --------------------------- closest mesh point on the grid ---------------------------------
|
|
|
|
|
|
|
|
template<typename Opt>
|
|
|
|
struct get_closest_point <two_real_times,matrix_valued,Opt> {
|
2013-08-27 14:20:50 +02:00
|
|
|
typedef typename gf_mesh<two_real_times, Opt>::type mesh_t;
|
2013-08-24 14:47:47 +02:00
|
|
|
|
|
|
|
// // NOT FINISHED, NOT TESTED
|
|
|
|
// template<typename G, typename T>
|
|
|
|
// static typename mesh_t::index_t invoke(G const * g, closest_pt_wrap<T,T> const & p) {
|
|
|
|
// return std::floor( double(p.value) / g->mesh().delta() + 0.5);
|
|
|
|
// }
|
2013-07-17 19:24:07 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-09-06 18:12:50 +02:00
|
|
|
// h5 name
|
|
|
|
template<typename Opt> struct h5_name<two_real_times,matrix_valued,Opt> { static std::string invoke(){ return "GfTwoRealTime";}};
|
|
|
|
template<typename Opt> struct h5_name<two_real_times,scalar_valued,Opt> { static std::string invoke(){ return "GfTwoRealTime_s";}};
|
|
|
|
|
2013-07-17 19:24:07 +02:00
|
|
|
/// --------------------------- evaluator ---------------------------------
|
2013-09-06 18:12:50 +02:00
|
|
|
|
|
|
|
template<typename Opt, typename Target>
|
|
|
|
struct evaluator<two_real_times,Target,Opt> {
|
|
|
|
static constexpr int arity = 2;
|
|
|
|
typedef typename std::conditional < std::is_same<Target, matrix_valued>::value, arrays::matrix<std::complex<double>>, std::complex<double>>::type rtype;
|
|
|
|
template<typename G>
|
|
|
|
rtype operator() (G const * g, double t0, double t1) const {
|
|
|
|
size_t n0,n1; double w0,w1; bool in;
|
|
|
|
std::tie(in, n0, w0) = windowing(std::get<0>(g->mesh().components()),t0);
|
|
|
|
if (!in) TRIQS_RUNTIME_ERROR <<" Evaluation out of bounds";
|
|
|
|
std::tie(in, n1, w1) = windowing(std::get<1>(g->mesh().components()),t1);
|
|
|
|
if (!in) TRIQS_RUNTIME_ERROR <<" Evaluation out of bounds";
|
|
|
|
auto gg = on_mesh(*g);
|
|
|
|
return (1-w0) * ( (1-w1) * gg(n0, n1) + w1 * gg(n0, n1+1) ) + w0 * ( (1-w1) * gg(n0+1, n1) + w1 * gg(n0+1, n1+1));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-17 19:24:07 +02:00
|
|
|
/// --------------------------- data access ---------------------------------
|
2013-09-06 18:12:50 +02:00
|
|
|
|
2013-07-17 19:24:07 +02:00
|
|
|
template<typename Opt> struct data_proxy<two_real_times,matrix_valued,Opt> : data_proxy_array<std::complex<double>,3> {};
|
2013-09-06 18:12:50 +02:00
|
|
|
template<typename Opt> struct data_proxy<two_real_times,scalar_valued,Opt> : data_proxy_array<std::complex<double>,1> {};
|
|
|
|
|
2013-07-17 19:24:07 +02:00
|
|
|
// ------------------------------- Factories --------------------------------------------------
|
2013-09-06 18:12:50 +02:00
|
|
|
|
|
|
|
//matrix_valued
|
2013-07-17 19:24:07 +02:00
|
|
|
template<typename Opt> struct factories<two_real_times, matrix_valued,Opt> {
|
|
|
|
typedef gf<two_real_times, matrix_valued,Opt> gf_t;
|
2013-08-27 14:20:50 +02:00
|
|
|
typedef gf_mesh<two_real_times, Opt> mesh_t;
|
2013-07-17 19:24:07 +02:00
|
|
|
static gf_t make_gf(double tmax, double n_time_slices, tqa::mini_vector<size_t,2> shape) {
|
2013-08-27 14:20:50 +02:00
|
|
|
auto m = gf_mesh<two_real_times,Opt>(tmax, n_time_slices);
|
2013-08-20 16:15:43 +02:00
|
|
|
typename gf_t::data_regular_t A(shape.front_append(m.size())); A() =0;
|
2013-07-17 19:24:07 +02:00
|
|
|
return gf_t (m, std::move(A), nothing(), nothing() ) ;
|
|
|
|
}
|
|
|
|
};
|
2013-09-06 18:12:50 +02:00
|
|
|
|
|
|
|
//scalar_valued
|
|
|
|
template<typename Opt> struct factories<two_real_times, scalar_valued,Opt> {
|
|
|
|
typedef gf<two_real_times, scalar_valued,Opt> gf_t;
|
|
|
|
typedef gf_mesh<two_real_times, Opt> mesh_t;
|
|
|
|
|
|
|
|
static gf_t make_gf(double tmax, double n_time_slices) {
|
|
|
|
auto m = gf_mesh<two_real_times,Opt>(tmax, n_time_slices);
|
2013-09-11 20:48:03 +02:00
|
|
|
typename gf_t::data_regular_t A(m.size()); A() =0;
|
2013-09-06 18:12:50 +02:00
|
|
|
return gf_t (m, std::move(A), nothing(), nothing() ) ;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-28 13:28:19 +02:00
|
|
|
} // gfs_implementation
|
2013-09-06 18:12:50 +02:00
|
|
|
|
2013-08-24 14:47:47 +02:00
|
|
|
// ------------------------------- Additionnal free function for this gf --------------------------------------------------
|
2013-09-06 18:12:50 +02:00
|
|
|
|
2013-08-24 14:47:47 +02:00
|
|
|
// from g(t,t') and t, return g(t-t') for any t'>t
|
|
|
|
//
|
2013-09-11 20:48:03 +02:00
|
|
|
inline gf<retime> slice (gf_view<two_real_times> const & g, double t) {
|
2013-07-19 13:28:30 +02:00
|
|
|
auto const & m = std::get<0> (g.mesh().components()); //one-time mesh
|
|
|
|
long it = get_closest_mesh_pt_index(m, t); //index of t on this mesh
|
2013-07-17 19:24:07 +02:00
|
|
|
long nt = m.size() - it;
|
2013-07-19 13:28:30 +02:00
|
|
|
if (it+1 < nt) nt = it+1 ; //nt=length of the resulting GF's mesh
|
2013-09-06 18:12:50 +02:00
|
|
|
double dt = m.delta();
|
2013-07-19 13:28:30 +02:00
|
|
|
auto res = make_gf<retime>(0, 2*(nt-1)*dt, nt, g(t,t).shape());
|
2013-07-17 19:24:07 +02:00
|
|
|
res() = 0;
|
|
|
|
auto _ = arrays::range();// everyone
|
|
|
|
for(long sh=0; sh<nt; sh++){
|
|
|
|
res.data()(sh,_,_) = g.data()(g.mesh().index_to_linear(std::make_tuple( it+sh, it-sh) ),_,_);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2013-09-06 18:12:50 +02:00
|
|
|
|
2013-07-17 19:24:07 +02:00
|
|
|
// Get the 1 time mesh from the 2 times cartesian product (for cython interface mainly)
|
|
|
|
template<typename M>
|
2013-09-06 18:12:50 +02:00
|
|
|
auto get_1d_mesh_from_2times_mesh(M const & m) DECL_AND_RETURN(std::get<0>(m.components()));
|
|
|
|
|
2013-07-17 19:24:07 +02:00
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
|