replace variable length array on stack with std::unique_ptr()

this closes #2757
This commit is contained in:
Axel Kohlmeyer
2021-05-11 11:48:44 -04:00
parent af6eae29d4
commit ead311adf8

View File

@ -42,6 +42,7 @@
#include <cmath>
#include <cstring>
#include <memory>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -724,7 +725,9 @@ void FixChargeRegulation::forward_ions_multival() {
double energy_before = energy_stored;
double factor = 1;
double dummyp[3];
int mm[salt_charge_ratio + 1];// particle ID array for all ions to be inserted
// particle ID array for all ions to be inserted
auto mm = std::unique_ptr<int[]>(new int[salt_charge_ratio + 1]);
if (salt_charge[0] <= -salt_charge[1]) {
// insert one anion and (salt_charge_ratio) cations
@ -778,9 +781,12 @@ void FixChargeRegulation::backward_ions_multival() {
double energy_before = energy_stored;
double factor = 1;
double dummyp[3]; // dummy particle
int mm[salt_charge_ratio + 1]; // particle ID array for all deleted ions
double qq[salt_charge_ratio + 1]; // charge array for all deleted ions
int mask_tmp[salt_charge_ratio + 1]; // temporary mask array
// particle ID array for all deleted ions
auto mm = std::unique_ptr<int[]>(new int[salt_charge_ratio + 1]);
// charge array for all deleted ions
auto qq = std::unique_ptr<double[]>(new double[salt_charge_ratio + 1]);
// temporary mask array
auto mask_tmp = std::unique_ptr<int[]>(new int[salt_charge_ratio + 1]);
if (salt_charge[0] <= -salt_charge[1]) {
// delete one anion and (salt_charge_ratio) cations