use consistent names, avoid memory leaks, fix off-by-1 error in fourier dihedral

This commit is contained in:
Axel Kohlmeyer
2022-02-27 11:57:40 -05:00
parent 7824e43339
commit bc9e45ca5a
20 changed files with 135 additions and 149 deletions

View File

@ -363,13 +363,12 @@ void AngleCharmmIntel::pack_force_const(ForceConst<flt_t> &fc,
template <class flt_t> template <class flt_t>
void AngleCharmmIntel::ForceConst<flt_t>::set_ntypes(const int nangletypes, void AngleCharmmIntel::ForceConst<flt_t>::set_ntypes(const int nangletypes,
Memory *memory) { Memory *memory) {
if (memory != nullptr) _memory = memory;
if (nangletypes != _nangletypes) { if (nangletypes != _nangletypes) {
if (_nangletypes > 0) _memory->destroy(fc);
_memory->destroy(fc);
if (nangletypes > 0) if (nangletypes > 0)
_memory->create(fc,nangletypes,"anglecharmmintel.fc"); _memory->create(fc,nangletypes,"anglecharmmintel.fc");
} }
_nangletypes = nangletypes; _nangletypes = nangletypes;
_memory = memory;
} }

View File

@ -60,7 +60,7 @@ class AngleCharmmIntel : public AngleCharmm {
} fc_packed1; } fc_packed1;
fc_packed1 *fc; fc_packed1 *fc;
ForceConst() : _nangletypes(0) {} ForceConst() : fc(nullptr), _nangletypes(0) {}
~ForceConst() { set_ntypes(0, nullptr); } ~ForceConst() { set_ntypes(0, nullptr); }
void set_ntypes(const int nangletypes, Memory *memory); void set_ntypes(const int nangletypes, Memory *memory);

View File

@ -343,13 +343,11 @@ void AngleHarmonicIntel::pack_force_const(ForceConst<flt_t> &fc,
template <class flt_t> template <class flt_t>
void AngleHarmonicIntel::ForceConst<flt_t>::set_ntypes(const int nangletypes, void AngleHarmonicIntel::ForceConst<flt_t>::set_ntypes(const int nangletypes,
Memory *memory) { Memory *memory) {
if (memory != nullptr) _memory = memory;
if (nangletypes != _nangletypes) { if (nangletypes != _nangletypes) {
if (_nangletypes > 0) _memory->destroy(fc);
_memory->destroy(fc);
if (nangletypes > 0) if (nangletypes > 0)
_memory->create(fc,nangletypes,"anglecharmmintel.fc"); _memory->create(fc,nangletypes,"anglecharmmintel.fc");
} }
_nangletypes = nangletypes; _nangletypes = nangletypes;
_memory = memory;
} }

View File

@ -60,7 +60,7 @@ class AngleHarmonicIntel : public AngleHarmonic {
} fc_packed1; } fc_packed1;
fc_packed1 *fc; fc_packed1 *fc;
ForceConst() : _nangletypes(0) {} ForceConst() : fc(nullptr), _nangletypes(0) {}
~ForceConst() { set_ntypes(0, nullptr); } ~ForceConst() { set_ntypes(0, nullptr); }
void set_ntypes(const int nangletypes, Memory *memory); void set_ntypes(const int nangletypes, Memory *memory);

View File

