6#include "./vertex_factories.hpp"
11 std::vector<vertex_factory_t> make_vertex_factories(
params_t const ¶ms, triqs::mc_tools::random_generator &rng,
12 std::optional<block2_gf_const_view<mesh::dlr_imfreq, matrix_valued>> D0_iw,
13 std::optional<gf_const_view<mesh::dlr_imfreq, matrix_valued>> Jperp_iw) {
15 std::vector<vertex_factory_t> vertex_factories;
19 std::vector<vertex_idx_t> indices;
20 std::vector<U_scalar_t> amplitudes;
23 for (
auto const &term : params.h_int) {
24 amplitudes.push_back(-U_scalar_t(term.coef));
25 auto const &m = term.monomial;
26 if (m.size() != 4 or !(m[0].dagger and m[1].dagger and !m[2].dagger and !m[3].dagger))
27 TRIQS_RUNTIME_ERROR <<
" Monimial in h_int is not of the form c^+ c^+ c c \n";
29 auto [bl_cdag_0, idx_cdag_0] = get_int_indices(m[0], params.gf_struct);
30 auto [bl_cdag_1, idx_cdag_1] = get_int_indices(m[1], params.gf_struct);
31 auto [bl_c_1, idx_c_1] = get_int_indices(m[2], params.gf_struct);
32 auto [bl_c_0, idx_c_0] = get_int_indices(m[3], params.gf_struct);
34 indices.push_back({bl_cdag_0, idx_cdag_0, bl_c_0, idx_c_0, bl_cdag_1, idx_cdag_1, bl_c_1, idx_c_1});
37 if (indices.size() > 0) {
39 auto l = [beta = params.beta, n_s = params.n_s, indices = std::move(indices), amplitudes = std::move(amplitudes), &rng] {
40 int n = rng(indices.size());
43 double prop_proba = 1.0 / (beta * indices.size() * n_s);
44 return vertex_t{indices[n], t, t, t, t, amplitudes[n] / n_s, prop_proba, n, s};
47 vertex_factories.emplace_back(l);
54 std::vector<vertex_idx_t> indices;
55 std::vector<int> labels;
56#ifdef INTERACTION_IS_COMPLEX
57 std::vector<gf<imtime, scalar_valued>> D0_tau_lst;
59 std::vector<gf<imtime, scalar_real_valued>> D0_tau_lst;
63 long n_h_int = std::distance(params.h_int.begin(), params.h_int.end());
66 int n_bl = (*D0_iw).size1();
67 int R = (*D0_iw)(0, 0).target_shape()[0];
68 for (
int bl1 : range(n_bl))
69 for (
int bl2 : range(n_bl)) {
70 auto D0_tau_bl = make_gf_imtime(make_gf_dlr((*D0_iw)(bl1, bl2)), params.n_tau_dynamical_interactions);
73 for (
int a = 0; a < D0_tau_bl.target_shape()[0]; a++)
74 for (
int b = 0; b < D0_tau_bl.target_shape()[1]; b++) {
75 auto d = slice_target_to_scalar(D0_tau_bl, a, b);
78 if (max_norm(d) > 1e-10) {
79 indices.push_back({bl1, a, bl1, a, bl2, b, bl2, b});
80 labels.push_back(n_h_int + bl1 * n_bl * R * R + bl2 * R * R + a * R + b);
81#ifdef INTERACTION_IS_COMPLEX
82 D0_tau_lst.emplace_back(d);
84 if (!is_gf_real(d, 1e-8))
85 std::cerr <<
"WARNING: Assuming real interaction values, but found Imag(D0(tau)) > 1e-8. Casting to Real.\n";
86 D0_tau_lst.emplace_back(real(d));
92 if (indices.size() > 0) {
93 auto l = [beta = params.beta, n_s = params.n_s, indices = std::move(indices), labels = std::move(labels), D0_tau_lst = std::move(D0_tau_lst),
95 int n = rng(indices.size());
98 auto [sig, dtau] = cyclic_difference(t, tp);
100 double prop_proba = 1.0 / (beta * beta * indices.size() * n_s);
101 return vertex_t{indices[n], t, t, tp, tp, -D0_tau_lst[n](dtau) / n_s, prop_proba, labels[n], s};
104 vertex_factories.emplace_back(l);
111 std::vector<vertex_idx_t> indices;
112#ifdef INTERACTION_IS_COMPLEX
113 std::vector<gf<imtime, scalar_valued>> Jperp_tau_lst;
115 std::vector<gf<imtime, scalar_real_valued>> Jperp_tau_lst;
118 if (params.n_blocks() != 2) TRIQS_RUNTIME_ERROR <<
"Jperp requires exactly two blocks corresponding to the spins";
121 auto Jperp_tau = make_gf_imtime(make_gf_dlr(*Jperp_iw), params.n_tau_dynamical_interactions);
124 for (
int a = 0; a < Jperp_tau.target_shape()[0]; a++)
125 for (
int b = 0; b < Jperp_tau.target_shape()[1]; b++) {
126 auto d = slice_target_to_scalar(Jperp_tau, a, b);
128 if (max_norm(d) > 1e-10) {
129 indices.push_back({1, a, 0, a, 0, b, 1, b});
130 indices.push_back({0, a, 1, a, 1, b, 0, b});
131#ifdef INTERACTION_IS_COMPLEX
132 Jperp_tau_lst.emplace_back(d);
133 Jperp_tau_lst.emplace_back(d);
135 if (!is_gf_real(d, 1e-8)) std::cerr <<
"WARNING: Assuming real interaction values, but found Imag(Jperp(tau)) > 1e-8. Casting to Real.\n";
136 Jperp_tau_lst.emplace_back(real(d));
137 Jperp_tau_lst.emplace_back(real(d));
142 if (indices.size() > 0) {
143 auto l = [beta = params.beta, indices = std::move(indices), Jperp_tau_lst = std::move(Jperp_tau_lst), &rng] {
144 int n = rng(indices.size());
147 auto [sig, dtau] = cyclic_difference(t, tp);
148 double prop_proba = 1.0 / (beta * beta * indices.size());
149 return vertex_t{indices[n], t, t, tp, tp, Jperp_tau_lst[n](dtau) / 2.0, prop_proba};
152 vertex_factories.emplace_back(l);
156 return vertex_factories;
A struct combining both constr_params_t and solve_params_t.
static tau_t get_random(RNG &rng)
Get a random point in $[0,\beta[$.