From 5abd6e5122508132f20a3445f83d15b4b4f065a8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer <akohlmey@gmail.com> Date: Mon, 16 Jan 2017 11:08:48 -0500 Subject: [PATCH] reordering operations in Pair::init_style() to avoid segfaults w/o a kspace style --- src/KSPACE/pair_buck_long_coul_long.cpp | 43 +++++++++++---------- src/KSPACE/pair_lj_long_coul_long.cpp | 50 +++++++++++++------------ 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/KSPACE/pair_buck_long_coul_long.cpp b/src/KSPACE/pair_buck_long_coul_long.cpp index 6504af57d9..86c9926710 100644 --- a/src/KSPACE/pair_buck_long_coul_long.cpp +++ b/src/KSPACE/pair_buck_long_coul_long.cpp @@ -51,6 +51,9 @@ PairBuckLongCoulLong::PairBuckLongCoulLong(LAMMPS *lmp) : Pair(lmp) dispersionflag = ewaldflag = pppmflag = 1; respa_enable = 1; writedata = 1; + ftable = NULL; + fdisptable = NULL; + qdist = 0.0; } /* ---------------------------------------------------------------------- @@ -230,7 +233,27 @@ void PairBuckLongCoulLong::init_style() // require an atom style with charge defined if (!atom->q_flag && (ewald_order&(1<<1))) - error->all(FLERR,"Pair style buck/long/coul/long requires atom attribute q"); + error->all(FLERR, + "Invoking coulombic in pair style buck/long/coul/long requires atom attribute q"); + + // ensure use of KSpace long-range solver, set two g_ewalds + + if (force->kspace == NULL) + error->all(FLERR,"Pair style requires a KSpace style"); + if (ewald_order&(1<<1)) g_ewald = force->kspace->g_ewald; + if (ewald_order&(1<<6)) g_ewald_6 = force->kspace->g_ewald_6; + + // set rRESPA cutoffs + + if (strstr(update->integrate_style,"respa") && + ((Respa *) update->integrate)->level_inner >= 0) + cut_respa = ((Respa *) update->integrate)->cutoff; + else cut_respa = NULL; + + // setup force tables + + if (ncoultablebits && (ewald_order&(1<<1))) init_tables(cut_coul,cut_respa); + if (ndisptablebits && (ewald_order&(1<<6))) init_tables_disp(cut_buck_global); // request regular or rRESPA neighbor lists if neighrequest_flag != 0 @@ -271,24 +294,6 @@ void PairBuckLongCoulLong::init_style() } cut_coulsq = cut_coul * cut_coul; - - // set rRESPA cutoffs - - if (strstr(update->integrate_style,"respa") && - ((Respa *) update->integrate)->level_inner >= 0) - cut_respa = ((Respa *) update->integrate)->cutoff; - else cut_respa = NULL; - - // ensure use of KSpace long-range solver, set two g_ewalds - - if (force->kspace == NULL) - error->all(FLERR,"Pair style requires a KSpace style"); - if (ewald_order&(1<<1)) g_ewald = force->kspace->g_ewald; - if (ewald_order&(1<<6)) g_ewald_6 = force->kspace->g_ewald_6; - // setup force tables - - if (ncoultablebits && (ewald_order&(1<<1))) init_tables(cut_coul,cut_respa); - if (ndisptablebits && (ewald_order&(1<<6))) init_tables_disp(cut_buck_global); } /* ---------------------------------------------------------------------- diff --git a/src/KSPACE/pair_lj_long_coul_long.cpp b/src/KSPACE/pair_lj_long_coul_long.cpp index 5ae607a2f0..f4c48a5bfe 100644 --- a/src/KSPACE/pair_lj_long_coul_long.cpp +++ b/src/KSPACE/pair_lj_long_coul_long.cpp @@ -81,10 +81,12 @@ void PairLJLongCoulLong::settings(int narg, char **arg) { if (narg != 3 && narg != 4) error->all(FLERR,"Illegal pair_style command"); - ewald_off = 0; ewald_order = 0; - options(arg, 6); - options(++arg, 1); + ewald_off = 0; + + options(arg,6); + options(++arg,1); + if (!comm->me && ewald_order == ((1<<1) | (1<<6))) error->warning(FLERR,"Using largest cutoff for lj/long/coul/long"); if (!*(++arg)) @@ -226,7 +228,26 @@ void PairLJLongCoulLong::init_style() if (!atom->q_flag && (ewald_order&(1<<1))) error->all(FLERR, - "Invoking coulombic in pair style lj/coul requires atom attribute q"); + "Invoking coulombic in pair style lj/long/coul/long requires atom attribute q"); + + // ensure use of KSpace long-range solver, set two g_ewalds + + if (force->kspace == NULL) + error->all(FLERR,"Pair style requires a KSpace style"); + if (ewald_order&(1<<1)) g_ewald = force->kspace->g_ewald; + if (ewald_order&(1<<6)) g_ewald_6 = force->kspace->g_ewald_6; + + // set rRESPA cutoffs + + if (strstr(update->integrate_style,"respa") && + ((Respa *) update->integrate)->level_inner >= 0) + cut_respa = ((Respa *) update->integrate)->cutoff; + else cut_respa = NULL; + + // setup force tables + + if (ncoultablebits && (ewald_order&(1<<1))) init_tables(cut_coul,cut_respa); + if (ndisptablebits && (ewald_order&(1<<6))) init_tables_disp(cut_buck_global); // request regular or rRESPA neighbor lists if neighrequest_flag != 0 @@ -265,27 +286,8 @@ void PairLJLongCoulLong::init_style() } else irequest = neighbor->request(this,instance_me); } - cut_coulsq = cut_coul * cut_coul; - - // set rRESPA cutoffs - - if (strstr(update->integrate_style,"respa") && - ((Respa *) update->integrate)->level_inner >= 0) - cut_respa = ((Respa *) update->integrate)->cutoff; - else cut_respa = NULL; - - // ensure use of KSpace long-range solver, set g_ewald - - if (force->kspace == NULL) - error->all(FLERR,"Pair style requires a KSpace style"); - if (force->kspace) g_ewald = force->kspace->g_ewald; - if (force->kspace) g_ewald_6 = force->kspace->g_ewald_6; - - // setup force tables - - if (ncoultablebits && (ewald_order&(1<<1))) init_tables(cut_coul,cut_respa); - if (ndisptablebits && (ewald_order&(1<<6))) init_tables_disp(cut_lj_global); + cut_coulsq = cut_coul * cut_coul; } /* ---------------------------------------------------------------------- -- GitLab