示例#1
0
int main() {

  // inverse temperature
  double beta = 1 / T;

  // random number generator
  boost::mt19937 eng(SEED);
  boost::variate_generator<boost::mt19937&, boost::uniform_real<> >
    random_01(eng, boost::uniform_real<>());

  // spin configuration
  std::vector<int> spins(L);
  for (int s = 0; s < L; ++s) spins[s] = (random_01() < 0.5 ? 1 : -1);

  // measurement
  double ene = 0;
  double mag = 0;
  double mag2 = 0;
  double mag4 = 0;

  // timer
  boost::timer tm;
  
  for (int mcs = 0; mcs < MCSTEP + MCTHRM; ++mcs) {
    for (int s = 0; s < L; ++s) {
      double diff = 2 * spins[s] * (spins[left(s)] + spins[right(s)]);
      if (random_01() < 0.5 * (1 + std::tanh(-0.5 * beta * diff))) spins[s] = -spins[s];
    }
    if (mcs >= MCTHRM) {
      double m = 0;
      double g = 0;
      for (int s = 0; s < L; ++s) {
        g -= spins[s] * spins[right(s)];
        m += spins[s];
      }
      g /= L;
      m /= L;
      ene += g;
      mag += m;
      mag2 += m * m;
      mag4 += std::pow(m, 4);
    }
  }

  // output results
  std::cout << "Energy = " << ene / MCSTEP << std::endl;
  std::cout << "Magnetization = " << mag / MCSTEP << std::endl;
  std::cout << "Magnetization^2 = " << mag2 / MCSTEP << std::endl;
  std::cout << "Magnetization^4 = " << mag4 / MCSTEP << std::endl;
  std::cout << "Binder Ratio of Magnetization = " << mag2 * mag2 / mag4 / MCSTEP << std::endl;
  std::cerr << "Elapsed time = " << tm.elapsed() << " sec\n";

  return 0;
}
示例#2
0
文件: test.cpp 项目: yanglp091/oops
void prepare_data(string filename)
{/*{{{*/
    // create defect center
    double x =  0.0, y = 0.0, z = 0.89175;
    vec coord; coord << x << y << z;
    NVCenter nv(NVCenter::N14, coord);
    
    double magBx = 0.0,  magBy =  0.0, magBz = 1e-5;
    nv.set_magB(magBx, magBy, magBz);
    nv.make_espin_hamiltonian();

    cout << nv.get_eigen_state(0) << endl;
    cout << nv.get_eigen_state(1) << endl;

    cSPIN espin=nv.get_espin();
    PureState st0(nv.get_eigen_state(0));
    PureState st1(nv.get_eigen_state(1));
    espin.set_coordinate(coord);
    cout << "espin coordinate = " << espin.get_coordinate() << endl;

    // create bath spins
    cSpinSourceFromFile spin_file(filename);
    cSpinCollection spins(&spin_file);
    spins.make();

    vector<cSPIN> sl = spins.getSpinList();

    cout << sl[0].get_coordinate() << sl[0].get_gamma() << endl;
    cout << sl[1].get_coordinate() << sl[1].get_gamma() << endl;


    vec magB; magB << magBx << magBy << magBz;
    SpinZeemanInteraction zee(sl, magB);
    SpinDipolarInteraction dip(sl);
    DipolarField hf_field0(sl, espin, st0);
    DipolarField hf_field1(sl, espin, st1);

    Hamiltonian hami0(sl);
    hami0.addInteraction(zee);
    hami0.addInteraction(dip);
    hami0.addInteraction(hf_field0);
    hami0.make();

    Hamiltonian hami1(sl);
    hami1.addInteraction(zee);
    hami1.addInteraction(dip);
    hami1.addInteraction(hf_field1);
    hami1.make();


    cout << hami0.getMatrix() << endl;
    cout << hami1.getMatrix() << endl;

    Liouvillian lv0(hami0, SHARP);
    Liouvillian lv1(hami1, FLAT);
    Liouvillian lvH = lv0 - lv1;


    double rate = 2.0*datum::pi*1e4;
    vec axis; axis << 1.0 << 1.0 << 1.0;
    SpinDephasing dephasing(sl, rate, normalise(axis));
    LiouvilleSpaceOperator dephaseOperator(sl);
    dephaseOperator.addInteraction(dephasing);
    dephaseOperator.make();

    QuantumOperator lv = lvH + dephaseOperator;
    lv.saveMatrix("lv");


    vec _bath_polarization = zeros<vec>(3);
    SpinPolarization p(sl, _bath_polarization);
    DensityOperator ds(sl);
    ds.addStateComponent(p);
    ds.make();
    ds.makeVector();
    cout << ds.getVector() << endl;
    cout << ds.getMatrix() << endl;


}/*}}}*/