Esempio n. 1
0
void calc_long_range_forces()
{
#ifdef ELECTROSTATICS  
  /* calculate k-space part of electrostatic interaction. */
  switch (coulomb.method) {
#ifdef P3M
  case COULOMB_ELC_P3M:
    if (elc_params.dielectric_contrast_on) {
      ELC_P3M_modify_p3m_sums_both();
      ELC_p3m_charge_assign_both();
      ELC_P3M_self_forces();
    }
    else
      p3m_charge_assign();

    p3m_calc_kspace_forces(1,0);

    if (elc_params.dielectric_contrast_on)
      ELC_P3M_restore_p3m_sums();
 
    ELC_add_force(); 

    break;
  case COULOMB_P3M:
    p3m_charge_assign();
#ifdef NPT
    if(integ_switch == INTEG_METHOD_NPT_ISO)
      nptiso.p_vir[0] += p3m_calc_kspace_forces(1,1);
    else
#endif
      p3m_calc_kspace_forces(1,0);
    break;
#endif
  case COULOMB_EWALD:
#ifdef NPT
    if(integ_switch == INTEG_METHOD_NPT_ISO)
      nptiso.p_vir[0] += EWALD_calc_kspace_forces(1,1);
    else
#endif
      EWALD_calc_kspace_forces(1,0);
    break;
  case COULOMB_MAGGS:
    maggs_calc_forces();
    break;
  case COULOMB_MMM2D:
    MMM2D_add_far_force();
    MMM2D_dielectric_layers_force_contribution();
  }
#endif  /*ifdef ELECTROSTATICS */

#ifdef DIPOLES  
  /* calculate k-space part of the magnetostatic interaction. */
  switch (coulomb.Dmethod) {
#ifdef DP3M
  case DIPOLAR_MDLC_P3M:
     add_mdlc_force_corrections();
    //fall through 
  case DIPOLAR_P3M:
    dp3m_dipole_assign();
#ifdef NPT
    if(integ_switch == INTEG_METHOD_NPT_ISO) {
      nptiso.p_vir[0] += dp3m_calc_kspace_forces(1,1);
      fprintf(stderr,"dipolar_P3M at this moment is added to p_vir[0]\n");    
    } else
#endif
      dp3m_calc_kspace_forces(1,0);

      break;
#endif
  case DIPOLAR_ALL_WITH_ALL_AND_NO_REPLICA: 
      dawaanr_calculations(1,0);
      break;
  case DIPOLAR_MDLC_DS:
     add_mdlc_force_corrections();
    //fall through 
  case DIPOLAR_DS: 
        magnetic_dipolar_direct_sum_calculations(1,0);
      break;

  }
#endif  /*ifdef DIPOLES */
}
Esempio n. 2
0
void calc_long_range_forces()
{
#ifdef ELECTROSTATICS  
	/* calculate k-space part of electrostatic interaction. */
  switch (coulomb.method) {
#ifdef P3M
  case COULOMB_ELC_P3M:
    if (elc_params.dielectric_contrast_on) {
      ELC_P3M_modify_p3m_sums_both();
      ELC_p3m_charge_assign_both();
      ELC_P3M_self_forces();
    }
    else
      p3m_charge_assign();
    
    p3m_calc_kspace_forces(1,0);
    
    if (elc_params.dielectric_contrast_on)
      ELC_P3M_restore_p3m_sums();
    
    ELC_add_force();
    
    break;
#endif
#ifdef CUDA
  case COULOMB_P3M_GPU:
    if (this_node == 0) {
      FORCE_TRACE(printf("Computing GPU P3M forces.\n"));
      p3m_gpu_add_farfield_force();
    }
    /* there is no NPT handling here as long as we cannot compute energies.
       This is checked in integrator_npt_sanity_checks() when integration starts. */
    break;
#endif
#ifdef P3M
  case COULOMB_P3M:
    FORCE_TRACE(printf("%d: Computing P3M forces.\n", this_node));
    p3m_charge_assign();
#ifdef NPT
    if (integ_switch == INTEG_METHOD_NPT_ISO)
      nptiso.p_vir[0] += p3m_calc_kspace_forces(1,1);
    else
#endif
      p3m_calc_kspace_forces(1, 0);
    break;
#endif
  case COULOMB_MAGGS:
    maggs_calc_forces();
    break;
  case COULOMB_MMM2D:
    MMM2D_add_far_force();
    MMM2D_dielectric_layers_force_contribution();
    break;
#ifdef SCAFACOS
  case COULOMB_SCAFACOS:
    Electrostatics::Scafacos::add_long_range_force();
    break;
#endif
  default:
    break;
  }

/* If enabled, calculate electrostatics contribution from electrokinetics species. */ 
#ifdef EK_ELECTROSTATIC_COUPLING
  ek_calculate_electrostatic_coupling();
#endif

#endif  /*ifdef ELECTROSTATICS */
 
#ifdef DIPOLES  
  /* calculate k-space part of the magnetostatic interaction. */
  switch (coulomb.Dmethod) {
#ifdef DP3M
  case DIPOLAR_MDLC_P3M:
    add_mdlc_force_corrections();
    //fall through 
  case DIPOLAR_P3M:
    dp3m_dipole_assign();
#ifdef NPT
    if(integ_switch == INTEG_METHOD_NPT_ISO) {
      nptiso.p_vir[0] += dp3m_calc_kspace_forces(1,1);
      fprintf(stderr,"dipolar_P3M at this moment is added to p_vir[0]\n");    
    } else
#endif
      dp3m_calc_kspace_forces(1,0);
    
    break;
#endif
  case DIPOLAR_ALL_WITH_ALL_AND_NO_REPLICA: 
    dawaanr_calculations(1,0);
    break;
  case DIPOLAR_MDLC_DS:
    add_mdlc_force_corrections();
    //fall through 
  case DIPOLAR_DS: 
    magnetic_dipolar_direct_sum_calculations(1,0);
    break;
  case DIPOLAR_DS_GPU: 
    // Do nothing. It's an actor
    break;
  case DIPOLAR_NONE:
      break;
  default:
      runtimeErrorMsg() <<"unknown dipolar method";
      break;
  }
#endif  /*ifdef DIPOLES */
}
void calc_long_range_forces()
{
#ifdef ELECTROSTATICS  
  /* calculate k-space part of electrostatic interaction. */
  if (!(iccp3m_initialized && iccp3m_cfg.set_flag)) {
    switch (coulomb.method) {
  #ifdef P3M
    case COULOMB_ELC_P3M:
      if (elc_params.dielectric_contrast_on) {
        ELC_P3M_modify_p3m_sums_both();
        ELC_p3m_charge_assign_both();
        ELC_P3M_self_forces();
      }
      else
        p3m_charge_assign();
  
      p3m_calc_kspace_forces(1,0);
  
      if (elc_params.dielectric_contrast_on)
        ELC_P3M_restore_p3m_sums();
   
      ELC_add_force(); 
  
      break;
#ifdef CUDA
    case COULOMB_P3M_GPU:
      if (this_node == 0) p3m_gpu_add_farfield_force();
  #ifdef NPT
      printf("NPT can not be used in conjunction with the GPU P3M\n"); //TODO fix this?
      exit(1); //TODO ALTERNATIVELY CHECK IF BAROSTAT IS ACTUALLY ON
  #endif
      break;
#endif
    case COULOMB_P3M:
      p3m_charge_assign();
  #ifdef NPT
      if(integ_switch == INTEG_METHOD_NPT_ISO)
        nptiso.p_vir[0] += p3m_calc_kspace_forces(1,1);
      else
  #endif
        p3m_calc_kspace_forces(1,0);
      break;
  #endif
    case COULOMB_MAGGS:
      maggs_calc_forces();
      break;
    case COULOMB_MMM2D:
      MMM2D_add_far_force();
      MMM2D_dielectric_layers_force_contribution();
    }
  }
#endif  /*ifdef ELECTROSTATICS */

#ifdef DIPOLES  
  /* calculate k-space part of the magnetostatic interaction. */
  switch (coulomb.Dmethod) {
#ifdef DP3M
  case DIPOLAR_MDLC_P3M:
    add_mdlc_force_corrections();
    //fall through 
  case DIPOLAR_P3M:
    dp3m_dipole_assign();
#ifdef NPT
    if(integ_switch == INTEG_METHOD_NPT_ISO) {
      nptiso.p_vir[0] += dp3m_calc_kspace_forces(1,1);
      fprintf(stderr,"dipolar_P3M at this moment is added to p_vir[0]\n");    
    } else
#endif
      dp3m_calc_kspace_forces(1,0);
    
    break;
#endif
  case DIPOLAR_ALL_WITH_ALL_AND_NO_REPLICA: 
    dawaanr_calculations(1,0);
    break;
  case DIPOLAR_MDLC_DS:
    add_mdlc_force_corrections();
    //fall through 
  case DIPOLAR_DS: 
    magnetic_dipolar_direct_sum_calculations(1,0);
    break;
  }
#endif  /*ifdef DIPOLES */
}
Esempio n. 4
0
void calc_long_range_energies()
{
#ifdef ELECTROSTATICS  
  /* calculate k-space part of electrostatic interaction. */
  switch (coulomb.method) {
#ifdef P3M
  case COULOMB_P3M:
    p3m_charge_assign(); 
    energy.coulomb[1] = p3m_calc_kspace_forces(0,1);
    break;
  case COULOMB_ELC_P3M:
    // assign the original charges first
    // they may not have been assigned yet
    p3m_charge_assign(); 
    if(!elc_params.dielectric_contrast_on)
      energy.coulomb[1] = p3m_calc_kspace_forces(0,1);
    else {
      energy.coulomb[1] = 0.5*p3m_calc_kspace_forces(0,1); 
      energy.coulomb[1]+= 0.5*ELC_P3M_dielectric_layers_energy_self(); 

      //  assign both original and image charges now
      ELC_p3m_charge_assign_both();
      ELC_P3M_modify_p3m_sums_both();

      energy.coulomb[1] += 0.5*p3m_calc_kspace_forces(0,1); 

      //assign only the image charges now
      ELC_p3m_charge_assign_image();
      ELC_P3M_modify_p3m_sums_image();

      energy.coulomb[1]-= 0.5*p3m_calc_kspace_forces(0,1); 
    }
    energy.coulomb[2] = ELC_energy();
    break;
#endif
  case COULOMB_MMM2D:
    *energy.coulomb += MMM2D_far_energy();
    *energy.coulomb += MMM2D_dielectric_layers_energy_contribution();
    break;
    /* calculate electric part of energy (only for MAGGS) */
  case COULOMB_MAGGS:
    *energy.coulomb += maggs_electric_energy();
    break;
  }
#endif  /* ifdef ELECTROSTATICS */

#ifdef DIPOLES
  switch (coulomb.Dmethod) {
#ifdef DP3M
  case DIPOLAR_P3M:
    dp3m_dipole_assign(); 
    energy.dipolar[1] = dp3m_calc_kspace_forces(0,1);
    break;
  case DIPOLAR_MDLC_P3M:
    dp3m_dipole_assign(); 
    energy.dipolar[1] = dp3m_calc_kspace_forces(0,1);
    energy.dipolar[2] = add_mdlc_energy_corrections();
    break;
#endif
  case DIPOLAR_ALL_WITH_ALL_AND_NO_REPLICA:
    energy.dipolar[1] = dawaanr_calculations(0,1);
    break;
  case DIPOLAR_MDLC_DS:
    energy.dipolar[1] = magnetic_dipolar_direct_sum_calculations(0,1);
    energy.dipolar[2] = add_mdlc_energy_corrections();
    break;
  case DIPOLAR_DS:
    energy.dipolar[1] = magnetic_dipolar_direct_sum_calculations(0,1);
    break;
  
  } 
#endif /* ifdef DIPOLES */

}
Esempio n. 5
0
void calc_long_range_energies()
{
#ifdef ELECTROSTATICS  
  /* calculate k-space part of electrostatic interaction. */
	switch (coulomb.method) {
#ifdef P3M
	case COULOMB_P3M_GPU:
        //printf("long range energy calculation not implemented for GPU P3M\n"); //TODO make right
		break;
	case COULOMB_P3M:
		p3m_charge_assign();
		energy.coulomb[1] = p3m_calc_kspace_forces(0,1);
		break;
	case COULOMB_ELC_P3M:
		// assign the original charges first
		// they may not have been assigned yet
		p3m_charge_assign();
		if(!elc_params.dielectric_contrast_on)
			energy.coulomb[1] = p3m_calc_kspace_forces(0,1);
		else {
			energy.coulomb[1] = 0.5*p3m_calc_kspace_forces(0,1);
			energy.coulomb[1]+= 0.5*ELC_P3M_dielectric_layers_energy_self();

			//  assign both original and image charges now
			ELC_p3m_charge_assign_both();
			ELC_P3M_modify_p3m_sums_both();

			energy.coulomb[1] += 0.5*p3m_calc_kspace_forces(0,1);

			//assign only the image charges now
			ELC_p3m_charge_assign_image();
			ELC_P3M_modify_p3m_sums_image();

			energy.coulomb[1]-= 0.5*p3m_calc_kspace_forces(0,1);
		}
		energy.coulomb[2] = ELC_energy();
		break;
#endif
#ifdef SCAFACOS
        case COULOMB_SCAFACOS:
          assert(! Scafacos::dipolar());
	  *energy.coulomb += Scafacos::long_range_energy(); break;
#endif	  
	case COULOMB_MMM2D:
		*energy.coulomb += MMM2D_far_energy();
		*energy.coulomb += MMM2D_dielectric_layers_energy_contribution();
		break;
		/* calculate electric part of energy (only for MAGGS) */
	case COULOMB_MAGGS:
		*energy.coulomb += maggs_electric_energy();
		break;
	default: break;
  }
#endif  /* ifdef ELECTROSTATICS */

#ifdef DIPOLES
  switch (coulomb.Dmethod) {
#ifdef DP3M
  case DIPOLAR_P3M:
    dp3m_dipole_assign(); 
    energy.dipolar[1] = dp3m_calc_kspace_forces(0,1);
    break;
  case DIPOLAR_MDLC_P3M:
    dp3m_dipole_assign(); 
    energy.dipolar[1] = dp3m_calc_kspace_forces(0,1);
    energy.dipolar[2] = add_mdlc_energy_corrections();
    break;
#endif
  case DIPOLAR_ALL_WITH_ALL_AND_NO_REPLICA:
    energy.dipolar[1] = dawaanr_calculations(0,1);
    break;
  case DIPOLAR_MDLC_DS:
    energy.dipolar[1] = magnetic_dipolar_direct_sum_calculations(0,1);
    energy.dipolar[2] = add_mdlc_energy_corrections();
    break;
  case DIPOLAR_DS:
    energy.dipolar[1] = magnetic_dipolar_direct_sum_calculations(0,1);
    break;
  case DIPOLAR_DS_GPU:
    // Do nothing, it's an actor.
    break;
#ifdef SCAFACOS_DIPOLES
  case DIPOLAR_SCAFACOS:
    assert(Scafacos::dipolar());
    energy.dipolar[1] = Scafacos::long_range_energy();
#endif
  case DIPOLAR_NONE:
      break;
  default:
    runtimeErrorMsg() <<"unknown dipolar method";
    break;
  } 
#endif /* ifdef DIPOLES */

}