Ejemplo n.º 1
0
void EnemyList::spawnNewRandom(double playerX, double playerY, GLuint* enemyTextureID)
{
	double enemyX = playerX + RandomGen().getRand(20, -20);
	double enemyY = playerY + RandomGen().getRand(20, 18);
	CompShip enemy(0, enemyX, enemyY, enemyTextureID);
	addNewEnemy(enemy);
	//std::cout << "ADDED NEW ENEMY: " << enemyList.size() << std::endl;
}
Ejemplo n.º 2
0
/** advance all the walkers with killnode==yes
 */
void WFMCUpdateAllWithReweight::advanceWalkers(WalkerIter_t it
        , WalkerIter_t it_end, bool measure)
{
    for (; it != it_end; ++it)
    {
        Walker_t& thisWalker(**it);
        W.loadWalker(thisWalker,false);
        setScaledDriftPbyPandNodeCorr(m_tauovermass,W.G,drift);
        //create a 3N-Dimensional Gaussian with variance=1
        makeGaussRandomWithEngine(deltaR,RandomGen);
        //reject illegal positions or big displacement
        if (!W.makeMoveWithDrift(thisWalker,drift,deltaR, m_sqrttau))
        {
            H.rejectedMove(W,thisWalker);
            H.auxHevaluate(W,thisWalker);
            continue;
        }
        ///W.R = m_sqrttau*deltaR + thisWalker.Drift;
        ///W.R += thisWalker.R;
        ///W.update();
        //save old local energy
        RealType eold = thisWalker.Properties(LOCALENERGY);
        RealType enew = eold;
        //evaluate wave function
        RealType logpsi(Psi.evaluateLog(W));
        bool accepted=false;
        enew=H.evaluate(W);
        RealType logGf = -0.5*Dot(deltaR,deltaR);
        setScaledDriftPbyPandNodeCorr(m_tauovermass,W.G,drift);
        deltaR = thisWalker.R - W.R - drift;
        RealType logGb = -m_oneover2tau*Dot(deltaR,deltaR);
        RealType prob= std::min(std::exp(logGb-logGf +2.0*(logpsi-thisWalker.Properties(LOGPSI))),1.0);
        if (RandomGen() > prob)
        {
            enew=eold;
            thisWalker.Age++;
            //           thisWalker.Properties(R2ACCEPTED)=0.0;
            //           thisWalker.Properties(R2PROPOSED)=rr_proposed;
            H.rejectedMove(W,thisWalker);
        }
        else
        {
            thisWalker.Age=0;
            accepted=true;
            W.saveWalker(thisWalker);
            //           rr_accepted = rr_proposed;
            //           thisWalker.resetProperty(logpsi,Psi.getPhase(),enew,rr_accepted,rr_proposed,nodecorr);
            thisWalker.resetProperty(logpsi,Psi.getPhase(),enew);
            H.auxHevaluate(W,thisWalker);
            H.saveProperty(thisWalker.getPropertyBase());
        }
        thisWalker.Weight *= std::exp(-Tau*(enew -thisWalker.PropertyHistory[Eindex][Elength]));
        thisWalker.addPropertyHistoryPoint(Eindex,enew);
        if (accepted)
            ++nAccept;
        else
            ++nReject;
    }
}
Ejemplo n.º 3
0
  void VMCUpdatePbyP::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end) 
  {

    while(it != it_end) 
    {
      Walker_t& thisWalker(**it);
      Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

      W.R = thisWalker.R;
      w_buffer.rewind();
      W.copyFromBuffer(w_buffer);
      Psi.copyFromBuffer(W,w_buffer);

      RealType psi_old = thisWalker.Properties(SIGN);
      RealType psi = psi_old;

      for(int iter=0; iter<nSubSteps; iter++) {

        makeGaussRandomWithEngine(deltaR,RandomGen);
        bool stucked=true;
        for(int iat=0; iat<W.getTotalNum(); iat++) {

          PosType dr = m_sqrttau*deltaR[iat];
          PosType newpos = W.makeMove(iat,dr);

          RealType ratio = Psi.ratio(W,iat);
          RealType prob = std::min(1.0e0,ratio*ratio);
          if(RandomGen() < prob) { 
            stucked=false;
            ++nAccept;
            W.acceptMove(iat);
            Psi.acceptMove(W,iat);
          } else {
            ++nReject; 
            W.rejectMove(iat); 
            Psi.rejectMove(iat);
          }
        }
        if(stucked) {
          ++nAllRejected;
        }
      }

      thisWalker.R = W.R;
      w_buffer.rewind();
      W.updateBuffer(w_buffer);
      RealType logpsi = Psi.updateBuffer(W,w_buffer);
      //W.copyToBuffer(w_buffer);
      //RealType logpsi = Psi.evaluate(W,w_buffer);

      RealType eloc=H.evaluate(W);

      thisWalker.resetProperty(logpsi,Psi.getPhase(),eloc);
      H.saveProperty(thisWalker.getPropertyBase());
      ++it;
    }
  }