@ -323,13 +323,12 @@ void BondFENEIntel::pack_force_const(ForceConst<flt_t> &fc,
template <class flt_t> template <class flt_t>
void BondFENEIntel::ForceConst<flt_t>::set_ntypes(const int nbondtypes, void BondFENEIntel::ForceConst<flt_t>::set_ntypes(const int nbondtypes,
Memory *memory) { Memory *memory) {
if (memory != nullptr) _memory = memory;
if (nbondtypes != _nbondtypes) { if (nbondtypes != _nbondtypes) {
if (_nbondtypes > 0) _memory->destroy(fc);
_memory->destroy(fc);
if (nbondtypes > 0) if (nbondtypes > 0)
_memory->create(fc,nbondtypes,"bondfeneintel.fc"); _memory->create(fc,nbondtypes,"bondfeneintel.fc");
} }
_nbondtypes = nbondtypes; _nbondtypes = nbondtypes;
_memory = memory;
} }

View File

@ -60,7 +60,7 @@ class BondFENEIntel : public BondFENE {
} fc_packed1; } fc_packed1;
fc_packed1 *fc; fc_packed1 *fc;
ForceConst() : _nbondtypes(0) {} ForceConst() : fc(nullptr), _nbondtypes(0) {}
~ForceConst() { set_ntypes(0, nullptr); } ~ForceConst() { set_ntypes(0, nullptr); }
void set_ntypes(const int nbondtypes, Memory *memory); void set_ntypes(const int nbondtypes, Memory *memory);

View File

@ -291,13 +291,12 @@ void BondHarmonicIntel::pack_force_const(ForceConst<flt_t> &fc,
template <class flt_t> template <class flt_t>
void BondHarmonicIntel::ForceConst<flt_t>::set_ntypes(const int nbondtypes, void BondHarmonicIntel::ForceConst<flt_t>::set_ntypes(const int nbondtypes,
Memory *memory) { Memory *memory) {
if (memory != nullptr) _memory = memory;
if (nbondtypes != _nbondtypes) { if (nbondtypes != _nbondtypes) {
if (_nbondtypes > 0) _memory->destroy(fc);
_memory->destroy(fc);
if (nbondtypes > 0) if (nbondtypes > 0)
_memory->create(fc,nbondtypes,"bondharmonicintel.fc"); _memory->create(fc,nbondtypes,"bondharmonicintel.fc");
} }
_nbondtypes = nbondtypes; _nbondtypes = nbondtypes;
_memory = memory;
} }

View File

@ -60,7 +60,7 @@ class BondHarmonicIntel : public BondHarmonic {
} fc_packed1; } fc_packed1;
fc_packed1 *fc; fc_packed1 *fc;
ForceConst() : _nbondtypes(0) {} ForceConst() : fc(nullptr), _nbondtypes(0) {}
~ForceConst() { set_ntypes(0, nullptr); } ~ForceConst() { set_ntypes(0, nullptr); }
void set_ntypes(const int nbondtypes, Memory *memory); void set_ntypes(const int nbondtypes, Memory *memory);

View File

