Skip to content

Commit c476389

Browse files
committed
1. update LRI::set_tensors_map2()
1 parent 044099e commit c476389

File tree

9 files changed

+70
-38
lines changed

9 files changed

+70
-38
lines changed

include/RI/global/Map_Operator.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ namespace Map_Operator
4141
m.insert(ptr2, m2.end());
4242
return m;
4343
}
44+
45+
// m2 cover m1
46+
template<typename Tkey, typename Tvalue>
47+
std::map<Tkey,Tvalue> cover(const std::map<Tkey,Tvalue> &m1, const std::map<Tkey,Tvalue> &m2)
48+
{
49+
std::map<Tkey,Tvalue> m = m1;
50+
for(const auto &item : m2)
51+
m[item.first] = item.second;
52+
return m;
53+
}
4454
}
4555

4656
}

include/RI/physics/Exx.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ void Exx<TA,Tcell,Ndim,Tdata>::set_Cs(
3838
const Tdata_real &threshold_C,
3939
const std::string &save_name_suffix)
4040
{
41-
this->lri.set_tensors_map2( Cs, Label::ab::a, threshold_C, "Cs_a_"+save_name_suffix );
42-
this->lri.set_tensors_map2( Cs, Label::ab::b, threshold_C, "Cs_b_"+save_name_suffix );
41+
this->lri.set_tensors_map2( Cs, Label::ab::a, {{"threshold_filter", threshold_C}}, "Cs_a_"+save_name_suffix );
42+
this->lri.set_tensors_map2( Cs, Label::ab::b, {{"threshold_filter", threshold_C}}, "Cs_b_"+save_name_suffix );
4343
this->flag_finish.C = true;
4444
}
4545

@@ -49,7 +49,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::set_Vs(
4949
const Tdata_real &threshold_V,
5050
const std::string &save_name_suffix)
5151
{
52-
this->lri.set_tensors_map2( Vs, Label::ab::a0b0, threshold_V, "Vs_"+save_name_suffix );
52+
this->lri.set_tensors_map2( Vs, Label::ab::a0b0, {{"threshold_filter", threshold_V}}, "Vs_"+save_name_suffix );
5353
this->flag_finish.V = true;
5454
}
5555

