1919 *
2020 ******************************************************************************/
2121#include < limits>
22+ #include < boost/preprocessor/seq/for_each.hpp>
23+ #include < boost/preprocessor/seq/for_each_product.hpp>
2224
2325#include " som_core.hpp"
2426#include " kernels/fermiongf_imtime.hpp"
@@ -119,10 +121,7 @@ som_core::som_core(gf_const_view<imtime> g_tau, gf_const_view<imtime> S_tau,
119121 mesh (g_tau.mesh()), kind(kind), norms(make_default_norms(norms,get_target_shape(g_tau)[0 ])),
120122 rhs (input_data_r_t ()), error_bars(input_data_r_t ()) {
121123
122- if (kind != FermionGf && kind != BosonCorr && kind != BosonAutoCorr && kind != ZeroTemp)
123- fatal_error (" unknown observable kind " + to_string (kind));
124-
125- if (kind != ZeroTemp) check_gf_stat (g_tau, observable_statistics (kind));
124+ if (is_stat_relevant (kind)) check_gf_stat (g_tau, observable_statistics (kind));
126125
127126 check_input_gf (g_tau,S_tau);
128127 if (!is_gf_real (g_tau) || !is_gf_real (S_tau))
@@ -137,10 +136,7 @@ som_core::som_core(gf_const_view<imfreq> g_iw, gf_const_view<imfreq> S_iw,
137136 mesh (g_iw.mesh()), kind(kind), norms(make_default_norms(norms,get_target_shape(g_iw)[0 ])),
138137 rhs (input_data_c_t ()), error_bars(input_data_c_t ()) {
139138
140- if (kind != FermionGf && kind != BosonCorr && kind != BosonAutoCorr && kind != ZeroTemp)
141- fatal_error (" unknown observable kind " + to_string (kind));
142-
143- if (kind != ZeroTemp) check_gf_stat (g_iw, observable_statistics (kind));
139+ if (is_stat_relevant (kind)) check_gf_stat (g_iw, observable_statistics (kind));
144140
145141 check_input_gf (g_iw,S_iw);
146142 if (!is_gf_real_in_tau (g_iw) || !is_gf_real_in_tau (S_iw))
@@ -157,10 +153,7 @@ som_core::som_core(gf_const_view<legendre> g_l, gf_const_view<legendre> S_l,
157153 mesh (g_l.mesh()), kind(kind), norms(make_default_norms(norms,get_target_shape(g_l)[0 ])),
158154 rhs (input_data_r_t ()), error_bars(input_data_r_t ()) {
159155
160- if (kind != FermionGf && kind != BosonCorr && kind != BosonAutoCorr && kind != ZeroTemp)
161- fatal_error (" unknown observable kind " + to_string (kind));
162-
163- if (kind != ZeroTemp) check_gf_stat (g_l, observable_statistics (kind));
156+ if (is_stat_relevant (kind)) check_gf_stat (g_l, observable_statistics (kind));
164157
165158 check_input_gf (g_l,S_l);
166159 if (!is_gf_real (g_l) || !is_gf_real (S_l))
@@ -177,9 +170,17 @@ void som_core::run(run_parameters_t const& p) {
177170
178171 params = p;
179172
180- if ((kind == BosonAutoCorr || kind == ZeroTemp) && params.energy_window .first < 0 ) {
181- params.energy_window .first = 0 ;
182- if (params.verbosity > 0 ) warning (" left boundary of the energy window is reset to 0" );
173+ double e_min, e_max;
174+ std::tie (e_min,e_max) = max_energy_window (kind);
175+ if (params.energy_window .first < e_min) {
176+ params.energy_window .first = e_min;
177+ if (params.verbosity > 0 )
178+ warning (" left boundary of the energy window is reset to " + std::to_string (e_min));
179+ }
180+ if (params.energy_window .second > e_max) {
181+ params.energy_window .second = e_max;
182+ if (params.verbosity > 0 )
183+ warning (" right boundary of the energy window is reset to " + std::to_string (e_max));
183184 }
184185
185186 if (params.energy_window .first >= params.energy_window .second )
@@ -202,20 +203,12 @@ void som_core::run(run_parameters_t const& p) {
202203 triqs::signal_handler::start ();
203204 run_status = 0 ;
204205 try {
205- #define RUN_IMPL_CASE (ok, mk ) case (int (ok) + 4 * mesh_traits<mk>::index): run_impl<kernel<ok,mk>>(); break ;
206- switch (int (kind) + 4 * mesh.index ()) {
207- RUN_IMPL_CASE (FermionGf,imtime);
208- RUN_IMPL_CASE (FermionGf,imfreq);
209- RUN_IMPL_CASE (FermionGf,legendre);
210- RUN_IMPL_CASE (BosonCorr,imtime);
211- RUN_IMPL_CASE (BosonCorr,imfreq);
212- RUN_IMPL_CASE (BosonCorr,legendre);
213- RUN_IMPL_CASE (BosonAutoCorr,imtime);
214- RUN_IMPL_CASE (BosonAutoCorr,imfreq);
215- RUN_IMPL_CASE (BosonAutoCorr,legendre);
216- RUN_IMPL_CASE (ZeroTemp,imtime);
217- RUN_IMPL_CASE (ZeroTemp,imfreq);
218- RUN_IMPL_CASE (ZeroTemp,legendre);
206+ #define RUN_IMPL_CASE (r, okmk ) \
207+ case (int (BOOST_PP_SEQ_ELEM (0 ,okmk)) + \
208+ n_observable_kinds * mesh_traits<BOOST_PP_SEQ_ELEM (1 ,okmk)>::index): \
209+ run_impl<kernel<BOOST_PP_SEQ_ENUM (okmk)>>(); break ;
210+ switch (int (kind) + n_observable_kinds * mesh.index ()) {
211+ BOOST_PP_SEQ_FOR_EACH_PRODUCT (RUN_IMPL_CASE , (ALL_OBSERVABLES )(ALL_INPUT_MESHES ))
219212 }
220213 #undef RUN_IMPL_CASE
221214 } catch (stopped & e) {
@@ -461,65 +454,30 @@ template<typename MeshType>
461454void triqs_gf_view_assign_delegation (gf_view<MeshType> g, som_core const & cont) {
462455 auto gf_dim = cont.results .size ();
463456 check_gf_dim (g, gf_dim);
464- if (cont.kind != ZeroTemp ) check_gf_stat (g, observable_statistics (cont.kind ));
457+ if (is_stat_relevant ( cont.kind ) ) check_gf_stat (g, observable_statistics (cont.kind ));
465458
466459 g () = 0 ;
460+ #define FILL_DATA_CASE (r, data, ok ) \
461+ case ok: { \
462+ kernel<ok,MeshType> kern (g.mesh ()); \
463+ for (int i : range (gf_dim)) fill_data (g, i, kern (cont.results [i])); \
464+ return ; \
465+ }
467466 switch (cont.kind ) {
468- case FermionGf: {
469- kernel<FermionGf,MeshType> kern (g.mesh ());
470- for (int i : range (gf_dim)) fill_data (g, i, kern (cont.results [i]));
471- return ;
472- }
473- case BosonCorr: {
474- kernel<BosonCorr,MeshType> kern (g.mesh ());
475- for (int i : range (gf_dim)) fill_data (g, i, kern (cont.results [i]));
476- return ;
477- }
478- case BosonAutoCorr: {
479- kernel<BosonAutoCorr,MeshType> kern (g.mesh ());
480- for (int i : range (gf_dim)) fill_data (g, i, kern (cont.results [i]));
481- return ;
482- }
483- case ZeroTemp: {
484- kernel<ZeroTemp,MeshType> kern (g.mesh ());
485- for (int i : range (gf_dim)) fill_data (g, i, kern (cont.results [i]));
486- return ;
487- }
488- default :
489- fatal_error (" unknown observable kind " + to_string (cont.kind ));
467+ BOOST_PP_SEQ_FOR_EACH (FILL_DATA_CASE , _, ALL_OBSERVABLES )
468+ default : fatal_error (" unknown observable kind " + to_string (cont.kind ));
490469 }
470+ #undef FILL_DATA_CASE
491471}
492472
493473template <> void triqs_gf_view_assign_delegation<refreq>(gf_view<refreq> g_w, som_core const & cont) {
494-
495- bool bosoncorr = cont.kind == BosonCorr || cont.kind == BosonAutoCorr;
496- if (cont.kind != FermionGf && !bosoncorr && cont.kind != ZeroTemp)
497- fatal_error (" unknown observable kind " + to_string (cont.kind ));
498474 auto gf_dim = cont.results .size ();
499475 check_gf_dim (g_w, gf_dim);
500-
501- g_w () = 0 ;
502- auto & tail = g_w.singularity ();
503-
504- for (int i : range (gf_dim)) {
505- auto const & conf = cont.results [i];
506- for (auto const & rect : conf) {
507- for (auto e : g_w.mesh ()) g_w.data ()(e.index (),i,i) += rect.hilbert_transform (double (e), bosoncorr);
508- tail.data ()(range (),i,i) += rect.tail_coefficients (tail.order_min (),tail.order_max (), bosoncorr);
509-
510- if (cont.kind == BosonAutoCorr) {
511- // Add a reflected rectangle
512- rectangle reflected_rect (-rect.center , rect.width , rect.height , const_cast <som_core&>(cont).ci );
513- for (auto e : g_w.mesh ()) g_w.data ()(e.index (),i,i) += reflected_rect.hilbert_transform (double (e), true );
514- tail.data ()(range (),i,i) += reflected_rect.tail_coefficients (tail.order_min (),tail.order_max (), true );
515- }
516- }
517-
518- if (bosoncorr) {
519- g_w.data ()(range (),i,i) *= -1.0 /M_PI ;
520- tail.data ()(range (),i,i) *= -1.0 /M_PI ;
521- }
522- }
476+ for (int i : range (gf_dim))
477+ back_transform (cont.kind ,
478+ cont.results [i],
479+ const_cast <som_core&>(cont).ci ,
480+ slice_target_to_scalar (g_w, i, i));
523481}
524482
525483template void triqs_gf_view_assign_delegation<imtime>(gf_view<imtime>, som_core const &);
0 commit comments