Пример #1
0
void on_short_range_ia_change()
{
    EVENT_TRACE(fprintf(stderr, "%d: on_short_range_ia_changes\n", this_node));
    invalidate_obs();

    recalc_maximal_cutoff();
    cells_on_geometry_change(0);

    recalc_forces = 1;
}
Пример #2
0
void on_parameter_change(int field)
{
    EVENT_TRACE(fprintf(stderr, "%d: on_parameter_change %s\n", this_node, fields[field].name));

    switch (field) {
    case FIELD_BOXL:
        grid_changed_box_l();
        /* Electrostatics cutoffs mostly depend on the system size,
           therefore recalculate them. */
        recalc_maximal_cutoff();
        cells_on_geometry_change(0);
        break;
    case FIELD_MIN_GLOBAL_CUT:
        recalc_maximal_cutoff();
        cells_on_geometry_change(0);
        break;
    case FIELD_SKIN:
        cells_on_geometry_change(0);
    case FIELD_PERIODIC:
        cells_on_geometry_change(CELL_FLAG_GRIDCHANGED);
        break;
    case FIELD_NODEGRID:
        grid_changed_n_nodes();
        cells_on_geometry_change(CELL_FLAG_GRIDCHANGED);
        break;
    case FIELD_MINNUMCELLS:
    case FIELD_MAXNUMCELLS:
        cells_re_init(CELL_STRUCTURE_CURRENT);
    case FIELD_TEMPERATURE:
        on_temperature_change();
        reinit_thermo = 1;
        break;
    case FIELD_TIMESTEP:
#ifdef LB_GPU
        if(this_node == 0) {
            if (lattice_switch & LATTICE_LB_GPU) {
                lb_reinit_parameters_gpu();
            }
        }
#endif
#ifdef LB
        if (lattice_switch & LATTICE_LB) {
            lb_reinit_parameters();
        }
#endif
    case FIELD_LANGEVIN_GAMMA:
    case FIELD_DPD_TGAMMA:
    case FIELD_DPD_GAMMA:
    case FIELD_NPTISO_G0:
    case FIELD_NPTISO_GV:
    case FIELD_NPTISO_PISTON:
        reinit_thermo = 1;
        break;
#ifdef NPT
    case FIELD_INTEG_SWITCH:
        if (integ_switch != INTEG_METHOD_NPT_ISO)
            nptiso.invalidate_p_vel = 1;
        break;
#endif
    case FIELD_THERMO_SWITCH:
        /* DPD needs ghost velocities, other thermostats not */
        on_ghost_flags_change();
        break;
#ifdef LB
    case FIELD_LATTICE_SWITCH:
        /* LB needs ghost velocities */
        on_ghost_flags_change();
        break;
#endif
    }
}
Пример #3
0
void init_node_grid()
{
  grid_changed_n_nodes();
  cells_on_geometry_change(CELL_FLAG_GRIDCHANGED);
}
Пример #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 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();
}
Пример #5
0
void propagate_press_box_pos_and_rescale_npt()
{
#ifdef NPT
  if(integ_switch == INTEG_METHOD_NPT_ISO) {
    Cell *cell;
    Particle *p;
    int i, j, np, c;
    double scal[3]={0.,0.,0.}, L_new=0.0;

    /* finalize derivation of p_inst */
    finalize_p_inst_npt();

    /* adjust \ref nptiso_struct::nptiso.volume; prepare pos- and vel-rescaling */
    if (this_node == 0) {
      nptiso.volume += nptiso.inv_piston*nptiso.p_diff*0.5*time_step;
      scal[2] = SQR(box_l[nptiso.non_const_dim])/pow(nptiso.volume,2.0/nptiso.dimension);
      nptiso.volume += nptiso.inv_piston*nptiso.p_diff*0.5*time_step;
      if (nptiso.volume < 0.0) {
	char *errtxt = runtime_error(128 + 3*ES_DOUBLE_SPACE);
        ERROR_SPRINTF(errtxt, "{015 your choice of piston=%g, dt=%g, p_diff=%g just caused the volume to become negative, decrease dt} ",
                nptiso.piston,time_step,nptiso.p_diff);
	nptiso.volume = box_l[0]*box_l[1]*box_l[2];
	scal[2] = 1;
      }

      L_new = pow(nptiso.volume,1.0/nptiso.dimension);
      //      printf(stdout,"Lnew, %f: volume, %f: dim, %f: press, %f \n", L_new, nptiso.volume, nptiso.dimension,nptiso.p_inst );
      //    fflush(stdout);

      scal[1] = L_new/box_l[nptiso.non_const_dim];
      scal[0] = 1/scal[1];
    }
    MPI_Bcast(scal,  3, MPI_DOUBLE, 0, comm_cart);

    /* propagate positions while rescaling positions and velocities */
    for (c = 0; c < local_cells.n; c++) {
      cell = local_cells.cell[c]; p  = cell->part; np = cell->n;
      for(i = 0; i < np; i++) {	
#ifdef VIRTUAL_SITES
	if (ifParticleIsVirtual(&p[i])) continue;
#endif
	for(j=0; j < 3; j++){
#ifdef EXTERNAL_FORCES
	  if (!(p[i].l.ext_flag & COORD_FIXED(j))) {
#endif	    
	    if(nptiso.geometry & nptiso.nptgeom_dir[j]) {
	      p[i].r.p[j]      = scal[1]*(p[i].r.p[j] + scal[2]*p[i].m.v[j]);
	      p[i].l.p_old[j] *= scal[1];
	      p[i].m.v[j]     *= scal[0];
	    } else {
	      p[i].r.p[j] += p[i].m.v[j];
	    }

#ifdef EXTERNAL_FORCES
	  }
#endif
	}
	ONEPART_TRACE(if(p[i].p.identity==check_id) fprintf(stderr,"%d: OPT:PV_1 v_new=(%.3e,%.3e,%.3e)\n",this_node,p[i].m.v[0],p[i].m.v[1],p[i].m.v[2]));
	ONEPART_TRACE(if(p[i].p.identity==check_id) fprintf(stderr,"%d: OPT:PPOS p=(%.3f,%.3f,%.3f)\n",this_node,p[i].r.p[0],p[i].r.p[1],p[i].r.p[2])); 
#ifdef ADDITIONAL_CHECKS
	force_and_velocity_check(&p[i]); 
#endif
      }
    }

    resort_particles = 1; 

    /* Apply new volume to the box-length, communicate it, and account for necessary adjustments to the cell geometry */
    if (this_node == 0) {
      for ( i = 0 ; i < 3 ; i++ ){ 
	if ( nptiso.geometry & nptiso.nptgeom_dir[i] ) {
	  box_l[i] = L_new;
	} else if ( nptiso.cubic_box ) {
	  box_l[i] = L_new;
	}
      }
    }
    MPI_Bcast(box_l, 3, MPI_DOUBLE, 0, comm_cart);

    /* fast box length update */
    grid_changed_box_l();
    recalc_maximal_cutoff();
    cells_on_geometry_change(CELL_FLAG_FAST);
  }