Exemplo n.º 1
0
void thermo_init_npt_isotropic()
{
  if (nptiso.piston != 0.0) {
#if defined (FLATNOISE)
    nptiso_pref1 = -nptiso_gamma0*0.5 * time_step;
#ifdef MULTI_TIMESTEP
    if (smaller_time_step > 0.) 
      nptiso_pref2 = sqrt(12.0*temperature*nptiso_gamma0*time_step) * smaller_time_step;
    else
#endif
      nptiso_pref2 = sqrt(12.0*temperature*nptiso_gamma0*time_step) * time_step;
    nptiso_pref3 = -nptiso_gammav*(1.0/nptiso.piston)*0.5*time_step;
    nptiso_pref4 = sqrt(12.0*temperature*nptiso_gammav*time_step);
#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM)
    nptiso_pref1 = -nptiso_gamma0*0.5 * time_step;
    nptiso_pref2 = sqrt(1.0*temperature*nptiso_gamma0*time_step) * time_step;
    nptiso_pref3 = -nptiso_gammav*(1.0/nptiso.piston)*0.5*time_step;
    nptiso_pref4 = sqrt(1.0*temperature*nptiso_gammav*time_step);
#else
#error No Noise defined
#endif
    THERMO_TRACE(fprintf(stderr,"%d: thermo_init_npt_isotropic: nptiso_pref1=%f, nptiso_pref2=%f, nptiso_pref3=%f, nptiso_pref4=%f \n",this_node,nptiso_pref1,nptiso_pref2,nptiso_pref3,nptiso_pref4));
  }
  else {
    thermo_switch = ( thermo_switch ^ THERMO_NPT_ISO );
    THERMO_TRACE(fprintf(stderr,"%d: thermo_init_npt_isotropic: switched off nptiso (piston=%f; thermo_switch=%d) \n",this_node,nptiso.piston,thermo_switch));
  }
}
Exemplo n.º 2
0
void thermo_init_dpd()
{
  extern double dpd_gamma,dpd_r_cut,dpd_pref1,dpd_pref2;
  /*extern int dpd_wf;*/
#ifdef TRANS_DPD
  extern double dpd_tgamma,dpd_tr_cut,dpd_pref3,dpd_pref4;
  /*extern int dpd_twf;*/
#endif
  /* prefactor friction force */
  /* NOTE: velocities are scaled with time_step, so divide by time_step here*/
  dpd_pref1 = dpd_gamma/time_step;  
  /* prefactor random force */
  /*NOTE random force is propto sqrt(time_step)*/
  dpd_pref2 = sqrt(24.0*temperature*dpd_gamma/time_step);
  dpd_r_cut_inv = 1.0/dpd_r_cut;
#ifdef TRANS_DPD
  /* NOTE: velocities are scaled with time_step, so divide by time_step here*/
  dpd_pref3 = dpd_tgamma/time_step;
  /*NOTE random force is propto sqrt(time_step)*/
  dpd_pref4 = sqrt(24.0*temperature*dpd_tgamma/time_step);
  dpd_tr_cut_inv = 1.0/dpd_tr_cut;
#endif
  THERMO_TRACE(fprintf(stderr,"%d: thermo_init_dpd: dpd_pref1=%f, dpd_pref2=%f",
		       this_node,dpd_pref1,dpd_pref2));
#ifdef TRANS_DPD
  THERMO_TRACE(fprintf(stderr,",dpd_pref3=%f, dpd_pref4=%f\n",dpd_pref3,dpd_pref4));
#endif
  THERMO_TRACE(fprintf(stderr,"\n"));
}
Exemplo n.º 3
0
void thermo_init_langevin() 
{
  int j;
  langevin_pref1 = -langevin_gamma/time_step;
#if defined (FLATNOISE)
  langevin_pref2 = sqrt(24.0*temperature*langevin_gamma/time_step);
#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM)
  langevin_pref2 = sqrt(2.0*temperature*langevin_gamma/time_step);
#else
#error No Noise defined
#endif
#ifdef MULTI_TIMESTEP
  if (smaller_time_step > 0.) {
    langevin_pref1_small = -langevin_gamma/smaller_time_step;
 #ifndef LANGEVIN_PER_PARTICLE
    langevin_pref2_small = sqrt(24.0*temperature*langevin_gamma/smaller_time_step);
 #endif
  } else {
    langevin_pref1_small = -langevin_gamma/time_step;
 #ifndef LANGEVIN_PER_PARTICLE
    langevin_pref2_small = sqrt(24.0*temperature*langevin_gamma/time_step);
 #endif
  }
#endif
  
#ifdef ROTATION 
#ifndef ROTATIONAL_INERTIA
  if ( langevin_gamma_rotation < 0.0 )
  {
    langevin_gamma_rotation = langevin_gamma;
  }
#else
  if (( langevin_gamma_rotation[0] < 0.0 ) || (langevin_gamma_rotation[1] < 0.0) || (langevin_gamma_rotation[2] < 0.0))
  for ( j = 0 ; j < 3 ; j++)
  {
    langevin_gamma_rotation[j] = langevin_gamma;
  }
#endif
#ifndef ROTATIONAL_INERTIA
#if defined (FLATNOISE)
  langevin_pref2_rotation = sqrt(24.0*temperature*langevin_gamma_rotation/time_step);
#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM)
  langevin_pref2_rotation = sqrt(2.0*temperature*langevin_gamma_rotation/time_step);
#else
#error No Noise defined
#endif
#else
#if defined (FLATNOISE)
  for ( j = 0 ; j < 3 ; j++) langevin_pref2_rotation[j] = sqrt(24.0*temperature*langevin_gamma_rotation[j]/time_step);
#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM)
  for ( j = 0 ; j < 3 ; j++) langevin_pref2_rotation[j] = sqrt(2.0*temperature*langevin_gamma_rotation[j]/time_step);
#else
#error No Noise defined
#endif
#endif // ROTATIONAL_INERTIA
  THERMO_TRACE(fprintf(stderr,"%d: thermo_init_langevin: langevin_gamma_rotation=%f, langevin_pref2_rotation=%f",this_node, langevin_gamma_rotation,langevin_pref2_rotation));
#endif
  THERMO_TRACE(fprintf(stderr,"%d: thermo_init_langevin: langevin_pref1=%f, langevin_pref2=%f",this_node,langevin_pref1,langevin_pref2));  
}
Exemplo n.º 4
0
int tclcommand_ghmc(ClientData data, Tcl_Interp *interp, int argc, char **argv) 
{
#ifdef GHMC
  int status = TCL_OK;

  THERMO_TRACE(fprintf(stderr,"%d: ghmc:\n",this_node));
  Tcl_ResetResult(interp);

  /* print ghmc status */
  if(argc == 1) {
    status = tclcommand_ghmc_print_status(interp) ;
  }
  else if (ARG1_IS_S("statistics")) {
    status = tclcommand_ghmc_print_statistics(interp);
  }  
  else {
    Tcl_AppendResult(interp, "Unknown keyword: \n", (char *)NULL);
    status = tclcommand_ghmc_print_usage(interp);
  }

  return status;

#else

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

#endif
}
Exemplo n.º 5
0
/** set the particle torques to the friction term, i.e. \f$\tau_i=-\gamma w_i + \xi_i\f$.
    The same friction coefficient \f$\gamma\f$ is used as that for translation.
*/
inline void friction_thermo_langevin_rotation(Particle *p)
{
    extern double langevin_pref2_rotation;

    int j;
    double switch_rotate = 1.0;
    if ( langevin_rotate == false )
    {
        switch_rotate = 0.0;
    }




    // Rotational degrees of virtual sites are thermostatted,
    // so no switching here


    // Here the thermostats happens
    for ( j = 0 ; j < 3 ; j++)
    {
#ifdef ROTATIONAL_INERTIA
        p->f.torque[j] = -langevin_gamma_rotation*p->m.omega[j] + switch_rotate*langevin_pref2_rotation*noise;
#else
        p->f.torque[j] = -langevin_gamma_rotation*p->m.omega[j] + switch_rotate*langevin_pref2_rotation*noise;
#endif
    }

    ONEPART_TRACE(if(p->p.identity==check_id) fprintf(stderr,"%d: OPT: LANG f = (%.3e,%.3e,%.3e)\n",this_node,p->f.f[0],p->f.f[1],p->f.f[2]));
    THERMO_TRACE(fprintf(stderr,"%d: Thermo: P %d: force=(%.3e,%.3e,%.3e)\n",this_node,p->p.identity,p->f.f[0],p->f.f[1],p->f.f[2]));
}
Exemplo n.º 6
0
int tclcommand_thermostat(ClientData data, Tcl_Interp *interp, int argc, char **argv) 
{
  int err = TCL_OK;
  THERMO_TRACE(fprintf(stderr,"%d: thermostat:\n",this_node));

  /* print thermostat status */
  if(argc == 1) return tclcommand_thermostat_print_all(interp);
  
  if ( ARG1_IS_S("set") )          {
    argc--;
    argv++;

    if (argc == 1) {
      Tcl_AppendResult(interp, "wrong # args: \n", (char *)NULL);
      return tclcommand_thermostat_print_usage(interp, argc, argv);
    }
  }
  if ( ARG1_IS_S("off") )
    err = tclcommand_thermostat_parse_off(interp, argc, argv);
  else if ( ARG1_IS_S("langevin"))
    err = tclcommand_thermostat_parse_langevin(interp, argc, argv);
#ifdef DPD
  else if ( ARG1_IS_S("dpd") )
    err = tclcommand_thermostat_parse_dpd(interp, argc, argv);
#endif
#ifdef INTER_DPD
  else if ( ARG1_IS_S("inter_dpd") )
    err = tclcommand_thermostat_parse_inter_dpd(interp, argc, argv);
#endif
#ifdef NPT
  else if ( ARG1_IS_S("npt_isotropic") )
    err = tclcommand_thermostat_parse_npt_isotropic(interp, argc, argv);
#endif
#if defined(LB) || defined(LB_GPU)
  else if ( ARG1_IS_S("lb"))
    err = tclcommand_thermostat_parse_lb(interp, argc-1, argv+1);
#endif
#ifdef GHMC
  else if ( ARG1_IS_S("ghmc") )
    err = tclcommand_thermostat_parse_ghmc(interp, argc, argv);
#endif
  else if ( ARG1_IS_S("cpu"))
    err = tclcommand_thermostat_parse_cpu(interp, argc, argv);
#if defined(SD) || defined(BD)
#ifdef SD
  else if ( ARG1_IS_S("sd") )
    err = tclcommand_thermostat_parse_sd(interp, argc, argv);
#endif // SD
  else if ( ARG1_IS_S("bd") )
    err = tclcommand_thermostat_parse_bd(interp, argc, argv);
#endif //SD || BD
  else {
    Tcl_AppendResult(interp, "Unknown thermostat ", argv[1], "\n", (char *)NULL);
    return tclcommand_thermostat_print_usage(interp, argc, argv);
  }
  return gather_runtime_errors(interp, err);
}
Exemplo n.º 7
0
void thermo_init_ghmc()
{
		ghmc_att=0;
		ghmc_acc=0;
    
		cosp = ghmc_phi;
    sinp = sin(acos(ghmc_phi));
		
		ghmcdata.hmlt_old=0;
		ghmcdata.hmlt_new=0;
		beta=1.0/temperature;
		
    THERMO_TRACE(fprintf(stderr,"%d: thermo_init_ghmc: ghmc_csp=%f, ghmc_snp=%f \n",this_node,cosp,sinp));
}
Exemplo n.º 8
0
void thermo_init_langevin() 
{
  langevin_pref1 = -langevin_gamma/time_step;
#if defined (FLATNOISE)
  langevin_pref2 = sqrt(24.0*temperature*langevin_gamma/time_step);
#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM)
  langevin_pref2 = sqrt(2.0*temperature*langevin_gamma/time_step);
#else
#error No Noise defined
#endif
#ifdef MULTI_TIMESTEP
  if (smaller_time_step > 0.) {
    langevin_pref1_small = -langevin_gamma/smaller_time_step;
 #ifndef LANGEVIN_PER_PARTICLE
    langevin_pref2_small = sqrt(24.0*temperature*langevin_gamma/smaller_time_step);
 #endif
  } else {
    langevin_pref1_small = -langevin_gamma/time_step;
 #ifndef LANGEVIN_PER_PARTICLE
    langevin_pref2_small = sqrt(24.0*temperature*langevin_gamma/time_step);
 #endif
  }
#endif
  
#ifdef ROTATION 
  langevin_gamma_rotation = langevin_gamma/3;
#if defined (FLATNOISE)
  langevin_pref2_rotation = sqrt(24.0*temperature*langevin_gamma_rotation/time_step);
#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM)
  langevin_pref2_rotation = sqrt(2.0*temperature*langevin_gamma_rotation/time_step);
#else
#error No Noise defined
#endif
  THERMO_TRACE(fprintf(stderr,"%d: thermo_init_langevin: langevin_gamma_rotation=%f, langevin_pref2_rotation=%f",this_node, langevin_gamma_rotation,langevin_pref2_rotation));
#endif
  THERMO_TRACE(fprintf(stderr,"%d: thermo_init_langevin: langevin_pref1=%f, langevin_pref2=%f",this_node,langevin_pref1,langevin_pref2));  
}
Exemplo n.º 9
0
/** overwrite the forces of a particle with
    the friction term, i.e. \f$ F_i= -\gamma v_i + \xi_i\f$.
*/
inline void friction_thermo_langevin(Particle *p)
{
    extern double langevin_pref1, langevin_pref2;

    double langevin_pref1_temp, langevin_pref2_temp;

#ifdef MULTI_TIMESTEP
    extern double langevin_pref1_small;
#ifndef LANGEVIN_PER_PARTICLE
    extern double langevin_pref2_small;
#endif /* LANGEVIN_PER_PARTICLE */
#endif /* MULTI_TIMESTEP */

    int j;
    double switch_trans = 1.0;
    if ( langevin_trans == false )
    {
        switch_trans = 0.0;
    }

    // Virtual sites related decision making
#ifdef VIRTUAL_SITES
#ifndef VIRTUAL_SITES_THERMOSTAT
    // In this case, virtual sites are NOT thermostated
    if (ifParticleIsVirtual(p))
    {
        for (j=0; j<3; j++)
            p->f.f[j]=0;

        return;
    }
#endif /* VIRTUAL_SITES_THERMOSTAT */
#ifdef THERMOSTAT_IGNORE_NON_VIRTUAL
    // In this case NON-virtual particles are NOT thermostated
    if (!ifParticleIsVirtual(p))
    {
        for (j=0; j<3; j++)
            p->f.f[j]=0;

        return;
    }
#endif /* THERMOSTAT_IGNORE_NON_VIRTUAL */
#endif /* VIRTUAL_SITES */

    // Get velocity effective in the thermostatting
    double velocity[3];
    for (int i = 0; i < 3; i++) {
        // Particle velocity
        velocity[i] = p->m.v[i];
#ifdef ENGINE
        // In case of the engine feature, the velocity is relaxed
        // towards a swimming velocity oriented parallel to the
        // particles director
        velocity[i] -= (p->swim.v_swim*time_step)*p->r.quatu[i];
#endif

        // Local effective velocity for leeds-edwards boundary conditions
        velocity[i]=le_frameV(i,velocity,p->r.p);
    } // for

    // Determine prefactors for the friction and the noise term

    // first, set defaults
    langevin_pref1_temp = langevin_pref1;
    langevin_pref2_temp = langevin_pref2;

    // Override defaults if per-particle values for T and gamma are given
#ifdef LANGEVIN_PER_PARTICLE
    // If a particle-specific gamma is given
    if(p->p.gamma >= 0.)
    {
        langevin_pref1_temp = -p->p.gamma/time_step;
        // Is a particle-specific temperature also specified?
        if(p->p.T >= 0.)
            langevin_pref2_temp = sqrt(24.0*p->p.T*p->p.gamma/time_step);
        else
            // Default temperature but particle-specific gamma
            langevin_pref2_temp = sqrt(24.0*temperature*p->p.gamma/time_step);

    } // particle specific gamma
    else
    {
        langevin_pref1_temp = -langevin_gamma/time_step;
        // No particle-specific gamma, but is there particle-specific temperature
        if(p->p.T >= 0.)
            langevin_pref2_temp = sqrt(24.0*p->p.T*langevin_gamma/time_step);
        else
            // Defaut values for both
            langevin_pref2_temp = langevin_pref2;
    }
#endif /* LANGEVIN_PER_PARTICLE */

    // Multi-timestep handling
    // This has to be last, as it may set the prefactors to 0.
#ifdef MULTI_TIMESTEP
    if (smaller_time_step > 0.) {
        langevin_pref1_temp *= time_step/smaller_time_step;
        if (p->p.smaller_timestep==1 && current_time_step_is_small==1)
            langevin_pref2_temp *= sqrt(time_step/smaller_time_step);
        else if (p->p.smaller_timestep != current_time_step_is_small) {
            langevin_pref1_temp  = 0.;
            langevin_pref2_temp  = 0.;
        }
    }
#endif /* MULTI_TIMESTEP */


    // Do the actual thermostatting
    for ( j = 0 ; j < 3 ; j++)
    {
#ifdef EXTERNAL_FORCES
        // If individual coordinates are fixed, set force to 0.
        if ((p->p.ext_flag & COORD_FIXED(j)))
            p->f.f[j] = 0;
        else
#endif
        {
            // Apply the force
            p->f.f[j] = langevin_pref1_temp*velocity[j] + switch_trans*langevin_pref2_temp*noise;
        }
    } // END LOOP OVER ALL COMPONENTS


    // printf("%d: %e %e %e %e %e %e\n",p->p.identity, p->f.f[0],p->f.f[1],p->f.f[2], p->m.v[0],p->m.v[1],p->m.v[2]);
    ONEPART_TRACE(if(p->p.identity==check_id) fprintf(stderr,"%d: OPT: LANG f = (%.3e,%.3e,%.3e)\n",this_node,p->f.f[0],p->f.f[1],p->f.f[2]));
    THERMO_TRACE(fprintf(stderr,"%d: Thermo: P %d: force=(%.3e,%.3e,%.3e)\n",this_node,p->p.identity,p->f.f[0],p->f.f[1],p->f.f[2]));
}