Ejemplo n.º 4
0
CompShip::CompShip(int type, double compX, double compY, GLuint* enemyTextureID)
{
	this->compX = compX;
	this->compY = compY;
	this->enemyType = enemyType;
	this->fireFreq = 0;
	this->destroyed = false;
	this->colliding = false;
	this->hasLineOfSight = false;
	this->enemyTextureID = enemyTextureID;
	this->cAngle = 0.1;
	this->mult = RandomGen().getRand(1, -1);
	this->minTransDist = Point(0, 0);
	this->enemyType = type;
	box = BoundingQuad(4);

	if (enemyType == 0)
	{
		enemyHP = 1;
		box.points[0].setPoint(-1, -1);
		box.points[1].setPoint(-1, 1);
		box.points[2].setPoint(1, 1);
		box.points[3].setPoint(1, -1);
		box.pointsN[0].setPoint(-1, -1);
		box.pointsN[1].setPoint(-1, 1);
		box.pointsN[2].setPoint(1, 1);
		box.pointsN[3].setPoint(1, -1);
	}
	else
	{
		spawnFreq = 0;
		enemyHP = 5;
		box.points[0].setPoint(-2, -4);
		box.points[1].setPoint(-2, 4);
		box.points[2].setPoint(2, 4);
		box.points[3].setPoint(2, -4);
		box.pointsN[0].setPoint(-2, -4);
		box.pointsN[1].setPoint(-2, 4);
		box.pointsN[2].setPoint(2, 4);
		box.pointsN[3].setPoint(2, -4);
	}
}
Ejemplo n.º 5
0
int main (int argc, char *argv[])
{

    int ncpu=4, ndim=3,i,nmode=31,init_rand=600;
    double mode[ndim][nmode];
    double fourforce[ndim][nmode];
    double projtens[ndim][ndim][nmode];
    int seed_gauss[ncpu][4];
    int forcseed[4];

    RandomGen randomGen = RandomGen();

    randomGen.rans(ncpu,init_rand,seed_gauss);

    for (int i=0; i<ncpu; i++) {

        printf("%d %d %d %d\n",
               seed_gauss[i][0],
               seed_gauss[i][1],
               seed_gauss[i][2],
               seed_gauss[i][3]);

    }

    forcseed[0] = seed_gauss[0][0];
    forcseed[1] = seed_gauss[0][1];
    forcseed[2] = seed_gauss[0][2];
    forcseed[3] = seed_gauss[0][3];

    for (int imode=0; imode<nmode; imode++) {
        double randomnumber;
        randomGen.gaussDev(forcseed, randomnumber);
        printf("%d %.20g\n",imode+1,randomnumber);
    }

    return 0;
}
Ejemplo n.º 6
0
void StarField::initialise(double xPos, double yPos)
{
	if (starField.empty())
	{
		for (int i = 0; i < smallCount; i++)
		{
			if (i < mediumCount)
			{
				Star star(RandomGen().getRand(xPos + 30,
					xPos - 30),
					RandomGen().getRand(yPos + 18,
					yPos - 18),
					MED_STAR_PARALLAX_SPEED,
					MED_STAR_PARALLAX_SPEED,
					MED_STAR_BRIGHTNESS);
				starField.push_back(star);
			}
			if (i < largeCount)
			{
				Star star(RandomGen().getRand(xPos + 30,
					xPos - 30),
					RandomGen().getRand(yPos + 18,
					yPos - 18),
					LARGE_STAR_PARALLAX_SPEED,
					LARGE_STAR_PARALLAX_SPEED,
					HIGH_STAR_BRIGHTNESS);
				starField.push_back(star);
			}
			Star star(RandomGen().getRand(xPos + 30,
				xPos - 30),
				RandomGen().getRand(yPos + 18,
				yPos - 18),
				SMALL_STAR_PARALLAX_SPEED,
				SMALL_STAR_PARALLAX_SPEED,
				LOW_STAR_BRIGHTNESS);
			starField.push_back(star);
		}
	}
	else
	{
		starField.clear();
		initialise();
	}
}
Ejemplo n.º 7
0
void StarField::initialise()
{
	if (starField.empty())
	{
		for (int i = 0; i < smallCount; i++)
		{
			if (i < mediumCount)
			{
				Star star(RandomGen().getRand(playerRef->getPlayerX() + 30,
					playerRef->getPlayerX() - 30),
					RandomGen().getRand(playerRef->getPlayerY() + 18,
					playerRef->getPlayerY() - 18),
					MED_STAR_PARALLAX_SPEED,
					MED_STAR_PARALLAX_SPEED,
					MED_STAR_BRIGHTNESS);
				starField.push_back(star);
			}
			if (i < largeCount)
			{
				Star star(RandomGen().getRand(playerRef->getPlayerX() + 30,
					playerRef->getPlayerX() - 30),
					RandomGen().getRand(playerRef->getPlayerY() + 18,
					playerRef->getPlayerY() - 18),
					LARGE_STAR_PARALLAX_SPEED,
					LARGE_STAR_PARALLAX_SPEED,
					HIGH_STAR_BRIGHTNESS);
				starField.push_back(star);
			}
			Star star(RandomGen().getRand(playerRef->getPlayerX() + 30,
				playerRef->getPlayerX() - 30),
				RandomGen().getRand(playerRef->getPlayerY() + 18,
				playerRef->getPlayerY() - 18),
				SMALL_STAR_PARALLAX_SPEED,
				SMALL_STAR_PARALLAX_SPEED,
				LOW_STAR_BRIGHTNESS);
			starField.push_back(star);
		}
	}
	else
	{
		starField.clear();
		initialise();
	}
}
Ejemplo n.º 8
0
int main(int argc, char **argv) {

	int n, rank, size, new_rank;
	int count;
	unsigned char black[] = { 0, 0, 0 };

	MPI::Init(argc, argv);
	size = MPI::COMM_WORLD.Get_size();
	rank = MPI::COMM_WORLD.Get_rank();
	MPI_Status status ;
	MPI_Request request;

	int FstSkelSize;
	int* ranks1;
	int* ranks2;
	ranks1 = (int*)malloc((size/2)*sizeof(int));
	ranks2 = (int*)malloc((size/2)*sizeof(int));

	for (int i=0; i<size/2; i++){
		ranks1[i] = i;
		ranks2[i] = (size/2)+i;
	}

	MPI_Group orig_group, group_farm,group_map;
	MPI_Comm new_comm,comm_farm;

	/* Extract the original group handle */

	MPI_Comm_group(MPI_COMM_WORLD, &orig_group);


	/* Divide tasks into two distinct groups based upon rank */

	FstSkelSize = size/2;
	if (rank < size/2) { MPI_Group_incl(orig_group, size/2, ranks1, &group_map);}
	else { MPI_Group_incl(orig_group, size/2, ranks2, &group_map); }

	MPI_Comm_create(MPI_COMM_WORLD, group_map, &new_comm);

	MPI_Group_rank (group_map, &new_rank);

	cout << "myRank: " << rank <<" myNewRank: "<< new_rank << endl;

	unsigned char** MatrixR;
	unsigned char** MatrixG;
	unsigned char** MatrixB;

	int height,width =0;

	//parameters for the scatter
	int * displ;
	int *scounts;
	displ = (int*)malloc((size-FstSkelSize-1)*sizeof(int));
	scounts = (int*)malloc((size-FstSkelSize-1)*sizeof(int));


	double x,y;
	double xstart,xstep,ystart,ystep;
	double xend, yend;
	double z,zi,newz,newzi;
	double colour;
	int iter,dest,source;
	long col;
	int i,j,k;
	int inset;
	int fd;
	int neg;

	int EOS = 0;

	//stream process for Mandelbrot farm
	if (rank == 0){

		for (int m=0; m<atoi(argv[1]);m++){

			/*Images have two possible sizes*/
			if (rand() > RAND_MAX/2){
				width = 800;
				height = 600;
			}
			else{
				width = 600;
				height = 480;
			}


			/*Generate randomly the extremes*/
			xstart = RandomGen(-2,2);
			//cout << "xstart " << xstart << endl;
			xend = RandomGen(xstart,2);
			//cout << "xend " << xend << endl;
			ystart = RandomGen(-2,2);
			yend = RandomGen(ystart,2);
			//			 all processes in a communicator
			//receive the rank of the destination
			MPI_Recv(&dest,1,MPI_INT,MPI_ANY_SOURCE,5,MPI_COMM_WORLD,&status);
			MPI_Send(&EOS,1, MPI_INT, dest, 5, MPI_COMM_WORLD);
			//send width height and parameters
			MPI_Send(&width,1, MPI_INT, dest, 5, MPI_COMM_WORLD);
			MPI_Send(&height,1, MPI_INT, dest, 5, MPI_COMM_WORLD);
			MPI_Send(&xstart,1, MPI_DOUBLE, dest, 5, MPI_COMM_WORLD);
			MPI_Send(&ystart,1, MPI_DOUBLE, dest, 5, MPI_COMM_WORLD);
			MPI_Send(&xend,1, MPI_DOUBLE, dest, 5, MPI_COMM_WORLD);
			MPI_Send(&yend,1, MPI_DOUBLE, dest, 5, MPI_COMM_WORLD);

		}
		EOS++;
		for (int i=0; i<FstSkelSize-1;i++){
			MPI_Recv(&dest,1,MPI_INT,MPI_ANY_SOURCE,5,MPI_COMM_WORLD,&status);
			MPI_Send(&EOS,1, MPI_INT, dest, 5, MPI_COMM_WORLD);
		}
	}


	if (rank > 0 && rank < FstSkelSize){
		iter = 200;

		while (1){
			//Send my rank for on demand farm
			MPI_Send(&rank,1, MPI_INT, 0, 5, MPI_COMM_WORLD);
			//cout << "rank sent "<< rank<<endl;
			MPI_Recv(&EOS,1,MPI_INT,0,5,MPI_COMM_WORLD,&status);
			//cout <<"EOS: " << EOS << endl;
			if (EOS != 0) break;
			MPI_Recv(&width,1,MPI_INT,0,5,MPI_COMM_WORLD,&status);
			MPI_Recv(&height,1,MPI_INT,0,5,MPI_COMM_WORLD,&status);
			MPI_Recv(&xstart,1,MPI_DOUBLE,0,5,MPI_COMM_WORLD,&status);
			MPI_Recv(&ystart,1,MPI_DOUBLE,0,5,MPI_COMM_WORLD,&status);
			MPI_Recv(&xend,1,MPI_DOUBLE,0,5,MPI_COMM_WORLD,&status);
			MPI_Recv(&yend,1,MPI_DOUBLE,0,5,MPI_COMM_WORLD,&status);

			//Allocate space for matrixes
			malloc2duchar(&MatrixR,width,height);
			malloc2duchar(&MatrixG,width,height);
			malloc2duchar(&MatrixB,width,height);



			/* these are used for calculating the points corresponding to the pixels */
			xstep = (xend-xstart)/width;
			ystep = (yend-ystart)/height;

			/*the main loop */
			x = xstart;
			//cout << "xstart: "<<xstart<<endl;
			y = ystart;
			//cout << "ystart: "<<ystart<<endl;
			for (i=0; i<width; i++)
			{
				//printf("Now on line: %d\n", i);
				for (j=0; j<height; j++)
				{
					z = 0;
					zi = 0;
					inset = 1;
					for (k=0; k<iter; k++)
					{
						/* z^2 = (a+bi)(a+bi) = a^2 + 2abi - b^2 */
						newz = (z*z)-(zi*zi) + x;
						newzi = 2*z*zi + y;
						z = newz;
						zi = newzi;
						if(((z*z)+(zi*zi)) > 4)
						{
							inset = 0;
							colour = k;
							k = iter;
							break;
						}
					}
					if (inset)
					{
						MatrixR[i][j] = 255;
						MatrixG[i][j] = 255;
						MatrixB[i][j] = 255;
					}
					else
					{
						MatrixR[i][j] = sin(colour)*255;
						MatrixG[i][j] = cos(colour)*255;
						MatrixB[i][j] = (colour/iter)*255;
					}
					x += xstep;

				}
				y += ystep;

				x = xstart;
			}

			//pass the matrix to the scatterer
			MPI_Send(&rank,1, MPI_INT, FstSkelSize, 5, MPI_COMM_WORLD);
			MPI_Send(&EOS,1, MPI_INT, FstSkelSize, 5, MPI_COMM_WORLD);
			MPI_Send(&width,1, MPI_INT, FstSkelSize, 5, MPI_COMM_WORLD);
			MPI_Send(&height,1, MPI_INT, FstSkelSize, 5, MPI_COMM_WORLD);
			MPI_Send(&(MatrixR[0][0]),width*height, MPI_UNSIGNED_CHAR, FstSkelSize,15, MPI_COMM_WORLD);
			MPI_Send(&(MatrixG[0][0]),width*height, MPI_UNSIGNED_CHAR, FstSkelSize,15, MPI_COMM_WORLD);
			MPI_Send(&(MatrixB[0][0]),width*height, MPI_UNSIGNED_CHAR, FstSkelSize,15, MPI_COMM_WORLD);
			//free the matrixes
			free2duchar(&MatrixB);
			free2duchar(&MatrixG);
			free2duchar(&MatrixR);

		}
		MPI_Send(&rank,1, MPI_INT, FstSkelSize, 5, MPI_COMM_WORLD);
		MPI_Send(&EOS,1, MPI_INT, FstSkelSize, 5, MPI_COMM_WORLD);

		//	cout << "end of " << rank << endl;

	}

	double widthLocal,widthBound;
	unsigned char *BufferR;
	unsigned char *BufferG;
	unsigned char *BufferB;
	int myWidth;

	// in this case I am the scatterer
	if (rank == FstSkelSize){
		int oldwidth=width;
		int oldheight=height;
		int count =0;

		while(count < rank-1){
			//receive the end of stream
			MPI_Recv(&source,1,MPI_INT,MPI_ANY_SOURCE,5,MPI_COMM_WORLD,&status);
			MPI_Recv(&EOS,1,MPI_INT,source,5,MPI_COMM_WORLD,&status);
			//cout << rank << " " << "EOS: "<< EOS << endl;
			if (EOS == 0){
				MPI_Recv(&width,1,MPI_INT,source,5,MPI_COMM_WORLD,&status);
				MPI_Recv(&height,1,MPI_INT,source,5,MPI_COMM_WORLD,&status);

				widthBound = floor( (double)width / (double)(size-FstSkelSize-1) );
				cout << widthBound*height << endl;

				if (oldwidth != width || oldheight != height){
					if (oldwidth > 0){
						free2duchar(&MatrixB);
						free2duchar(&MatrixG);
						free2duchar(&MatrixR);}
					//Allocate space for matrixes
					malloc2duchar(&MatrixR,width,height);
					malloc2duchar(&MatrixG,width,height);
					malloc2duchar(&MatrixB,width,height);
				}


				for (int dest = 1; dest <= (size-FstSkelSize-1); dest++)
				{
					scounts[dest-1] = widthBound;
					displ[dest-1] = 0;
					if (dest == size-FstSkelSize-1 ) {
						cout <<"ciao" <<endl;
						scounts[dest-1] = scounts[dest-1] +(width % (size-FstSkelSize-1));
					}
					scounts[dest-1] = scounts [dest-1]*height;
					if (dest > 1)
						MPI_Send(&(scounts[dest-1]),1, MPI_INT, rank+dest-1, 5, MPI_COMM_WORLD);
					else
						myWidth=scounts[dest-1];
				}

				cout << "rank " << rank << " mywidth "<< scounts[0] <<endl;
				MPI_Recv(&(MatrixR[0][0]),width*height,MPI_UNSIGNED_CHAR,source,15,MPI_COMM_WORLD,&status);
				MPI_Recv(&(MatrixG[0][0]),width*height,MPI_UNSIGNED_CHAR,source,15,MPI_COMM_WORLD,&status);
				MPI_Recv(&(MatrixB[0][0]),width*height,MPI_UNSIGNED_CHAR,source,15,MPI_COMM_WORLD,&status);

			}
			else count++;
		}
	}


	if (rank > FstSkelSize && rank < size-1){
		MPI_Recv(&myWidth,1,MPI_INT,FstSkelSize,5,MPI_COMM_WORLD,&status);
		cout << rank << " " << myWidth << endl;
		/*//Do computations on sub-image
						CImg<unsigned char> oImage(widthLocal,height,1,3,0);


						for(int x = 0; x < widthLocal; x++)
						{
							for (int y = 0; y < height; y++)
							{
								oImage.draw_point(x, y, black);
								const unsigned char color[] = { MatrixR[x][y], MatrixG[x][y],MatrixB[x][y] };
								oImage.draw_point(x, y, color);
							}
						}
						char a[16]; int n;
						n = sprintf(a,"%d.png",(rank+count)*(count+1));
						count++;
						//oImage.save(a);*/
	}

	if(rank >= FstSkelSize && rank < size-1){
		BufferR = (unsigned char*)malloc(myWidth*sizeof(unsigned char));
		MPI_Scatterv(&(MatrixR[0][0]),scounts,displ,MPI_UNSIGNED_CHAR,BufferR,myWidth,MPI_UNSIGNED_CHAR,0,new_comm);
		//	MPI_Scatterv(&(MatrixG[0][0]),scounts,displ,MPI_UNSIGNED_CHAR,BufferG,widthBound*height,MPI_UNSIGNED_CHAR,0,new_comm);
		//	MPI_Scatterv(&(MatrixB[0][0]),scounts,displ,MPI_UNSIGNED_CHAR,BufferB,widthBound*height,MPI_UNSIGNED_CHAR,0,new_comm);

	}




	MPI::Finalize();
	exit(0);



}
Ejemplo n.º 9
0
  void VMCUpdatePbyPWithDrift::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end) 
  {

    while(it != it_end) 
    {
      Walker_t& thisWalker(**it);
      Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

      W.R = thisWalker.R;
      w_buffer.rewind();
      W.copyFromBuffer(w_buffer);
      Psi.copyFromBuffer(W,w_buffer);

      RealType psi_old = thisWalker.Properties(SIGN);
      RealType psi = psi_old;
      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandomWithEngine(deltaR,RandomGen);

      bool moved = false;

      for(int iat=0; iat<W.getTotalNum(); iat++) {

        PosType dr = m_sqrttau*deltaR[iat]+thisWalker.Drift[iat];
        PosType newpos = W.makeMove(iat,dr);

        //RealType ratio = Psi.ratio(W,iat);
        RealType ratio = Psi.ratio(W,iat,dG,dL);

        G = W.G+dG;

        //RealType forwardGF = exp(-0.5*dot(deltaR[iat],deltaR[iat]));
        //dr = (*it)->R[iat]-newpos-Tau*G[iat]; 
        //RealType backwardGF = exp(-oneover2tau*dot(dr,dr));
        RealType logGf = -0.5e0*dot(deltaR[iat],deltaR[iat]);

        RealType scale=getDriftScale(Tau,G);
        //COMPLEX WARNING
        //dr = thisWalker.R[iat]-newpos-scale*G[iat];
        dr = thisWalker.R[iat]-newpos-scale*real(G[iat]);

        RealType logGb = -m_oneover2tau*dot(dr,dr);

        RealType prob = std::min(1.0e0,ratio*ratio*exp(logGb-logGf));

        //alternatively
        if(RandomGen() < prob) { 
          moved = true;
          ++nAccept;
          W.acceptMove(iat);
          Psi.acceptMove(W,iat);
          W.G = G;
          W.L += dL;

          //thisWalker.Drift = scale*G;
          assignDrift(scale,G,thisWalker.Drift);

        } else {
          ++nReject; 
          W.rejectMove(iat); Psi.rejectMove(iat);
        }
      }

      if(moved) {
        w_buffer.rewind();
        W.copyToBuffer(w_buffer);
        psi = Psi.evaluate(W,w_buffer);

        thisWalker.R = W.R;
        RealType eloc=H.evaluate(W);
        thisWalker.resetProperty(log(abs(psi)), psi,eloc);
        H.saveProperty(thisWalker.getPropertyBase());
      }
      else {
        ++nAllRejected;
      }
      ++it;
    }
  }
