3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-27 06:43:40 +01:00
dft_tools/test/triqs/gfs/test_fit_tail.cpp

127 lines
4.4 KiB
C++
Raw Normal View History

2014-02-03 21:51:40 +01:00
#//define TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
#include <triqs/gfs.hpp>
#include <triqs/gfs/local/fit_tail.hpp>
using triqs::arrays::make_shape;
using namespace triqs::gfs;
using triqs::gfs::local::tail;
#define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) <<std::endl<<std::endl;
void test_0(){
2014-02-03 21:51:40 +01:00
triqs::clef::placeholder<0> iom_;
double beta =10;
int N=100;
auto gw = gf<imfreq>{{beta, Fermion, N},{1,1}};
auto gw_s = gf<imfreq, scalar_valued>{{beta, Fermion, N}};
2014-02-03 21:51:40 +01:00
triqs::arrays::array<double,1> c(3);
triqs::clef::placeholder<1> i_;
c(i_) << (2*i_+1);
int size=0; //means we don't know any moments
int order_min=1; //means that the first moment in the final tail will be the first moment
auto known_moments = tail(make_shape(1,1), size, order_min); //length is 0, first moment to fit is order_min
gw(iom_) << c(0)/iom_ + c(1)/iom_/iom_ + c(2)/iom_/iom_/iom_;
gw_s(iom_) << c(0)/iom_ + c(1)/iom_/iom_ + c(2)/iom_/iom_/iom_;
2014-02-03 21:51:40 +01:00
TEST(gw.singularity());
2014-02-03 21:51:40 +01:00
//erase tail
for(auto &i : gw.singularity().data()) i = 0.0;
for(auto &i : gw_s.singularity().data()) i = 0.0;
2014-02-03 21:51:40 +01:00
size_t wn_min=50; //frequency to start the fit
size_t wn_max=90; //final fitting frequency (included)
int n_moments=3; //number of moments in the final tail (including known ones)
//restore tail
fit_tail(gw, known_moments, n_moments, wn_min, wn_max);
fit_tail(gw_s, known_moments, n_moments, wn_min, wn_max);
2014-02-03 21:51:40 +01:00
TEST(gw.singularity());
TEST(gw_s.singularity());
/*
2014-02-03 21:51:40 +01:00
for(size_t i=0; i<first_dim(c); i++){
double diff = std::abs( c(i) - gw.singularity().data()(i,0,0) );
//std::cout<< "diff: " << diff <<std::endl;
if (diff > precision) TRIQS_RUNTIME_ERROR<<" fit_tail error : diff="<<diff<<"\n";
2014-02-03 21:51:40 +01:00
}
*/
2014-02-03 21:51:40 +01:00
//erase tail
for(auto &i : gw.singularity().data()) i = 0.0;
//now with a known moment
size=1; //means that we know one moment
order_min=1; //means that the first moment in the final tail will be the first moment
known_moments = tail(make_shape(1,1), size, order_min); //length is 0, first moment to fit is order_min
known_moments(1)=1.;//set the first moment
fit_tail(gw, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
2014-02-03 21:51:40 +01:00
TEST(gw.singularity());
/*
2014-02-03 21:51:40 +01:00
for(size_t i=0; i<first_dim(c); i++){
double diff = std::abs( c(i) - gw.singularity().data()(i,0,0) );
//std::cout<< "diff: " << diff <<std::endl;
if (diff > precision) TRIQS_RUNTIME_ERROR<<" fit_tail error : diff="<<diff<<"\n";
2014-02-03 21:51:40 +01:00
}
*/
}
void test_1(){
//real life test: find tails of 1/(iom -1)
triqs::clef::placeholder<0> iom_;
double beta =10;
int N=100;
auto gw = gf<imfreq>{{beta, Fermion, N}, {1, 1}};
auto gw_b = gf<imfreq>{{beta, Boson, N}, {1, 1}};
gw(iom_) << 1/(iom_-1);
gw_b(iom_) << 1/(iom_-1);
2014-02-03 21:51:40 +01:00
size_t wn_min=50; //frequency to start the fit
size_t wn_max=90; //final fitting frequency (included)
int n_moments=4; //number of moments in the final tail (including known ones)
int size=1; //means that we know one moment
int order_min=1; //means that the first moment in the final tail will be the first moment
auto known_moments = tail(make_shape(1,1), size, order_min); //length is 0, first moment to fit is order_min
known_moments(1)=1.;//set the first moment
fit_tail(gw, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
fit_tail(gw_b, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
TEST(gw.singularity());
TEST(gw_b.singularity());
}
void test_2(){
//real life test: find tails of 1/(iom -1) -- with positive and negative matsubara
triqs::clef::placeholder<0> iom_;
double beta =10;
int N=200;
auto gw = gf<imfreq>{{beta, Fermion, N, false}, {1, 1}};
gw(iom_) << 1/(iom_-1);
size_t wn_min=50; //frequency to start the fit
size_t wn_max=90; //final fitting frequency (included)
int n_moments=4; //number of moments in the final tail (including known ones)
int size=1; //means that we know one moment
int order_min=1; //means that the first moment in the final tail will be the first moment
auto known_moments = tail(make_shape(1,1), size, order_min); //length is 0, first moment to fit is order_min
known_moments(1)=1.;//set the first moment
fit_tail(gw, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values
TEST(gw.singularity());
}
2014-02-03 21:51:40 +01:00
int main() {
test_0();
test_1();
test_2();
2014-02-03 21:51:40 +01:00
}