void computeLaplaceEquation(
    LocalMatrix* localMatrix, int nprocs, int rank, int delta
) {
    int iStart = 1;
    int iEnd = localMatrix->totalLines;
    
    if (rank == 0) { iStart++; }
    if (rank == nprocs -1) { iEnd--; }
    
    double err = 1.0;
    while (err > delta) {
        err = 0;
        for (int i = iStart ; i < iEnd - 1 ; i++) {
            for (int j = 1 ; j < localMatrix->cols - 1 ; j++) {
                double newValue = 0.25 * (
                    get(localMatrix, i + 1, j) +
                    get(localMatrix, i - 1, j) +
                    get(localMatrix, i, j + 1) +
                    get(localMatrix, i, j - 1)
                );
                
                err += newValue - get(localMatrix, i, j);
                err *= err;
                set(localMatrix, i, j, newValue);
            }
        }
        
        double tmpErr;
        MPI_Allreduce(&err, &tmpErr, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
        err = sqrt(tmpErr);
        
        updateBoundaries(localMatrix, nprocs, rank);
    }
}
/** This is a generic routine. It creates a new alignment by making a copy of the old one.
 */
void ImplAlignment::insertCol(
		const Position & from,
		const Position & residues )
{
	debug_func_cerr( 5 );
	if (from >= getColTo()) return;
	Position p = std::max( from, getColFrom());

	const HAlignment copy = getClone();

	AlignmentIterator it     = copy->begin();
	AlignmentIterator it_end = copy->end();

	clear();

	mScore = copy->getScore();

	for (; it != it_end && (*it).mCol < p; ++it)
		addPair( ResiduePair(*it) );

	for (; it != it_end; ++it)
	{
		addPair( ResiduePair(it->mRow, it->mCol+residues, it->mScore) );
	}

	updateBoundaries();
	setChangedLength();
	return;
}
//--------------------------------------------------------------------------------------------------------------
void ImplAlignment::removePair( const ResiduePair & pair )
{
	debug_func_cerr( 5 );
	if (pair.mRow == mRowFrom || pair.mRow == mRowTo || pair.mCol == mColFrom || pair.mCol == mColTo )
		updateBoundaries();
	setChangedLength();
}
VisualObject::VisualObject(std::string textureName, sf::Vector2f startPosition, sf::RenderWindow* window){
    // Initialise sprite and texture.
    _texture = new sf::Texture;
    _texture->loadFromFile(resourcePath() + textureName);
    _sprite = new sf::Sprite;
    _sprite->setTexture(*_texture);
    _sprite->setPosition(startPosition);
    _window = window;
    // Initialise bounding information.
    updateBoundaries();
}
Exemple #5
0
//--------------------------------------------------------------
void Projection::setMapPointInScreen (double x,double y,  int pi,int pj)
{
	while (x > 180.0) {
		x -= 360.0;
	}
	while (x < -180.0) {
		x += 360.0;
	}

//printf("setMapPointInScreen  x=%f y=%f   pi=%d pj=%d\n", x,y, pi,pj);
	
	// Recherche dichotomique de la valeur de CX,CY pour que le pt (x,y) soit près de (pi,pj)
	// ie. screen2map(i,j) = (x,y)
	int n; 
	double xx, yy;
	double vmin, vtest, vmax;
	
	// Cherche CY
	vmin = -360;
	vmax =  360;
	n = 0;
	CX = x;    // valeur provisoire
	do {
		n ++;
		vtest = (vmin+vmax)/2.0;
		CY = vtest;
		screen2map(pi,pj, &xx,&yy);
		if (y < yy)
			vmax = vtest;
		else
			vmin = vtest;
		//printf("Y %3d : y=%f yy=%f CY=%f\n", n, y,yy, CY);
	} while (n<30 && fabs(yy-y)>1e-4);

	// Cherche CX
	vmin = -360;
	vmax =  360;
	n = 0;
	do {
		n ++;
		vtest = (vmin+vmax)/2.0;
		CX = vtest;
		screen2map(pi,pj, &xx,&yy);
		if (x < xx)
			vmax = vtest;
		else
			vmin = vtest;
		//printf("X %3d : x=%f xx=%f \n", n, x,xx);
	} while (n<30 && fabs(xx-x)>1e-4);
	
	updateBoundaries();
}
Exemple #6
0
//--------------------------------------------------------------
void Projection_ZYGRIB::setScale(double sc)
{
    double sx, sy, scaleall;

	sx = W/360.0;
	sy = H/180.0;
	scaleall = (sx<sy) ? sx : sy; // scaleall = Zoom sur la terre entière (limite max)
    scale = sc;
    if (scale < scaleall)
        scale = scaleall;
    if (scale > scalemax)
        scale = scalemax;
    updateBoundaries();
}
Exemple #7
0
//--------------------------------------------------------------
void Projection_libproj::setScale(double sc)
{
    double scaleall;
    
	scaleall = 0.4; // scaleall = Zoom sur la terre entière (limite max)
    
    scale = sc;
    if (scale < scaleall)
        scale = scaleall;
    if (scale > scalemax)
        scale = scalemax;
    updateBoundaries();
//printf("setScale(%f) -> scale=%f\n", sc,scale);
}
/* It is necessary to iterate from mFrowFrom to mRowTo, since the alignment need not be linear
 */
void ImplAlignmentVector::removeColRegion( Position from, Position to)
{
	debug_func_cerr(5);

	Position pos;

	if (mRowFrom == NO_POS) return;

	for (pos = mRowFrom; pos < mRowTo; pos++)
		if (mPairs[pos].mRow != NO_POS && mPairs[pos].mCol >= from && mPairs[pos].mCol < to)
			mPairs[pos] = ResiduePair();

	updateBoundaries();
	setChangedLength();
	return;
}
//-----------------------------------------------------------------------------------------------------------
void ImplAlignmentVector::map(
		const HAlignment & other,
		const CombinationMode & mode )
{
	debug_func_cerr(5);

	// mapping is efficient for mode C{R,C}, for all others
	// revert to the default mapping mode.
	if (mode == RR || mode == RC)
		return ImplAlignment::map( other, mode );

	if (mode == CR)
	{
		for (Position x = 0; x < mPairs.size(); ++x)
			if (mPairs[x].mRow != NO_POS)
			{
				Position p = mapRowToCol(mPairs[x].mCol);
				if (p != NO_POS)
					mPairs[x].mCol = p;
				else
				{
					mPairs[x].mRow = mPairs[x].mCol = NO_POS;
					mPairs[x].mScore = 0;
				}

			}
	}
	else if (mode == CC )
	{
		for (Position x = 0; x < mPairs.size(); ++x)
			if (mPairs[x].mRow != NO_POS)
			{
				Position p = mapColToRow(mPairs[x].mCol);
				if (p != NO_POS)
					mPairs[x].mCol = p;
				else
				{
					mPairs[x].mRow = mPairs[x].mCol = NO_POS;
					mPairs[x].mScore = 0;
				}
			}
	}

	updateBoundaries();
	setChangedLength();
	return;
}
//-----------------------------------------------------------------------------------------------------------
void ImplAlignmentVector::insertRow(
		const Position & from,
		const Position & residues )
{
	if (from >= mRowTo) return;
	Position p = std::max( from, mRowFrom);

	for (Position x = p; x < mRowTo; ++x)
		if (mPairs[x].mRow != NO_POS)
			mPairs[x].mRow += residues;

	mPairs.insert( mPairs.begin() + p, residues, ResiduePair() );

	updateBoundaries();
	setChangedLength();
	return;
}
//-----------------------------------------------------------------------------------------------------------
void ImplAlignmentVector::insertCol(
		const Position & from,
		const Position & residues )
{
	debug_func_cerr( 5 );
	if (from >= mColTo) return;
	Position p = std::max( from, mColFrom);

	for (Position x = mRowFrom; x < mRowTo; ++x)
	{
		if (mPairs[x].mCol >= from)
			mPairs[x].mCol += residues;
	}

	updateBoundaries();
	setChangedLength();
	return;
}
/** This is a generic routine. It creates a new alignment by making a copy of the old one.
 */
void ImplAlignment::removeRowRegion( Position from, Position to)
{

	const HAlignment copy = getClone();

	AlignmentIterator it     = copy->begin();
	AlignmentIterator it_end = copy->end();

	clear();

	mScore = copy->getScore();

	for (; it != it_end; ++it)
	{
		if ( (*it).mRow < from || (*it).mRow >= to)
			addPair( ResiduePair(*it) );
	}

	updateBoundaries();
	setChangedLength();
	return;
}
//-----------------------------------------------------------------------------------------------------------
void ImplAlignmentVector::removeRowRegion( Position from, Position to)
{
	debug_func_cerr(5);

	Position pos;
	if (from == NO_POS || from < mRowFrom)
		from = mRowFrom;

	if (to == NO_POS || to > mRowTo)
		to = mRowTo;

	debug_cerr( 5, "deleting in row from " << from << " to " << to );

	// delete aligned positions
	for ( Position pos = from; pos < to; ++pos)
		mPairs[pos] = ResiduePair();

	updateBoundaries();

	setChangedLength();

	return;
}
Exemple #14
0
//--------------------------------------------------------------
void Projection::setScreenSize (int w, int h) {
    W = w;
    H = h;
    updateBoundaries();
}