Exemplo n.º 1
0
void energy_calc(double *result)
{
  if (!check_obs_calc_initialized())
    return;

  init_energies(&energy);

  on_observable_calc();
  
  switch (cell_structure.type) {
  case CELL_STRUCTURE_LAYERED:
    layered_calculate_energies();
    break;
  case CELL_STRUCTURE_DOMDEC: 
    if(dd.use_vList) {
      if (rebuild_verletlist)  
	build_verlet_lists();
      calculate_verlet_energies();
    }
    else
      calculate_link_cell_energies();
    break;
  case CELL_STRUCTURE_NSQUARE:
    nsq_calculate_energies();
  }
  /* rescale kinetic energy */
  energy.data.e[0] /= (2.0*time_step*time_step);

  calc_long_range_energies();
  
  /* gather data */
  MPI_Reduce(energy.data.e, result, energy.data.n, MPI_DOUBLE, MPI_SUM, 0, comm_cart);
}
Exemplo n.º 2
0
void on_integration_start()
{
    char *errtext;

    EVENT_TRACE(fprintf(stderr, "%d: on_integration_start\n", this_node));
    INTEG_TRACE(fprintf(stderr,"%d: on_integration_start: reinit_thermo = %d, resort_particles=%d\n",
                        this_node,reinit_thermo,resort_particles));

    /********************************************/
    /* sanity checks                            */
    /********************************************/

    if ( time_step < 0.0 ) {
        errtext = runtime_error(128);
        ERROR_SPRINTF(errtext, "{010 time_step not set} ");
    }
    if ( skin < 0.0 ) {
        errtext = runtime_error(128);
        ERROR_SPRINTF(errtext,"{011 skin not set} ");
    }
    if ( temperature < 0.0 ) {
        errtext = runtime_error(128);
        ERROR_SPRINTF(errtext,"{012 thermostat not initialized} ");
    }

#ifdef NPT
    if (integ_switch == INTEG_METHOD_NPT_ISO) {
        if (nptiso.piston <= 0.0) {
            char *errtext = runtime_error(128);
            ERROR_SPRINTF(errtext,"{014 npt on, but piston mass not set} ");
        }

#ifdef ELECTROSTATICS

        switch(coulomb.method) {
        case COULOMB_NONE:
            break;
#ifdef P3M
        case COULOMB_P3M:
            break;
#endif /*P3M*/
        default: {
            char *errtext = runtime_error(128);
            ERROR_SPRINTF(errtext,"{014 npt only works with P3M} ");
        }
        }
#endif /*ELECTROSTATICS*/

#ifdef DIPOLES

        switch (coulomb.Dmethod) {
        case DIPOLAR_NONE:
            break;
#ifdef DP3M
        case DIPOLAR_P3M:
            break;
#endif
        default: {
            char *errtext = runtime_error(128);
            ERROR_SPRINTF(errtext,"NpT does not work with your dipolar method, please use P3M.");
        }
        }
#endif  /* ifdef DIPOLES */
    }
#endif /*NPT*/

    if (!check_obs_calc_initialized()) return;

#ifdef LB
    if(lattice_switch & LATTICE_LB) {
        if (lbpar.agrid <= 0.0) {
            errtext = runtime_error(128);
            ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
        }
        if (lbpar.tau <= 0.0) {
            errtext = runtime_error(128);
            ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
        }
        if (lbpar.rho <= 0.0) {
            errtext = runtime_error(128);
            ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
        }
        if (lbpar.viscosity <= 0.0) {
            errtext = runtime_error(128);
            ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
        }
        if (dd.use_vList && skin>=lbpar.agrid/2.0) {
            errtext = runtime_error(128);
            ERROR_SPRINTF(errtext, "{104 LB requires either no Verlet lists or that the skin of the verlet list to be less than half of lattice-Boltzmann grid spacing.} ");
        }
    }
#endif
#ifdef LB_GPU
    if(this_node == 0) {
        if(lattice_switch & LATTICE_LB_GPU) {
            if (lbpar_gpu.agrid < 0.0) {
                errtext = runtime_error(128);
                ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
            }
            if (lbpar_gpu.tau < 0.0) {
                errtext = runtime_error(128);
                ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
            }
            if (lbpar_gpu.rho < 0.0) {
                errtext = runtime_error(128);
                ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
            }
            if (lbpar_gpu.viscosity < 0.0) {
                errtext = runtime_error(128);
                ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
            }
            if (lb_reinit_particles_gpu) {
                lb_realloc_particles_gpu();
                lb_reinit_particles_gpu = 0;
            }
        }
    }

#endif

#ifdef METADYNAMICS
    meta_init();
#endif

#ifdef REACTIONS
    if(reaction.rate != 0.0) {
        if(max_cut < reaction.range) {
            errtext = runtime_error(128);
            ERROR_SPRINTF(errtext,"{105 Reaction range of %f exceeds maximum cutoff of %f} ", reaction.range, max_cut);
        }
    }
#endif

    /********************************************/
    /* end sanity checks                        */
    /********************************************/


    /* Prepare the thermostat */
    if (reinit_thermo) {
        thermo_init();
        reinit_thermo = 0;
        recalc_forces = 1;
    }

    /* Ensemble preparation: NVT or NPT */
    integrate_ensemble_init();

#ifdef SCAFACOS
    /* initialize Scafacos, set up the system and solver specific parameters, all on
    each node. functions include MPI_Bcast */

    mpi_bcast_coulomb_method();

    switch(coulomb.method) {
    case COULOMB_SCAFACOS_DIRECT:
    case COULOMB_SCAFACOS_EWALD:
    case COULOMB_SCAFACOS_FMM:
    case COULOMB_SCAFACOS_MEMD:
    case COULOMB_SCAFACOS_MMM1D:
    case COULOMB_SCAFACOS_MMM2D:
    case COULOMB_SCAFACOS_P2NFFT:
    case COULOMB_SCAFACOS_P3M:
    case COULOMB_SCAFACOS_PEPC:
    case COULOMB_SCAFACOS_PP3MG:
    case COULOMB_SCAFACOS_VMG: {
        mpi_scafacos_bcast_common_params();
        mpi_scafacos_bcast_solver_specific();
        mpi_scafacos_init();
        mpi_scafacos_common_set();
        mpi_scafacos_solver_specific_set();
        break;
    }
    default:
        break;
    }
    /* tune in order to generate at least defaults for cutoff, transfer the cutoff back
    to Espresso and generate new cell system on each node*/
    switch(coulomb.method) {
    case COULOMB_SCAFACOS_P2NFFT:
        if( scafacos.short_range_flag == 0 ) {
            scafacos_tune();
            recalc_maximal_cutoff();
            cells_on_geometry_change(0);
        }
        break;
    case COULOMB_SCAFACOS_P3M:
        if( scafacos.short_range_flag == 0 ) {
            scafacos_tune();
            recalc_maximal_cutoff();
            cells_on_geometry_change(0);
        }
    default:
        break;
    }
#endif
    /* Update particle and observable information for routines in statistics.c */
    invalidate_obs();
    freePartCfg();

    on_observable_calc();
}
Exemplo n.º 3
0
void pressure_calc(double *result, double *result_t, double *result_nb, double *result_t_nb, int v_comp)
{
  int n, i;
  double volume = box_l[0]*box_l[1]*box_l[2];

  if (!check_obs_calc_initialized())
    return;

  init_virials(&virials);

  init_p_tensor(&p_tensor);
  
  init_virials_non_bonded(&virials_non_bonded);

  init_p_tensor_non_bonded(&p_tensor_non_bonded);

  on_observable_calc();

  switch (cell_structure.type) {
  case CELL_STRUCTURE_LAYERED:
    layered_calculate_virials(v_comp);
    break;
  case CELL_STRUCTURE_DOMDEC:
    if(dd.use_vList) {
      if (rebuild_verletlist)  
	build_verlet_lists();
      calculate_verlet_virials(v_comp);
    }
    else
      calculate_link_cell_virials(v_comp);
    break;
  case CELL_STRUCTURE_NSQUARE:
    nsq_calculate_virials(v_comp);
  }
  /* rescale kinetic energy (=ideal contribution) */
#ifdef ROTATION_PER_PARTICLE
    fprintf(stderr, "Switching rotation per particle (#define ROTATION_PER_PARTICLE) and pressure calculation are incompatible.\n");
#endif
  
  virials.data.e[0] /= (3.0*volume*time_step*time_step);

  calc_long_range_virials();

  for (n = 1; n < virials.data.n; n++)
    virials.data.e[n] /= 3.0*volume;

    
 /* stress tensor part */
 /* The ROTATION option does not effect stress tensor calculations
    since rotational energy is not included in the ideal term (unlike
    for the pressure) */
  for(i=0; i<9; i++)
    p_tensor.data.e[i] /= (volume*time_step*time_step);
  
  for(i=9; i<p_tensor.data.n; i++)
    p_tensor.data.e[i]  /= volume;
  
  /* Intra- and Inter- part of nonbonded interaction */
  for (n = 0; n < virials_non_bonded.data_nb.n; n++)
    virials_non_bonded.data_nb.e[n] /= 3.0*volume;
  
  for(i=0; i<p_tensor_non_bonded.data_nb.n; i++)
    p_tensor_non_bonded.data_nb.e[i]  /= volume;
  
  /* gather data */
  MPI_Reduce(virials.data.e, result, virials.data.n, MPI_DOUBLE, MPI_SUM, 0, comm_cart);
  MPI_Reduce(p_tensor.data.e, result_t, p_tensor.data.n, MPI_DOUBLE, MPI_SUM, 0, comm_cart);
  
  MPI_Reduce(virials_non_bonded.data_nb.e, result_nb, virials_non_bonded.data_nb.n, MPI_DOUBLE, MPI_SUM, 0, comm_cart);
  MPI_Reduce(p_tensor_non_bonded.data_nb.e, result_t_nb, p_tensor_non_bonded.data_nb.n, MPI_DOUBLE, MPI_SUM, 0, comm_cart); 
}
Exemplo n.º 4
0
void on_integration_start()
{
  char *errtext;

  EVENT_TRACE(fprintf(stderr, "%d: on_integration_start\n", this_node));
  INTEG_TRACE(fprintf(stderr,"%d: on_integration_start: reinit_thermo = %d, resort_particles=%d\n",
		      this_node,reinit_thermo,resort_particles));

  /********************************************/
  /* sanity checks                            */
  /********************************************/

  if ( time_step < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext, "{010 time_step not set} ");
  }
  if ( skin < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{011 skin not set} ");
  }
  if ( temperature < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{012 thermostat not initialized} ");
  }
  
