Unverified Commit 6d70c393 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #2239 from akohlmey/collected-small-changes

Collected small changes and fixes for the next patch release
parents 211beaee 02ff2068
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ endif()
# we require C++11 without extensions
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "Use compiler extensions")

########################################################################
# User input options                                                   #
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ FixGravityKokkos<DeviceType>::FixGravityKokkos(LAMMPS *lmp, int narg, char **arg
/* ---------------------------------------------------------------------- */

template<class DeviceType>
void FixGravityKokkos<DeviceType>::post_force(int vflag)
void FixGravityKokkos<DeviceType>::post_force(int /*vflag*/)
{
  // update gravity due to variables

+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ void FixLangevinKokkos<DeviceType>::grow_arrays(int nmax)
/* ---------------------------------------------------------------------- */

template<class DeviceType>
void FixLangevinKokkos<DeviceType>::initial_integrate(int vflag)
void FixLangevinKokkos<DeviceType>::initial_integrate(int /*vflag*/)
{
  atomKK->sync(execution_space,datamask_read);
  atomKK->modified(execution_space,datamask_modify);
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ void FixSetForceKokkos<DeviceType>::init()
/* ---------------------------------------------------------------------- */

template<class DeviceType>
void FixSetForceKokkos<DeviceType>::post_force(int vflag)
void FixSetForceKokkos<DeviceType>::post_force(int /*vflag*/)
{
  atomKK->sync(execution_space, X_MASK | F_MASK | MASK_MASK);

+51 −65
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "comm.h"
#include "update.h"
#include "force.h"
#include "info.h"
#include "kspace.h"
#include "pair.h"
#include "error.h"
@@ -45,7 +46,8 @@ using namespace FixConst;
/* ---------------------------------------------------------------------- */

FixTuneKspace::FixTuneKspace(LAMMPS *lmp, int narg, char **arg) :
  Fix(lmp, narg, arg)
  Fix(lmp, narg, arg),
  acc_str(""), kspace_style(""), pair_style(""), base_pair_style("")
{
  if (narg < 3) error->all(FLERR,"Illegal fix tune/kspace command");

@@ -98,10 +100,9 @@ void FixTuneKspace::init()
  if (force->kspace->dipoleflag)
    error->all(FLERR,"Cannot use fix tune/kspace with dipole long-range solver");

  store_old_kspace_settings();
  double old_acc = force->kspace->accuracy/force->kspace->two_charge_force;
  char old_acc_str[16];
  snprintf(old_acc_str,16,"%g",old_acc);
  strncpy(new_acc_str,old_acc_str,16);
  acc_str = std::to_string(old_acc);

  int itmp;
  double *p_cutoff = (double *) force->pair->extract("cut_coul",itmp);
@@ -120,34 +121,35 @@ void FixTuneKspace::pre_exchange()
  if (next_reneighbor != update->ntimestep) return;
  next_reneighbor = update->ntimestep + nevery;

  Info *info = new Info(lmp);
  bool has_msm = info->has_style("pair", base_pair_style + "/msm");
  delete info;

  double time = get_timing_info();

  if (strcmp(force->kspace_style,"ewald") == 0) ewald_time = time;
  if (strcmp(force->kspace_style,"pppm") == 0) pppm_time = time;
  if (strcmp(force->kspace_style,"msm") == 0) msm_time = time;
  if (utils::strmatch(force->kspace_style,"^ewald")) ewald_time = time;
  if (utils::strmatch(force->kspace_style,"^pppm")) pppm_time = time;
  if (utils::strmatch(force->kspace_style,"^msm")) msm_time = time;

  niter++;
  if (niter == 1) {
    // test Ewald
    store_old_kspace_settings();
    strcpy(new_kspace_style,"ewald");
    snprintf(new_pair_style,64,"%s/long",base_pair_style);
    update_pair_style(new_pair_style,pair_cut_coul);
    update_kspace_style(new_kspace_style,new_acc_str);
    pair_style = base_pair_style + "/long";
    update_pair_style(pair_style,pair_cut_coul);
    update_kspace_style("ewald",acc_str);
  } else if (niter == 2) {
    // test PPPM
    store_old_kspace_settings();
    strcpy(new_kspace_style,"pppm");
    snprintf(new_pair_style,64,"%s/long",base_pair_style);
    update_pair_style(new_pair_style,pair_cut_coul);
    update_kspace_style(new_kspace_style,new_acc_str);
  } else if (niter == 3) {
    pair_style = base_pair_style + "/long";
    update_pair_style(pair_style,pair_cut_coul);
    update_kspace_style("pppm",acc_str);
  } else if (has_msm && (niter == 3)) {
    // test MSM
    store_old_kspace_settings();
    strcpy(new_kspace_style,"msm");
    snprintf(new_pair_style,64,"%s/msm",base_pair_style);
    update_pair_style(new_pair_style,pair_cut_coul);
    update_kspace_style(new_kspace_style,new_acc_str);
    pair_style = base_pair_style + "/msm";
    update_pair_style(pair_style,pair_cut_coul);
    update_kspace_style("msm",acc_str);
  } else if (niter == 4) {
    store_old_kspace_settings();
    if (comm->me == 0)
@@ -156,16 +158,17 @@ void FixTuneKspace::pre_exchange()
                                     "msm_time = {}\n",
                                     ewald_time, pppm_time, msm_time));
    // switch to fastest one
    strcpy(new_kspace_style,"ewald");
    snprintf(new_pair_style,64,"%s/long",base_pair_style);
    if (msm_time == 0.0) msm_time = 1.0e300;
    kspace_style = "ewald";
    pair_style = base_pair_style + "/long";
    if (pppm_time < ewald_time && pppm_time < msm_time)
      strcpy(new_kspace_style,"pppm");
      kspace_style = "pppm";
    else if (msm_time < pppm_time && msm_time < ewald_time) {
      strcpy(new_kspace_style,"msm");
      snprintf(new_pair_style,64,"%s/msm",base_pair_style);
      kspace_style = "msm";
      pair_style = base_pair_style + "/msm";
    }
    update_pair_style(new_pair_style,pair_cut_coul);
    update_kspace_style(new_kspace_style,new_acc_str);
    update_pair_style(pair_style,pair_cut_coul);
    update_kspace_style(kspace_style,acc_str);
  } else {
    adjust_rcut(time);
  }
@@ -207,30 +210,26 @@ double FixTuneKspace::get_timing_info()

void FixTuneKspace::store_old_kspace_settings()
{
  int n = strlen(force->kspace_style) + 1;
  char *old_kspace_style = new char[n];
  strcpy(old_kspace_style,force->kspace_style);
  strcpy(new_kspace_style,old_kspace_style);
  double old_acc = force->kspace->accuracy_relative;
  char old_acc_str[16];
  snprintf(old_acc_str,16,"%g",old_acc);
  strcpy(new_pair_style,force->pair_style);
  strcpy(base_pair_style,force->pair_style);
  char *trunc;
  if ((trunc = strstr(base_pair_style, "/long")) != NULL) *trunc = '\0';
  if ((trunc = strstr(base_pair_style, "/msm" )) != NULL) *trunc = '\0';
  kspace_style = force->kspace_style;
  pair_style = force->pair_style;

  std::size_t found;
  if (std::string::npos != (found = pair_style.rfind("/long")))
    base_pair_style = pair_style.substr(0,found);
  else if (std::string::npos != (found = pair_style.rfind("/msm")))
    base_pair_style = pair_style.substr(0,found);
  else base_pair_style = pair_style;

  old_differentiation_flag = force->kspace->differentiation_flag;
  old_slabflag = force->kspace->slabflag;
  old_slab_volfactor = force->kspace->slab_volfactor;
  delete[] old_kspace_style;
}

/* ----------------------------------------------------------------------
   update the pair style if necessary, preserving the settings
------------------------------------------------------------------------- */

void FixTuneKspace::update_pair_style(char *new_pair_style,
void FixTuneKspace::update_pair_style(const std::string &new_pair_style,
                                      double pair_cut_coul)
{
  int itmp;
@@ -238,7 +237,7 @@ void FixTuneKspace::update_pair_style(char *new_pair_style,
  *p_cutoff = pair_cut_coul;

  // check to see if we need to change pair styles
  if (strcmp(new_pair_style,force->pair_style) == 0) return;
  if (new_pair_style == force->pair_style) return;

  // create a temporary file to store current pair settings
  FILE *p_pair_settings_file;
@@ -247,8 +246,9 @@ void FixTuneKspace::update_pair_style(char *new_pair_style,
  rewind(p_pair_settings_file);
  if (comm->me == 0)
    utils::logmesg(lmp,fmt::format("Creating new pair style: {}\n",new_pair_style));

  // delete old pair style and create new one
  force->create_pair(new_pair_style,1);
  force->create_pair(new_pair_style.c_str(),1);

  // restore current pair settings from temporary file
  force->pair->read_restart(p_pair_settings_file);
@@ -267,26 +267,14 @@ void FixTuneKspace::update_pair_style(char *new_pair_style,
   update the kspace style if necessary
------------------------------------------------------------------------- */

void FixTuneKspace::update_kspace_style(char *new_kspace_style,
                                        char *new_acc_str)
void FixTuneKspace::update_kspace_style(const std::string &new_kspace_style,
                                        const std::string &new_acc_str)
{
  // create kspace style char string

  int narg = 2;
  char **arg;
  arg = NULL;
  int maxarg = 100;
  arg = (char **) memory->srealloc(arg,maxarg*sizeof(char *),"tune/kspace:arg");
  int n = 12;
  arg[0] = new char[n];
  strcpy(arg[0],new_kspace_style);
  arg[1] = new char[n];
  strcpy(arg[1],new_acc_str);

  // delete old kspace style and create new one

  force->create_kspace(arg[0],1);
  force->kspace->settings(narg-1,&arg[1]);
  char *tmp_acc_str = (char *)new_acc_str.c_str();
  force->create_kspace(new_kspace_style.c_str(),1);
  force->kspace->settings(1,&tmp_acc_str);
  force->kspace->differentiation_flag = old_differentiation_flag;
  force->kspace->slabflag = old_slabflag;
  force->kspace->slab_volfactor = old_slab_volfactor;
@@ -305,8 +293,6 @@ void FixTuneKspace::update_kspace_style(char *new_kspace_style,
  // Re-init computes to update pointers to virials, etc.

  for (int i = 0; i < modify->ncompute; i++) modify->compute[i]->init();

  memory->sfree(arg);
}

/* ----------------------------------------------------------------------
@@ -315,7 +301,7 @@ void FixTuneKspace::update_kspace_style(char *new_kspace_style,

void FixTuneKspace::adjust_rcut(double time)
{
  if (strcmp(force->kspace_style,"msm") == 0) return;
  if (utils::strmatch(force->kspace_style,"^msm")) return;
  if (converged) return;

  double temp;
@@ -401,8 +387,8 @@ void FixTuneKspace::adjust_rcut(double time)
    utils::logmesg(lmp,fmt::format("Adjusted Coulomb cutoff for real space: {}\n", current_cutoff));

  store_old_kspace_settings();
  update_pair_style(new_pair_style,pair_cut_coul);
  update_kspace_style(new_kspace_style,new_acc_str);
  update_pair_style(pair_style,pair_cut_coul);
  update_kspace_style(kspace_style,acc_str);
}

/* ----------------------------------------------------------------------
Loading