/* momentum update step of ghmc with temperature scaling */ void tscale_momentum_update() { int i, j, c, np; Particle *part; //fprintf(stderr,"%d: temp before update: %f\n",this_node,calc_local_temp()); save_last_state(); simple_momentum_update(); //fprintf(stderr,"%d: temp after simple update: %f\n",this_node,calc_local_temp()); double tempt, tempr; calc_kinetic(&tempt, &tempr); tempt /= (1.5*n_total_particles); tempr /= (1.5*n_total_particles); double scalet = sqrt(temperature / tempt); #ifdef ROTATION double scaler = sqrt(temperature / tempr); #endif 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++) { for (j = 0; j < 3; j++) { part[i].m.v[j] *= scalet; #ifdef ROTATION part[i].m.omega[j] *= scaler; #endif } } } //fprintf(stderr,"%d: temp after scale: %f\n",this_node,calc_local_temp()); 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 for (j = 0; j < 3; j++) { part[i].m.v[j] = cosp*(part[i].l.m_ls.v[j])+sinp*(part[i].m.v[j]); #ifdef ROTATION part[i].m.omega[j] = cosp*(part[i].l.m_ls.omega[j])+sinp*(part[i].m.omega[j]); #endif } } } //fprintf(stderr,"%d : temp after partial update: %f\n",this_node,calc_local_temp()); }
/* 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()); }
void ghmc_init() { INTEG_TRACE(fprintf(stderr,"%d: ghmc_init:\n",this_node)); ghmcdata.att=0; ghmcdata.acc=0; save_last_state(); }
int tclcommand_save_state(ClientData data, Tcl_Interp *interp, int argc, char **argv) { #ifdef GHMC Tcl_ResetResult(interp); /* save system state */ save_last_state(); 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 }