3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-26 06:14:14 +01:00

Fix #66: when mc_sign_type is complex

- for complex type sign, we do not do the previous check
(to be improved), since isinf, signbit are not defined for
complex numbers.
This commit is contained in:
Olivier Parcollet 2014-03-28 15:37:37 +01:00
parent c996c3ff7d
commit 9c979ceb0b

View File

@ -162,6 +162,20 @@ namespace triqs { namespace mc_tools {
normaliseProba();// ready to run after each add ! normaliseProba();// ready to run after each add !
} }
private:
bool attempt_treat_infinite_ratio(std::complex<double>, double &) { return true; }
bool attempt_treat_infinite_ratio(double rate_ratio, double &abs_rate_ratio) {
bool is_inf = std::isinf(rate_ratio);
if (is_inf) { // in case the ratio is infinite
abs_rate_ratio = 100; // 1.e30; // >1 for metropolis
try_sign_ratio = (std::signbit(rate_ratio) ? -1 : 1); // signbit -> true iif the number is negative
}
return !is_inf;
}
public:
/** /**
* - Picks up one of the move at random (weighted by their proposition probability), * - Picks up one of the move at random (weighted by their proposition probability),
* - Call attempt method of that move * - Call attempt method of that move
@ -184,10 +198,7 @@ namespace triqs { namespace mc_tools {
#endif #endif
MCSignType rate_ratio = current->attempt(); MCSignType rate_ratio = current->attempt();
double abs_rate_ratio; double abs_rate_ratio;
if (std::isinf(rate_ratio)) { // in case the ratio is infinite if (attempt_treat_infinite_ratio(rate_ratio, abs_rate_ratio)) { // in case the ratio is infinite
abs_rate_ratio = 100; //1.e30; // >1 for metropolis
try_sign_ratio = (std::signbit(rate_ratio) ? -1 : 1); // signbit -> true iif the number is negative
} else {
if (!std::isfinite(std::abs(rate_ratio))) if (!std::isfinite(std::abs(rate_ratio)))
TRIQS_RUNTIME_ERROR << "Monte Carlo Error : the rate is not finite in move " << name_of_currently_selected(); TRIQS_RUNTIME_ERROR << "Monte Carlo Error : the rate is not finite in move " << name_of_currently_selected();
abs_rate_ratio = std::abs(rate_ratio); abs_rate_ratio = std::abs(rate_ratio);