Ejemplo n.º 10
0
  /** advance all the walkers with killnode==no
   * @param nat number of particles to move
   * 
   * When killnode==no, any move resulting in node-crossing is treated
   * as a normal rejection.
   */
  void DMCNonLocalUpdate::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end,
      bool measure) 
  {

    //RealType plusFactor(Tau*Gamma);
    //RealType minusFactor(-Tau*(1.0-Alpha*(1.0+Gamma)));

    for(; it!=it_end; ++it)
    {
      Walker_t& thisWalker(**it);

      //save old local energy
      RealType eold    = thisWalker.Properties(LOCALENERGY);
      RealType signold = thisWalker.Properties(SIGN);
      RealType enew  = eold;

      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandomWithEngine(deltaR,RandomGen);

      W.R = m_sqrttau*deltaR + thisWalker.R + thisWalker.Drift;
      
      //update the distance table associated with W
      //DistanceTable::update(W);
      W.update();
      
      //evaluate wave function
      RealType logpsi(Psi.evaluateLog(W));

      nonLocalOps.reset();

      bool accepted=false; 
      if(branchEngine->phaseChanged(Psi.getPhase(),thisWalker.Properties(SIGN))) 
      {
        thisWalker.Age++;
        ++nReject;
      } 
      else 
      {
        //RealType enew(H.evaluate(W,nonLocalOps.Txy));
        enew=H.evaluate(W,nonLocalOps.Txy);
        RealType logGf = -0.5*Dot(deltaR,deltaR);
        setScaledDrift(Tau,W.G,drift);

        deltaR = (*it)->R - W.R - drift;
        RealType logGb = -m_oneover2tau*Dot(deltaR,deltaR);

        RealType prob= std::min(std::exp(logGb-logGf +2.0*(logpsi-thisWalker.Properties(LOGPSI))),1.0);
        if(RandomGen() > prob){
          thisWalker.Age++;
          ++nReject;
          enew=eold;
        } else {
          accepted=true;  
          thisWalker.R = W.R;
          thisWalker.Drift = drift;
          thisWalker.resetProperty(logpsi,Psi.getPhase(),enew);
          H.saveProperty(thisWalker.getPropertyBase());
          //emixed = (emixed+enew)*0.5;
          //eold=enew;
          ++nAccept;
        }
      }

      int ibar=nonLocalOps.selectMove(RandomGen());

      //make a non-local move
      if(ibar) {
        int iat=nonLocalOps.id(ibar);
        W.R[iat] += nonLocalOps.delta(ibar);
        W.update();
        logpsi=Psi.evaluateLog(W);
        setScaledDrift(Tau,W.G,thisWalker.Drift);
        thisWalker.resetProperty(logpsi,Psi.getPhase(),eold);
        thisWalker.R[iat] = W.R[iat];
        ++NonLocalMoveAccepted;
      } 

      thisWalker.Weight *= branchEngine->branchWeight(eold,enew);
      //branchEngine->accumulate(eold,1);
    }
  }
