Beispiel #1
0
/* partial momentum update step for ghmc */
void partial_momentum_update()
{

	int i, j, c, np;
  Particle *part;
	double sigmat, sigmar;

	//fprintf(stderr,"%d: temp before partial update: %f. expected: %f\n",this_node,calc_local_temp(),temperature);
	sigmat = sqrt(temperature); sigmar = sqrt(temperature);
	for (c = 0; c < local_cells.n; c++) {
    np   = local_cells.cell[c]->n;
    part = local_cells.cell[c]->part;
    for (i = 0; i < np; i++) {
			#ifdef MASS
				sigmat = sqrt(temperature / PMASS(part[i]));
			#endif
      for (j = 0; j < 3; j++) {
				part[i].m.v[j] = cosp*(part[i].m.v[j])+sinp*(sigmat*gaussian_random()*time_step);
				#ifdef ROTATION
					#ifdef ROTATIONAL_INERTIA
						sigmar = sqrt(temperature / part[i].p.rinertia[j]);
					#endif
					part[i].m.omega[j] = cosp*(part[i].m.omega[j])+sinp*(sigmar*gaussian_random());
				#endif	
			}
    }
	}
	//fprintf(stderr,"%d: temp after partial update: %f\n", this_node, calc_local_temp());
}
Beispiel #2
0
/* momentum update step of ghmc */
void simple_momentum_update()
{
	
	int i, j, c, np;
  Particle *part;
	double sigmat, sigmar;
	

	sigmat = sqrt(temperature); sigmar = sqrt(temperature);
	for (c = 0; c < local_cells.n; c++) {
    np   = local_cells.cell[c]->n;
    part = local_cells.cell[c]->part;
    for (i = 0; i < np; i++) {
			#ifdef VIRTUAL_SITES
				if (ifParticleIsVirtual(&part[i])) continue;
			#endif
			
			#ifdef MASS
				sigmat = sqrt(temperature / PMASS(part[i]));
			#endif
      for (j = 0; j < 3; j++) {
				part[i].m.v[j] = sigmat*gaussian_random()*time_step;
				#ifdef ROTATION
					#ifdef ROTATIONAL_INERTIA
						sigmar = sqrt(temperature / part[i].p.rinertia[j]);
					#endif
					part[i].m.omega[j] = sigmar*gaussian_random();
				#endif	
			}
    }
	}
	
	//fprintf(stderr,"%d: temp after simple update: %f\n",this_node,calc_local_temp());
	
}
Beispiel #3
0
static void create_burst(xProcess_PCB_ptr process)
{
  time_t burst_length;
  time_t io_service_time;
  char buffer[BUFFER_SIZE];

  /* Determine the length of the CPU burst */
  burst_length = gaussian_random(CPU_BURST_MEDIAN, CPU_BURST_SIGMA);

  /*
   * Determine the manner in which the quantum will end.  The idle
   * process always runs to the end of its quantum
   */

  if (xSimulator_time() + burst_length > timer_time) { /* CPU Burst */
    /* Determine if the process will end on this CPU burst */
    if (0 == (rand() % END_PROCESS_PROBABILITY)) {
      burst_length = rand() % (timer_time - xSimulator_time());
      process_end_time = xSimulator_time() + burst_length;
      process_end_event = schedule_event(process_end_time, xSystem_process_end, NULL);
    } else {
      /* Just allow the timer to handle everything */
    }
  } else { /* The slice ends with blocking I/O */
    io_start_time = xSimulator_time() + burst_length;
    io_service_time = gaussian_random(IO_BURST_MEDIAN, IO_BURST_SIGMA);
    io_end_time = io_start_time + io_service_time;

    io_start_event = schedule_event(io_start_time, xSystem_io_start, NULL);
    io_end_event = schedule_event(io_end_time, xSystem_io_end, process);

    snprintf(buffer, BUFFER_SIZE, "Scheduled I/O burst to end at %08ld.", io_end_time);
    print(process, buffer);
  }
}
std::vector<std::pair<int, int> > generate_distro(double distro_radius, int num_points)
{
	std::vector<std::pair<int, int> > distribution;

	for (int i = 0; i < num_points; i++)
		distribution.push_back(
			std::pair<int, int>(
				(int) gaussian_random(0, distro_radius),
				(int) gaussian_random(0, distro_radius)
			)
		);

	return distribution;
}
Beispiel #5
0
static void create_process(void)
{
  xProcess_PCB_ptr process;
  time_t time;

  process = xProcess_create(rand() % (PRIORITY_MAXIMUM + 1));
  time = xSimulator_time() +
    gaussian_random(CPU_BURST_MEDIAN, CPU_BURST_SIGMA);

  schedule_event(time, xSystem_process_start, process);
}
Beispiel #6
0
inline int calc_drude_forces(Particle *p1, Particle *p2, Bonded_ia_parameters *iaparams, double dx[3], double force1[3], double force2[3])
{
  int dummy,i;
  double dist2 = sqrlen(dx);
  double dist = sqrt(dist2);

  if ((iaparams->p.drude.r_cut > 0.0) && (dist > iaparams->p.drude.r_cut))
    return 1;

  double force_harmonic[3] = {0., 0., 0.};
  double force_subt_elec[3] = {0., 0., 0.};
  double force_lv_com[3] = {0., 0., 0.};
  double force_lv_dist[3] = {0., 0., 0.};

  double chgfac = p1->p.q*p2->p.q;

  double fac_harmonic = -iaparams->p.drude.k;
  double gamma_c = iaparams->p.drude.gamma_core;
  double gamma_d = iaparams->p.drude.gamma_drude;
  double temp_c = iaparams->p.drude.temp_core;
  double temp_d = iaparams->p.drude.temp_drude;

  double mass_c = p1->p.mass;
  double mass_d = p2->p.mass;
  double mass_tot = mass_d + mass_c;
  double mass_tot_inv = 1.0 / mass_tot;
  double mass_red = mass_d * mass_c / mass_tot;
  double mass_red_inv = 1.0 / mass_red;

  //double rnd_c[3] = { (d_random()-0.5), (d_random()-0.5), (d_random()-0.5) };
  //double rnd_d[3] = { (d_random()-0.5), (d_random()-0.5), (d_random()-0.5) };


  for (i=0;i<3;i++)  {
    double com_vel = mass_tot_inv * (mass_c * p1->m.v[i] + mass_d * p2->m.v[i]);
    //force_lv_com[i] =  -gamma_c / time_step * com_vel + sqrt(24.0 * gamma_c / time_step * temp_c) * (d_random()-0.5);
    force_lv_com[i] =  -gamma_c / time_step * com_vel + sqrt(2.0 * gamma_c / time_step * temp_c) * gaussian_random();
    double dist_vel = p2->m.v[i] - p1->m.v[i];
    //force_lv_dist[i] =  -gamma_d / time_step * dist_vel + sqrt(24.0 * gamma_d / time_step * temp_d) * (d_random()-0.5);
    force_lv_dist[i] =  -gamma_d / time_step * dist_vel + sqrt(2.0 * gamma_d / time_step * temp_d) * gaussian_random();
  }

  /* Apply forces: 
     -Harmonic bond
     -Langevin thermostat on distance core-drude and com in lab coords result in cross terms for velocities and rnd kicks */


  if (dist<ROUND_ERROR_PREC) {  /* dx[] == 0: the force is undefined. Let's use a random direction and no spring */
    for(i=0;i<3;i++) {
    	dx[i] = d_random()-0.5;
    }
  	dist2 = sqrlen(dx);
  	dist = sqrt(dist2);
    fac_harmonic = 0;
    fprintf(stderr,"dist<ROUND_ERROR_PREC");
  }
  
  for (i=0;i<3;i++)  {
     force_harmonic[i] = fac_harmonic*dx[i];
    
     force1[i] = mass_c * mass_tot_inv * force_lv_com[i] - force_lv_dist[i] + force_harmonic[i]; //Core
     force2[i] = mass_d * mass_tot_inv * force_lv_com[i] + force_lv_dist[i] - force_harmonic[i]; //Drude
     
     //force_subt_elec[i] = -coulomb.prefactor * chgfac * dx[i] / dist / dist2;
     //force1[i] = mass_c * mass_tot_inv * force_lv_com[i] - force_lv_dist[i] + force_harmonic[i] + force_subt_elec[i]; //Core
     //force2[i] = mass_d * mass_tot_inv * force_lv_com[i] + force_lv_dist[i] - force_harmonic[i] - force_subt_elec[i]; //Drude
     
     //force1[i] = force_com[i] + force_harmonic[i] + force_subt_elec[i]; //Core
     //force2[i] = force_com[i] - force_harmonic[i] - force_subt_elec[i]; //Drude
  }
  
  //fprintf(stderr,"Core Tot: %g %g %g\n", force1[0],force1[1],force1[2]);
  //fprintf(stderr,"Drude Tot: %g %g %g\n", force2[0],force2[1],force2[2]);

 /* 
  fprintf(stderr,"\ndx: %g %g %g\n", dx[0],dx[1],dx[2]);
  fprintf(stderr,"dv: %g %g %g\n", p2->m.v[0] - p1->m.v[0],p2->m.v[1] - p1->m.v[1],p2->m.v[2] - p1->m.v[2]);
  fprintf(stderr,"Harmonic: %g %g %g\n", force_harmonic[0],force_harmonic[1],force_harmonic[2]);
  fprintf(stderr,"Subt_elec: %g %g %g\n", force_subt_elec[0],force_subt_elec[1],force_subt_elec[2]);
  fprintf(stderr,"Dist: %g %g %g\n", force_lv_dist[0],force_lv_dist[1],force_lv_dist[2]);
  fprintf(stderr,"Com: %g %g %g\n", force_lv_com[0],force_lv_com[1],force_lv_com[2]);
  fprintf(stderr,"Core Tot: %g %g %g\n", force1[0],force1[1],force1[2]);
  fprintf(stderr,"Drude Tot: %g %g %g\n", force2[0],force2[1],force2[2]);
 */

  ONEPART_TRACE(if(p1->p.identity==check_id) fprintf(stderr,"%d: OPT: DRUDE f = (%.3e,%.3e,%.3e)\n",this_node,p1->f.f[0]+force1[0],p1->f.f[1]+force1[1],p1->f.f[2]+force1[2]));
  ONEPART_TRACE(if(p2->p.identity==check_id) fprintf(stderr,"%d: OPT: DRUDE f = (%.3e,%.3e,%.3e)\n",this_node,p2->f.f[0]+force2[0],p2->f.f[1]+force2[1],p2->f.f[2]+force2[2]));
  return 0;
  
}