@@ -59,10 +59,10 @@ void Exx<TA,Tcell,Ndim,Tdata>::set_Ds(
5959
const Tdata_real &threshold_D,
6060
const std::string &save_name_suffix)
6161
{
62-
this->lri.set_tensors_map2( Ds, Label::ab::a1b1, threshold_D, "Ds_a1b1_"+save_name_suffix );
63-
this->lri.set_tensors_map2( Ds, Label::ab::a1b2, threshold_D, "Ds_a1b2_"+save_name_suffix );
64-
this->lri.set_tensors_map2( Ds, Label::ab::a2b1, threshold_D, "Ds_a2b1_"+save_name_suffix );
65-
this->lri.set_tensors_map2( Ds, Label::ab::a2b2, threshold_D, "Ds_a2b2_"+save_name_suffix );
62+
this->lri.set_tensors_map2( Ds, Label::ab::a1b1, {{"threshold_filter", threshold_D}}, "Ds_a1b1_"+save_name_suffix );
63+
this->lri.set_tensors_map2( Ds, Label::ab::a1b2, {{"threshold_filter", threshold_D}}, "Ds_a1b2_"+save_name_suffix );
64+
this->lri.set_tensors_map2( Ds, Label::ab::a2b1, {{"threshold_filter", threshold_D}}, "Ds_a2b1_"+save_name_suffix );
65+
this->lri.set_tensors_map2( Ds, Label::ab::a2b2, {{"threshold_filter", threshold_D}}, "Ds_a2b2_"+save_name_suffix );
6666
this->flag_finish.D = true;
6767

6868
//if()
@@ -77,8 +77,8 @@ void Exx<TA,Tcell,Ndim,Tdata>::set_dCs(
7777
{
7878
for(std::size_t ipos=0; ipos<Npos; ++ipos)
7979
{
80-
this->lri.set_tensors_map2( dCs[ipos], Label::ab::a, threshold_dC, "dCs_a_"+std::to_string(ipos)+"_"+save_name_suffix );
81-
this->lri.set_tensors_map2( dCs[ipos], Label::ab::b, threshold_dC, "dCs_b_"+std::to_string(ipos)+"_"+save_name_suffix );
80+
this->lri.set_tensors_map2( dCs[ipos], Label::ab::a, {{"threshold_filter", threshold_dC}}, "dCs_a_"+std::to_string(ipos)+"_"+save_name_suffix );
81+
this->lri.set_tensors_map2( dCs[ipos], Label::ab::b, {{"threshold_filter", threshold_dC}}, "dCs_b_"+std::to_string(ipos)+"_"+save_name_suffix );
8282
}
8383
this->flag_finish.dC = true;
8484
}
@@ -91,7 +91,7 @@ void Exx<TA,Tcell,Ndim,Tdata>::set_dVs(
9191
{
9292
for(std::size_t ipos=0; ipos<Npos; ++ipos)
9393
{
94-
this->lri.set_tensors_map2( dVs[ipos], Label::ab::a0b0, threshold_dV, "dVs_"+std::to_string(ipos)+"_"+save_name_suffix );
94+
this->lri.set_tensors_map2( dVs[ipos], Label::ab::a0b0, {{"threshold_filter", threshold_dV}}, "dVs_"+std::to_string(ipos)+"_"+save_name_suffix );
9595
}
9696
this->flag_finish.dV = true;
9797
}

include/RI/physics/GW.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ void G0W0<TA,Tcell,Ndim,Tdata>::set_Cs(
3333
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
3434
const Tdata_real &threshold_C)
3535
{
36-
this->lri.set_tensors_map2( Cs, Label::ab::a, threshold_C, "Cs_a" );
37-
this->lri.set_tensors_map2( Cs, Label::ab::b, threshold_C, "Cs_b" );
36+
this->lri.set_tensors_map2( Cs, Label::ab::a, {{"threshold_filter", threshold_C}} );
37+
this->lri.set_tensors_map2( Cs, Label::ab::b, {{"threshold_filter", threshold_C}} );
3838
this->flag_finish.C = true;
3939
}
4040

@@ -49,13 +49,13 @@ void G0W0<TA, Tcell, Ndim, Tdata>::cal_Sigc(
4949
assert(this->flag_finish.stru);
5050
assert(this->flag_finish.C);
5151
// setup Green's function
52-
this->lri.set_tensors_map2( gf_tau, Label::ab::a1b1, threshold_G, "gf_a1b1" );
53-
this->lri.set_tensors_map2( gf_tau, Label::ab::a1b2, threshold_G, "gf_a1b2" );
54-
this->lri.set_tensors_map2( gf_tau, Label::ab::a2b1, threshold_G, "gf_a2b1" );
55-
this->lri.set_tensors_map2( gf_tau, Label::ab::a2b2, threshold_G, "gf_a2b2" );
52+
this->lri.set_tensors_map2( gf_tau, Label::ab::a1b1, {{"threshold_filter", threshold_G}} );
53+
this->lri.set_tensors_map2( gf_tau, Label::ab::a1b2, {{"threshold_filter", threshold_G}} );
54+
this->lri.set_tensors_map2( gf_tau, Label::ab::a2b1, {{"threshold_filter", threshold_G}} );
55+
this->lri.set_tensors_map2( gf_tau, Label::ab::a2b2, {{"threshold_filter", threshold_G}} );
5656

5757
// setup screened Coulomb interaction
58-
this->lri.set_tensors_map2( Wc_tau, Label::ab::a0b0, threshold_W, "Wc" );
58+
this->lri.set_tensors_map2( Wc_tau, Label::ab::a0b0, {{"threshold_filter", threshold_W}} );
5959

6060
std::vector<std::map<TA, std::map<TAC, Tensor<Tdata>>>> Sigc_vec(1);
6161
this->lri.coefficients = {nullptr};

include/RI/physics/RPA.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ void RPA<TA,Tcell,Ndim,Tdata>::set_Cs(
3030
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
3131
const Tdata_real &threshold_C)
3232
{
33-
this->lri.set_tensors_map2( Cs, Label::ab::a, threshold_C, "Cs_a" );
34-
this->lri.set_tensors_map2( Cs, Label::ab::b, threshold_C, "Cs_b" );
33+
this->lri.set_tensors_map2( Cs, Label::ab::a, {{"threshold_filter", threshold_C}} );
34+
this->lri.set_tensors_map2( Cs, Label::ab::b, {{"threshold_filter", threshold_C}} );
3535
this->flag_finish.C = true;
3636
}
3737

@@ -49,14 +49,14 @@ void RPA<TA,Tcell,Ndim,Tdata>::cal_chi0s(
4949

5050
auto set_Gs_a1 = [this, &threshold_G](const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Gs)
5151
{
52-
this->lri.set_tensors_map2( Gs, Label::ab::a1b1, threshold_G, "Gs_a1b1" );
53-
this->lri.set_tensors_map2( Gs, Label::ab::a1b2, threshold_G, "Gs_a1b2" );
52+
this->lri.set_tensors_map2( Gs, Label::ab::a1b1, {{"threshold_filter", threshold_G}} );
53+
this->lri.set_tensors_map2( Gs, Label::ab::a1b2, {{"threshold_filter", threshold_G}} );
5454
};
5555

5656
auto set_Gs_a2 = [this, &threshold_G](const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Gs)
5757
{
58-
this->lri.set_tensors_map2( Gs, Label::ab::a2b1, threshold_G, "Gs_a2b1" );
59-
this->lri.set_tensors_map2( Gs, Label::ab::a2b2, threshold_G, "Gs_a2b2" );
58+
this->lri.set_tensors_map2( Gs, Label::ab::a2b1, {{"threshold_filter", threshold_G}} );
59+
this->lri.set_tensors_map2( Gs, Label::ab::a2b2, {{"threshold_filter", threshold_G}} );
6060
};
6161

6262
std::vector<std::map<TA,std::map<TAC,Tensor<Tdata>>>> chi0s_vec(1);

include/RI/ri/LRI-set.hpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
#include "LRI.h"
99
#include "RI_Tools.h"
10+
#include "Label_Tools.h"
1011
#include "CS_Matrix.h"
12+
#include "../global/Map_Operator.h"
1113
#include <algorithm>
1214

1315
namespace RI
@@ -29,20 +31,34 @@ template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
2931
void LRI<TA,Tcell,Ndim,Tdata>::set_tensors_map2(
3032
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Ds_local,
3133
const Label::ab &label,
32-
const Tdata_real &threshold,
33-
const std::string &save_name)
34+
const std::map<std::string, double> &para_in,
35+
const std::string &save_name_in)
3436
{
35-
//if()
36-
std::map<TA, std::map<TAC, Tensor<Tdata>>> Ds_period = RI_Tools::cal_period(Ds_local, this->period);
37-
38-
std::map<TA, std::map<TAC, Tensor<Tdata>>> Ds_comm = this->parallel->comm_tensors_map2(label, std::move(Ds_period));
37+
const std::map<std::string, double> para_default = {
38+
{"flag_period", true},
39+
{"flag_comm", true},
40+
{"flag_filter", true},
41+
{"threshold_filter", 0.0}};
42+
const std::map<std::string, double> para = Map_Operator::cover(para_default, para_in);
3943

44+
const std::string save_name =
45+
save_name_in=="default"
46+
? Label_Tools::get_name(label)
47+
: save_name_in;
4048
this->data_ab_name[label] = save_name;
4149

42-
if(threshold)
43-
this->data_pool[save_name].Ds_ab = RI_Tools::filter(std::move(Ds_comm), filter_funcs[label], threshold);
44-
else
45-
this->data_pool[save_name].Ds_ab = std::move(Ds_comm);
50+
std::map<TA, std::map<TAC, Tensor<Tdata>>> Ds_new =
51+
para.at("flag_period")
52+
? RI_Tools::cal_period(Ds_local, this->period)
53+
: Ds_local;
54+
55+
if(para.at("flag_comm"))
56+
Ds_new = this->parallel->comm_tensors_map2(label, std::move(Ds_new));
57+
58+
if(para.at("flag_filter"))
59+
Ds_new = RI_Tools::filter(std::move(Ds_new), filter_funcs[label], para.at("threshold_filter"));
60+
61+
this->data_pool[save_name].Ds_ab = std::move(Ds_new);
4662

4763
this->data_pool[save_name].index_Ds_ab = RI_Tools::get_index(this->data_pool[save_name].Ds_ab);
4864

include/RI/ri/LRI.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ class LRI
4747
void set_tensors_map2(
4848
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Ds_local,
4949
const Label::ab &label,
50-
const Tdata_real &threshold,
51-
const std::string &save_name);
50+
const std::map<std::string, double> &para_in = {},
51+
const std::string &save_name_in = "default");
52+
// para:
53+
// "flag_period", true
54+
// "flag_comm", true
55+
// "flag_filter", true
56+
// "threshold_filter", 0.0
57+
// save_name: Label_Tools::get_name(label)
5258
//void set_tensors_map3(
5359
// const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Ds_local,
5460
// const std::string &label,

unittests/ri/LRI-speed-test.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace LRI_Speed_Test
8484
lri.csm.set_threshold(0);
8585

8686
for(const RI::Label::ab &label : RI::Label::array_ab)
87-
lri.set_tensors_map2(Ds_ab[label], label, 0, RI::Label_Tools::get_name(label));
87+
lri.set_tensors_map2(Ds_ab[label], label);
8888

8989
timeval t_begin;
9090
gettimeofday(&t_begin, NULL);

unittests/ri/LRI-test.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace LRI_Test
9595
lri.csm.set_threshold(1E-10);
9696

9797
for(const RI::Label::ab &label : RI::Label::array_ab)
98-
lri.set_tensors_map2(Ds_ab[label], label, 0, RI::Label_Tools::get_name(label));
98+
lri.set_tensors_map2(Ds_ab[label], label);
9999
{
100100
std::vector<T_Ds> Ds_result;
101101
lri.cal({RI::Label::ab_ab::a0b0_a1b1}, Ds_result);

unittests/ri/LRI_Loop3-test.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace LRI_Loop3_Test
9595
lri.csm.set_threshold(1E-10);
9696

9797
for(const RI::Label::ab &label : RI::Label::array_ab)
98-
lri.set_tensors_map2(Ds_ab[label], label, 0, RI::Label_Tools::get_name(label));
98+
lri.set_tensors_map2(Ds_ab[label], label);
9999
{
100100
std::vector<T_Ds> Ds_result;
101101
lri.cal_loop3({RI::Label::ab_ab::a0b0_a1b1}, Ds_result);

0 commit comments

Comments
 (0)