@ -261,10 +261,10 @@ void DihedralCharmmIntel::eval(const int vflag,
if (c > (flt_t)1.0) c = (flt_t)1.0; if (c > (flt_t)1.0) c = (flt_t)1.0;
if (c < (flt_t)-1.0) c = (flt_t)-1.0; if (c < (flt_t)-1.0) c = (flt_t)-1.0;
const flt_t tcos_shift = fc.bp[type].cos_shift; const flt_t tcos_shift = fc.fc[type].cos_shift;
const flt_t tsin_shift = fc.bp[type].sin_shift; const flt_t tsin_shift = fc.fc[type].sin_shift;
const flt_t tk = fc.bp[type].k; const flt_t tk = fc.fc[type].k;
const int m = fc.bp[type].multiplicity; const int m = fc.fc[type].multiplicity;
flt_t p = (flt_t)1.0; flt_t p = (flt_t)1.0;
flt_t ddf1, df1; flt_t ddf1, df1;
@ -539,10 +539,10 @@ void DihedralCharmmIntel::eval(const int vflag,
(int *) neighbor->dihedrallist[0]; (int *) neighbor->dihedrallist[0];
const flt_t * _noalias const weight = &(fc.weight[0]); const flt_t * _noalias const weight = &(fc.weight[0]);
const flt_t * _noalias const x_f = &(x[0].x); const flt_t * _noalias const x_f = &(x[0].x);
const flt_t * _noalias const cos_shift = &(fc.bp[0].cos_shift); const flt_t * _noalias const cos_shift = &(fc.fc[0].cos_shift);
const flt_t * _noalias const sin_shift = &(fc.bp[0].sin_shift); const flt_t * _noalias const sin_shift = &(fc.fc[0].sin_shift);
const flt_t * _noalias const k = &(fc.bp[0].k); const flt_t * _noalias const k = &(fc.fc[0].k);
const int * _noalias const multiplicity = &(fc.bp[0].multiplicity); const int * _noalias const multiplicity = &(fc.fc[0].multiplicity);
const flt_t * _noalias const plj1 = &(fc.ljp[0][0].lj1); const flt_t * _noalias const plj1 = &(fc.ljp[0][0].lj1);
const flt_t * _noalias const plj2 = &(fc.ljp[0][0].lj2); const flt_t * _noalias const plj2 = &(fc.ljp[0][0].lj2);
const flt_t * _noalias const plj3 = &(fc.ljp[0][0].lj3); const flt_t * _noalias const plj3 = &(fc.ljp[0][0].lj3);
@ -937,8 +937,8 @@ void DihedralCharmmIntel::pack_force_const(ForceConst<flt_t> &fc,
{ {
const int tp1 = atom->ntypes + 1; const int tp1 = atom->ntypes + 1;
const int bp1 = atom->ndihedraltypes + 1; const int dp1 = atom->ndihedraltypes + 1;
fc.set_ntypes(tp1,bp1,memory); fc.set_ntypes(tp1,dp1,memory);
buffers->set_ntypes(tp1); buffers->set_ntypes(tp1);
if (weightflag) { if (weightflag) {
@ -952,11 +952,11 @@ void DihedralCharmmIntel::pack_force_const(ForceConst<flt_t> &fc,
} }
} }
for (int i = 1; i < bp1; i++) { for (int i = 1; i < dp1; i++) {
fc.bp[i].multiplicity = multiplicity[i]; fc.fc[i].multiplicity = multiplicity[i];
fc.bp[i].cos_shift = cos_shift[i]; fc.fc[i].cos_shift = cos_shift[i];
fc.bp[i].sin_shift = sin_shift[i]; fc.fc[i].sin_shift = sin_shift[i];
fc.bp[i].k = k[i]; fc.fc[i].k = k[i];
fc.weight[i] = weight[i]; fc.weight[i] = weight[i];
} }
} }
@ -965,27 +965,24 @@ void DihedralCharmmIntel::pack_force_const(ForceConst<flt_t> &fc,
template <class flt_t> template <class flt_t>
void DihedralCharmmIntel::ForceConst<flt_t>::set_ntypes(const int npairtypes, void DihedralCharmmIntel::ForceConst<flt_t>::set_ntypes(const int npairtypes,
const int nbondtypes, const int ndihderaltypes,
Memory *memory) { Memory *memory) {
if (memory != nullptr) _memory = memory;
if (npairtypes != _npairtypes) { if (npairtypes != _npairtypes) {
if (_npairtypes > 0) _memory->destroy(ljp);
_memory->destroy(ljp);
if (npairtypes > 0) if (npairtypes > 0)
memory->create(ljp,npairtypes,npairtypes,"fc.ljp"); _memory->create(ljp,npairtypes,npairtypes,"fc.ljp");
} }
if (nbondtypes != _nbondtypes) { if (ndihderaltypes != _ndihderaltypes) {
if (_nbondtypes > 0) { _memory->destroy(fc);
_memory->destroy(bp); _memory->destroy(weight);
_memory->destroy(weight);
}
if (nbondtypes > 0) { if (ndihderaltypes > 0) {
_memory->create(bp,nbondtypes,"dihedralcharmmintel.bp"); _memory->create(fc,ndihderaltypes,"dihedralcharmmintel.fc");
_memory->create(weight,nbondtypes,"dihedralcharmmintel.weight"); _memory->create(weight,ndihderaltypes,"dihedralcharmmintel.weight");
} }
} }
_npairtypes = npairtypes; _npairtypes = npairtypes;
_nbondtypes = nbondtypes; _ndihderaltypes = ndihderaltypes;
_memory = memory;
} }

View File

@ -64,16 +64,16 @@ class DihedralCharmmIntel : public DihedralCharmm {
} fc_packed3; } fc_packed3;
fc_packed1 **ljp; fc_packed1 **ljp;
fc_packed3 *bp; fc_packed3 *fc;
flt_t *weight; flt_t *weight;
ForceConst() : _npairtypes(0), _nbondtypes(0) {} ForceConst() : ljp(nullptr), fc(nullptr), _npairtypes(0), _ndihderaltypes(0) {}
~ForceConst() { set_ntypes(0, 0, nullptr); } ~ForceConst() { set_ntypes(0, 0, nullptr); }
void set_ntypes(const int npairtypes, const int nbondtypes, Memory *memory); void set_ntypes(const int npairtypes, const int ndihderaltypes, Memory *memory);
private: private:
int _npairtypes, _nbondtypes; int _npairtypes, _ndihderaltypes;
Memory *_memory; Memory *_memory;
}; };
ForceConst<float> force_const_single; ForceConst<float> force_const_single;

