Exemplo n.º 1
0
// Compute the sign of the config from scratch
void Configuration::update_Sign() {

  int s =0;
  vector<int> n_op_with_a(Na,0), n_op_with_dag_a(Na,0);

  // In this first part we compute the sign to bring the configuration to
  // d^_1 d^_1 d^_1 ... d_1 d_1 d_1   d^_2 d^_2 ... d_2 d_2   ...   d^_n .. d_n

  // loop over the operators "op" in the trace (right to left)
  for (Configuration::OP_REF op = DT.OpRef_begin(); ! op.atEnd(); ++op) {

    // the info of the operator in "op"
    BlockInfo op_info(info[op->Op->Number]);

    // Check
    if ((op_info.a == -1) && (op->Op->Statistic != Hloc::Operator::Bosonic))
      TRIQS_RUNTIME_ERROR<<"Sign Computation : Operators must be fundamental or bosonic !!";

    //DEBUG. check fundamental ops.
    if (op_info.a != -1) assert (op->Op->Statistic == Hloc::Operator::Fermionic);

    // Skip the bosonic operator in the sign computation
    if (op->Op->Statistic == Hloc::Operator::Bosonic) continue;

    // how many operators with a smaller a than "op" are there on the right of "op"?
    for (int a = 0; a < op_info.a; a++) s += n_op_with_a[a];
    n_op_with_a[op_info.a]++;

    // if "op" is not a dagger how many operators of the same a but with a dagger are there on his right?
    if (!op_info.dagger)
      s += n_op_with_dag_a[op_info.a];
    else
      n_op_with_dag_a[op_info.a]++;
  }

  // Now we compute the sign to bring the configuration to
  // d_1 d^_1 d_1 d^_1 ... d_1 d^_1   ...   d_n d^_n ... d_n d^_n

  for (int a = 0; a < Na; a++) {
    int n = dets[a]->NumberOfC();
    s +=  n*(n+1)/2;
  }

  OldSign = CurrentSign;
  CurrentSign = (s%2==0 ? 1 : -1);

}
  mc_weight_type Try() {
   det = Config.dets[a_level]; 
   // NB the det pointer has to be recomputed each time, since global moves will change it

#ifdef DEBUG
   std::cout << "I AM IN Try for Insert_Cdag_C_Delta_SegmentPicture" << std::endl;
   std::cout << "CONFIG BEFORE: " << Config.DT << std::endl;
   // for (int a = 0; a<Config.Na; ++a) print_det(Config.dets[a]);
#endif

   // Pick up a time to insert the first operator
   double tau1 = Random(Config.Beta);

   // Now find the operator A on the same a level at later time, with cyclicity
   // and compute the maximal *oriented* length between the 2 operators (with cyclicity)
   Configuration::OP_REF A;
   if (det->size()>0) { // non empty
    Configuration::DET_TYPE::Cdagger_iterator itCdag = det->Cdagger_begin();
    Configuration::DET_TYPE::C_iterator       itC    = det->C_begin(); 
    while ( (itCdag != det->Cdagger_end()) && (itCdag->tau > tau1) ) {++itCdag;}
    while ( (itC != det->C_end()) &&  (itC->tau > tau1) ) {++itC;}
    if (itCdag != det->Cdagger_begin()) --itCdag; else itCdag = --det->Cdagger_end(); 
    if (itC != det->C_begin()) --itC; else itC = --det->C_end();
    double rC = Config.CyclicOrientedTimeDistance((*itC)->tau - tau1);
    double rCdag = Config.CyclicOrientedTimeDistance((*itCdag)->tau - tau1);
    A = ( rC > rCdag ? *itCdag : * itC);
    try_insert_length_max  = min(rC,rCdag);
   }
   else { // empty case.
    try_insert_length_max  = Config.Beta;
    A  = Config.DT.OpRef_end();
   }    

   // pick up the actual segment length
   double rr= Random(try_insert_length_max-2*EPSILON) + EPSILON;

   // deduce the time of the second operator
   double tau2 = Config.CyclicOrientedTimeDistance(tau1 + rr);

   // record the length of the kinks
   if (Config.RecordStatisticConfigurations) {
    deltaTau = Config.CyclicOrientedTimeDistance(tau2 - tau1);
    HISTO_Length_Kinks_Proposed<< abs(deltaTau);
   }

   // Choose the operators to be inserted
   const Hloc::Operator 
    & OpCdag(*Config.CdagOps[a_level][0]),
    & OpC(*Config.COps[a_level][0]);

   // shall we add C^+ C or  C C^+
   // we look whether the next operator is a dagger
   bool Op1_is_dagger = true;
   if (!A.atEnd()) {
    const Configuration::BlockInfo & INFO(Config.info[A->Op->Number]); 
    assert(INFO.isFundamental());
    Op1_is_dagger = INFO.dagger;
   }

   // Insert the operators Op1 and Op2. 
   // O1 will always be the dagger : 
   // Cf doc of insertTwoOperators, order of output OPREF is the same as input operators 
   Configuration::OP_REF O1, O2;
   tie (no_trivial_reject,O1,O2) = (Op1_is_dagger ? 
     Config.DT.insertTwoOperators(tau1,OpCdag,tau2,OpC) : 
     Config.DT.insertTwoOperators(tau2,OpCdag,tau1,OpC));
   if (!no_trivial_reject) return 0;

   double tauCdag = (Op1_is_dagger ? tau1 : tau2);
   double tauC = (Op1_is_dagger ? tau2 : tau1);

   // Find the position for insertion in the determinant
   // NB : the determinant store the C in decreasing order.
   int numCdag=1;
   for (Configuration::DET_TYPE::Cdagger_iterator p= det->Cdagger_begin();
     (p != det->Cdagger_end()) && (p->tau > tauCdag)  ; ++p, ++numCdag) {}
   int numC=1;
   for (Configuration::DET_TYPE::C_iterator p= det->C_begin(); 
     (p != det->C_end()) &&  (p->tau > tauC) ; ++p, ++numC) {}

   // acceptance probability
   mc_weight_type p = Config.DT.ratioNewTrace_OldTrace() * det->try_insert(numCdag-1,numC-1,O1,O2);
   int Na(det->size()+1); 
   // !!! det not modified until det->complete_operation is called, so I need to compensate by +1
   double Tratio = Config.Beta * try_insert_length_max / (Na ==1 ? 1 : 2*Na);
   // (Na... term : cf remove move...
#ifdef DEBUG
   std::cout << "Trace Ratio: " << Config.DT.ratioNewTrace_OldTrace() << std::endl;
   std::cout << "p*T: " << p*Tratio << std::endl;
   std::cout << "CONFIG AFTER: " << Config.DT << std::endl;
   //for (int a = 0; a<Config.Na; ++a) print_det(Config.dets[a]);
#endif

   return p*Tratio;
  }