-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhybretintfun.cpp
More file actions
125 lines (113 loc) · 5.49 KB
/
hybretintfun.cpp
File metadata and controls
125 lines (113 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/****************************************************************************
*
* ALPS DMFT Project
*
* Copyright (C) 2012 by Emanuel Gull <gull@pks.mpg.de>,
*
* based on an earlier version by Philipp Werner and Emanuel Gull
*
*
* This software is part of the ALPS Applications, published under the ALPS
* Application License; you can use, redistribute it and/or modify it under
* the terms of the license, either version 1 or (at your option) any later
* version.
*
* You should have received a copy of the ALPS Application License along with
* the ALPS Applications; see the file LICENSE.txt. If not, the license is also
* available from http://alps.comp-phys.org/.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#include"hybretintfun.hpp"
//construct a retarded interaction function. ntime: number of time slices.
//noffidag_orbitals: number of offdiagonal orbitals. ndiag_orbitals: number
//of diagonal orbitals.
ret_int_fun::ret_int_fun(const alps::params &p):
green_function<double>(p["N"].as<int>()+1, 1, 2)//2 "flavors": K and K'
{
bool use_retarded_interaction=p.exists("cthyb.RET_INT_K");
if(!use_retarded_interaction) return;
beta_=p["BETA"];
//read in Green's function from a file
read_interaction_K_function(p);
interaction_K_function_sanity_check();
extern int global_mpi_rank;
if(global_mpi_rank==0){
std::cout<<*this<<std::endl;
}
}
void ret_int_fun::interaction_K_function_sanity_check(void){
for(std::size_t i=0; i<ntime();++i)
for(std::size_t j=0; j<nflavor();++j)
if(operator()(i,j) < 0. && j==0) throw std::invalid_argument("Problem with retarded interaction function: RET_INT_K(\\tau) < 0. K should always be positive!");
}
//this routine reads in the retarded interaction function, either from a text file or from an hdf5 file (for easy passing of binary data).
//In case of text files the file format is index - hyb_1 - hyb2 - hyb3 - ... in columns that go from time=0 to time=beta. Note that
//the retarded interaction function is in imaginary time and always positive both for negative and positive times. It is also symmetric.
void ret_int_fun::read_interaction_K_function(const alps::params &p){
if(!p.exists("cthyb.RET_INT_K")) throw(std::invalid_argument(std::string("Parameter RET_INT_K missing, filename for retarded interaction function not specified.")));
std::string fname=p["cthyb.RET_INT_K"];
if(p.exists("cthyb.K_IN_HDF5") && p["cthyb.K_IN_HDF5"]){//attempt to read from h5 archive
alps::hdf5::archive ar(fname, alps::hdf5::archive::READ);
std::vector<double> tmp(ntime());
ar["/Ret_int_K"] >> tmp;
for(std::size_t i=0; i<ntime(); i++)
operator()(i,0)=tmp[i];
tmp.clear();
ar["/Ret_int_Kp"] >> tmp;
for(std::size_t i=0; i<ntime(); i++)
operator()(i,1)=tmp[i];
tmp.clear();
}
else{//read from text file
std::ifstream infile(fname.c_str());
if(!infile.good()){
throw(std::invalid_argument(std::string("could not open retarded interaction file (text format) ") + p["cthyb.RET_INT_K"].as<std::string>()));
}
for (std::size_t i=0; i<ntime(); i++) {
if(!infile.good()){
throw(std::invalid_argument(std::string("could not read retarded interaction file (text format) ") + p["cthyb.RET_INT_K"].as<std::string>() + ". probably wrong number of lines"));
}
double dummy;
infile >> dummy;
//std::cout<<i<<" "<<ntime()<<" "<<"dummy: "<<dummy<<std::endl;
for (std::size_t j=0; j<nflavor(); j++){
if(!infile.good()){
throw(std::invalid_argument(std::string("could not read retarded interaction file (text format) ") + p["cthyb.RET_INT_K"].as<std::string>() + ". probably wrong number of columns"));
}
double delta;
infile >> delta;
operator()(i,j)=delta;
}
}
}
}
std::ostream &operator<<(std::ostream &os, const ret_int_fun &K){
os<<"the retarded interaction function and derivative are: "<<std::endl;
for(int i=0;i<10;++i){ std::cout<<i<<" "; for(std::size_t j=0;j<K.nflavor();++j){ std::cout<<K(i,j)<<" ";} std::cout<<std::endl; }
os<<"... *** etc *** ...\n";
os<<K.ntime()-1<<" "; for(std::size_t j=0;j<K.nflavor();++j){ std::cout<<K(K.ntime()-1,j)<<" ";} std::cout<<std::endl;
return os;
}
//linear interpolation of the retarded interaction function
double ret_int_fun::interpolate(double time) const{
time=std::abs(time);
double n = time/beta_*(ntime()-1);
int n_lower = (int)n; // interpolate linearly between n_lower and n_lower+1
return operator()(n_lower,0) + (n-n_lower)*(operator()(n_lower+1,0)-operator()(n_lower,0));
}
//linear interpolation of the retarded interaction function.
double ret_int_fun::interpolate_deriv(double time) const{
//if(time<-beta_ || time > beta_) std::cout<< "!!" << std::endl;
if(time<0.) return -1.*interpolate_deriv(-time);
double n = time/beta_*(ntime()-1);
int n_lower = (int)n; // interpolate linearly between n_lower and n_lower+1
return operator()(n_lower,1) + (n-n_lower)*(operator()(n_lower+1,1)-operator()(n_lower,1));
}