fix memory leak and avoid uninitialized data access
This commit is contained in:
@ -140,6 +140,8 @@ FixChargeRegulation::FixChargeRegulation(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
nsalt_successes = 0;
|
nsalt_successes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
FixChargeRegulation::~FixChargeRegulation() {
|
FixChargeRegulation::~FixChargeRegulation() {
|
||||||
|
|
||||||
memory->destroy(ptype_ID);
|
memory->destroy(ptype_ID);
|
||||||
@ -153,14 +155,23 @@ FixChargeRegulation::~FixChargeRegulation() {
|
|||||||
int igroupall = group->find("all");
|
int igroupall = group->find("all");
|
||||||
neighbor->exclusion_group_group_delete(exclusion_group, igroupall);
|
neighbor->exclusion_group_group_delete(exclusion_group, igroupall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (groupstrings) {
|
||||||
|
for (int i = 0; i < ngroups; ++i) delete[] groupstrings[i];
|
||||||
|
memory->destroy(groupstrings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int FixChargeRegulation::setmask() {
|
int FixChargeRegulation::setmask() {
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
mask |= PRE_EXCHANGE;
|
mask |= PRE_EXCHANGE;
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::init() {
|
void FixChargeRegulation::init() {
|
||||||
|
|
||||||
triclinic = domain->triclinic;
|
triclinic = domain->triclinic;
|
||||||
@ -246,6 +257,8 @@ void FixChargeRegulation::init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::pre_exchange() {
|
void FixChargeRegulation::pre_exchange() {
|
||||||
|
|
||||||
if (next_reneighbor != update->ntimestep) return;
|
if (next_reneighbor != update->ntimestep) return;
|
||||||
@ -372,6 +385,8 @@ void FixChargeRegulation::pre_exchange() {
|
|||||||
next_reneighbor = update->ntimestep + nevery;
|
next_reneighbor = update->ntimestep + nevery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::forward_acid() {
|
void FixChargeRegulation::forward_acid() {
|
||||||
|
|
||||||
double energy_before = energy_stored;
|
double energy_before = energy_stored;
|
||||||
@ -429,17 +444,16 @@ void FixChargeRegulation::forward_acid() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::backward_acid() {
|
void FixChargeRegulation::backward_acid() {
|
||||||
|
|
||||||
double energy_before = energy_stored;
|
double energy_before = energy_stored;
|
||||||
double factor;
|
double factor;
|
||||||
int mask_tmp;
|
int mask_tmp;
|
||||||
double dummyp[3];
|
double dummyp[3] = {0.0, 0.0, 0.0};
|
||||||
double pos[3];
|
double pos[3] = {0.0, 0.0, 0.0}; // acid/base particle position
|
||||||
pos[0] = 0;
|
double pos_all[3] = {0.0, 0.0, 0.0};
|
||||||
pos[1] = 0;
|
|
||||||
pos[2] = 0; // acid/base particle position
|
|
||||||
double pos_all[3];
|
|
||||||
int m1 = -1, m2 = -1;
|
int m1 = -1, m2 = -1;
|
||||||
|
|
||||||
m1 = get_random_particle(acid_type, -1, 0, dummyp);
|
m1 = get_random_particle(acid_type, -1, 0, dummyp);
|
||||||
@ -507,16 +521,15 @@ void FixChargeRegulation::backward_acid() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::forward_base() {
|
void FixChargeRegulation::forward_base() {
|
||||||
|
|
||||||
double energy_before = energy_stored;
|
double energy_before = energy_stored;
|
||||||
double factor;
|
double factor;
|
||||||
double dummyp[3];
|
double dummyp[3] = {0.0, 0.0, 0.0};
|
||||||
double pos[3];
|
double pos[3] = {0.0, 0.0, 0.0}; // acid/base particle position
|
||||||
pos[0] = 0;
|
double pos_all[3] = {0.0, 0.0, 0.0};
|
||||||
pos[1] = 0;
|
|
||||||
pos[2] = 0; // acid/base particle position
|
|
||||||
double pos_all[3];
|
|
||||||
int m1 = -1, m2 = -1;
|
int m1 = -1, m2 = -1;
|
||||||
|
|
||||||
m1 = get_random_particle(base_type, 0, 0, dummyp);
|
m1 = get_random_particle(base_type, 0, 0, dummyp);
|
||||||
@ -567,17 +580,16 @@ void FixChargeRegulation::forward_base() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::backward_base() {
|
void FixChargeRegulation::backward_base() {
|
||||||
|
|
||||||
double energy_before = energy_stored;
|
double energy_before = energy_stored;
|
||||||
double factor;
|
double factor;
|
||||||
double dummyp[3];
|
double dummyp[3] = {0.0, 0.0, 0.0};
|
||||||
|
double pos[3] = {0.0, 0.0, 0.0}; // acid/base particle position
|
||||||
|
double pos_all[3] = {0.0, 0.0, 0.0};
|
||||||
int mask_tmp;
|
int mask_tmp;
|
||||||
double pos[3];
|
|
||||||
pos[0] = 0;
|
|
||||||
pos[1] = 0;
|
|
||||||
pos[2] = 0; // acid/base particle position
|
|
||||||
double pos_all[3];
|
|
||||||
int m1 = -1, m2 = -1;
|
int m1 = -1, m2 = -1;
|
||||||
|
|
||||||
m1 = get_random_particle(base_type, 1, 0, dummyp);
|
m1 = get_random_particle(base_type, 1, 0, dummyp);
|
||||||
@ -644,11 +656,13 @@ void FixChargeRegulation::backward_base() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::forward_ions() {
|
void FixChargeRegulation::forward_ions() {
|
||||||
|
|
||||||
double energy_before = energy_stored;
|
double energy_before = energy_stored;
|
||||||
double factor;
|
double factor;
|
||||||
double dummyp[3];
|
double dummyp[3] = {0.0, 0.0, 0.0};
|
||||||
int m1 = -1, m2 = -1;
|
int m1 = -1, m2 = -1;
|
||||||
factor = volume_rx * volume_rx * c10pI_plus * c10pI_minus /
|
factor = volume_rx * volume_rx * c10pI_plus * c10pI_minus /
|
||||||
((1 + ncation) * (1 + nanion));
|
((1 + ncation) * (1 + nanion));
|
||||||
@ -679,13 +693,14 @@ void FixChargeRegulation::forward_ions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::backward_ions() {
|
void FixChargeRegulation::backward_ions() {
|
||||||
|
|
||||||
double energy_before = energy_stored;
|
double energy_before = energy_stored;
|
||||||
double factor;
|
double factor;
|
||||||
int mask1_tmp = 0, mask2_tmp = 0;
|
int mask1_tmp = 0, mask2_tmp = 0;
|
||||||
double dummyp[3];
|
double dummyp[3] = {0.0, 0.0, 0.0};
|
||||||
int m1 = -1, m2 = -1;
|
int m1 = -1, m2 = -1;
|
||||||
|
|
||||||
m1 = get_random_particle(cation_type, +1, 0, dummyp);
|
m1 = get_random_particle(cation_type, +1, 0, dummyp);
|
||||||
@ -761,11 +776,13 @@ void FixChargeRegulation::backward_ions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::forward_ions_multival() {
|
void FixChargeRegulation::forward_ions_multival() {
|
||||||
|
|
||||||
double energy_before = energy_stored;
|
double energy_before = energy_stored;
|
||||||
double factor = 1;
|
double factor = 1;
|
||||||
double dummyp[3];
|
double dummyp[3] = {0.0, 0.0, 0.0};
|
||||||
|
|
||||||
// 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]);
|
auto mm = std::unique_ptr<int[]>(new int[salt_charge_ratio + 1]);
|
||||||
@ -819,11 +836,13 @@ void FixChargeRegulation::forward_ions_multival() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::backward_ions_multival() {
|
void FixChargeRegulation::backward_ions_multival() {
|
||||||
|
|
||||||
double energy_before = energy_stored;
|
double energy_before = energy_stored;
|
||||||
double factor = 1;
|
double factor = 1;
|
||||||
double dummyp[3]; // dummy particle
|
double dummyp[3] = {0.0, 0.0, 0.0}; // dummy particle
|
||||||
// particle ID array for all deleted ions
|
// particle ID array for all deleted ions
|
||||||
auto mm = std::unique_ptr<int[]>(new int[salt_charge_ratio + 1]);
|
auto mm = std::unique_ptr<int[]>(new int[salt_charge_ratio + 1]);
|
||||||
// charge array for all deleted ions
|
// charge array for all deleted ions
|
||||||
@ -940,6 +959,8 @@ void FixChargeRegulation::backward_ions_multival() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int FixChargeRegulation::insert_particle(int ptype, double charge, double rd, double *target) {
|
int FixChargeRegulation::insert_particle(int ptype, double charge, double rd, double *target) {
|
||||||
|
|
||||||
// insert a particle of type (ptype) with charge (charge) within distance (rd) of (target)
|
// insert a particle of type (ptype) with charge (charge) within distance (rd) of (target)
|
||||||
@ -1010,6 +1031,8 @@ int FixChargeRegulation::insert_particle(int ptype, double charge, double rd, do
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int FixChargeRegulation::get_random_particle(int ptype, double charge, double rd, double *target) {
|
int FixChargeRegulation::get_random_particle(int ptype, double charge, double rd, double *target) {
|
||||||
|
|
||||||
// returns a randomly chosen particle of type (ptype) with charge (charge)
|
// returns a randomly chosen particle of type (ptype) with charge (charge)
|
||||||
@ -1074,6 +1097,8 @@ int FixChargeRegulation::get_random_particle(int ptype, double charge, double rd
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
double FixChargeRegulation::energy_full() {
|
double FixChargeRegulation::energy_full() {
|
||||||
if (triclinic) domain->x2lamda(atom->nlocal);
|
if (triclinic) domain->x2lamda(atom->nlocal);
|
||||||
domain->pbc();
|
domain->pbc();
|
||||||
@ -1133,6 +1158,8 @@ double FixChargeRegulation::energy_full() {
|
|||||||
return total_energy;
|
return total_energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int FixChargeRegulation::particle_number_xrd(int ptype, double charge, double rd, double *target) {
|
int FixChargeRegulation::particle_number_xrd(int ptype, double charge, double rd, double *target) {
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -1162,6 +1189,8 @@ int FixChargeRegulation::particle_number_xrd(int ptype, double charge, double rd
|
|||||||
return count_sum;
|
return count_sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int FixChargeRegulation::particle_number(int ptype, double charge) {
|
int FixChargeRegulation::particle_number(int ptype, double charge) {
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -1174,6 +1203,8 @@ int FixChargeRegulation::particle_number(int ptype, double charge) {
|
|||||||
return count_sum;
|
return count_sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
double FixChargeRegulation::compute_vector(int n) {
|
double FixChargeRegulation::compute_vector(int n) {
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return nacid_attempts + nbase_attempts + nsalt_attempts;
|
return nacid_attempts + nbase_attempts + nsalt_attempts;
|
||||||
@ -1250,6 +1281,8 @@ void FixChargeRegulation::restart(char *buf)
|
|||||||
error->all(FLERR,"Must not reset timestep when restarting fix gcmc");
|
error->all(FLERR,"Must not reset timestep when restarting fix gcmc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::setThermoTemperaturePointer() {
|
void FixChargeRegulation::setThermoTemperaturePointer() {
|
||||||
int ifix = -1;
|
int ifix = -1;
|
||||||
ifix = modify->find_fix(idftemp);
|
ifix = modify->find_fix(idftemp);
|
||||||
@ -1263,6 +1296,8 @@ void FixChargeRegulation::setThermoTemperaturePointer() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void FixChargeRegulation::assign_tags() {
|
void FixChargeRegulation::assign_tags() {
|
||||||
// Assign tags to ions with zero tags
|
// Assign tags to ions with zero tags
|
||||||
if (atom->tag_enable) {
|
if (atom->tag_enable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user