Example #1
0
int main (int, char **) {
	Lattice L = SV();
	L.relax(1e-14);
	L.tau = L.tau_rw();
	L.optimize (cost_cp);
	H.L->info ("Modulus: tau = {}", L.tau);

	Pen p (Color(255,0,0),1,Color(255,255,0));

	Figure F;

	vector<cpx> fd;
	fd.push_back(L(coo(1,1)));
	fd.push_back(L(coo(2,1)));
	fd.push_back(L(coo(2,2)));
	fd.push_back(L(coo(1,2)));
	F.add (std::make_unique <Polygon> (fd, Pen(0,0,200,true)));

	for (int i=0; i<3; ++i)
		for (int j=0; j<3; ++j)
			for (unsigned k=0; k<L.n; ++k)
				F.add (std::make_unique <Circle> (L(coo(i,j),k), L.r[k], Pen(0,.2)));

	for (int i=0; i<3; ++i)
		for (int j=0; j<3; ++j)
			for (unsigned k=0; k<L.n; ++k)
				for (unsigned l=0; l<L.adj[k].size(); ++l)
					F.add (std::make_unique <Segment> (L(coo(i,j),k), L(coo(i,j),k) + L.shift(k,l), Pen(0,.1)));

	F.show(); F.pause(); F.output_pdf();
	return 0;
}
Example #2
0
Sentence::Sentence(const Lattice &l)
{
	int i,n = l.get_word_count();
	syllables.resize(n); // pre-allocation
	for (i = 0;i < n;i ++) {
		const WordEntryRefs &wers = l.get_we(i);
		for (int j = 0;j < wers.size();j ++) {
			const WordEntry *pwe = wers[j];
			vector<strid> vsy;
			pwe->node.node->get_syllables(vsy);
			if (syllables.size() < i+vsy.size())
				syllables.resize(i+vsy.size());
			Sentence::Syllable sy;
			sy.span = 1;
			sy.sent_ = this;
			sy.start = 0;
			for (int pos = 0;pos < vsy.size(); pos ++) {
				sy.id = vsy[pos];
				sy.cid = get_ngram()[get_std_syllable(get_ngram()[sy.id])];
				syllables[i+pos] = sy;
			}
		}
	}
	int start = 0;
	for (i = 0;i < syllables.size();i ++) {
		if (i > 0) {
			sent_ += " ";
			start ++;
		}
		string s = get_ngram()[syllables[i].id];
		sent_ += s;
		syllables[i].start = start;
		start += s.size();
	}
}
void TransfererRunner::putTargetForm_(Lattice& lattice, Lattice::EdgeDescriptor edge, zvalue surf) {

    // could be a form or a token
    bool isForm = ZPAIRP(surf);

    std::string category =
        (isForm ? zvalue_to_string(ZPAIRC(surf)->getSecond()) : "T");

    zvalue text =
        (isForm ? ZPAIRC(surf)->getFirst() : surf);

    LayerTagCollection tags =
        lattice.getLayerTagManager().createTagCollection(
            isForm ? targetFormTags_ : targetTokenTags_);

    AnnotationItem annotationItem(category, StringFrag(zvalue_to_string(text)));

    lattice.getAnnotationItemManager().setValue(
        annotationItem, "SurfacePosition", formsCounter_++);

    Lattice::EdgeSequence::Builder builder(lattice);
    builder.addEdge(edge);

    Lattice::VertexDescriptor fromVertex = lattice.getEdgeSource(edge);
    Lattice::VertexDescriptor toVertex = lattice.getEdgeTarget(edge);

    lattice.addEdge(
        fromVertex,
        toVertex,
        annotationItem,
        tags,
        builder.build());
}
Example #4
0
void CloverLeaf2x2(Lattice& lattice, Matrix& pl,  int* pos, int mu, int nu)
{
  Matrix P0,P1,P2,P3;
  // 1x2 size
  P0.ZeroMatrix();
  P1.ZeroMatrix();
  P2.ZeroMatrix();
  P3.ZeroMatrix();
  
  // each direction could be {0,1,2,3,4,5,6,7} coresponding to
  // the directions {n_x, n_y, n_z, n_t, -n_x, -n_y, -n_z, -n_t}
  int dirs0[8]={mu,mu, nu, nu, mu+4,mu+4, nu+4, nu+4};
  lattice.PathOrdProdPlus(P0, pos, dirs0, 8);
    
  int dirs1[8]={nu+4, nu+4, mu+4, mu+4, nu, nu, mu,mu };
  lattice.PathOrdProdPlus(P1, pos, dirs1, 8);
  
  int dirs2[8]={nu, nu, mu+4, mu+4, nu+4, nu+4, mu, mu };
  lattice.PathOrdProdPlus(P2, pos, dirs2, 8);
  
  int dirs3[8]={mu,mu, nu+4, nu+4, mu+4, mu+4, nu, nu };
  lattice.PathOrdProdPlus(P3, pos, dirs3, 8);
  
  P0 -=  P1;
  P0 +=  P2;
  P0 -=  P3;
  P0 *= 1.0/16;
   
  moveMem((Float*) &pl,(Float*) &P0, 18 * sizeof(Float) );
  
}
int get_alternativelikelyhood_coordinates(float* Matrix, std::vector<double>& coordinates, std::vector<double>& likelyhoods, Lattice lattice, int distance, double& H_tot, int K_iteration)
{

  int D;
  
  if (lattice.get_dimensions() == 2)
    {
      D = lattice.area();
    }
  else
    {
      D = lattice.volume();
    }

  if (K_iteration == distance)
      {
	++K_iteration;
      }
  
  H_tot = likelyhoods.at(K_iteration);
  
  int S = K_iteration * D;
  std::vector<double>::const_iterator it;
  
  int i = 0;
  for (it = (coordinates.begin() + S);  it != (coordinates.begin() + S + D); ++it)
    {
      Matrix[i] = *it;
      ++i;
    }

  return K_iteration;
}
void TransfererRunner::processEdge(Lattice& lattice, Lattice::EdgeDescriptor edge) {
    std::cerr << "PROCESSING:";

    tmil::FileParsingScriptFactory* scriptFactory = new tmil::FileParsingScriptFactory;

    boost::shared_ptr<tmil::Transferer> transferer_;

    transferer_.reset(
        new tmil::Transferer(
            scriptFactory,
            lattice.getAnnotationItemManager().getZObjectsHolderPtr(),
            lattice.getAnnotationItemManager().getSymbolFactory()));

    transferer_->include(rulesFile_.string().c_str());

    EdgeToZsyntreeConverter converter(lattice);
    zsyntree* tree = converter.convertEdgeToZsyntree(edge);

    std::cerr << "  GOT SOURCE:" << tree->zsyntree_to_string() << std::endl;

    zsyntree* targetTree = transferer_->doTranslate(tree, NULL, NULL);

    std::cerr << "  GOT TARGET:" << targetTree->zsyntree_to_string() << std::endl;

    putZsyntreeIntoLattice(
        lattice,
        lattice.getLayerTagManager().createTagCollection(tags_),
        targetTree);

    putTargetForms_(
        lattice,
        targetTree,
        transferer_);
}
int get_maxlikelyhood_coordinates(float* Matrix, std::vector<double>& coordinates, std::vector<double>& likelyhoods, Lattice lattice)
{

  int D;
  
  if (lattice.get_dimensions() == 2)
    {
      D = lattice.area();
    }
  else
    {
      D = lattice.volume();
    }

  std::vector<double>::iterator max_likelyhood = std::max_element(likelyhoods.begin(),likelyhoods.end());
  
  int distance = std::distance(likelyhoods.begin(), max_likelyhood);
  int S = distance * D;
  std::vector<double>::const_iterator it;
  
  int i = 0;
  for (it = (coordinates.begin() + S);  it != (coordinates.begin() + S + D); ++it)
    {
      Matrix[i] = *it;
      ++i;
    }
 
  return distance;
}
void matrixmap_2D(float* Matrix, float** ptrMatrix, Lattice lattice)
{
  int M = lattice.get_M();
  int N = lattice.get_N();

  for(int i = 1; i <= N; i++)
    {
      for (int j = 1; j <= M; j++)
	{
	  ptrMatrix[ i + j*(N+2) ] = &(Matrix[ (i-1) + (j-1)*N ]);
	}     
    }
  
  for(int k = 1; k <= M; k++)
    {
      ptrMatrix[k*(N+2)] = &(Matrix[(k*N-1)]);
      ptrMatrix[N+1 + k*(N+2)] = &(Matrix[(k-1)*N]);
    }
  
  for(int k = 1; k <= N; k++)
    {
      ptrMatrix[k] = &(Matrix[(M-1)*N + k - 1]);
      ptrMatrix[k + (N+2)*(M+1)] = &(Matrix[k-1]);
    }
  
  //corners
  ptrMatrix[0] = &(Matrix[N*M-1]);
  ptrMatrix[N+1] = &(Matrix[N*(M-1)]);
  ptrMatrix[(N+2)*(M+1)] = &(Matrix[N-1]);
  ptrMatrix[(N+2)*(M+2)-1] = &(Matrix[0]); 
     
}
Example #9
0
static int chooseNextVariableByRandom (Lattice <T> & lattice, BitSet & allowed)
{
    int count = 0;
    static bool inited = false;

    if (!inited)
    {
        srand (time (NULL));
        inited = true;
    }

    for (unsigned int i = 0; i < lattice.variables (); i++)
    {
        if (allowed[i])
            count++;
    }

    if (count == 0)
        return -1;

    int random = rand () % count;

    for (unsigned int i = 0; i < lattice.variables (); i++)
    {
        if (allowed[i])
        {
            if (random == 0)
            {
                return i;
            }
            random--;
        }
    }
    return -1;
}
Example #10
0
// multiply exp( - i Q ) in `mu' direction. 
void twist_links(Lattice &lat, const Float Q, const int mu)
{
  // multiply su3 links by u1 links
  // assumes both are in canonical order!
  // link =  exp(-i A_mu Q) where Q is the 
  // quark electric charge or twist angle
  int x[4];
  Complex cc(cos(Q), -sin(Q)); 
  
  Matrix temp;
  for(x[3]=0; x[3]<GJP.TnodeSites();x[3]++){
    for(x[2]=0; x[2]<GJP.ZnodeSites();x[2]++){
      for(x[1]=0; x[1]<GJP.YnodeSites();x[1]++){
	for(x[0]=0; x[0]<GJP.XnodeSites();x[0]++){
	  int offset_x = lat.GsiteOffset(x);
	  // the link matrix at current site, in direction mu:
	  Matrix *su3_link = lat.GaugeField() + offset_x + mu;
	  //cTimesVec((float*)&temp, *(float*)phase, *((float*)phase+1), 
	  cTimesVec((IFloat*)&temp, (IFloat)cc.real(), (IFloat)cc.imag(), 
		    (IFloat*)su3_link, 18);
	  moveMem((IFloat*)su3_link, (IFloat*)&temp, 18);
	}
      }
    }
  }
}
Example #11
0
//From a single initial lattice
Flow::Flow(Lattice& state, bool firstrow) {
	cols = state.colSize();
	rows = state.rowSize();
	if(firstrow) { //if true 
		system.push_back(state);
	}
}
Example #12
0
RayGenerator::RayGenerator(const Lattice & l, unsigned char dim): l(l), dim(dim) {
    max = l.size() / l.N()(dim);
    origin = l.dx()/2;
    origin(dim) = 0;
    origin += l.bbox().min();
    stride = l.N()((dim+2)%3);

}
Example #13
0
//Return true if Lattice size matches up with that dictated by flow file, false otherwise
void Flow::checkLatticeSize(Lattice testlattice) {
	if (testlattice.rowSize() != Flow::getRows()) {
		throw runtime_error("Row size inequal.\n");
	}
	if(testlattice.colSize() != Flow::getCols()) {
		throw runtime_error("Column size inequal.\n");
	}
}
Example #14
0
//Constructor which creates a cubeArray from a gas, assigning each LatElem dim cubes in each dimension
//Boolean will remove the boundary of gas model
CubeArray::CubeArray(Model* model, int dim, bool boundariesRemoved) {
	int stacks = model->timeSize(); 
	int rows = 0; 
	int cols = 0;
	if(stacks > 0) {
		rows = model->getLatT(0).rowSize(); 
		cols = model->getLatT(0).colSize(); 
	}
	int n = (dim - 1); 
	int rowsBoolConsider = (boundariesRemoved ? rows - 2 : rows); 
	int colsBoolConsider = (boundariesRemoved ? cols - 2 : cols); 
	int newStacks = 2*n + (n-1)*(stacks-2) + (stacks-1); 
	int newRows = 2*n + (n-1)*(rowsBoolConsider - 2) + (rowsBoolConsider - 1); 
	int newCols = 2*n + (n-1)*(colsBoolConsider - 2) + (colsBoolConsider - 1); 
	cubes.resize(newStacks); 
	for(int i = 0; i < (newStacks); i++) {
		cubes[i].resize(newRows);
		for(int j = 0; j < (newRows); j++) { 
		cubes[i][j].resize(newCols); 
		}
	}
	for(int i = 0; i < stackSize(); i++) { 
		for(int j = 0; j < rowSize(); j++) { 
			for(int k = 0; k < colSize(); k++) { 
				cubes[i][j][k].setType(CubeElem::Empty); 
			}
		} 
	} 
	int stackInd = 0,rowInd,colInd;
	int lowerBound = (boundariesRemoved ? 1:0);
	int rowsUpperBound = (boundariesRemoved ? rows - 1 : rows);
	int colsUpperBound = (boundariesRemoved ? cols - 1 : cols);
	for(int k = 0; k < stacks; k++) { 
		rowInd = 0; 
		Lattice l = model->getLatT(k); 
		vector < vector < CubeElem > > stack; 
		for(int i = lowerBound ; i < rowsUpperBound ; i++) {
			colInd = 0; 
			vector< CubeElem > row;  
			for(int j = lowerBound; j < colsUpperBound; j++) {
				CubeElem::CubeType t = (l.getElement(i,j)->getValue() == 1 ? CubeElem::Full : CubeElem::Empty); 
				if(t == CubeElem::Full) {
					for(int x = 0; x <= n; x++) { 
						for (int y = 0; y <= n; y++) { 
							for(int z = 0; z <= n; z++) {
								cubes[stackInd+x][rowInd+y][colInd+z].setType(t); 
							}
						} 
					}
				}
				colInd += n;
			}
			rowInd += n; 
		}
		stackInd += n; 
	}
	setCubeNeighbours();
}
Example #15
0
 inline void operator() (Lattice& L, IndexList& idx)
 {
     typedef typename Lattice::element element;
     for(int dim = 0; dim < idx.size(); ++dim)
     {
         sum += L(idx) * L.get_n_left(idx, dim);
         sum += L(idx) * L.get_n_right(idx, dim);
     }
 }