Ejemplo n.º 11
0
  /** advance all the walkers with killnode==no
   * @param nat number of particles to move
   * 
   * When killnode==no, any move resulting in node-crossing is treated
   * as a normal rejection.
   */
  void DMCNonLocalUpdatePbyP::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end,
      bool measure) 
  {

    for(; it!=it_end; ++it)
    {
      Walker_t& thisWalker(**it);
      Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

      RealType eold(thisWalker.Properties(LOCALENERGY));
      RealType vqold(thisWalker.Properties(DRIFTSCALE));
      //RealType emixed(eold), enew(eold);
      RealType enew(eold);

      W.R = thisWalker.R;
      w_buffer.rewind();
      W.copyFromBuffer(w_buffer);
      Psi.copyFromBuffer(W,w_buffer);

      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandom(deltaR);
      bool notcrossed(true);
      int nAcceptTemp(0);
      int nRejectTemp(0);

      RealType rr_proposed=0.0;
      RealType rr_accepted=0.0;
      for(int iat=0; iat<NumPtcl; ++iat)
      {
        //PosType dr(m_sqrttau*deltaR[iat]+thisWalker.Drift[iat]);
        RealType sc=getDriftScale(Tau,W.G[iat]);
        PosType dr(m_sqrttau*deltaR[iat]+sc*real(W.G[iat]));

        //RealType rr=dot(dr,dr);
        RealType rr=Tau*dot(deltaR[iat],deltaR[iat]);
        rr_proposed+=rr;

        if(rr>m_r2max)//too big move
        {
          ++nRejectTemp; continue;
        }

        PosType newpos(W.makeMove(iat,dr));
        RealType ratio=Psi.ratio(W,iat,dG,dL);

        //node is crossed reject the move
        if(Psi.getPhase() > numeric_limits<RealType>::epsilon()) 
        {
          ++nRejectTemp;
          ++nNodeCrossing;
          W.rejectMove(iat); Psi.rejectMove(iat);
        } 
        else 
        {
          G = W.G+dG;
          RealType logGf = -0.5*dot(deltaR[iat],deltaR[iat]);

          //RealType scale=getDriftScale(Tau,G);
          RealType scale=getDriftScale(Tau,G[iat]);
          dr = thisWalker.R[iat]-newpos-scale*real(G[iat]); 

          RealType logGb = -m_oneover2tau*dot(dr,dr);
          RealType prob = std::min(1.0,ratio*ratio*std::exp(logGb-logGf));
          if(RandomGen() < prob) 
          { 
            ++nAcceptTemp;
            W.acceptMove(iat);
            Psi.acceptMove(W,iat);
            W.G = G;
            W.L += dL;
            //assignDrift(scale,G,thisWalker.Drift);
            rr_accepted+=rr;
          } 
          else 
          {
            ++nRejectTemp; 
            W.rejectMove(iat); Psi.rejectMove(iat);
          }
        } 
      }//end of drift+diffusion for all the particles of a walker

      nonLocalOps.reset();
      if(nAcceptTemp>0) 
      {//need to overwrite the walker properties
        thisWalker.R = W.R;
        w_buffer.rewind();
        W.copyToBuffer(w_buffer);
        RealType psi = Psi.evaluate(W,w_buffer);
        enew= H.evaluate(W,nonLocalOps.Txy);
        thisWalker.resetProperty(std::log(abs(psi)),psi,enew,rr_accepted,rr_proposed,1.0);
        H.saveProperty(thisWalker.getPropertyBase());

        thisWalker.Drift=W.G;
      } 
      else 
      {
        thisWalker.Age++;
        thisWalker.Properties(R2ACCEPTED)=0.0;
        ++nAllRejected;
        enew=eold;//copy back old energy
      }

      int ibar = nonLocalOps.selectMove(RandomGen());

      //make a non-local move
      if(ibar) 
      {
        int iat=nonLocalOps.id(ibar);
        PosType newpos(W.makeMove(iat, nonLocalOps.delta(ibar)));
        RealType ratio=Psi.ratio(W,iat,dG,dL);
        W.acceptMove(iat);
        Psi.acceptMove(W,iat);
        W.G += dG;
        W.L += dL;

        PAOps<RealType,OHMMS_DIM>::copy(W.G,thisWalker.Drift);

        thisWalker.R[iat]=W.R[iat];
        w_buffer.rewind();
        W.copyToBuffer(w_buffer);
        RealType psi = Psi.evaluate(W,w_buffer);

        ++NonLocalMoveAccepted;
      }

      thisWalker.Weight *= branchEngine->branchWeight(eold,enew);

      nAccept += nAcceptTemp;
      nReject += nRejectTemp;
    }
  }
