diff --git a/src/KOKKOS/pair_mliap_kokkos.cpp b/src/KOKKOS/pair_mliap_kokkos.cpp index b1f411651f..856492565a 100644 --- a/src/KOKKOS/pair_mliap_kokkos.cpp +++ b/src/KOKKOS/pair_mliap_kokkos.cpp @@ -41,6 +41,7 @@ PairMLIAPKokkos::PairMLIAPKokkos(class LAMMPS* l) : PairMLIAP(l) kokkosable = 1; execution_space = ExecutionSpaceFromDevice::space; datamask_modify = 0; + is_child=true; } /* ---------------------------------------------------------------------- */ @@ -53,6 +54,10 @@ PairMLIAPKokkos::~PairMLIAPKokkos() memoryKK->destroy_kokkos(k_setflag, setflag); memoryKK->destroy_kokkos(k_eatom,eatom); memoryKK->destroy_kokkos(k_vatom,vatom); + delete model; + delete descriptor; + model=nullptr; + descriptor=nullptr; allocated = 0; } @@ -146,6 +151,7 @@ void PairMLIAPKokkos::allocate() template void PairMLIAPKokkos::settings(int narg, char ** arg) { + std::vector new_args; int iarg=0; while (iarg < narg) { if (strcmp(arg[iarg],"model") == 0) { @@ -163,8 +169,10 @@ void PairMLIAPKokkos::settings(int narg, char ** arg) #else error->all(FLERR,"Using pair_style mliap model mliappy requires ML-IAP with python support"); #endif - } else - iarg += 2; + } else { + new_args.push_back(arg[iarg++]); + new_args.push_back(arg[iarg++]); + } } else if (strcmp(arg[iarg],"descriptor") == 0) { if (strcmp(arg[iarg+1],"so3") == 0) { if (iarg+3 > narg) error->all(FLERR,"Illegal pair_style mliap command"); @@ -172,11 +180,11 @@ void PairMLIAPKokkos::settings(int narg, char ** arg) descriptor = new MLIAPDescriptorSO3Kokkos(lmp,arg[iarg+2]); iarg += 3; } else - iarg ++; + new_args.push_back(arg[iarg++]); } else - iarg++; + new_args.push_back(arg[iarg++]); } - PairMLIAP::settings(narg, arg); + PairMLIAP::settings(new_args.size(), new_args.data()); } diff --git a/src/ML-IAP/pair_mliap.cpp b/src/ML-IAP/pair_mliap.cpp index d5c8486115..28e8a1e493 100644 --- a/src/ML-IAP/pair_mliap.cpp +++ b/src/ML-IAP/pair_mliap.cpp @@ -49,7 +49,10 @@ PairMLIAP::PairMLIAP(LAMMPS *lmp) : restartinfo = 0; one_coeff = 1; manybody_flag = 1; + is_child = false; centroidstressflag = CENTROID_NOTAVAIL; + model=nullptr; + descriptor=nullptr; } /* ---------------------------------------------------------------------- */ @@ -61,7 +64,9 @@ PairMLIAP::~PairMLIAP() delete model; delete descriptor; delete data; - + model=nullptr; + descriptor=nullptr; + data=nullptr; if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); @@ -131,53 +136,51 @@ void PairMLIAP::settings(int narg, char ** arg) { if (narg < 2) utils::missing_cmd_args(FLERR, "pair_style mliap", error); + // This is needed because the unit test calls settings twice + if (!is_child) { + delete model; + model = nullptr; + delete descriptor; + descriptor = nullptr; + } + // process keywords - int iarg = 0; - - //Check to see if there are more than one model or descriptor - bool has_model=(model!=nullptr), has_descriptor=(descriptor!=nullptr); - int nmodel=0,ndescriptor=0; - for (int iarg=0;iargall(FLERR,"One can only specify one model and one descriptor"); while (iarg < narg) { if (strcmp(arg[iarg],"model") == 0) { if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap model", error); + if (model != nullptr) error->all(FLERR,"Illegal multiple pair_style mliap model definition"); if (strcmp(arg[iarg+1],"linear") == 0) { if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap model linear", error); - if (!has_model) model = new MLIAPModelLinear(lmp,arg[iarg+2]); + model = new MLIAPModelLinear(lmp,arg[iarg+2]); iarg += 3; } else if (strcmp(arg[iarg+1],"quadratic") == 0) { if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap model quadratic", error); - if (!has_model) model = new MLIAPModelQuadratic(lmp,arg[iarg+2]); + model = new MLIAPModelQuadratic(lmp,arg[iarg+2]); iarg += 3; } else if (strcmp(arg[iarg+1],"nn") == 0) { if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap model nn", error); - if (!has_model) model = new MLIAPModelNN(lmp,arg[iarg+2]); + model = new MLIAPModelNN(lmp,arg[iarg+2]); iarg += 3; } else if (strcmp(arg[iarg+1],"mliappy") == 0) { #ifdef MLIAP_PYTHON if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap mliappy", error); - if (!has_model) model = new MLIAPModelPython(lmp,arg[iarg+2]); + model = new MLIAPModelPython(lmp,arg[iarg+2]); iarg += 3; #else error->all(FLERR,"Using pair_style mliap model mliappy requires ML-IAP with python support"); #endif } else error->all(FLERR,"Unknown pair_style mliap model keyword: {}", arg[iarg]); - } else if (strcmp(arg[iarg],"descriptor") == 0 && (descriptor==nullptr || has_descriptor)) { + } else if (strcmp(arg[iarg],"descriptor") == 0) { if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap descriptor", error); + if (descriptor != nullptr) error->all(FLERR,"Illegal multiple pair_style mliap descriptor definition"); if (strcmp(arg[iarg+1],"sna") == 0) { if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap descriptor sna", error); - if (!has_descriptor) descriptor = new MLIAPDescriptorSNAP(lmp,arg[iarg+2]); + descriptor = new MLIAPDescriptorSNAP(lmp,arg[iarg+2]); iarg += 3; } else if (strcmp(arg[iarg+1],"so3") == 0) { if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap descriptor so3", error); - if (!has_descriptor) descriptor = new MLIAPDescriptorSO3(lmp,arg[iarg+2]); + descriptor = new MLIAPDescriptorSO3(lmp,arg[iarg+2]); iarg += 3; } else error->all(FLERR,"Illegal pair_style mliap command"); diff --git a/src/ML-IAP/pair_mliap.h b/src/ML-IAP/pair_mliap.h index a8327b11c6..9d7e08964d 100644 --- a/src/ML-IAP/pair_mliap.h +++ b/src/ML-IAP/pair_mliap.h @@ -44,6 +44,7 @@ class PairMLIAP : public Pair { class MLIAPModel *model; class MLIAPDescriptor *descriptor; class MLIAPData *data; + bool is_child; }; } // namespace LAMMPS_NS