Example #16
0
EdgeToZsyntreeConverter::EdgeToZsyntreeConverter(Lattice& latticeArg)
    :lattice(latticeArg),
     sym_fac(latticeArg.getAnnotationItemManager().getSymbolFactory()),
     holder(latticeArg.getAnnotationItemManager().getZObjectsHolderPtr()),
     lexemeTag_(latticeArg.getLayerTagManager().createSingletonTagCollection("lexeme")),
     formTag_(latticeArg.getLayerTagManager().createSingletonTagCollection("form")),
     parseTerminalTag_(latticeArg.getLayerTagManager().createSingletonTagCollection("parse-terminal")),
     equivMask_(lattice.getLayerTagManager().getSingletonMask("bilexicon")) {
}
Example #17
0
bool SimpleSubsystem::lattice_makes_sense (const Lattice &lattice) const
{
    if (lattice.n_dimensions() != subsystem_length.size())
        return false;
    for (unsigned int i = 0; i < lattice.n_dimensions(); ++i) {
        if (lattice.dimensions[i] < (int) subsystem_length[i])
            return false;
    }
    return true;
}
Example #18
0
 inline void operator() (Lattice& L, IndexList& idx) 
 {
     typename Lattice::element delta = 0;
     for(int dim = 0; dim < idx.size(); ++dim)
     {
         delta += L.get_n_left(idx, dim);
         delta += L.get_n_right(idx, dim);
     }
     L(idx) += delta;
 }
