示例#1
0
double UNIFAQ::UNIFAQMixture::ln_gamma_R(const double tau, std::size_t i, std::size_t itau){
    if (itau == 0) {
        set_temperature(T_r / tau);
        double summer = 0;
        for (std::vector<UNIFAQLibrary::Group>::const_iterator it = unique_groups.begin(); it != unique_groups.end(); ++it) {
            std::size_t k = it->sgi;
            std::size_t count = group_count(i, k);
            if (count > 0){
                summer += count*(m_lnGammag.find(k)->second - pure_data[i].lnGamma.find(k)->second);
            }
        }
        //printf("log(gamma)_{%d}: %g\n", i+1, summer);
        return summer;
    }
    else {
        double dtau = 0.01*tau;
        return (ln_gamma_R(tau + dtau, i, itau - 1) - ln_gamma_R(tau - dtau, i, itau - 1)) / (2 * dtau);
    }
}
示例#2
0
文件: brown.c 项目: Jumziey/modsim
void run(Par *par)
{
  int i, itherm, nstep, istep, isamp, iblock, st;
  int nsamp = par->nsamp, nblock = par->nblock;
  char wfile[FNAMESIZE];
  Vec *pos, *vel, *force;
  double ekin, epot;
  double v0[NV], v1[NV], v2[NV];
  FILE *estream = NULL;

  // Initialize

  if (par->alpha > 0.0) {
    printf("Seed for random number generator: %d.\n", par->seed);
    init_ran(par->seed);
  }

  pos = malloc(par->n * sizeof(Vec));
  force = malloc(par->n * sizeof(Vec));
  vel = malloc(par->n * sizeof(Vec));

  // Read from file...
  if (par->readfile)
    st = read_conf(par->n, pos, vel, par->readfile);
  else {
    init_pos(par->n, &par->L, pos);
    set_temperature(par->n, par->t, vel);
  }

  // Get file name for writing to.
  get_filename(par, wfile);

  // Open file for writing energy results
  estream = fopen_wfile("efile/", wfile);
  if (!estream) return;

  measure(par->n, &par->L, pos, vel, &epot, &ekin);
  printf("Energy = %g \n", epot);

  double test;
  for(i=0; i<par->ntherm; i++) {
    test = pos[5].x;
    step(par, pos, vel, force);
    if(test == pos[5].x)
      printf("aha!\n");
  }
  //printf("rx ry vx vy = %g  %g  %g  %g\n", pos[0].x, pos[0].y, vel[0].x, vel[0].y);

  // Run and collect values
  printf("\nSimulate %d blocks x %d samples each: ", par->nblock, par->nsamp);
  fflush(stdout);

  init_vcorr(par->n, par->deltat, 0.1, 5.0);

  // Initialize for measuring a histogram of particle distances for
  // distances up to 5.0 and bin size 0.02.
  // init_pcorr(par->n, 0.02, 5.0);
  for (i = 0; i < NV; i++) v1[i] = v2[i] = 0.0;

  nstep = rint(1.0 / par->deltat);
  for (iblock = 0; iblock < nblock; iblock++) {

    for (i = 0; i < NV; i++) v0[i] = 0.0;
    for (isamp = 0; isamp < nsamp; isamp++) {
      for (istep = 0; istep < nstep; istep++) {
	      step(par, pos, vel, force);
	      measure_vcorr(par->n, vel);
      }

      // measure_pcorr(par->n, &par->L, pos);

      measure(par->n, &par->L, pos, vel, &epot, &ekin);
      if (estream) fprintf(estream, "%d %g\n", isamp + nsamp * iblock, epot + ekin);
      v0[0] += epot;
      //v0[1] += ekin;
      //v0[2] += epot + ekin;
    }
    for (i = 0; i < NV; i++) {
      v0[i] /= nsamp;
      v1[i] += v0[i];
      v2[i] += v0[i] * v0[i];
    }

    printf("%d ", iblock + 1);	fflush(stdout);
  }
  printf("\n");

  if (estream) fclose(estream);

  for (i = 0; i < NV; i++) {
    v1[i] /= nblock;
    v2[i] /= nblock;
  }

  // Write configuration to the named file.
  write_conf(par->n, pos, vel, "conf/", wfile);

  // Write velocity correlation results to files.
  write_vcorr(par->n, wfile);
  // write_pcorr(par->n, wfile);

  // Print out some results
  printf("\n");
  printf("v1: %.3f v2: %.3f nblock: %d \n",v1[0],v2[0],nblock);
  print_standard_error("Potential E:  ", v1[0], v2[0], nblock);
  //print_standard_error("Kinetic  E:   ", v1[1], v2[1], nblock);
  //print_standard_error("Total energy: ", v1[2], v2[2], nblock);


  // From the virial theorem:  pressure = N * T + Virial / Dimensionality

  free(vel);
  free(pos);
  
}
int main(int argc,char* argv[])
{
	
	if(argc != 3)
	{
		printf("缺少参数:error!\n");
		exit(0);
	}
	 
 	
	//*********打开串口并设置波特率*********	
	
	char *dev = (char*)argv[2]; //串口

	int fd = OpenDev(dev);           //打开串口函数
    if(fd<0)
    {
   	    close(fd);
        return FALSE;
    }

	int set_res=set_speed(fd,9600);          //设置串口

	if(set_res==FALSE)
 	{
 		close(fd);
   		return FALSE;
  	}

	if (set_Parity(fd,8,1,'N') == FALSE)
	{
		close(fd);
		return FALSE;
	}

	//***********从文件中读出指令*************** 
	int temperature = atoi(argv[1]);
	
	set_temperature(temperature);
	
    //*********发送命令************** 
	int send_res = Send_order(fd,outcommand,24);

	if(send_res==FALSE)
 	{
 		close(fd);
   		return FALSE;
	}

    char total_buff[1024];
	int length = Recv_data(fd,total_buff);//读取串口数据
	printf("接收数据长度为:%d\n",length);
	
	int j;//显示接收到的字符
    FILE *stream;
	stream = fopen("receiveinfo","w+");
	for (j = 0 ; j < length; j++)
	{       
		printf("%02X  ", total_buff[j]);
		fprintf(stream, "%02X", total_buff[j]);	
	}    
	fclose(stream);           
	printf("\n");  

	close(fd);
	return 0;

}
示例#4
0
TCU_readings::TCU_readings(uint16_t throttle_value_1, uint16_t throttle_value_2, uint16_t brake_value, uint16_t temperature) {
    set_throttle_value_1(throttle_value_1);
    set_throttle_value_2(throttle_value_2);
    set_brake_value(brake_value);
    set_temperature(temperature);
}
示例#5
0
// Yep, this is actually -*- c++ -*-
void init_extruder()
{
  //reset motor1
  motor1_control = MC_PWM;
  motor1_dir = MC_FORWARD;
  motor1_pwm = 0;
  motor1_target_rpm = 0;
  motor1_current_rpm = 0;
  
  //reset motor2
  motor2_control = MC_PWM;
  motor2_dir = MC_FORWARD;
  motor2_pwm = 0;
  motor2_target_rpm = 0;
  motor2_current_rpm = 0;
	
  //free up 9/10
  servo1.detach();
  servo2.detach();

  //init our PID stuff.
  speed_error = 0;
  iState = 0;
  dState = 0;
  pGain = SPEED_INITIAL_PGAIN;
  iGain = SPEED_INITIAL_IGAIN;
  dGain = SPEED_INITIAL_DGAIN;

  temp_control_enabled = true;
#if TEMP_PID
  temp_iState = 0;
  temp_dState = 0;
  temp_pGain = TEMP_PID_PGAIN;
  temp_iGain = TEMP_PID_IGAIN;
  temp_dGain = TEMP_PID_DGAIN;
  temp_pid_update_windup();
#endif
	
  //encoder pins are for reading.
  pinMode(ENCODER_A_PIN, INPUT);
  pinMode(ENCODER_B_PIN, INPUT);

  //pullups on our encoder pins
  digitalWrite(ENCODER_A_PIN, HIGH);
  digitalWrite(ENCODER_B_PIN, HIGH);

  //attach our interrupt handler
  attachInterrupt(0, read_quadrature, CHANGE);

  //setup our motor control pins.
  pinMode(MOTOR_1_SPEED_PIN, OUTPUT);
  pinMode(MOTOR_2_SPEED_PIN, OUTPUT);
  pinMode(MOTOR_1_DIR_PIN, OUTPUT);
  pinMode(MOTOR_2_DIR_PIN, OUTPUT);

  //turn them off and forward.
  digitalWrite(MOTOR_1_SPEED_PIN, LOW);
  digitalWrite(MOTOR_2_SPEED_PIN, LOW);
  digitalWrite(MOTOR_1_DIR_PIN, HIGH);
  digitalWrite(MOTOR_2_DIR_PIN, HIGH);

  //setup our various accessory pins.
  pinMode(HEATER_PIN, OUTPUT);
  pinMode(FAN_PIN, OUTPUT);
  pinMode(VALVE_PIN, OUTPUT);

  //turn them all off
  digitalWrite(HEATER_PIN, LOW);
  digitalWrite(FAN_PIN, LOW);
  digitalWrite(VALVE_PIN, LOW);

  //setup our debug pin.
  pinMode(DEBUG_PIN, OUTPUT);
  digitalWrite(DEBUG_PIN, LOW);

  //default to zero.
  set_temperature(0);

  setupTimer1Interrupt();
}