#ifdef NPT
  if (integ_switch == INTEG_METHOD_NPT_ISO) {
    if (nptiso.piston <= 0.0) {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{014 npt on, but piston mass not set} ");
    }
  
#ifdef ELECTROSTATICS

    switch(coulomb.method) {
    case COULOMB_NONE:  break;
#ifdef P3M
    case COULOMB_P3M:   break;
#endif /*P3M*/
    default: {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{014 npt only works with P3M} ");
    }
    }
#endif /*ELECTROSTATICS*/

#ifdef DIPOLES

    switch (coulomb.Dmethod) {
    case DIPOLAR_NONE: break;
#ifdef DP3M
    case DIPOLAR_P3M: break;
#endif
    default: {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"NpT does not work with your dipolar method, please use P3M.");
    }
    }
#endif  /* ifdef DIPOLES */
  }
#endif /*NPT*/

  if (!check_obs_calc_initialized()) return;

#ifdef LB
  if(lattice_switch & LATTICE_LB) {
    if (lbpar.agrid <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
    }
    if (lbpar.tau <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
    }
    if (lbpar.rho <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
    }
    if (lbpar.viscosity <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
    }
    if (dd.use_vList && skin>=lbpar.agrid/2.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext, "{104 LB requires either no Verlet lists or that the skin of the verlet list to be less than half of lattice-Boltzmann grid spacing.} ");
    }
  }
