From b129b3d17bd9570d3734265371d7801f7ce7102d Mon Sep 17 00:00:00 2001 From: tayral Date: Tue, 4 Feb 2014 11:24:28 +0000 Subject: [PATCH] Added basic doc + additional test for tail fitting - added test for a 'real-life' GF + corresponding output - added basic usage documentation for tail fitting from c++. Full implementation details yet to be written --- doc/reference/c++/gf/set_tail_from_fit.rst | 67 ++++++++++++++++++++++ doc/reference/c++/gf/tail.rst | 35 +++++++++++ test/triqs/gfs/test_fit_tail.cpp | 45 ++++++++++----- test/triqs/gfs/test_fit_tail.output | 48 ++++++++++++++++ 4 files changed, 182 insertions(+), 13 deletions(-) create mode 100644 doc/reference/c++/gf/set_tail_from_fit.rst create mode 100644 test/triqs/gfs/test_fit_tail.output diff --git a/doc/reference/c++/gf/set_tail_from_fit.rst b/doc/reference/c++/gf/set_tail_from_fit.rst new file mode 100644 index 00000000..dbd27796 --- /dev/null +++ b/doc/reference/c++/gf/set_tail_from_fit.rst @@ -0,0 +1,67 @@ +Fitting the tail of a Matsubara Green's function +################################################# + +API +~~~~~ + +The tail of a given ``gf/gf> gw`` can be fitted using the two following functions: + + ``void set_tail_from_fit(gf &gf, tail_view known_moments, int n_moments, size_t wn_min, size_t wn_max, bool replace_by_fit = false);`` + + ``void set_tail_from_fit(gf> &block_gf, tail_view known_moments, int n_moments, size_t wn_min, size_t wn_max, bool replace_by_fit = false);`` + + +where + ++-------------+----------------+----------------------------------------------------------------------+----------+ +| type | name | description | default | ++=============+================+======================================================================+==========+ +| gf | gf | Green's function to be fit | no | ++-------------+----------------+----------------------------------------------------------------------+----------+ +| tail_view | known_moments | known part of the tail | no | ++-------------+----------------+----------------------------------------------------------------------+----------+ +| int | n_moments | number of moments in the final tail (including known ones) | no | ++-------------+----------------+----------------------------------------------------------------------+----------+ +| size_t | wn_min | frequency to start the fit | no | ++-------------+----------------+----------------------------------------------------------------------+----------+ +| size_t | wn_max | final fitting frequency (included) | no | ++-------------+----------------+----------------------------------------------------------------------+----------+ +| bool | replace_by_fit | if true, replace the gf data in the fitting range by the tail values | true | ++-------------+----------------+----------------------------------------------------------------------+----------+ + + +Example +~~~~~~~~ + +.. compileblock:: + + #include + #include + using namespace triqs::gfs; + int main(){ + triqs::clef::placeholder<0> iom_; + double beta =10; + int N=100; + + auto gw = gf{{beta, Fermion, N}, {1, 1}}; + gw(iom_) << 1/(iom_-1); + + size_t wn_min=50, wn_max=90; + int n_moments=4; + 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 = local::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 + + set_tail_from_fit(gw, known_moments, n_moments, wn_min, wn_max, true); + + std::cout << gw.singularity() << std::endl; + } + + + +Implementation +~~~~~~~~~~~~~~~ + +The fitting problem is written as a linear system of equations, which is solved by SVD. + diff --git a/doc/reference/c++/gf/tail.rst b/doc/reference/c++/gf/tail.rst index 680a02c5..71d4aef7 100644 --- a/doc/reference/c++/gf/tail.rst +++ b/doc/reference/c++/gf/tail.rst @@ -38,6 +38,41 @@ In TRIQS, the tail is implemented as an object ``tail``. Here is a simple exampl std::cout << t << std::endl; } + + +Fitting the tail of a Green's function +--------------------------------------- + +Given an imaginary-frequency Green's function, one can compute the moments of its high-frequency tail with the function ``set_tail_from_fit``: + + +.. compileblock:: + + #include + #include + using namespace triqs::gfs; + int main(){ + triqs::clef::placeholder<0> iom_; + double beta =10; + int N=100; + + auto gw = gf{{beta, Fermion, N}, {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 = local::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 + set_tail_from_fit(gw, known_moments, n_moments, wn_min, wn_max, true);//true replace the gf data in the fitting range by the tail values + std::cout << gw.singularity() << std::endl; + } + + +The full documentation of ``set_tail_from_fit`` is :doc:`here`. + API **** Here are the main methods of the ``tail`` class: diff --git a/test/triqs/gfs/test_fit_tail.cpp b/test/triqs/gfs/test_fit_tail.cpp index d7bf9a80..65dc8001 100644 --- a/test/triqs/gfs/test_fit_tail.cpp +++ b/test/triqs/gfs/test_fit_tail.cpp @@ -7,8 +7,7 @@ using triqs::arrays::make_shape; using namespace triqs::gfs; using triqs::gfs::local::tail; #define TEST(X) std::cout << BOOST_PP_STRINGIZE((X)) << " ---> "<< (X) < precision) TRIQS_RUNTIME_ERROR<<" fit_tail error : diff="< precision) TRIQS_RUNTIME_ERROR<<" fit_tail error : diff="< precision) TRIQS_RUNTIME_ERROR<<" fit_tail error : diff="< precision) TRIQS_RUNTIME_ERROR<<" fit_tail error : diff="< iom_; + double beta =10; + int N=100; + auto gw = gf{{beta, Fermion, N}, {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 + set_tail_from_fit(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()); +} + +int main() { + test_0(); + test_1(); } diff --git a/test/triqs/gfs/test_fit_tail.output b/test/triqs/gfs/test_fit_tail.output new file mode 100644 index 00000000..53ac69ae --- /dev/null +++ b/test/triqs/gfs/test_fit_tail.output @@ -0,0 +1,48 @@ +(gw.singularity()) ---> tail/tail_view: min/smallest/max = -1 1 8 + ... Order -1 = +[[(0,0)]] + ... Order 0 = +[[(0,0)]] + ... Order 1 = +[[(1,0)]] + ... Order 2 = +[[(3,0)]] + ... Order 3 = +[[(5,0)]] + ... Order 4 = +[[(0,0)]] + ... Order 5 = +[[(0,0)]] + ... Order 6 = +[[(0,0)]] + ... Order 7 = +[[(0,0)]] + ... Order 8 = +[[(0,0)]] + +(gw.singularity()) ---> tail/tail_view: min/smallest/max = 1 1 3 + ... Order 1 = +[[(1,0)]] + ... Order 2 = +[[(3,0)]] + ... Order 3 = +[[(5,0)]] + +(gw.singularity()) ---> tail/tail_view: min/smallest/max = 1 1 3 + ... Order 1 = +[[(1,0)]] + ... Order 2 = +[[(3,0)]] + ... Order 3 = +[[(5,0)]] + +(gw.singularity()) ---> tail/tail_view: min/smallest/max = 1 1 4 + ... Order 1 = +[[(1,0)]] + ... Order 2 = +[[(1,0)]] + ... Order 3 = +[[(0.999251,0)]] + ... Order 4 = +[[(0.998655,0)]] +