Ejemplo n.º 12
0
  /** advance all the walkers with killnode==no
   * @param nat number of particles to move
   * 
   * When killnode==no, any move resulting in node-crossing is treated
   * as a normal rejection.
   */
  void DMCUpdatePbyPWithRejection::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end,
      bool measure) 
  {

    myTimers[0]->start();
    for(;it != it_end;++it) 
    {
      //MCWalkerConfiguration::WalkerData_t& w_buffer = *(W.DataSet[iwalker]);
      Walker_t& thisWalker(**it);
      Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

      W.loadWalker(thisWalker,true);
      //W.R = thisWalker.R;
      //w_buffer.rewind();
      //W.copyFromBuffer(w_buffer);
      Psi.copyFromBuffer(W,w_buffer);

      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandomWithEngine(deltaR,RandomGen);
      int nAcceptTemp(0);
      int nRejectTemp(0);
      //copy the old energy and scale factor of drift
      RealType eold(thisWalker.Properties(LOCALENERGY));
      RealType vqold(thisWalker.Properties(DRIFTSCALE));
      RealType enew(eold);
      RealType rr_proposed=0.0;
      RealType rr_accepted=0.0;
      RealType gf_acc=1.0;

      myTimers[1]->start();
      for(int iat=0; iat<NumPtcl; ++iat) 
      {
        PosType dr;
        //get the displacement
        //RealType sc=getDriftScale(m_tauovermass,W.G[iat]);
        //PosType dr(m_sqrttau*deltaR[iat]+sc*real(W.G[iat]));
        getScaledDrift(m_tauovermass,W.G[iat],dr);
        dr += m_sqrttau*deltaR[iat];

        //RealType rr=dot(dr,dr);
        RealType rr=m_tauovermass*dot(deltaR[iat],deltaR[iat]);
        rr_proposed+=rr;

        if(rr>m_r2max)
        {
          ++nRejectTemp; continue;
        }

        //PosType newpos(W.makeMove(iat,dr));
        if(!W.makeMoveAndCheck(iat,dr)) continue;
        PosType newpos(W.R[iat]);
        RealType ratio=Psi.ratio(W,iat,dG,dL);
        bool valid_move=false;

        //node is crossed reject the move
        //if(Psi.getPhase() > numeric_limits<RealType>::epsilon()) 
        if(branchEngine->phaseChanged(Psi.getPhaseDiff())) 
        {
          ++nRejectTemp;
          ++nNodeCrossing;
          W.rejectMove(iat); Psi.rejectMove(iat);
        } 
        else 
        {
          G = W.G+dG;
          RealType logGf = -0.5*dot(deltaR[iat],deltaR[iat]);
          
          //Use the force of the particle iat
          //RealType scale=getDriftScale(m_tauovermass,G[iat]);
          //dr = thisWalker.R[iat]-newpos-scale*real(G[iat]);
          getScaledDrift(m_tauovermass, G[iat], dr);
          dr = thisWalker.R[iat] - newpos - dr;

          RealType logGb = -m_oneover2tau*dot(dr,dr);
          RealType prob = ratio*ratio*std::exp(logGb-logGf);
          //this is useless
          //RealType prob = std::min(1.0,ratio*ratio*std::exp(logGb-logGf));
          if(RandomGen() < prob) 
          { 
            valid_move=true;
            ++nAcceptTemp;
            W.acceptMove(iat);
            Psi.acceptMove(W,iat);
            W.G = G;
            W.L += dL;
            rr_accepted+=rr;
            gf_acc *=prob;//accumulate the ratio 
          } 
          else 
          {
            ++nRejectTemp; 
            W.rejectMove(iat); Psi.rejectMove(iat);
          }
        } 

      }
      myTimers[1]->stop();
      
      RealType nodecorr_old=thisWalker.Properties(DRIFTSCALE);
      RealType nodecorr=nodecorr_old;
      bool advanced=true;

      if(UseTMove) nonLocalOps.reset();

      if(nAcceptTemp>0) 
      {//need to overwrite the walker properties
        myTimers[2]->start();
        thisWalker.Age=0;
        thisWalker.R = W.R;

        nodecorr=getNodeCorrection(W.G,drift);

        //w_buffer.rewind();
        //W.copyToBuffer(w_buffer);
        RealType logpsi = Psi.evaluateLog(W,w_buffer);
        W.saveWalker(thisWalker);

        myTimers[2]->stop();

        myTimers[3]->start();
        if(UseTMove)
          enew= H.evaluate(W,nonLocalOps.Txy);
        else
          enew= H.evaluate(W);
        myTimers[3]->stop();

        //thisWalker.resetProperty(std::log(abs(psi)),psi,enew,rr_accepted,rr_proposed,nodecorr);
        thisWalker.resetProperty(logpsi,Psi.getPhase(),enew,rr_accepted,rr_proposed,nodecorr );
        H.auxHevaluate(W,thisWalker);
        H.saveProperty(thisWalker.getPropertyBase());
      } 
      else 
      {//all moves are rejected: does not happen normally with reasonable wavefunctions
        advanced=false;
        H.rejectedMove(W,thisWalker); 
        thisWalker.Age++;
        thisWalker.Properties(R2ACCEPTED)=0.0;
        ++nAllRejected;
        enew=eold;//copy back old energy
        gf_acc=1.0;
      }

      if(UseTMove)
      {
        //make a non-local move
        int ibar=nonLocalOps.selectMove(RandomGen());
        if(ibar) 
        {
          myTimers[2]->start();
          int iat=nonLocalOps.id(ibar);
          PosType newpos(W.makeMove(iat, nonLocalOps.delta(ibar)));
          RealType ratio=Psi.ratio(W,iat,dG,dL);
          W.acceptMove(iat);
          Psi.acceptMove(W,iat);
          W.G += dG;
          W.L += dL;

          //PAOps<RealType,OHMMS_DIM>::copy(W.G,thisWalker.Drift);

          //thisWalker.R[iat]=W.R[iat];
          //w_buffer.rewind();
          //W.copyToBuffer(w_buffer);
          RealType logpsi = Psi.evaluateLog(W,w_buffer);
          W.saveWalker(thisWalker);
          ++NonLocalMoveAccepted;
          myTimers[2]->stop();
        }
      }

      //2008-06-26: select any
      //bare green function by setting nodecorr=nodecorr_old=1.0
      thisWalker.Weight *= branchEngine->branchWeight(enew,eold);


      //Filtering extreme energies
      //thisWalker.Weight *= branchEngine->branchWeight(eold,enew);

      //using the corrections: see QMCUpdateBase::getNodeCorrection 
      //thisWalker.Weight *= branchEngine->branchWeight(enew,eold,nodecorr,nodecorr_old);
      
      //using the corrections: see QMCUpdateBase::getNodeCorrection  including gf_acc
      //RealType odd=std::min(gf_acc,1.0)
      //thisWalker.Weight *= branchEngine->branchWeight(enew,eold,nodecorr,nodecorr_oldi,odd);

      nAccept += nAcceptTemp;
      nReject += nRejectTemp;

    }
    myTimers[0]->stop();
  }
