Пример #1
0
/* monte carlo step of ghmc - evaluation stage */
void ghmc_mc()
{
			INTEG_TRACE(fprintf(stderr,"%d: ghmc_mc:\n",this_node));
			
		  double boltzmann;
			
      int ekin_update_flag = 0;
			hamiltonian_calc(ekin_update_flag);
			
      //make MC decision only on the master
      if (this_node==0) {
      
        ghmcdata.att++;
      
        //metropolis algorithm
        boltzmann = ghmcdata.hmlt_new - ghmcdata.hmlt_old;
        if (boltzmann < 0)
          boltzmann = 1.0;
        else if (boltzmann > 30)
          boltzmann = 0.0;
        else
          boltzmann = exp(-beta*boltzmann);
        
        //fprintf(stderr,"old hamiltonian : %f, new hamiltonian: % f, boltzmann factor: %f\n",ghmcdata.hmlt_old,ghmcdata.hmlt_new,boltzmann);

        if ( d_random() < boltzmann) {
          ghmcdata.acc++;
          ghmc_mc_res = GHMC_MOVE_ACCEPT;
        } else {
          ghmc_mc_res = GHMC_MOVE_REJECT;
        }
        
      }
      
      //let all nodes know about the MC decision result
      mpi_bcast_parameter(FIELD_GHMC_RES);
      
      if (ghmc_mc_res == GHMC_MOVE_ACCEPT) {
        save_last_state();
        //fprintf(stderr,"%d: mc move accepted\n",this_node);
      } else {
        load_last_state();
        //fprintf(stderr,"%d: mc move rejected\n",this_node);
        
        //if the move is rejected we might need to resort particles according to the loaded configurations
        cells_resort_particles(CELL_GLOBAL_EXCHANGE);
        invalidate_obs();
        
        if (ghmc_mflip == GHMC_MFLIP_ON) {
          momentum_flip();
        } else if (ghmc_mflip == GHMC_MFLIP_RAND) {
          if (d_random() < 0.5) momentum_flip();
        }
      }      
        
      //fprintf(stderr,"%d: temp after mc: %f\n",this_node,calc_local_temp());
}
Пример #2
0
int tclcommand_load_state(ClientData data, Tcl_Interp *interp, int argc, char **argv) 
{
#ifdef GHMC

  Tcl_ResetResult(interp);

  /* load last saved system state */
  load_last_state();
  cells_resort_particles(CELL_GLOBAL_EXCHANGE);
  invalidate_obs();

  return TCL_OK;

#else

  INTEG_TRACE(fprintf(stderr,"%d: call to ghmc but not compiled in!\n",this_node));
  return tclcommand_ghmc_print_usage(interp);

#endif
}