#endif
#ifdef LB_GPU
if(this_node == 0){
  if(lattice_switch & LATTICE_LB_GPU) {
    if (lbpar_gpu.agrid < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
    }
    if (lbpar_gpu.tau < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
    }
    if (lbpar_gpu.rho < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
    }
    if (lbpar_gpu.viscosity < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
    }
    if (lb_reinit_particles_gpu) {
	lb_realloc_particles_gpu();
	lb_reinit_particles_gpu = 0;
    }
  }
}

#endif

#ifdef METADYNAMICS
  meta_init();
#endif

#ifdef CATALYTIC_REACTIONS
if(reaction.ct_rate != 0.0) {

   if( dd.use_vList == 0 || cell_structure.type != CELL_STRUCTURE_DOMDEC) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{105 The CATALYTIC_REACTIONS feature requires verlet lists and domain decomposition} ");
      check_runtime_errors();
    }

  if(max_cut < reaction.range) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{106 Reaction range of %f exceeds maximum cutoff of %f} ", reaction.range, max_cut);
  }
}
#endif

  /********************************************/
  /* end sanity checks                        */
  /********************************************/


  /* Prepare the thermostat */
  if (reinit_thermo) {
    thermo_init();
    reinit_thermo = 0;
    recalc_forces = 1;
  }

  /* Ensemble preparation: NVT or NPT */
  integrate_ensemble_init();

  /* Update particle and observable information for routines in statistics.c */
  invalidate_obs();
  freePartCfg();

  on_observable_calc();
}
Exemplo n.º 5
0
void on_integration_start()
{
  char *errtext;
  int i;

  EVENT_TRACE(fprintf(stderr, "%d: on_integration_start\n", this_node));
  INTEG_TRACE(fprintf(stderr,"%d: on_integration_start: reinit_thermo = %d, resort_particles=%d\n",
		      this_node,reinit_thermo,resort_particles));

  /********************************************/
  /* sanity checks                            */
  /********************************************/

  if ( time_step < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext, "{010 time_step not set} ");
  }
  if ( skin < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{011 skin not set} ");
  }
  if ( temperature < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{012 thermostat not initialized} ");
  }

  for (i = 0; i < 3; i++)
    if (local_box_l[i] < max_range) {
      errtext = runtime_error(128 + TCL_INTEGER_SPACE);
      ERROR_SPRINTF(errtext,"{013 box_l in direction %d is still too small} ", i);
    }
  
