Beispiel #1
0
void mpi_manager_1D::determin_OtherRanks() {

	// Find neighbouring ranks:
	MPI_Cart_shift(comm1d, 0, 1, &left , &right);

	// Determine ranks of neighbour processes:
	int shiftcoord;

	Neighbours.resize(Index::set(-ntasks), Index::set(ntasks));
	Neighbours.clear();

	for(int pos=-ntasks; pos<=ntasks; ++pos){
		shiftcoord = (coords + pos);
		if(shiftcoord < 0) shiftcoord += ntasks;

		if(shiftcoord>=0 && shiftcoord<ntasks) {
			// Now determine rank at relative shifted position
			// std::cout << " Cart ";
			// std::cout << shiftcoord[0] << " ";
			// std::cout << shiftcoord[1] << " ";
			// std::cout << rank << " ";
			// std::cout << nproc[0] << " ";
			// std::cout << nproc[1] << " ";
			// std::cout << std::endl;
			MPI_Cart_rank(comm1d, &shiftcoord, &Neighbours(pos));
		} else {
			// If outside domain set to error value
			Neighbours(pos) = MPI_PROC_NULL;
		}

	
	}


	NeighboursCyclic.resize(Index::set(-ntasks), Index::set(ntasks));
	NeighboursCyclic.clear();

	for(int pos=-ntasks; pos<=ntasks; ++pos){
		shiftcoord = (coords + pos)%ntasks;
		if(shiftcoord < 0) shiftcoord += ntasks;

		// Now determine rank at relative shifted position
		MPI_Cart_rank(comm1d, &shiftcoord, &NeighboursCyclic(pos));
			
	}
	
	// Now determine absolute position of ranks
	AllRanks.resize(ntasks);

	for(int coord=0; coord<ntasks; ++coord) {
		MPI_Cart_rank(comm1d, &coord, &AllRanks(coord));
	}

}
Beispiel #2
0
template<class T1, class T2> bool Skeleton_fast<T1,T2>::operator() ( clipper::Xmap<T1>& xskl, const clipper::Xmap<T2>& xmap ) const
{
  std::vector<int> index;
  Xmap_base::Map_reference_index ix;
  
  /* now get the map in sorted order.
     We only sort those points which are to be considered, i.e. non-zero */
  for ( ix = xmap.first(); !ix.last(); ix.next() )
    if ( xskl[ix] > 0 )
      index.push_back( ix.index() );
  Map_index_sort::sort_increasing( xmap, index );

  /* make neighbours
     The neighbours of a point are the other grid points which are
     'near' it.  The exact choice depends on the grid geometry. The
     cutoff is chosen to give 18-20 neighbours. For a cubic grid,
     these are a 3x3x3 cube without the vertices, for a hex grid they
     are a hexagonal cylinder. */
  neigh = Neighbours( xmap );

  /* make the skeleton map. This will contain:
      0 for non-skeleton grids (inter ridge spaces)
      1 for untested grids
      1 for skeleton grids (ridges)
     (The untested and skeleton grids can have the same value,
     because the untested ones are still in the index).
     We loop through point in order, starting with the lowest
     and decide whether each one is part of the skeleton. */
  for ( int i = 0; i < index.size(); i++ )
    if ( !isInSkel( xskl, xskl.coord_of(index[i]) ) )
      xskl.set_data( index[ i ], 0 );

  return true;
}
Beispiel #3
0
int mpi_manager_1D::get_OtherRankRel(int ishift) const {
	//! Get rank at some coordinate
	assert(std::abs(ishift)<=ntasks);

	return Neighbours(ishift);
	
}
Beispiel #4
0
void BreakableMesh::splitPolygons(NeighbourInfo n1, NeighbourInfo &n2, int init, std::vector<Polygon> &oldPolygons,
                                  std::vector<Polygon> &newPolygons) {
    Polygon& poly1 = getPolygon(n1.neighbour);
    std::vector<int> poly1_points = poly1.getPoints();
    oldPolygons.push_back(poly1);

    //Include new points on the mesh
    int p1 = this->points.push_back(n1.intersection);
    int p2 = this->points.push_back(n2.intersection);

    //Split the old polygon and generate new ones
    std::vector<int> new1 = {p1, p2};
    std::vector<int> new2 = {p2, p1};

    UniqueList<int> newPoints;
    Pair<int> pairs = computeNewPolygons(n1, n2, poly1, newPolygons,
                                         new1, new2, p1, p2, init, -1, -1);

    if(init>=0){
        this->getPolygon(init).insertOnSegment(n1.edge, p1);
    }

    this->getPolygon(n2.neighbour).insertOnSegment(n2.edge, p2);

    // Get the edge information for the old polygon and update it
    if(!n1.isVertex){
        this->edges.delete_element(n1.edge);
    }
    if(!n2.isVertex){
        this->edges.delete_element(n2.edge);
    }

    std::vector<IndexSegment> segments1;
    std::vector<IndexSegment> segments2;

    this->getPolygon(pairs.first).getSegments(segments1);
    this->getPolygon(pairs.second).getSegments(segments2);

    this->edges.insert(IndexSegment(p1,p2),Neighbours(n1.neighbour,n1.neighbour));

    for (int i = 0; i < segments1.size() ; ++i) {
        this->edges.replace_neighbour(segments1[i], n1.neighbour, pairs.first);
    }

    for (int i = 0; i < segments2.size() ; ++i) {
        this->edges.replace_neighbour(segments2[i], n1.neighbour, pairs.second);
    }

    if(!n1.isVertex){
        this->edges.insert_if_null(IndexSegment(p1,n1.edge.getFirst()),init);
        this->edges.insert_if_null(IndexSegment(p1,n1.edge.getSecond()), init);
    }

    if(!n2.isVertex){
        this->edges.insert_if_null(IndexSegment(p2,n2.edge.getFirst()), n2.neighbour);
        this->edges.insert_if_null(IndexSegment(p2,n2.edge.getSecond()), n2.neighbour);
    }

    n2.extraPoint = p2;
}
Beispiel #5
0
int mpi_manager_2D::get_OtherRankRel(int delx, int dely) const {
	//! Get rank at some coordinate
	assert(std::abs(delx)<=nproc[0]);
	assert(std::abs(dely)<=nproc[1]);

	return Neighbours(delx, dely);
	
}
Beispiel #6
0
void Automaton::Update(void)
{
    for (int i=0; i<height; i++)
	for (int j=0; j<width; j++) {
	    StateCount[(*front)(i,j)]--;
	    (*back)(i,j) = Transition[State[(*front)(i,j)].code](Neighbours(i,j));
	    StateCount[(*back)(i,j)]++;
	}
    LMatrix <statecode> *temp;
    temp = front;
    front = back;
    back = temp;
}
Beispiel #7
0
void Automaton::Update(void)
{
    if (!running) return;
    if (counter_max == 20) return;
    if (counter < counter_max) {
        counter++;
        return;
    }

    counter = 0;
    for (int i = 0; i < aheight; i++)
        for (int j = 0; j < awidth; j++) {
            StateCount[(*front)(i,j)]--;
            int neigh_live = Neighbours(i,j,LLIVE);
            int current = (*front)(i,j);

            if (current == LLIVE) {
                if (survive.contains(neigh_live))
                    (*back)(i,j) = LLIVE;
                else
                    (*back)(i,j) = LDEAD;
            } else { if (current == LDEAD) {
                if (bear.contains(neigh_live))
                    (*back)(i,j) = LLIVE;
                else
                    (*back)(i,j) = LDEAD;
                }
            }
            StateCount[(*back)(i,j)]++;
        }
    LMatrix <statecode> *temp;
    temp = front;
    front = back;
    back = temp;
    emit updated();
}
Beispiel #8
0
void mpi_manager_2D::determin_OtherRanks() {

	// Find neighbouring ranks:
	MPI_Cart_shift(comm2d, 0, 1, &left , &right);
	MPI_Cart_shift(comm2d, 1, 1, &front, &back);

	// Determine ranks of neighbour processes:
	int shiftcoord[DIM];
	int lbound[DIM],ubound[DIM];
	for(int dim=0;dim<DIM;dim++){
		lbound[dim]=-nproc[dim];
		ubound[dim]= nproc[dim];
	}
	Neighbours.resize(lbound,ubound);
	Neighbours.clear();

	for(int dim0=-nproc[0]; dim0<=nproc[0]; dim0++){
		shiftcoord[0] = (coords[0]+dim0);
		if(shiftcoord[0] < 0) shiftcoord[0]+=nproc[0];
		for(int dim1=-nproc[1]; dim1<=nproc[1]; dim1++){
			shiftcoord[1] = (coords[1]+dim1);
			if(shiftcoord[1] < 0) shiftcoord[1]+=nproc[1];

			if(shiftcoord[0]>=0 && shiftcoord[0]<nproc[0] &&
			   shiftcoord[1]>=0 && shiftcoord[1]<nproc[1]) {
				// Now determine rank at relative shifted position
				// std::cout << " Cart ";
				// std::cout << shiftcoord[0] << " ";
				// std::cout << shiftcoord[1] << " ";
				// std::cout << rank << " ";
				// std::cout << nproc[0] << " ";
				// std::cout << nproc[1] << " ";
				// std::cout << std::endl;
				MPI_Cart_rank(comm2d, shiftcoord, &Neighbours(dim0,dim1));
			} else {
				// If outside domain set to error value
				Neighbours(dim0, dim1) = MPI_PROC_NULL;
			}

		}
	}

	NeighboursCyclic.resize(lbound,ubound);
	NeighboursCyclic.clear();

	for(int dim0=-nproc[0]; dim0<=nproc[0]; dim0++){
		shiftcoord[0] = (coords[0]+dim0)%nproc[0];
		if(shiftcoord[0] < 0) shiftcoord[0]+=nproc[0];
		for(int dim1=-nproc[1]; dim1<=nproc[1]; dim1++){
			shiftcoord[1] = (coords[1]+dim1)%nproc[1];
			if(shiftcoord[1] < 0) shiftcoord[1]+=nproc[1];

			// Now determine rank at relative shifted position
			MPI_Cart_rank(comm2d, shiftcoord, &NeighboursCyclic(dim0,dim1));

		}
	}
	
	// Now determine absolute position of ranks
	AllRanks.resize(Index::set(0,0),
	                Index::set(nproc[0]-1,nproc[1]-1));

	for(int dim1=0; dim1<nproc[1]; ++dim1) {
		for(int dim0=0; dim0<nproc[0]; ++dim0) {
			int coord[2] = {dim0, dim1};
			MPI_Cart_rank(comm2d, coord, &AllRanks(dim0, dim1));
		}
	}

}
Beispiel #9
0
Pair<int> BreakableMesh::breakPolygons(NeighbourInfo n1, NeighbourInfo &n2, int init, std::vector<Polygon> &oldPolygons,
                                       std::vector<Polygon> &newPolygons, UniqueList<Pair<int>> &newPoints) {
    Polygon& poly1 = getPolygon(n1.neighbour);
    oldPolygons.push_back(poly1);

    //Include new points on the mesh
    int p1 = this->points.push_back(n1.intersection);
    int p2 = this->points.push_back(n2.intersection);

    int p3;
    if(n1.extraPoint<0){
        p3 = this->points.force_push_back(n1.intersection);
    } else{
        p3 = n1.extraPoint;
    }

    int p4 = this->points.force_push_back(n2.intersection);

    Pair<int> entryPair = Pair<int>(p1, p3);
    Pair<int> exitPair = Pair<int>(p2, p4);

    newPoints.push_back(entryPair);
    newPoints.push_back(exitPair);

    //Split the old polygon and generate new ones
    std::vector<int> new1 = {p1, p2};
    std::vector<int> new2 = {p4, p3};

    Pair<int> pairs = computeNewPolygons(n1, n2, poly1, newPolygons,
                                         new1, new2, p1, p2, init, p3, p4);

    if(init>=0){
        this->getPolygon(init).insertOnSegment(n1.edge, {p3, p1});
        edges.insert(IndexSegment(p1,p3), init);
    }

    this->getPolygon(n2.neighbour).insertOnSegment(n2.edge, {p2, p4});
    edges.insert(IndexSegment(p2,p4), n2.neighbour);

    // Get the edge information for the old polygon and update it
    if(!n1.isVertex){
        this->edges.delete_element(n1.edge);
        if(n1.extraPoint>=0){
            this->edges.delete_element(IndexSegment(p1,p3));
        }
    }
    if(!n2.isVertex){
        this->edges.delete_element(n2.edge);
    }

    std::vector<IndexSegment> segments1;
    std::vector<IndexSegment> segments2;

    this->getPolygon(pairs.first).getSegments(segments1);
    this->getPolygon(pairs.second).getSegments(segments2);

    this->edges.insert(IndexSegment(p1,p2),Neighbours(pairs.first,-1));
    this->edges.insert(IndexSegment(p3,p4),Neighbours(n1.neighbour,-1));

    for (int i = 0; i < segments1.size() ; ++i) {
        this->edges.replace_neighbour(segments1[i], n1.neighbour, pairs.first);
    }

    for (int i = 0; i < segments2.size() ; ++i) {
        this->edges.replace_neighbour(segments2[i], n1.neighbour, pairs.second);
    }

    if(!n1.isVertex){
        this->edges.insert_if_null(IndexSegment(p1, this->getPolygon(pairs.first).getVertex(n1.edge.getFirst(), n1.edge.getSecond())),init);
        this->edges.insert_if_null(IndexSegment(p3, this->getPolygon(pairs.second).getVertex(n1.edge.getFirst(), n1.edge.getSecond())), init);
    }

    if(!n2.isVertex){
        this->edges.insert_if_null(IndexSegment(p2, this->getPolygon(pairs.first).getVertex(n2.edge.getFirst(), n2.edge.getSecond())), n2.neighbour);
        this->edges.insert_if_null(IndexSegment(p4, this->getPolygon(pairs.second).getVertex(n2.edge.getFirst(), n2.edge.getSecond())), n2.neighbour);
    }

    n2.extraPoint = p4;

    return exitPair;
}