Пример #1
0
double SpinAdapted::det_energy (const Slater& s)
{
  // energy of a single slater determinant, used in truncation                                                                            
  double energy = 0;
  Slater bra;
  Slater ket;

  for (int i = 0; i < s.size (); ++i)
    {
      ket = s;
      bra = s;
      energy += ket.trace (bra.d(i).c(i)) *
        v_1 (i,i);
    }

  // diagonal                                                                                                                             
  for (int i = 0; i < s.size (); ++i)
    for (int j = 0; j < s.size (); ++j)
      {
	ket = s;
	bra = s;
	energy += .5 * ket.trace (bra.d(j).d(i).c(j).c(i))
	  * (v_2 (i,j,j,i) - v_2 (i,j,i,j));
      }

  return energy;
}
Пример #2
0
void test16() {
    CS225::SparseVector v;
    for (int i=0;i<6;++i)  v[i]=i+1;
    std::cout << "v = " << v << std::endl;

    CS225::SparseVector v_1(0*v);
    std::cout << "CS225::SparseVector v_1(0*v);\n";
    v_1.PrintRaw();
}
Пример #3
0
float Shape::avgEdgeLength()
{
  float total_length = 0.0;
  for (int i = 0; i < face_list.size() / 3; ++i)
  {
    int v[3] = { face_list[3 * i + 0], face_list[3 * i + 1], face_list[3 * i + 2] };
    Vector3f v_0(vertex_list[3 * v[0] + 0], vertex_list[3 * v[0] + 1], vertex_list[3 * v[0] + 2]);
    Vector3f v_1(vertex_list[3 * v[1] + 0], vertex_list[3 * v[1] + 1], vertex_list[3 * v[1] + 2]);
    Vector3f v_2(vertex_list[3 * v[2] + 0], vertex_list[3 * v[2] + 1], vertex_list[3 * v[2] + 2]);
    total_length += (v_0 - v_1).norm() + (v_1 - v_2).norm() + (v_2 - v_0).norm();
  }
  return total_length / face_list.size();
}
Пример #4
0
std::vector<Csf> Csf::distributeNonSpinAdapted (const int n, const int sp, const IrrepVector &sym, const int left, const int right, const int edge)
{
  std::vector<Csf> s;
  
  int na = 0;
  int nb = 0;
  na = (n + sp) / 2;
  nb = (n - sp) / 2;

  // let's count how many left and right orbitals there actually are
  int actualOrbs = right - left;
  int actualNA, actualNB;
  actualNA = actualNB = 0;
  for (int i=left; i<right; ++i)
    {
      if((SpinOf(i) == 1))
	++actualNA;
      else
	++actualNB;
    }

  // cannot form this combination
  if (na > actualNA || nb > actualNB || na < 0 || nb < 0) 
    {
      return s;
    }

  // now make orbital occupancies
  std::vector<int> alphaSeed (actualNA);
  std::vector<int> betaSeed (actualNB);
  for (int i = 0; i < na; ++i)
    alphaSeed [i] = -1;
  for (int i = 0; i < nb; ++i)
    betaSeed [i] = -1;

  // okay now make some permutations (at most GUESS_PERMUTATIONS)
  std::vector< std::vector<int> > alphaList; alphaList.push_back (alphaSeed);
  std::vector< std::vector<int> > betaList; betaList.push_back (betaSeed);
  int numberOfGuesses = dmrginp.guess_permutations();
  while (next_permutation (alphaSeed.begin (), alphaSeed.end ()) && numberOfGuesses--)      
    alphaList.push_back (alphaSeed);
  numberOfGuesses = dmrginp.guess_permutations();;
  while (next_permutation (betaSeed.begin (), betaSeed.end ()) && numberOfGuesses--)
    betaList.push_back (betaSeed);
  

  // okay - we have all the permutations. 
  // make list of available alpha and beta orbitals in energy ordering.
  std::vector<int> orbitalAlphaList;
  std::vector<int> orbitalBetaList;

  multimap <double, int> alphaMap;
  multimap <double, int> betaMap;

  int alphaIndex = 0;
  int betaIndex = 0;

  // scan orbitals from left to right, pick out orbitals which are occupied in the hartree-fock reference
  for (int i=left; i<right; ++i)
  {
    if (dmrginp.hf_occupancy()[i])
    {
      if ((SpinOf(i) == 1)) // 0 to take into account case of nospin
      {
	orbitalAlphaList.push_back(alphaIndex);
	++alphaIndex;
      }
      else
      {
	orbitalBetaList.push_back(betaIndex);
	++betaIndex;
      }
    }
    else if ((SpinOf(i) == 1)) // not HF orb, but alpha orb
    {
      alphaMap.insert(pair<double, int>(v_1(i, i), alphaIndex));
      ++alphaIndex;
    }
    else // beta orb
    {
      betaMap.insert(pair<double, int>(v_1(i, i), betaIndex));
      ++betaIndex;
    }
  }

  for (multimap<double, int>::iterator m=alphaMap.begin (); m!=alphaMap.end (); ++m)
    orbitalAlphaList.push_back(m->second);
  for (multimap<double, int>::iterator m=betaMap.begin (); m!=betaMap.end (); ++m)
    orbitalBetaList.push_back(m->second);

  // Now convert permutation lists to energy ordered form
  for (int i=0; i<alphaList.size (); ++i)
    ConvertList (alphaList[i], orbitalAlphaList);
  for (int i=0; i<betaList.size (); ++i)
    ConvertList (betaList[i], orbitalBetaList);
  // Now catenate to make Slaters
  for (int i=0; i<alphaList.size(); ++i)
    for (int j=0; j<betaList.size(); ++j)
    {
      std::vector<bool> lbuffer(left, 0);
      std::vector<bool> rbuffer(edge - right, 0);
      
      std::vector<bool> orbs(right - left);
      int alphaI = 0;
      int betaI = 0;
      for (int orbI=0; orbI<right-left; ++orbI)
      {
	if (SpinOf(orbI + left) == 1)
	{
	  if (alphaList[i][alphaI]) orbs[orbI] = 1;
	  ++alphaI;
	}
	else
	{
	  if (betaList[j][betaI]) orbs[orbI] = 1;
	  ++betaI;
	}
      }
      std::vector<bool> tmp = lbuffer;
      for (std::vector<bool>::iterator it = orbs.begin(); it!=orbs.end(); ++it) tmp.push_back(*it);
      for (std::vector<bool>::iterator it = rbuffer.begin(); it!=rbuffer.end(); ++it) tmp.push_back(*it);
      Slater new_det = Slater (Orbstring (tmp));
      map<Slater, double> m;
      m[new_det] = 1.0;
      if(sym.getirrep() == AbelianSymmetryOf(new_det).getirrep())
	s.push_back (Csf(m,n,SpinSpace(sp), sp, IrrepVector(sym.getirrep(),0)));
    }
  return s;
}
Пример #5
0
std::vector< SpinAdapted::Csf > SpinAdapted::Csf::distribute (const int n, const int sp, const IrrepVector &sym, const int left, const int right, const int edge)
{
  std::vector< Csf > s;

  int na = 0;
  int nb = 0;
  na = (n + sp) / 2;
  nb = (n - sp) / 2;

  if(dmrginp.hamiltonian() == HEISENBERG && nb != 0) return s;
  // let's count how many left and right orbitals there actually are                                                                      
  int actualOrbs = dmrginp.spatial_to_spin()[right] - dmrginp.spatial_to_spin()[left];
  int actualNA, actualNB;
  actualNA = actualOrbs/2;
  actualNB = actualOrbs/2;

  // cannot form this combination 

  if (na > actualNA || nb > actualNB || na < 0 || nb < 0)
    {
      return s;
    }

  // now make orbital occupancies                                                                                                         
  std::vector<int> abSeed (right-left);
  for (int i = 0; i < max(na, nb); ++i)
    abSeed [i] = -1;

  // okay now make some permutations (at most GUESS_PERMUTATIONS)  
  std::vector< std::vector<int> > abList; abList.push_back (abSeed);

  int numberOfGuesses = dmrginp.guess_permutations();
  bool doAgain = true;
  int numtries = 0;
  while(doAgain && numtries <5000)
  {
    while (next_permutation (abSeed.begin (), abSeed.end ()) && numberOfGuesses--) 
      abList.push_back (abSeed);

    // make list of available alpha and beta orbitals in energy ordering.
    std::vector<int> orbitalList;
    
    multimap <double, int> orbMap;
    
    int alphaIndex = 0;
    
    // scan orbitals from left to right, pick out orbitals which have smallest v_1(i, i) integrals
    
    for (int i=left; i<right; ++i)
      {
	if (dmrginp.hf_occupancy()[dmrginp.spatial_to_spin()[i]]) {
	  orbitalList.push_back(alphaIndex);
	  alphaIndex++;
	  continue;
	}
	orbMap.insert(pair<double, int>(v_1(2*i, 2*i), alphaIndex));
	++alphaIndex;
      }
    
    for (multimap<double, int>::iterator m=orbMap.begin (); m!=orbMap.end (); ++m)
      orbitalList.push_back(m->second);
    

    // Now convert permutation lists to energy ordered form
    for (int i=0; i<abList.size (); ++i)
      ConvertList (abList[i], orbitalList);
    
    
    Slater last_det;
    // Now catenate to make Slaters
    for (int i=0; i<abList.size(); ++i)
      {
	std::vector<bool> lbuffer(dmrginp.spatial_to_spin()[left], 0);
	std::vector<bool> rbuffer(dmrginp.spatial_to_spin()[edge] - dmrginp.spatial_to_spin()[right], 0);
	
	std::vector<bool> orbs(dmrginp.spatial_to_spin()[right] - dmrginp.spatial_to_spin()[left], 0);
	int alphaI = 0;
	int betaI = 0;
	
	for (int orbI=0; orbI<(right-left); orbI++)
	{
	  if (abList[i][alphaI]) {
	    orbs[dmrginp.spatial_to_spin()[orbI]] = 1;
	    if (betaI < min(na, nb)) {
	      orbs[ dmrginp.spatial_to_spin()[orbI]+1] = 1;
	      ++betaI;
	    }
	  }
	  ++alphaI;
	}
	
	std::vector<bool> tmp = lbuffer;
	for (std::vector<bool>::iterator it = orbs.begin(); it!=orbs.end(); ++it) tmp.push_back(*it);
	for (std::vector<bool>::iterator it = rbuffer.begin(); it!=rbuffer.end(); ++it) tmp.push_back(*it);
	Slater new_det = Slater (Orbstring (tmp));
	map<Slater, double> m;
	m[new_det] = 1.0;
	last_det = new_det;

	if(sym.getirrep() == AbelianSymmetryOf(new_det).getirrep())
	  s.push_back ( Csf(m, n, SpinSpace(sp), sp, IrrepVector(sym.getirrep(), 0)) );
      }
    
    if (s.size() == 0) {
      numtries++;
      doAgain = true;
      abList.clear();
      numberOfGuesses = dmrginp.guess_permutations();
    }
    else
      doAgain = false;
  }
  
  return s;
}