Ejemplo n.º 1
0
	void FF_Restraint_Torsional::calcEnergiesVerbose(ForcefieldBase::AtomicVerbosity level)
	{
		calcForces();
		printf(" Tors. Restraint:    %10.3lf kcal/mol\n", epot * PhysicsConst::J2kcal * PhysicsConst::Na);
		
		if( level > Summary ) { 	
			printf("\n Breakdown by torsional restraint: \n"); 
			WorkSpace& wspace = getWSpace();

			epot = 0;
			if(!Passive)
			{
				for( int i = 0; i < torsion.size(); i++) 
				{ 
					calcDihedralForcesVerbose(wspace,torsion[i],epot);
				}
				wspace.ene.epot += epot;
			}
			else
			{
				for( int i = 0; i < torsion.size(); i++) 
				{ 
					calcDihedralForcesVerbosePassive(wspace,torsion[i],epot);
				}
			}
		}

	}
Ejemplo n.º 2
0
void otherTests(){
	int n = 20;
	particle * particles = malloc(n * sizeof(particle));
	initialize_2(particles, n);
	
	calcForces(particles, n);
	
	double max(double in1, double in2){
		double out;
		out = in2>in1?in2:in1;
		return out;
	}
Ejemplo n.º 3
0
void Demo::run(float timediff)
{
   //--Ball einfügen
   //if(spawnBall)
   {
      timeToSpawnBall -= timediff;
      if(timeToSpawnBall <= 0.0f)
      {
         doSpawnBall();
      }
   }
   calcForces(timediff);
}
Ejemplo n.º 4
0
	void FF_Custom::calcEnergiesVerbose(ForcefieldBase::AtomicVerbosity level)
	{
		if(!Active)
			return;
		epot = 0.0;
		int nforces = force.size();
		calcForces();
		if(level == Summary) 
		{
			printf(" %-16s%10.3lf kcal/mol\n",
				name_verbose.c_str(),
				double (epot) * PhysicsConst::J2kcal * PhysicsConst::Na);
			return;
		}

		for(int i = 0; i < nforces; i++) 
		{
			force[i].calcEnergyVerbose(this, level);
		}
	}
Ejemplo n.º 5
0
void velocityStep(particle * particles, int n, double h){
	int i;
	for(i=0;i<n;i++){
		particles[i].dvx = 0;
		particles[i].dvy = 0;
		particles[i].dvz = 0;
	}
	calcForces(particles, n);
	for(i=0;i<n;i++){
		particles[i].vx += h*particles[i].dvx;
		particles[i].vy += h*particles[i].dvy;
		particles[i].vz += h*particles[i].dvz;
	}
	//zeroing before and after to be sure
	for(i=0;i<n;i++){
		particles[i].dvx = 0;
		particles[i].dvy = 0;
		particles[i].dvz = 0;
	}
}
Ejemplo n.º 6
0
	void FF_Restraint_Torsional::calcEnergies()
	{
		calcForces();
	}
Ejemplo n.º 7
0
/* 
 * This is one of the few methods available externally.  Here we simply 
 * calculate the timestep to use for this iteration, calculate the new batch
 * of forces, and then propagate our variables forward through time.
 */
void iterate()
{
    calcNewTimestep();
    calcForces();
    step();

    /*
     * This is an experimental and only partially functional attempt to recenter
     * the domain upon a quantity of interest.  
     */
    if(recentering != NOCENTERING)
    {
        displacement d;
        
        if(recentering == BYMAXCENTER)
            d = displacementByCenter();
        
        if(momEquation)
        {
            shiftField(d, u->sol->toroidal->spectral);
            shiftField(d, u->sol->toroidal->force1);
            shiftField(d, u->sol->toroidal->force2);
            
            shiftField(d, u->sol->poloidal->spectral);
            shiftField(d, u->sol->poloidal->force1);
            shiftField(d, u->sol->poloidal->force2);
            
            shiftAvg(d, u->sol->mean_x);
            shiftAvg(d, u->sol->mean_xf1);
            shiftAvg(d, u->sol->mean_xf2);
            
            shiftAvg(d, u->sol->mean_y);
            shiftAvg(d, u->sol->mean_yf1);
            shiftAvg(d, u->sol->mean_yf2);
        }
        if(magEquation)
        {
            shiftField(d, B->sol->toroidal->spectral);
            shiftField(d, B->sol->toroidal->force1);
            shiftField(d, B->sol->toroidal->force2);
            
            shiftField(d, B->sol->poloidal->spectral);
            shiftField(d, B->sol->poloidal->force1);
            shiftField(d, B->sol->poloidal->force2);
            
            shiftAvg(d, B->sol->mean_x);
            shiftAvg(d, B->sol->mean_xf1);
            shiftAvg(d, B->sol->mean_xf2);
            
            shiftAvg(d, B->sol->mean_y);
            shiftAvg(d, B->sol->mean_yf1);
            shiftAvg(d, B->sol->mean_yf2);
        }
        if(tEquation)
        {
            shiftField(d, T->spectral);
            shiftField(d, T->force1);
            shiftField(d, T->force2);
        }
    }
    
    //make sure our state variables are up to date, both spectral and spatial
    if(momEquation)
    {
        recomposeSolenoidal(u->sol, u->vec);
        fftBackward(u->vec->x);
        fftBackward(u->vec->y);
        fftBackward(u->vec->z);
    }

    if(magEquation)
    {
        recomposeSolenoidal(B->sol, B->vec);
        fftBackward(B->vec->x);
        fftBackward(B->vec->y);
        fftBackward(B->vec->z);
    }

    if(tEquation)
    {
        fftBackward(T);
    }
}
Ejemplo n.º 8
0
        //! Integrating an ensemble
	void integrate_system(ensemble::SystemRef sys){
		const int nbod = sys.nbod();
		double acc[nbod][3];

		// Setting up Monitor
		monitor_t montest(_mon_params,sys,*_log) ;

		// begin init();
		const double sqrtGM = sqrt(sys[0].mass());
		convert_std_to_helio_pos_bary_vel_coord(sys);
		calcForces(sys,acc);
		// end init()

		for(int iter = 0 ; (iter < _max_iterations) && sys.is_active() ; iter ++ )
		  {

		// begin advance();
		    double hby2 = 0.5 * std::min( _destination_time - sys.time() ,  _time_step );

		// Step 1
		drift_step(sys,hby2);

		// Step 2: Kick Step
		for(int b=1;b<nbod;++b)
		  for(int c=0;c<3;++c)
		    sys[b][c].vel() += hby2 * acc[b][c];

		// __syncthreads();

		// 3: Kepler Drift Step (Keplerian orbit about sun/central body)
		for(int b=1;b<nbod;++b)
		  drift_kepler( sys[b][0].pos(),sys[b][1].pos(),sys[b][2].pos(),sys[b][0].vel(),sys[b][1].vel(),sys[b][2].vel(),sqrtGM, 2.0*hby2 );
		// __syncthreads();

		// TODO: check for close encounters here
		calcForces(sys,acc);

		// Step 4: Kick Step
		for(int b=1;b<nbod;++b)
		  for(int c=0;c<3;++c)
		    sys[b][c].vel() += hby2 * acc[b][c];
		// __syncthreads();

		// Step 5
		drift_step(sys,hby2);

		sys.time() += 2.0*hby2;

		// end advance

		const int thread_in_system_for_monitor = 0;
#if ASSUME_PROPAGATOR_USES_STD_COORDINATES
		montest( thread_in_system_for_monitor );
#else
		bool using_std_coord = false;
		bool needs_std_coord = montest.pass_one( thread_in_system_for_monitor );

		if(needs_std_coord) 
		  { 
		    convert_internal_to_std_coord(sys); 
		    using_std_coord = true; 
		  }
		
		//			__syncthreads();
		int new_state = montest.pass_two ( thread_in_system_for_monitor );

		if( montest.need_to_log_system() )
		  { log::system(*_log, sys); }
		
		//			__syncthreads();
		if(using_std_coord)
		  {
		    convert_std_to_internal_coord(sys);
		    using_std_coord = false;
		  }
#endif
			//			__syncthreads();			  

			if( sys.is_active() )
			  {
			    if( sys.time() >= _destination_time ) 
			      { sys.set_inactive();     }
			  }
			//			__syncthreads();

		  }

		// shutdown();
		convert_helio_pos_bary_vel_to_std_coord (sys);
	}
Ejemplo n.º 9
0
void Pong::run(float timediff)
{
   //--Spieler input verarbeiten und Spielerskelett Zeichnen
   for(std::vector<Player*>::iterator it = app->players.begin();
         it != app->players.end(); it++)
   {
      Player* pl = *it;
      if(pl != 0)
      {
         pl->processInput(timediff);
         pl->draw(Player::SKELETON | Player::BAR);
      }
   }

   if(app->players[app->PLAYER_LEFT] != 0)
   {
      if(app->players[app->PLAYER_LEFT]->getExit())
      {
         app->switchTo(app->GS_MENU);
      }
   }
   if(app->players[app->PLAYER_RIGHT] != 0)
   {
      if(app->players[app->PLAYER_RIGHT]->getExit())
      {
         app->switchTo(app->GS_MENU);
      }
   }

   //--Ball einfügen
   if(spawnBall)
   {
      timeToSpawnBall -= timediff;
      if(timeToSpawnBall <= 0.0f)
      {
         doSpawnBall();
      }
   }

   //--Spieler Verarbeiten
   if(app->playersActive == 2)
   {
      drawScores(app->players[app->PLAYER_LEFT]->getScore(), app->players[app->PLAYER_RIGHT]->getScore());

      if(!inMatch)
      {
         clearBalls();
         spawnBall = false;
         timeToMatch -= timediff;
         if(timeToMatch <= 0.0f)
         {
            startMatch();
         }
      }

      if(Application::enableEasterEggs)
      {
         doEsterEgg(app->PLAYER_LEFT,  app->players[app->PLAYER_LEFT]->getEsterEgg());
         doEsterEgg(app->PLAYER_RIGHT, app->players[app->PLAYER_RIGHT]->getEsterEgg());
      }
   }
   else
   {
      spawnBall = true;
   }

   if(calcForces(timediff)) //--bei Kollision sound ausgeben (nur wenn Spieler drin sind)
   {
      app->soundPlayer->effect("collision");
   }
}
Ejemplo n.º 10
0
	GPUAPI void kernel(T compile_time_param){
		if(sysid()>=_dens.nsys()) return;

		typedef Gravitation<T> GravitationInstance;

		// References to Ensemble and Shared Memory
		ensemble::SystemRef sys = _dens[sysid()];
		typedef typename GravitationInstance::shared_data grav_t;
		GravitationInstance calcForces(sys,*( (grav_t*) system_shared_data_pointer(this,compile_time_param) ) );

		/////////// Local variables /////////////
		const int nbod = T::n;               // Number of Bodies
		int b = thread_body_idx(nbod);       // Body id
		int c = thread_component_idx(nbod);  // Component id (x=0,y=1,z=2)
		int ij = thread_in_system();         // Pair id

		// Thread barrier predicates
		//		bool body_component_grid = (b < nbod) && (c < 3);         // Barrier to act on bodies and components
		//		bool first_thread_in_system = (thread_in_system() == 0);  // Barrier to select only the first thread


		//! Setting up Monitor
		monitor_t montest(_mon_params,sys,*_log) ;

		//! Setting up Propagator
		Propagator<T,GravitationInstance> prop(_prop_params,sys,calcForces);
		prop.b = b;
		prop.c = c;
		prop.ij = ij;
		//		prop.body_component_grid = body_component_grid;
		//		prop.first_thread_in_system = first_thread_in_system;

		////////// INTEGRATION //////////////////////
		
		prop.init();
		__syncthreads();


		for(int iter = 0 ; (iter < _max_iterations) && sys.is_active() ; iter ++ ) {

		        prop.max_timestep = _destination_time - sys.time();
			prop.advance();
			__syncthreads();

			bool thread_needs_std_coord  = false;
			bool using_std_coord = false;


#if ASSUME_PROPAGATOR_USES_STD_COORDINATES
			montest( thread_in_system() );
#else
			thread_needs_std_coord = montest.pass_one( thread_in_system() );
#if (__CUDA_ARCH__ >= 200) 
			// requires arch=compute_sm_20
			bool block_needs_std_coord = syncthreads_or((int)(thread_needs_std_coord));
#else
			// \todo Need to make this more intelligent for pre-Fermi GPUs.  For now just setting true, so it always makes the conversion on pre-Fermi GPUs
			//			void *ptr_shared_void = calcForces.unused_shared_data_pointer(system_per_block_gpu());
			//			int *ptr_shared_int = static_cast<int *>(ptr_shared_void);
			//			//			int put_back = *ptr_shared_int;
			//						*ptr_shared_int = 0;
			//			//			atomicOr(ptr_shared_int,thread_needs_std_coord);
			//			  //			if(thread_needs_std_coord) (*ptr_shared_int)++;
			//			__syncthreads();
			//			bool block_needs_std_coord = static_cast<bool>(*ptr_shared_int);
			//			*ptr_shared_int = put_back;
			bool block_needs_std_coord = true;
#endif			
			if(block_needs_std_coord) 
			  { 
			    prop.convert_internal_to_std_coord(); 
			    using_std_coord = true; 
			  }

			__syncthreads();
			int new_state = montest.pass_two ( thread_in_system() );

			if( montest.need_to_log_system() && (thread_in_system()==0) )
			  { log::system(*_log, sys); }
			    
			__syncthreads();
			if(using_std_coord)
			  {
			    prop.convert_std_to_internal_coord();
			    using_std_coord = false;
			  }
#endif
			__syncthreads();			  

			if( sys.is_active() && prop.is_first_thread_in_system() )
			  {
			    if( sys.time() >= _destination_time ) 
			      { sys.set_inactive();     }
			  }
			__syncthreads();

		}

		prop.shutdown();

	}