#ifdef NPT
  if (integ_switch == INTEG_METHOD_NPT_ISO) {
    if (nptiso.piston <= 0.0) {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{014 npt on, but piston mass not set} ");
    }
    if(cell_structure.type!=CELL_STRUCTURE_DOMDEC) {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{014 npt requires domain decomposition cellsystem} ");
    }
  
#ifdef ELECTROSTATICS

    switch(coulomb.method) {
      case COULOMB_NONE:  break;
#ifdef ELP3M
      case COULOMB_P3M:   break;
#endif /*ELP3M*/
      case COULOMB_EWALD: break;
      default: {
        char *errtext = runtime_error(128);
        ERROR_SPRINTF(errtext,"{014 npt only works with Ewald sum or P3M} ");
      }
    }
#endif /*ELECTROSTATICS*/
  }
  
#endif /*NPT*/

  if (!check_obs_calc_initialized()) return;

#ifdef LB
  if(lattice_switch & LATTICE_LB) {
    if (lbpar.agrid <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
    }
    if (lbpar.tau <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
    }
    if (lbpar.rho <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
    }
    if (lbpar.viscosity <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
    }
  }
#endif
#ifdef LB_GPU
if(this_node == 0){
  if(lattice_switch & LATTICE_LB_GPU) {
    if (lbpar_gpu.agrid < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
    }
    if (lbpar_gpu.tau < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
    }
    if (lbpar_gpu.rho < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
    }
    if (lbpar_gpu.viscosity < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
    }
    if (lb_reinit_particles_gpu) {
	lb_realloc_particles_gpu();
	lb_reinit_particles_gpu = 0;
    }
  }
}

#endif

#ifdef METADYNAMICS
  meta_init();
#endif

  /********************************************/
  /* end sanity checks                        */
  /********************************************/


  /* Prepare the thermostat */
  if (reinit_thermo) {
    thermo_init();
    reinit_thermo = 0;
    recalc_forces = 1;
  }

  /* Ensemble preparation: NVT or NPT */
  integrate_ensemble_init();

  /* Update particle and observable information for routines in statistics.c */
  invalidate_obs();
  freePartCfg();

  on_observable_calc();
}