Ejemplo n.º 13
0
void VMCUpdateRenyiWithDriftFast::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end, bool measure)
{
  myTimers[0]->start();
  WalkerIter_t begin(it);
  for (; it != it_end; ++it)
  {
    Walker_t& thisWalker(**it);
    Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);
    W.loadWalker(thisWalker,true);
    Psi.copyFromBuffer(W,w_buffer);
    myTimers[1]->start();
    bool moved = false;
    for (int iter=0; iter<nSubSteps; ++iter)
    {
      //create a 3N-Dimensional Gaussian with variance=1
      makeGaussRandomWithEngine(deltaR,RandomGen);
      moved = false;
      for(int ig=0; ig<W.groups(); ++ig) //loop over species
      {
        RealType tauovermass = Tau*MassInvS[ig];
        RealType oneover2tau = 0.5/(tauovermass);
        RealType sqrttau = std::sqrt(tauovermass);
        for (int iat=W.first(ig); iat<W.last(ig); ++iat)
        {
          GradType grad_now=Psi.evalGrad(W,iat), grad_new;
          PosType dr;
          getScaledDrift(tauovermass,grad_now,dr);
          dr += sqrttau*deltaR[iat];
          if (!W.makeMoveAndCheck(iat,dr))
          {
            ++nReject;
            continue;
          }
          //PosType newpos = W.makeMove(iat,dr);
          RealType ratio = Psi.ratioGrad(W,iat,grad_new);
          RealType prob = ratio*ratio;
          //zero is always rejected
          if (prob<numeric_limits<RealType>::epsilon())
          {
            ++nReject;
            W.rejectMove(iat);
            Psi.rejectMove(iat);
            continue;
          }
          RealType logGf = -0.5e0*dot(deltaR[iat],deltaR[iat]);
          getScaledDrift(tauovermass,grad_new,dr);
          dr = thisWalker.R[iat]-W.R[iat]-dr;
          RealType logGb = -oneover2tau*dot(dr,dr);
          if (RandomGen() < prob*std::exp(logGb-logGf))
          {
            moved = true;
            ++nAccept;
            W.acceptMove(iat);
            Psi.acceptMove(W,iat);
          }
          else
          {
            ++nReject;
            W.rejectMove(iat);
            Psi.rejectMove(iat);
          }
        }
      }
      //for subSteps must update thiswalker
      thisWalker.R=W.R;
      thisWalker.G=W.G;
      thisWalker.L=W.L;
    }
    myTimers[1]->stop();
    //Always compute the energy
    //if(moved)
    {
      myTimers[2]->start();
      //thisWalker.R = W.R;
      //w_buffer.rewind();
      //W.updateBuffer(w_buffer);
      RealType logpsi = Psi.updateBuffer(W,w_buffer,false);
      W.saveWalker(thisWalker);
      myTimers[2]->stop();
      myTimers[3]->start();
      RealType eloc=H.evaluate(W);
      myTimers[3]->stop();
      //thisWalker.resetProperty(std::log(abs(psi)), psi,eloc);
      thisWalker.resetProperty(logpsi,Psi.getPhase(), eloc);
      H.auxHevaluate(W,thisWalker);
      H.saveProperty(thisWalker.getPropertyBase());
    }
    if(!moved)
      ++nAllRejected;
    //else
    //{
    //  ++nAllRejected;
    //  H.rejectedMove(W,thisWalker);
    //}
  }
  myTimers[0]->stop();
}
Ejemplo n.º 14
0
void VMCUpdatePbyP::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end, bool measure)
{
  myTimers[0]->start();
  for (; it != it_end; ++it)
  {
    Walker_t& thisWalker(**it);
    W.loadWalker(thisWalker,true);
    Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);
    Psi.copyFromBuffer(W,w_buffer);
    myTimers[1]->start();
    for (int iter=0; iter<nSubSteps; ++iter)
    {
      makeGaussRandomWithEngine(deltaR,RandomGen);
      bool stucked=true;
      for(int ig=0; ig<W.groups(); ++ig) //loop over species
      {
        RealType sqrttau = std::sqrt(Tau*MassInvS[ig]);
        for (int iat=W.first(ig); iat<W.last(ig); ++iat)
        {
          PosType dr = sqrttau*deltaR[iat];
          //replace makeMove by makeMoveAndCheck
          //PosType newpos = W.makeMove(iat,dr);
          if (W.makeMoveAndCheck(iat,dr))
          {
            RealType ratio = Psi.ratio(W,iat);
            RealType prob = ratio*ratio;
            //RealType prob = std::min(1.0e0,ratio*ratio);
            if (RandomGen() < prob)
            {
              stucked=false;
              ++nAccept;
              W.acceptMove(iat);
              Psi.acceptMove(W,iat);
            }
            else
            {
              ++nReject;
              W.rejectMove(iat);
              Psi.rejectMove(iat);
            }
          }
          else //reject illegal moves
            ++nReject;
        } //iat
      }//ig for the species
      if (stucked)
      {
        ++nAllRejected;
        //H.rejectedMove(W,thisWalker);
      }
      thisWalker.R=W.R;
    }
    myTimers[1]->stop();
    myTimers[2]->start();
    //thisWalker.R = W.R;
    //PAOps<RealType,OHMMS_DIM>::copy(W.G,thisWalker.Drift);
    //w_buffer.rewind();
    //W.updateBuffer(w_buffer);
    RealType logpsi = Psi.updateBuffer(W,w_buffer,false);
    W.saveWalker(thisWalker);
    //W.copyToBuffer(w_buffer);
    //RealType logpsi = Psi.evaluate(W,w_buffer);
    myTimers[2]->stop();
    myTimers[3]->start();
    RealType eloc=H.evaluate(W);
    myTimers[3]->stop();
    thisWalker.resetProperty(logpsi,Psi.getPhase(),eloc);
    H.auxHevaluate(W,thisWalker);
    H.saveProperty(thisWalker.getPropertyBase());
  }
  myTimers[0]->stop();
}