Example #1
0
/** (Re-)initializes the fluid according to the given value of rho. */
void lb_reinit_fluid_gpu() {

  lbpar_gpu.your_seed = (unsigned int)i_random(max_ran);

  lb_init_GPU(&lbpar_gpu);

  LB_TRACE (fprintf(stderr,"lb_reinit_fluid_gpu \n"));
}
Example #2
0
/** (re-) allocation of the memory needed for the particles (cpu part)
*/
void lb_realloc_particles_gpu(){

  lbpar_gpu.number_of_particles = n_part;
  LB_TRACE (printf("#particles realloc\t %u \n", lbpar_gpu.number_of_particles));
  //fprintf(stderr, "%u \t \n", lbpar_gpu.number_of_particles);
  /**-----------------------------------------------------*/
  /** allocating of the needed memory for several structs */
  /**-----------------------------------------------------*/
  lbpar_gpu.your_seed = (unsigned int)i_random(max_ran);

  LB_TRACE (fprintf(stderr,"test your_seed %u \n", lbpar_gpu.your_seed));

  lb_realloc_particles_GPU_leftovers(&lbpar_gpu);
}
Example #3
0
/** (re-) allocation of the memory need for the particles (cpu part)*/
void lb_realloc_particles_gpu(){

  lbpar_gpu.number_of_particles = n_total_particles;
  LB_TRACE (printf("#particles realloc\t %u \n", lbpar_gpu.number_of_particles));
  /**-----------------------------------------------------*/
  /** allocating of the needed memory for several structs */
  /**-----------------------------------------------------*/
  /**Allocate struct for particle forces */
  size_t size_of_forces = lbpar_gpu.number_of_particles * sizeof(LB_particle_force_gpu);
  host_forces = realloc(host_forces, size_of_forces);

  lbpar_gpu.your_seed = (unsigned int)i_random(max_ran);

  LB_TRACE (fprintf(stderr,"test your_seed %u \n", lbpar_gpu.your_seed));
  lb_realloc_particle_GPU(&lbpar_gpu, &host_data);
}
Example #4
0
int find_particle_type(int type, int *id){ 
	int l_err=1;
	// type i not indexed, so no list for this particle exists
	for (int i = 0; i<Type.max_entry; i++){
		if ( Type.index[i] == type ){
			l_err=0;
			break;
		}
	}
	if ( l_err ) {
		return ES_ERROR;
	}
	if ( type_array[Index.type[type]].max_entry == 0 ){ 
		return ES_ERROR;
	}
	int rand_index = i_random ( type_array[Index.type[type]].max_entry );
	*id = type_array[Index.type[type]].id_list[rand_index];

	return ES_OK;
}
Example #5
0
/** initialize the forces for a real particle */
MDINLINE void init_local_particle_force(Particle *part)
{
#ifdef ADRESS
  double new_weight;
  if (ifParticleIsVirtual(part)) {
    new_weight = adress_wf_vector(part->r.p);
#ifdef ADRESS_INIT
    double old_weight = part->p.adress_weight;
    
    if(new_weight>0 && old_weight==0){
      double rand_cm_pos[3], rand_cm_vel[3], rand_weight, new_pos, old_pos;
      int it, dim, this_mol_id=part->p.mol_id, rand_mol_id, rand_type;
      int n_ats_this_mol=topology[this_mol_id].part.n, n_ats_rand_mol;
      
      //look for a random explicit particle
      rand_type=-1;
      rand_weight=-1;
      rand_mol_id=-1;
      n_ats_rand_mol=-1;
      
      while(rand_type != part->p.type || rand_weight != 1 || n_ats_rand_mol != n_ats_this_mol){
	rand_mol_id = i_random(n_molecules);
	rand_type   = local_particles[(topology[rand_mol_id].part.e[0])]->p.type;
	rand_weight = local_particles[(topology[rand_mol_id].part.e[0])]->p.adress_weight;
	n_ats_rand_mol = topology[rand_mol_id].part.n;
	
	if(!ifParticleIsVirtual(local_particles[(topology[rand_mol_id].part.e[0])]))
	  fprintf(stderr,"No virtual site found on molecule %d, with %d total molecules.\n",rand_mol_id, n_molecules);
      }
      
      //store CM position and velocity
      for(dim=0;dim<3;dim++){
	rand_cm_pos[dim]=local_particles[(topology[rand_mol_id].part.e[0])]->r.p[dim];
	rand_cm_vel[dim]=local_particles[(topology[rand_mol_id].part.e[0])]->m.v[dim];
      }
      
      //assign new positions and velocities to the atoms
      for(it=0;it<n_ats_this_mol;it++){
	if (!ifParticleIsVirtual(local_particles[topology[rand_mol_id].part.e[it]])) {
	  for(dim=0;dim<3;dim++){
	    old_pos = local_particles[topology[this_mol_id].part.e[it]]->r.p[dim];
	    new_pos = local_particles[topology[rand_mol_id].part.e[it]]->r.p[dim]-rand_cm_pos[dim]+part->r.p[dim];
	    //MAKE SURE THEY ARE IN THE SAME BOX
	    while(new_pos-old_pos>box_l[dim]*0.5)
	      new_pos=new_pos-box_l[dim];
	    while(new_pos-old_pos<-box_l[dim]*0.5)
	      new_pos=new_pos+box_l[dim];
	    
	    local_particles[(topology[this_mol_id].part.e[it])]->r.p[dim] = new_pos;
	    local_particles[(topology[this_mol_id].part.e[it])]->m.v[dim] = local_particles[(topology[rand_mol_id].part.e[it])]->m.v[dim]-rand_cm_vel[dim]+part->m.v[dim];
	  }   
	}
      }
    }
#endif
    part->p.adress_weight=new_weight;
  }
#endif
  if ( thermo_switch & THERMO_LANGEVIN )
    friction_thermo_langevin(part);
  else {
    part->f.f[0] = 0;
    part->f.f[1] = 0;
    part->f.f[2] = 0;
  }

#ifdef EXTERNAL_FORCES   
  if(part->l.ext_flag & PARTICLE_EXT_FORCE) {
    part->f.f[0] += part->l.ext_force[0];
    part->f.f[1] += part->l.ext_force[1];
    part->f.f[2] += part->l.ext_force[2];
  }
#endif
  
#ifdef ROTATION
  {
    double scale;
    /* set torque to zero */
    part->f.torque[0] = 0;
    part->f.torque[1] = 0;
    part->f.torque[2] = 0;
    
    /* and rescale quaternion, so it is exactly of unit length */	
    scale = sqrt( SQR(part->r.quat[0]) + SQR(part->r.quat[1]) +
		  SQR(part->r.quat[2]) + SQR(part->r.quat[3]));
    part->r.quat[0]/= scale;
    part->r.quat[1]/= scale;
    part->r.quat[2]/= scale;
    part->r.quat[3]/= scale;
  }
#endif

#ifdef ADRESS
  /* #ifdef THERMODYNAMIC_FORCE */
  if(ifParticleIsVirtual(part))
    if(part->p.adress_weight > 0 && part->p.adress_weight < 1)
      add_thermodynamic_force(part);
  /* #endif */  
#endif
}
Example #6
0
/**  Implementation of the tcl-command
     t_random [{ int \<n\> | seed [\<seed(0)\> ... \<seed(n_nodes-1)\>] | stat [status-list] }]
     <ul>
     <li> Without further arguments, it returns a random double between 0 and 1.
     <li> If 'int \<n\>' is given, it returns a random integer between 0 and n-1.
     <li> If 'seed'/'stat' is given without further arguments, it returns a tcl-list with
          the current seeds/status of the n_nodes active nodes; otherwise it issues the 
	  given parameters as the new seeds/status to the respective nodes.     
     </ul>
 */