Example #19
0
int countAllEdges(Lattice & lattice) {
    int result = 0;
    Lattice::EdgesSortedByTargetIterator ei
        = lattice.edgesSortedByTarget(lattice.getLayerTagManager().anyTag());
    while (ei.hasNext()) {
        ei.next();
        ++result;
    }
    return result;
}
Example #20
0
LatticeLevelIterator::LatticeLevelIterator(const Lattice& l)
{
	int max;

	max=l.max_k() ? l.max_k() : 1;
	
	L=&l;
	iter=SimpleIndex(l.dim(),max);
	overflow=false;
}
Example #21
0
void WFST::generate_misspelled_words(const vector<uint> &pos,int len,Segmentation &final_seg)
{
	const Lattice &words = *p_words;
	Lattice w;

	w.based_on(words);
	
	// 2. Compute the score, jump to 1. if score is too low (pruning 1)

	// create new (more compact) Lattice structure
	int i,n = words.get_word_count();
	for (i = 0;i < len;i ++) {
		const WordEntryRefs &fmap = words.get_fuzzy_map(pos[i]);
		int ii,nn = fmap.size();
		for (ii = 0;ii < nn;++ii)
			w.add(*fmap[ii]);
	}

	//cerr << w << endl;

	// 4. Create sections
	Sections sects;
	sects.construct(words);

	// 5. Call create_base_segmentation
	//Segmentation base_seg(words.we);
	//create_base_segmentation(words,sects,base_seg);


	// 6. Get the best segmentation of each section,
	// then merge to one big segment.
	n = sects.size();

	uint ii,nn;

	i = ii = 0;
	nn = words.get_word_count();
	
	final_seg.clear();
	while (ii < nn)
		if (i < n && sects[i].start == ii) {
			Segmentation seg;
			sects[i].segment_best(words,seg);
			copy(seg.begin(),
					 seg.end(),
					 back_insert_iterator< Segmentation >(final_seg));
			ii += sects[i].len;
			i ++;
		} else {
			// only word(i,*,0) exists
			final_seg.push_back(words.get_we(ii)[0]->id);
			ii += words.get_we(ii)[0]->len;
		}
}
Example #22
0
void pt_init(Lattice &Lat){
  PTArg pt_arg;
//Size of local volume in all four directions
  pt_arg.size[0] = GJP.XnodeSites();
  pt_arg.size[1] = GJP.YnodeSites();
  pt_arg.size[2] = GJP.ZnodeSites();
  pt_arg.size[3] = GJP.TnodeSites();
  //-------------------------------------------------
  //Added by Michael C.
  for(int i = 0; i < 4;i++)
    if(GJP.Nodes(i) == 1)
      pt_arg.local[i] = 1;
    else
      pt_arg.local[i] = 0;
  //-------------------------------------------------
  int temp = 0;
  for(int i = 0;i<4;i++){
    temp += GJP.NodeSites(i)*GJP.NodeCoor(i);
  }
  if (temp%2==0)
    pt_arg.evenodd = PT_EVEN;
  else
    pt_arg.evenodd = PT_ODD;
  pt_arg.gauge_field_addr = (IFloat *)Lat.GaugeField();

  StrOrdType str_ord = Lat.StrOrd();
  printf("str_ord=%d\n",str_ord);

  switch(str_ord){
    case CANONICAL:
      pt_arg.g_str_ord = PT_XYZT;
      pt_arg.v_str_ord = PT_XYZT;
      pt_arg.v_str_ord_cb = PT_TXYZ;
      pt_arg.g_conj = 0;
      break;
    case WILSON:
      pt_arg.g_str_ord = PT_XYZT_CB_O;
      pt_arg.v_str_ord = PT_XYZT_CB_O;
      pt_arg.v_str_ord_cb = PT_TXYZ;
      pt_arg.g_conj = 0;
      break;
    case STAG:
      pt_arg.g_str_ord = PT_XYZT;
      pt_arg.v_str_ord = PT_XYZT;
      pt_arg.v_str_ord_cb = PT_TXYZ;
      pt_arg.g_conj = 1;
      break;
    default:
      break;
  }
  pt_arg.prec = sizeof(IFloat);
  StaticPT.init(&pt_arg);
}
Example #23
0
bool SimpleSubsystem::position_is_within (unsigned int site_index, const Lattice &lattice) const
{
    BOOST_ASSERT(lattice_makes_sense(lattice));

    const LatticeSite site(lattice.site_from_index(site_index));
    for (unsigned int i = 0; i < lattice.n_dimensions(); ++i) {
        BOOST_ASSERT(site[i] >= 0);
        if (site[i] >= (int) subsystem_length[i])
            return false;
    }
    return true;
}
int main()
{
	cout << "Forward sweep, Wilmott, Student Edition p. 193\n";

	int depth;
	cout << "How many subdivisions? ";
	cin >> depth;

	// Create the binomal lattice data conainer
	const int n = 2;
	Lattice<double, int, n> lattice1(depth);


	// Test data; change to suit your own needs
	double rootValue = 12.0;// Stock price now
	double D0 = 0.04;		// Dividend yield
	double vol = 0.3;		// Volatility
	double r = 0.06;		// Interest
	double T = 1.0;				// Time to expiry

	cout << "Give value for expiry T: ";
	cin >> T;

	// Create the 'special' parameters
	double k = T / double (depth);
	double e = ::exp((r-D0)*k);
	double sr = ::sqrt(exp(vol*vol*k) - 1.0);

	double up = e * (1.0 + sr);
	double down = e * (1.0 - sr);

	// Populate lattice: forward induction
	Lattice<double, int, 2> newLattice = 
			StandardLattice::createLattice(depth, rootValue, up, down);

	// Now work back from the payoff function; BACKWARD INDUCTION

	// First make the discrete payoff
	double K = 10.0;
	Vector<double, int> RHS = CallPayOff(K, newLattice[newLattice.MaxIndex()]);
	Vector<double, int> RHS2 = PutPayOff(K, lattice1[lattice1.MaxIndex()]);

	double p = 0.5;
	double discounting = ::exp(- r*k);
	
	double optionPrice = StandardLattice::traverse(newLattice, RHS, p, discounting);
	double optionPrice2 = StandardLattice::traverse(newLattice, RHS2, p, discounting);

	cout << "\nOption price C " << optionPrice << endl;
	cout << "\nOption price P " << optionPrice2 << endl;

	return 0;
}
Example #25
0
int main(int arc, char **argv)
{
	Lattice lattice;

	lattice.set_size(100);
	lattice.populate();

	// std::cout << lattice.by_id().find(boost::make_tuple(5, 5, 1))->strength << "\n";


	return 0;
}
Example #26
0
void RuleMatcher::addPosEdges(Lattice &lattice) {
    LayerTagMask mask = lattice.getLayerTagManager().getMask(
            lattice.getLayerTagManager().
            createSingletonTagCollection("form")
            );

    std::multimap<Lattice::VertexDescriptor, std::string> posEdgesMap;
    Lattice::EdgesSortedBySourceIterator edgeIterator =
        lattice.edgesSortedBySource(mask);
    while (edgeIterator.hasNext()) {
        Lattice::EdgeDescriptor edge = edgeIterator.next();
        int start = lattice.getEdgeBeginIndex(edge);
        int end = start + lattice.getEdgeLength(edge);
        AnnotationItem annotationItem = lattice.getEdgeAnnotationItem(edge);
        if (lattice::isDiscarded(lattice, edge))
            continue; //skip discarded forms
        std::string partOfSpeech = lattice::getPartOfSpeech(lattice, edge);
        std::pair<
            std::multimap<Lattice::VertexDescriptor, std::string>::iterator,
            std::multimap<Lattice::VertexDescriptor, std::string>::iterator
                > posEdgesMapIt =
                posEdgesMap.equal_range(start);
        bool alreadyAdded = false;
        if (posEdgesMapIt.first != posEdgesMapIt.second) {
            while (posEdgesMapIt.first != posEdgesMapIt.second) {
                if (posEdgesMapIt.first->second ==
                        partOfSpeech) {
                    alreadyAdded = true;
                    break;
                }
                posEdgesMapIt.first ++;
            }
        }
        if (! alreadyAdded) {
            AnnotationItem ai(partOfSpeech);
            lattice.getAnnotationItemManager().setValue(ai, "discard", "0");
            lattice.getAnnotationItemManager().setValue(ai, "head", "0");
            Lattice::EdgeSequence::Builder seqBuilder(lattice);
            seqBuilder.addEdge(edge);
            lattice.addEdge(
                    start,
                    end,
                    ai,
                    lattice.getLayerTagManager().
                    createSingletonTagCollection("parse"),
                    seqBuilder.build()
                    );
            posEdgesMap.insert(std::pair< Lattice::VertexDescriptor, std::string>(
                        start, partOfSpeech));
        }
    }
}
void ctVarsExprsProductLattice::incorporateVarsMap(std::map<varID, Lattice *> lats, bool overwrite) {

	for(auto&item : lats) {
		if(varLatticeIndex.find(item.first) == varLatticeIndex.end()){
			varLatticeIndex[item.first] = lattices.size();
			lattices.push_back(item.second);
		} else if(overwrite){
			lattices[varLatticeIndex[item.first]]->copy(item.second);
		} else {
			Lattice *origLat = lattices[varLatticeIndex[item.first]];
			origLat->meetUpdate(item.second);
		}
	}
}
void Site::haloNext()
{
	index_++;
	
	//Can only leave boundary by reaching coord(0)=0, so otherwise done
	if(coordLocal(0)==0)
	{
		bool is_in_halo = 0;
		for(int i=1; i<lattice_->dim(); i++)
		{
			if( coordLocal(i)<0 || coordLocal(i)>=lattice_->sizeLocal(i) ) { is_in_halo = 1; break; }
		}
		if(!is_in_halo) index_ += lattice_->sizeLocal(0);
	}
}
Example #29
0
std::vector<unsigned int> some_random_configuration (unsigned int N_filled, const Lattice &lattice, RandomNumberGenerator &rng)
{
    BOOST_ASSERT(N_filled <= lattice.total_sites());

    const unsigned int n_dimensions = lattice.n_dimensions();

    // If in more than one dimension, occasionally we want to try placing
    // particles such that they are distributed as well as possible over a
    // certain dimension (rungs, legs, etc).  For determinantal wavefunctions
    // with certain orbital configurations, this can often be necessary to find
    // a non-zero amplitude in a reasonable amount of time.
    //
    // This method could be further optimized, but it is fast enough for now
    // (and is unlikely to be the bottleneck anyway).
    if (n_dimensions > 1 && rng.random_small_uint(3) == 0) {
        std::vector<unsigned int> v;
        std::set<unsigned int> vs;
        unsigned int spread_dimension = rng.random_small_uint(n_dimensions);
        unsigned int remaining = N_filled;
        while (remaining != 0) {
            std::vector<unsigned int> spread_coordinate;
            random_combination(spread_coordinate,
                               std::min(remaining, (unsigned int) lattice.dimensions[spread_dimension]),
                               lattice.dimensions[spread_dimension], rng);
            for (unsigned int i = 0; i < spread_coordinate.size(); ++i) {
                unsigned int proposed_site_index;
                do {
                    LatticeSite proposed_site(lattice.n_dimensions());
                    proposed_site[spread_dimension] = spread_coordinate[i];
                    for (unsigned int j = 0; j < n_dimensions; ++j) {
                        if (j != spread_dimension)
                            proposed_site[j] = rng.random_small_uint(lattice.dimensions[j]);
                    }
                    proposed_site.basis_index = rng.random_small_uint(lattice.basis_indices);
                    proposed_site_index = lattice.site_to_index(proposed_site);
                } while (!vs.insert(proposed_site_index).second); // try again until successful
                v.push_back(proposed_site_index);
            }
            remaining -= spread_coordinate.size();
        }
        return v;
    }

    // otherwise, fall back to just blindly choosing a random combination of sites
    std::vector<unsigned int> v;
    random_combination(v, N_filled, lattice.total_sites(), rng);
    return v;
}
Example #30
0
void CollectionMgr::submitPositions(int seq, FullAtomList &a,
				Lattice l, int prec)
{  
  int numAtoms = a.size();
  AtomIDList aid(numAtoms);
  PositionList d(numAtoms);
  for ( int i=0; i<numAtoms; ++i ) {
    aid[i] = a[i].id;
    d[i] = l.reverse_transform(a[i].position,a[i].transform);
  }
  CollectVectorInstance *c;
  if ( ( c = positions.submitData(seq,aid,d,prec) ) )
  {
    int aid_size = c->aid.size();
    int data_size = c->data.size();
    int fdata_size = c->fdata.size();
    CollectVectorMsg *msg
      = new (aid_size, data_size, fdata_size,0) CollectVectorMsg;
    msg->seq = c->seq;
    msg->aid_size = aid_size;
    msg->data_size = data_size;
    msg->fdata_size = fdata_size;
    memcpy(msg->aid,c->aid.begin(),aid_size*sizeof(AtomID));
    memcpy(msg->data,c->data.begin(),data_size*sizeof(Vector));
    memcpy(msg->fdata,c->fdata.begin(),fdata_size*sizeof(FloatVector));
    CProxy_CollectionMaster cm(master);
    cm.receivePositions(msg);
    c->free();
  }
}