mc_weight_type Try() {
#ifdef DEBUG
   std::cout << "I AM IN Try for Insert_Cdag_C_Delta" << 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 the value of alpha and choose the operators
   const Hloc::Operator 
    & Op1(*Config.CdagOps[a_level][Random(Nalpha)]),
    & Op2(*Config.COps[a_level][Random(Nalpha)]);

   // Choice of times.
   double tau1 = Random(Config.Beta), tau2 = Random(Config.Beta);

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

   // Insert the operators Op1 and Op2
   Configuration::OP_REF O1, O2;
   tie (no_trivial_reject,O1,O2) = Config.DT.insertTwoOperators(tau1,Op1,tau2,Op2);
   if (!no_trivial_reject) return 0;

   // pick up the determinant 
   // NB ; the det has to be recomputed each time, since global moves will change it
   det = Config.dets[a_level]; 
   int numCdag=1;

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

   // acceptance probability
   mc_weight_type p = Config.DT.ratioNewTrace_OldTrace() * det->try_insert(numCdag,numC,O1,O2);
   double Tratio =power(2*Nalpha* Config.Beta / double(2*(det->NumberOfC()+1)), 2);

#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;
  }
예제 #2
0
  mc_weight_type attempt() {
    
#ifdef DEBUG
    std::cout << "I AM IN attempt for Move" << std::endl;
    std::cout << "CONFIG BEFORE: " << Config.DT << std::endl;
    for (int a = 0; a < Config.Na; ++a) print_det(Config.dets[a]);
#endif

    // find an operator (anyone) to be moved.
    // to do this, I go over the DT trace
    const int L(Config.DT.Length());
    if (L==0) return 0;
    const int N(Random(L));

    // I go over the trace to find the op oldOpref
    // and then I get its info
    Configuration::OP_REF oldOpref = Config.DT.OpRef_begin();
    for (int i=0; i<N; ++i, ++oldOpref) {}
    int a = Config.info[oldOpref->Op->Number].a;
    int Nalpha = Config.COps[a].size();
    bool isdagger = Config.info[oldOpref->Op->Number].dagger;
    double oldtau = oldOpref->tau;

    // chose the new alpha (this is done here for compatibility)
    int newalpha = Random(Nalpha);

    int num;
    double tR, tL;
    det = Config.dets[a];
    Configuration::DET_TYPE::Cdagger_iterator itCdag = det->Cdagger_begin();
    Configuration::DET_TYPE::C_iterator       itC    = det->C_begin();

    if (det->size() > 1) {

      // find the C and Cdag operators at the right of oldOpref (at smaller times)
      // it might be Cdagger_end() or C_end()
      // also get the number num of oldOpref in the det
      num = 0;
      while ( (itCdag != det->Cdagger_end()) && (itCdag->tau >= oldtau) ) {++itCdag; if(isdagger) ++num;}
      while ( (itC != det->C_end()) &&  (itC->tau >= oldtau) ) {++itC; if(!isdagger) ++num;}

      // find the times of the operator at the right of oldOpref with cyclicity
      // then deduce the closest one and put its distance to oldOpref in tR
      double tRdag = (itCdag != det->Cdagger_end() ? (*itCdag)->tau : det->Cdagger_begin()->tau);
      double tRnodag = (itC != det->C_end() ? (*itC)->tau : det->C_begin()->tau);
      tR = std::min(Config.CyclicOrientedTimeDistance(oldtau - tRdag), Config.CyclicOrientedTimeDistance(oldtau - tRnodag));

      // move itCdag and itC to the operators on the left with cyclicity
      // find their times and deduce the closest one with distance tL
      if (isdagger) --itCdag; else --itC;
      if (itCdag != det->Cdagger_begin()) --itCdag; else itCdag = --det->Cdagger_end();
      if (itC != det->C_begin()) --itC; else itC = --det->C_end();
      tL = std::min(Config.CyclicOrientedTimeDistance((*itCdag)->tau - oldtau), Config.CyclicOrientedTimeDistance((*itC)->tau - oldtau));

    } else {

      num = 1;
      tR = (isdagger ?  Config.CyclicOrientedTimeDistance(oldtau - (*itC)->tau) : Config.CyclicOrientedTimeDistance(oldtau - (*itCdag)->tau));
      tL = (isdagger ?  Config.CyclicOrientedTimeDistance((*itC)->tau - oldtau) : Config.CyclicOrientedTimeDistance((*itCdag)->tau - oldtau));

    }

    // the new operator newOp with a new chosen alpha
    double newtau =  Config.CyclicOrientedTimeDistance(oldtau - tR + Random(tL + tR - 2*ctqmc_utils::EPSILON) + ctqmc_utils::EPSILON);
    const Hloc::Operator * newOp;
    newOp = (isdagger ? Config.CdagOps[a][newalpha] : Config.COps[a][newalpha]);

    // remove oldOpref and insert newOp in the Trace
    bool ok;
    Configuration::OP_REF Op;
    std::tie(ok,Op) = Config.DT.insert_and_remove_One_Operator(oldOpref, newtau, *newOp);
    if (!ok) return 0;

    // in the following we want to see if we need to roll the det
    roll_matrix = Configuration::DET_TYPE::None;

    // check if we went through \tau = 0 or \tau = \beta
    if (newtau - oldtau > tL) roll_matrix = (isdagger ? Configuration::DET_TYPE::Down  : Configuration::DET_TYPE::Right);
    if (oldtau - newtau > tR) roll_matrix = (isdagger ? Configuration::DET_TYPE::Up : Configuration::DET_TYPE::Left);

    // acceptance probability
    mc_weight_type p = Config.DT.ratioNewTrace_OldTrace() * (isdagger ? det->try_change_row(num-1,Op) : det->try_change_col(num-1,Op));

#ifdef DEBUG
    std::cout << "oldtau, tR, tL, newtau: " << oldtau << " " << tR << " " << tL << " " << newtau << endl;
    std::cout << "Trace Ratio: " << Config.DT.ratioNewTrace_OldTrace() << std::endl;
    std::cout << "Det Ratio: " << p/mc_weight_type(Config.DT.ratioNewTrace_OldTrace()) << std::endl;
    std::cout << "Rate: " << p << 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;
  }
  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;
  }