int tclcommand_t_random (ClientData data, Tcl_Interp *interp, int argc, char **argv) {
  char buffer[100 + TCL_DOUBLE_SPACE + 3*TCL_INTEGER_SPACE];
  int i,j,cnt, i_out, temp; 
  double d_out;

  if (argc == 1) {                  /* 't_random' */
    d_out = d_random();
    sprintf(buffer, "%f", d_out); Tcl_AppendResult(interp, buffer, (char *) NULL); return (TCL_OK);
  }

  /* argc > 1 */
  argc--; argv++;

  if ( ARG_IS_S(0,"int") )          /* 't_random int <n>' */
  {
    if(argc < 2)
    { 
      Tcl_AppendResult(interp, "\nWrong # of args: Usage: 't_random int <n>'", (char *) NULL); 
      return (TCL_ERROR); 
    }
    else 
    {
      if( !ARG_IS_I(1,i_out) )
      { 
        Tcl_AppendResult(interp, "\nWrong type: Usage: 't_random int <n>'", (char *) NULL); 
        return (TCL_ERROR); 
      }

      i_out = i_random(i_out);

      sprintf(buffer, "%d", i_out);
      Tcl_AppendResult(interp, buffer, (char *) NULL); 
      return (TCL_OK);
    }
  }
  else if ( ARG_IS_S(0,"seed") )    /* 't_random seed [<seed(0)> ... <seed(n_nodes-1)>]' */
  {
    long *seed = (long *) malloc(n_nodes*sizeof(long));

    if (argc <= 1)                  /* ESPResSo generates a seed */
    {
      mpi_random_seed(0,seed);

      for (i=0; i < n_nodes; i++) 
      {
	      sprintf(buffer, "%ld ", seed[i]); 
        Tcl_AppendResult(interp, buffer, (char *) NULL); 
      }
    }
    else if (argc < n_nodes+1)      /* Fewer seeds than nodes */
    { 
      sprintf(buffer, "Wrong # of args (%d)! Usage: 't_random seed [<seed(0)> ... <seed(%d)>]'", argc,n_nodes-1);
      Tcl_AppendResult(interp, buffer, (char *)NULL); 
      return (TCL_ERROR); 
    }
    else                            /* Get seeds for different nodes */
    {
      for (i=0; i < n_nodes; i++) 
      {
        if( !ARG_IS_I(i+1,temp) )
        { 
          sprintf(buffer, "\nWrong type for seed %d:\nUsage: 't_random seed [<seed(0)> ... <seed(%d)>]'", i+1 ,n_nodes-1);
          Tcl_AppendResult(interp, buffer, (char *)NULL);  
          return (TCL_ERROR); 
        }
        else
        {
          seed[i] = (long)temp;
        }
      }

      RANDOM_TRACE(
        printf("Got "); 

        for(i=0;i<n_nodes;i++) 
          printf("%ld ",seed[i]);

        printf("as new seeds.\n")
      );

      mpi_random_seed(n_nodes,seed);
    }

    free(seed); 
    return(TCL_OK);
  }
Example #7
0
/**  Implementation of the tcl-command
     t_random [{ int \<n\> | seed [\<seed(0)\> ... \<seed(n_nodes-1)\>] | stat [status-list] }]
     <ul>
     <li> Without further arguments, it returns a random double between 0 and 1.
     <li> If 'int \<n\>' is given, it returns a random integer between 0 and n-1.
     <li> If 'seed'/'stat' is given without further arguments, it returns a tcl-list with
          the current seeds/status of the n_nodes active nodes; otherwise it issues the 
	  given parameters as the new seeds/status to the respective nodes.     
     </ul>
 */
int tclcommand_t_random (ClientData data, Tcl_Interp *interp, int argc, char **argv) {
  char buffer[100 + TCL_DOUBLE_SPACE + 3*TCL_INTEGER_SPACE];

  if (argc == 1) {                  /* 't_random' */
    sprintf(buffer, "%f", d_random());
    Tcl_AppendResult(interp, buffer, (char *) NULL); return (TCL_OK);
  }

  /* argc > 1 */
  argc--; argv++;

  if ( ARG_IS_S(0,"int") )          /* 't_random int <n>' */
  {
    if(argc < 2)
    { 
      Tcl_AppendResult(interp, "\nWrong # of args: Usage: 't_random int <n>'", (char *) NULL); 
      return (TCL_ERROR); 
    }
    else 
    {
      int i_max;
      if( !ARG_IS_I(1,i_max) )
      { 
        Tcl_AppendResult(interp, "\nWrong type: Usage: 't_random int <n>'", (char *) NULL); 
        return (TCL_ERROR); 
      }

      sprintf(buffer, "%d", i_random(i_max));
      Tcl_AppendResult(interp, buffer, (char *) NULL); 
      return (TCL_OK);
    }
  }
  else if ( ARG_IS_S(0,"stat") ) {
    if(argc == 1) {
      Tcl_AppendResult(interp, Random::mpi_random_get_stat().c_str(), nullptr);

      return TCL_OK;
    } else {
      auto error_msg = [interp]() {
        Tcl_AppendResult(interp, "\nWrong # of args: Usage: 't_random stat \"<state(1)> ... <state(n_nodes*625)>\"'", (char *) NULL);
      };
      
      if(argc != 2) {
        error_msg();
        return TCL_ERROR;
      }
      std::vector<std::string> states(n_nodes);

      std::istringstream iss(argv[1]);
      std::string tmp;
      
      /** Argument counter to check that the caller provided enough numbers. */      
      int n_args = 0;
      for(int node = 0; (node < n_nodes) && std::getline(iss, tmp, ' '); node++) {
        n_args++;


        /** First one is handled different, because of the space */        
        states[node] = tmp;

        for(int i = 0; (i < 624) && std::getline(iss, tmp, ' '); i++) {
          n_args++;
          states[node].append(" ");
          states[node].append(tmp);
        }
      }

      if(n_args == n_nodes*625) {
        Random::mpi_random_set_stat(states);
        return TCL_OK;
      }
      else {
        error_msg();
        return TCL_ERROR;
      }
    }
  }
  
  else if ( ARG_IS_S(0,"seed") )    /* 't_random seed [<seed(0)> ... <seed(n_nodes-1)>]' */
  {
    std::vector<int> seeds(n_nodes);

    if ((argc > 1) && (argc < n_nodes+1))      /* Fewer seeds than nodes */
    { 
      sprintf(buffer, "Wrong # of args (%d)! Usage: 't_random seed [<seed(0)> ... <seed(%d)>]'", argc,n_nodes-1);
      Tcl_AppendResult(interp, buffer, (char *)NULL); 
      return (TCL_ERROR); 
    }
    
    if (argc <= 1)
    {
      std::iota(seeds.begin(), seeds.end(), 1);
      for(auto &seed: seeds)
      {
        sprintf(buffer, "%d ", seed); 
        Tcl_AppendResult(interp, buffer, (char *) NULL); 
      }
    }
    else                            /* Get seeds for different nodes */
    {
      for (int i = 0; i < n_nodes; i++) {
        if( !ARG_IS_I(i+1,seeds[i]) ) { 
          sprintf(buffer, "\nWrong type for seed %d:\nUsage: 't_random seed [<seed(0)> ... <seed(%d)>]'", i+1 ,n_nodes-1);
          Tcl_AppendResult(interp, buffer, (char *)NULL);  
          return (TCL_ERROR); 
        }
      }
    }

#ifdef RANDOM_TRACE
    printf("Got "); 
        
    for(int i=0;i<n_nodes;i++) 
      printf("%d ",seeds[i]);
        
    printf("as new seeds.\n");
#endif
    
    Random::mpi_random_seed(n_nodes,seeds);
    
    return(TCL_OK);
  }

  /* else */
  sprintf(buffer, "Usage: 't_random [{ int <n> | seed [<seed(0)> ... <seed(%d)>] }]'",n_nodes-1);
  Tcl_AppendResult(interp, "Unknown argument '",argv[0],"' requested!\n",buffer, (char *)NULL);
  return (TCL_ERROR); 
}
static void *clock_init (GtkWidget *window, GtkWidget *drawing_area)
{
    char  *env;
    state *st = (state *) calloc (1, sizeof (*st));

    st->window = window;
    st->drawing_area = drawing_area;
    st->width  = st->window->allocation.width;
    st->height = st->window->allocation.height;

    st->brightness  = brightness;
    st->grayscale   = grayscale;
    st->mono        = mono;
    st->pin         = pin;
    st->size        = size;
    st->wireframe   = wireframe;
    st->hide_index  = hide_index;
    st->hide_mark   = hide_mark;
    st->hide_second = hide_second;
    correct_options(st);

    st->bg_colour.red   = 0;
    st->bg_colour.green = 0;
    st->bg_colour.blue  = 0;

    st->face_colour.red    = (guint16)(0xffff*0.85);
    st->face_colour.green  = (guint16)(0xffff*0.85);
    st->face_colour.blue   = (guint16)(0xffff*0.85);
    if (face_spec_a)
        if (!gdk_color_parse(face_spec_a, &st->face_colour))
            g_warning("Can't parse color %s: using black.", (char *)face_spec_a);

    if(charset_opt_a){
      strncpy(charset, (char *)charset_opt_a, MAX_BUF);
    }
    else{
      strcpy(charset, "windows-1251");
    }

    if(FONT_FACE_a!=NULL){
      strncpy(FONT_FACE,FONT_FACE_a,MAX_BUF);
    }
    if(FONT_FACE_CLOCK_a!=NULL){
      strncpy(FONT_FACE_CLOCK,FONT_FACE_CLOCK_a,MAX_BUF);
    }
    if(WEATHER_AREA_a!=NULL){
      strncpy(WEATHER_AREA,WEATHER_AREA_a,MAX_BUF);
    }
    else{
      env=getenv("SIMPLEWEATHER_LOCATION");
      if(env!=NULL){
        strncpy(WEATHER_AREA,env,MAX_BUF);
      }
    }

    st->marks_colour.red   = 0xffff;
    st->marks_colour.green = 0xffff;
    st->marks_colour.blue  = 0xffff;

    st->line_colour.red    = 0x0000;
    st->line_colour.green  = 0x0000;
    st->line_colour.blue   = 0x0000;

    st->fill_colour.red    = 0xFFFF;
    st->fill_colour.green  = 0xFFFF;
    st->fill_colour.blue   = 0xFFFF;
    st->orient.x = i_random(2) * 2 - 1;
    st->orient.y = i_random(2) * 2 - 1;

    return st;
}