예제 #1
0
int
gs_fifobuffer_rseek(GsFIFOBuffer* fifo, int offset, int whence)
{
    if(whence == SEEK_END || whence == SEEK_SET){ return -1; }
    if(offset >= 0){
        if(offset > gs_fifobuffer_getUsedSize(fifo)){
            offset = gs_fifobuffer_getUsedSize(fifo);
        }
        return rbuffer(NULL, &offset);
    }else{
        offset = -offset;
        if(offset >= gs_fifobuffer_getWriterReaderDistance(fifo)){
            offset = gs_fifobuffer_getWriterReaderDistance(fifo);
        }
//        if(mMutex) mMutex->lock();
        if(fifo->mrptr >= fifo->mwptr){
            fifo->mrptr -= offset;
        }else{
            if(offset <= (fifo->mrptr - fifo->mBuf)){
                fifo->mrptr -= offset;
            }else{
                offset -= (fifo->mrptr - fifo->mBuf);
                fifo->mrptr = fifo->mBufEnd - offset;
            }
        }
        fifo->mDataSize += offset;
//        if(mMutex) mMutex->unlock();
    }
}
예제 #2
0
파일: csf.C 프로젝트: sanshar/StackBlock
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, int integralIndex)
{
  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 <500)
  {
    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[integralIndex](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;
}
예제 #3
0
파일: csf.C 프로젝트: sanshar/StackBlock
std::vector<Csf> Csf::distributeNonSpinAdapted (const int n, const int sp, const IrrepVector &sym, const int left, const int right, const int edge, int integralIndex)
{
  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[integralIndex](i, i), alphaIndex));
      ++alphaIndex;
    }
    else // beta orb
    {
      betaMap.insert(pair<double, int>(v_1[integralIndex](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;
}
예제 #4
0
OGREnvelope extract(
        Options& options,
        osmium::geom::OGRFactory<osmium::geom::Projection>& factory,
        osmium::memory::Buffer::t_iterator<osmium::OSMObject> begin,
        osmium::memory::Buffer::t_iterator<osmium::OSMObject> relations,
        osmium::memory::Buffer::t_iterator<osmium::OSMObject> end,
        osmium::Timestamp point_in_time) {

    options.vout << "Working on " << point_in_time << "...\n";
    options.vout << "  Filtering data...\n";

    // nodes and ways
    using diff_iterator = osmium::DiffIterator<osmium::memory::Buffer::t_iterator<osmium::OSMObject>>;
    osmium::memory::Buffer fbuffer{initial_buffer_size, osmium::memory::Buffer::auto_grow::yes};
    {
        const diff_iterator dbegin{begin, relations};
        const diff_iterator dend{relations, relations};

        std::for_each(dbegin, dend, [point_in_time, &fbuffer](const osmium::DiffObject& d) {
            if (d.is_visible_at(point_in_time)) {
                fbuffer.add_item(d.curr());
                fbuffer.commit();
            }
        });
    }
    options.vout << "  Done. Filtered data needs "
                 << (fbuffer.committed() / (1024 * 1024))
                 << " MBytes.\n";

    // relations
    osmium::memory::Buffer rbuffer(initial_buffer_size, osmium::memory::Buffer::auto_grow::yes);
    {
        const diff_iterator dbegin{relations, end};
        const diff_iterator dend{end, end};

        std::for_each(dbegin, dend, [point_in_time, &rbuffer](const osmium::DiffObject& d) {
            if (d.is_visible_at(point_in_time)) {
                rbuffer.add_item(d.curr());
                rbuffer.commit();
            }
        });
    }

    osmium::area::AssemblerLegacy::config_type assembler_config;
    osmium::area::MultipolygonManagerLegacy<osmium::area::AssemblerLegacy> mp_manager{assembler_config};

    options.vout << "  Reading relations...\n";
    osmium::apply(rbuffer, mp_manager);
    mp_manager.prepare_for_lookup();

    index_type index_pos;
    location_handler_type location_handler(index_pos);
    location_handler.ignore_errors();

    options.vout << "  Creating geometries...\n";
    const std::string date = point_in_time.to_iso().substr(0, 10);

    std::vector<std::string> datasource_options;
    std::string datasource_name{options.output_directory + "/" + date};
    if (options.output_format == "GeoJSON") {
        datasource_name += ".json";
    } else if (options.output_format == "SQLite") {
        datasource_name += ".db";
        datasource_options.push_back("SPATIALITE=TRUE");
        CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
        CPLSetConfigOption("OGR_SQLITE_CACHE", "512");
    }

    gdalcpp::Dataset dataset{options.output_format, datasource_name, gdalcpp::SRS{factory.proj_string()}, datasource_options};

#ifdef HANDLER
    HANDLER geom_handler{factory, dataset, date};
#else
    BuildingsHandler geom_handler{factory, dataset, date};
#endif
    osmium::apply(fbuffer.begin(),
                  fbuffer.end(),
                  location_handler,
                  geom_handler,
                  mp_manager.handler([&geom_handler](const osmium::memory::Buffer& buffer) {
        osmium::apply(buffer, geom_handler);
    }));

    return geom_handler.envelope();
}