View File

@ -225,10 +225,10 @@ void DihedralFourierIntel::eval(const int vflag,
if (EFLAG) deng = (flt_t)0.0; if (EFLAG) deng = (flt_t)0.0;
for (int j = 0; j < nterms[type]; j++) { for (int j = 0; j < nterms[type]; j++) {
const flt_t tcos_shift = fc.bp[j][type].cos_shift; const flt_t tcos_shift = fc.fc[j][type].cos_shift;
const flt_t tsin_shift = fc.bp[j][type].sin_shift; const flt_t tsin_shift = fc.fc[j][type].sin_shift;
const flt_t tk = fc.bp[j][type].k; const flt_t tk = fc.fc[j][type].k;
const int m = fc.bp[j][type].multiplicity; const int m = fc.fc[j][type].multiplicity;
flt_t p = (flt_t)1.0; flt_t p = (flt_t)1.0;
flt_t ddf1, df1; flt_t ddf1, df1;
@ -394,16 +394,16 @@ template <class flt_t, class acc_t>
void DihedralFourierIntel::pack_force_const(ForceConst<flt_t> &fc, void DihedralFourierIntel::pack_force_const(ForceConst<flt_t> &fc,
IntelBuffers<flt_t,acc_t> * /*buffers*/) IntelBuffers<flt_t,acc_t> * /*buffers*/)
{ {
const int bp1 = atom->ndihedraltypes + 1; const int dp1 = atom->ndihedraltypes + 1;
fc.set_ntypes(bp1, setflag, nterms, memory); fc.set_ntypes(dp1, setflag, nterms, memory);
for (int i = 1; i < bp1; i++) { for (int i = 1; i < dp1; i++) {
if (setflag[i]) { if (setflag[i]) {
for (int j = 0; j < nterms[i]; j++) { for (int j = 0; j < nterms[i]; j++) {
fc.bp[j][i].cos_shift = cos_shift[i][j]; fc.fc[j][i].cos_shift = cos_shift[i][j];
fc.bp[j][i].sin_shift = sin_shift[i][j]; fc.fc[j][i].sin_shift = sin_shift[i][j];
fc.bp[j][i].k = k[i][j]; fc.fc[j][i].k = k[i][j];
fc.bp[j][i].multiplicity = multiplicity[i][j]; fc.fc[j][i].multiplicity = multiplicity[i][j];
} }
} }
} }
@ -412,22 +412,20 @@ void DihedralFourierIntel::pack_force_const(ForceConst<flt_t> &fc,
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
template <class flt_t> template <class flt_t>
void DihedralFourierIntel::ForceConst<flt_t>::set_ntypes(const int nbondtypes, void DihedralFourierIntel::ForceConst<flt_t>::set_ntypes(const int ndihedraltypes,
int *setflag, int *setflag,
int *nterms, int *nterms,
Memory *memory) { Memory *memory) {
if (nbondtypes != _nbondtypes) { if (memory != nullptr) _memory = memory;
if (_nbondtypes > 0) if (ndihedraltypes != _ndihedraltypes) {
_memory->destroy(bp); _memory->destroy(fc);
if (nbondtypes > 0) { if (ndihedraltypes > 0) {
_maxnterms = 1; _maxnterms = 1;
for (int i = 1; i <= nbondtypes; i++) for (int i = 1; i < ndihedraltypes; i++)
if (setflag[i]) _maxnterms = MAX(_maxnterms, nterms[i]); if (setflag[i]) _maxnterms = MAX(_maxnterms, nterms[i]);
_memory->create(fc, _maxnterms, ndihedraltypes, "dihedralfourierintel.fc");
_memory->create(bp, _maxnterms, nbondtypes, "dihedralfourierintel.bp");
} }
} }
_nbondtypes = nbondtypes; _ndihedraltypes = ndihedraltypes;
_memory = memory;
} }

View File

@ -60,15 +60,15 @@ class DihedralFourierIntel : public DihedralFourier {
int multiplicity; int multiplicity;
} fc_packed1; } fc_packed1;
fc_packed1 **bp; fc_packed1 **fc;
ForceConst() : _nbondtypes(0) {} ForceConst() : fc(nullptr), _ndihedraltypes(0) {}
~ForceConst() { set_ntypes(0, nullptr, nullptr, nullptr); } ~ForceConst() { set_ntypes(0, nullptr, nullptr, nullptr); }
void set_ntypes(const int nbondtypes, int *setflag, int *nterms, Memory *memory); void set_ntypes(const int ndihedraltypes, int *setflag, int *nterms, Memory *memory);
private: private:
int _nbondtypes, _maxnterms; int _ndihedraltypes, _maxnterms;
Memory *_memory; Memory *_memory;
}; };
ForceConst<float> force_const_single; ForceConst<float> force_const_single;

View File

@ -220,10 +220,10 @@ void DihedralHarmonicIntel::eval(const int vflag,
if (c > (flt_t)1.0) c = (flt_t)1.0; if (c > (flt_t)1.0) c = (flt_t)1.0;
if (c < (flt_t)-1.0) c = (flt_t)-1.0; if (c < (flt_t)-1.0) c = (flt_t)-1.0;
const flt_t tcos_shift = fc.bp[type].cos_shift; const flt_t tcos_shift = fc.fc[type].cos_shift;
const flt_t tsin_shift = fc.bp[type].sin_shift; const flt_t tsin_shift = fc.fc[type].sin_shift;
const flt_t tk = fc.bp[type].k; const flt_t tk = fc.fc[type].k;
const int m = fc.bp[type].multiplicity; const int m = fc.fc[type].multiplicity;
flt_t p = (flt_t)1.0; flt_t p = (flt_t)1.0;
flt_t ddf1, df1; flt_t ddf1, df1;
@ -389,29 +389,28 @@ template <class flt_t, class acc_t>
void DihedralHarmonicIntel::pack_force_const(ForceConst<flt_t> &fc, void DihedralHarmonicIntel::pack_force_const(ForceConst<flt_t> &fc,
IntelBuffers<flt_t,acc_t> * /*buffers*/) IntelBuffers<flt_t,acc_t> * /*buffers*/)
{ {
const int bp1 = atom->ndihedraltypes + 1; const int dp1 = atom->ndihedraltypes + 1;
fc.set_ntypes(bp1,memory); fc.set_ntypes(dp1,memory);
for (int i = 1; i < bp1; i++) { for (int i = 1; i < dp1; i++) {
fc.bp[i].multiplicity = multiplicity[i]; fc.fc[i].multiplicity = multiplicity[i];
fc.bp[i].cos_shift = cos_shift[i]; fc.fc[i].cos_shift = cos_shift[i];
fc.bp[i].sin_shift = sin_shift[i]; fc.fc[i].sin_shift = sin_shift[i];
fc.bp[i].k = k[i]; fc.fc[i].k = k[i];
} }
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
template <class flt_t> template <class flt_t>
void DihedralHarmonicIntel::ForceConst<flt_t>::set_ntypes(const int nbondtypes, void DihedralHarmonicIntel::ForceConst<flt_t>::set_ntypes(const int ndihderaltypes,
Memory *memory) { Memory *memory) {
if (nbondtypes != _nbondtypes) { if (memory != nullptr) _memory = memory;
if (_nbondtypes > 0) if (ndihderaltypes != _ndihderaltypes) {
_memory->destroy(bp); _memory->destroy(fc);
if (nbondtypes > 0) if (ndihderaltypes > 0)
_memory->create(bp,nbondtypes,"dihedralcharmmintel.bp"); _memory->create(fc,ndihderaltypes,"dihedralcharmmintel.fc");
} }
_nbondtypes = nbondtypes; _ndihderaltypes = ndihderaltypes;
_memory = memory;
} }

View File

@ -60,15 +60,15 @@ class DihedralHarmonicIntel : public DihedralHarmonic {
int multiplicity; int multiplicity;
} fc_packed1; } fc_packed1;
fc_packed1 *bp; fc_packed1 *fc;
ForceConst() : _nbondtypes(0) {} ForceConst() : fc(nullptr), _ndihderaltypes(0) {}
~ForceConst() { set_ntypes(0, nullptr); } ~ForceConst() { set_ntypes(0, nullptr); }
void set_ntypes(const int nbondtypes, Memory *memory); void set_ntypes(const int ndihderaltypes, Memory *memory);
private: private:
int _nbondtypes; int _ndihderaltypes;
Memory *_memory; Memory *_memory;
}; };
ForceConst<float> force_const_single; ForceConst<float> force_const_single;

View File

@ -264,14 +264,14 @@ void DihedralOPLSIntel::eval(const int vflag,
const flt_t sin_4phim = (flt_t)2.0 * cos_2phi * sin_2phim; const flt_t sin_4phim = (flt_t)2.0 * cos_2phi * sin_2phim;
flt_t p, pd; flt_t p, pd;
p = fc.bp[type].k1*((flt_t)1.0 + c) + p = fc.fc[type].k1*((flt_t)1.0 + c) +
fc.bp[type].k2*((flt_t)1.0 - cos_2phi) + fc.fc[type].k2*((flt_t)1.0 - cos_2phi) +
fc.bp[type].k3*((flt_t)1.0 + cos_3phi) + fc.fc[type].k3*((flt_t)1.0 + cos_3phi) +
fc.bp[type].k4*((flt_t)1.0 - cos_4phi) ; fc.fc[type].k4*((flt_t)1.0 - cos_4phi) ;
pd = fc.bp[type].k1 - pd = fc.fc[type].k1 -
(flt_t)2.0 * fc.bp[type].k2 * sin_2phim + (flt_t)2.0 * fc.fc[type].k2 * sin_2phim +
(flt_t)3.0 * fc.bp[type].k3 * sin_3phim - (flt_t)3.0 * fc.fc[type].k3 * sin_3phim -
(flt_t)4.0 * fc.bp[type].k4 * sin_4phim; (flt_t)4.0 * fc.fc[type].k4 * sin_4phim;
flt_t edihed; flt_t edihed;
if (EFLAG) edihed = p; if (EFLAG) edihed = p;
@ -409,29 +409,28 @@ template <class flt_t, class acc_t>
void DihedralOPLSIntel::pack_force_const(ForceConst<flt_t> &fc, void DihedralOPLSIntel::pack_force_const(ForceConst<flt_t> &fc,
IntelBuffers<flt_t,acc_t> * /*buffers*/) IntelBuffers<flt_t,acc_t> * /*buffers*/)
{ {
const int bp1 = atom->ndihedraltypes + 1; const int dp1 = atom->ndihedraltypes + 1;
fc.set_ntypes(bp1,memory); fc.set_ntypes(dp1,memory);
for (int i = 1; i < bp1; i++) { for (int i = 1; i < dp1; i++) {
fc.bp[i].k1 = k1[i]; fc.fc[i].k1 = k1[i];
fc.bp[i].k2 = k2[i]; fc.fc[i].k2 = k2[i];
fc.bp[i].k3 = k3[i]; fc.fc[i].k3 = k3[i];
fc.bp[i].k4 = k4[i]; fc.fc[i].k4 = k4[i];
} }
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
template <class flt_t> template <class flt_t>
void DihedralOPLSIntel::ForceConst<flt_t>::set_ntypes(const int nbondtypes, void DihedralOPLSIntel::ForceConst<flt_t>::set_ntypes(const int ndihderaltypes,
Memory *memory) { Memory *memory) {
if (nbondtypes != _nbondtypes) { if (memory != nullptr) _memory = memory;
if (_nbondtypes > 0) if (ndihderaltypes != _ndihderaltypes) {
_memory->destroy(bp); _memory->destroy(fc);
if (nbondtypes > 0) if (ndihderaltypes > 0)
_memory->create(bp,nbondtypes,"dihedralcharmmintel.bp"); _memory->create(fc,ndihderaltypes,"dihedralcharmmintel.fc");
} }
_nbondtypes = nbondtypes; _ndihderaltypes = ndihderaltypes;
_memory = memory;
} }

View File

@ -59,15 +59,15 @@ class DihedralOPLSIntel : public DihedralOPLS {
flt_t k1, k2, k3, k4; flt_t k1, k2, k3, k4;
} fc_packed1; } fc_packed1;
fc_packed1 *bp; fc_packed1 *fc;
ForceConst() : _nbondtypes(0) {} ForceConst() : fc(nullptr), _ndihderaltypes(0) {}
~ForceConst() { set_ntypes(0, nullptr); } ~ForceConst() { set_ntypes(0, nullptr); }
void set_ntypes(const int nbondtypes, Memory *memory); void set_ntypes(const int ndihderaltypes, Memory *memory);
private: private:
int _nbondtypes; int _ndihderaltypes;
Memory *_memory; Memory *_memory;
}; };
ForceConst<float> force_const_single; ForceConst<float> force_const_single;

View File

@ -426,10 +426,10 @@ template <class flt_t, class acc_t>
void ImproperCvffIntel::pack_force_const(ForceConst<flt_t> &fc, void ImproperCvffIntel::pack_force_const(ForceConst<flt_t> &fc,
IntelBuffers<flt_t,acc_t> * /*buffers*/) IntelBuffers<flt_t,acc_t> * /*buffers*/)
{ {
const int bp1 = atom->nimpropertypes + 1; const int ip1 = atom->nimpropertypes + 1;
fc.set_ntypes(bp1,memory); fc.set_ntypes(ip1,memory);
for (int i = 1; i < bp1; i++) { for (int i = 1; i < ip1; i++) {
fc.fc[i].k = k[i]; fc.fc[i].k = k[i];
fc.fc[i].sign = sign[i]; fc.fc[i].sign = sign[i];
fc.fc[i].multiplicity = multiplicity[i]; fc.fc[i].multiplicity = multiplicity[i];
@ -439,15 +439,14 @@ void ImproperCvffIntel::pack_force_const(ForceConst<flt_t> &fc,
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
template <class flt_t> template <class flt_t>
void ImproperCvffIntel::ForceConst<flt_t>::set_ntypes(const int nimproper, void ImproperCvffIntel::ForceConst<flt_t>::set_ntypes(const int nimpropertypes,
Memory *memory) { Memory *memory) {
if (nimproper != _nimpropertypes) { if (memory != nullptr) _memory = memory;
if (_nimpropertypes > 0) if (nimpropertypes != _nimpropertypes) {
_memory->destroy(fc); _memory->destroy(fc);
if (nimproper > 0) if (nimpropertypes > 0)
_memory->create(fc,nimproper,"improperharmonicintel.fc"); _memory->create(fc,nimpropertypes,"improperharmonicintel.fc");
} }
_nimpropertypes = nimproper; _nimpropertypes = nimpropertypes;
_memory = memory;
} }

View File

@ -62,7 +62,7 @@ class ImproperCvffIntel : public ImproperCvff {
fc_packed1 *fc; fc_packed1 *fc;
ForceConst() : _nimpropertypes(0) {} ForceConst() : fc(nullptr), _nimpropertypes(0) {}
~ForceConst() { set_ntypes(0, nullptr); } ~ForceConst() { set_ntypes(0, nullptr); }
void set_ntypes(const int nimpropertypes, Memory *memory); void set_ntypes(const int nimpropertypes, Memory *memory);

View File

@ -379,10 +379,10 @@ template <class flt_t, class acc_t>
void ImproperHarmonicIntel::pack_force_const(ForceConst<flt_t> &fc, void ImproperHarmonicIntel::pack_force_const(ForceConst<flt_t> &fc,
IntelBuffers<flt_t,acc_t> * /*buffers*/) IntelBuffers<flt_t,acc_t> * /*buffers*/)
{ {
const int bp1 = atom->nimpropertypes + 1; const int ip1 = atom->nimpropertypes + 1;
fc.set_ntypes(bp1,memory); fc.set_ntypes(ip1,memory);
for (int i = 1; i < bp1; i++) { for (int i = 1; i < ip1; i++) {
fc.fc[i].k = k[i]; fc.fc[i].k = k[i];
fc.fc[i].chi = chi[i]; fc.fc[i].chi = chi[i];
} }
@ -391,15 +391,14 @@ void ImproperHarmonicIntel::pack_force_const(ForceConst<flt_t> &fc,
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
template <class flt_t> template <class flt_t>
void ImproperHarmonicIntel::ForceConst<flt_t>::set_ntypes(const int nimproper, void ImproperHarmonicIntel::ForceConst<flt_t>::set_ntypes(const int nimpropertypes,
Memory *memory) { Memory *memory) {
if (nimproper != _nimpropertypes) { if (memory != nullptr) _memory = memory;
if (_nimpropertypes > 0) if (nimpropertypes != _nimpropertypes) {
_memory->destroy(fc); _memory->destroy(fc);
if (nimproper > 0) if (nimpropertypes > 0)
_memory->create(fc,nimproper,"improperharmonicintel.fc"); _memory->create(fc,nimpropertypes,"improperharmonicintel.fc");
} }
_nimpropertypes = nimproper; _nimpropertypes = nimpropertypes;
_memory = memory;
} }

View File

@ -61,7 +61,7 @@ class ImproperHarmonicIntel : public ImproperHarmonic {
fc_packed1 *fc; fc_packed1 *fc;
ForceConst() : _nimpropertypes(0) {} ForceConst() : fc(nullptr), _nimpropertypes(0) {}
~ForceConst() { set_ntypes(0, nullptr); } ~ForceConst() { set_ntypes(0, nullptr); }
void set_ntypes(const int nimpropertypes, Memory *memory); void set_ntypes(const int nimpropertypes, Memory *memory);