diff --git a/src/ML-PACE/compute_pace.cpp b/src/ML-PACE/compute_pace.cpp index 223b8b4b19..f9e5ff8a30 100644 --- a/src/ML-PACE/compute_pace.cpp +++ b/src/ML-PACE/compute_pace.cpp @@ -2,7 +2,7 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov + LAMMPS Development team: developers@lammps.org Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under @@ -30,13 +30,25 @@ #include "memory.h" #include "error.h" +namespace LAMMPS_NS { +struct ACECimpl { + ACECimpl() : basis_set(nullptr), ace(nullptr) {} + ~ACECimpl() + { + delete basis_set; + delete ace; + } + ACECTildeBasisSet *basis_set; + ACECTildeEvaluator *ace; +}; +} + using namespace LAMMPS_NS; enum{SCALAR,VECTOR,ARRAY}; ComputePACE::ComputePACE(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg), cutsq(nullptr), list(nullptr), pace(nullptr), - paceall(nullptr), pace_peratom(nullptr), - basis_set(nullptr), ace(nullptr), map(nullptr), cg(nullptr) + paceall(nullptr), pace_peratom(nullptr), map(nullptr), cg(nullptr) { array_flag = 1; extarray = 0; @@ -46,6 +58,7 @@ ComputePACE::ComputePACE(LAMMPS *lmp, int narg, char **arg) : int ntypes = atom->ntypes; int nargmin = 4; + acecimpl = new ACECimpl; if (narg < nargmin) error->all(FLERR,"Illegal compute pace command"); bikflag = utils::inumeric(FLERR, arg[4], false, lmp); @@ -63,9 +76,10 @@ ComputePACE::ComputePACE(LAMMPS *lmp, int narg, char **arg) : */ //read in file with CG coefficients or c_tilde coefficients - basis_set = new ACECTildeBasisSet(arg[3]); - double cut = basis_set->cutoffmax; - cutmax = basis_set->cutoffmax; + auto potential_file_name = utils::get_potential_file_path(arg[3]); + acecimpl -> basis_set = new ACECTildeBasisSet(potential_file_name); + double cut = acecimpl -> basis_set->cutoffmax; + cutmax = acecimpl -> basis_set->cutoffmax; double cuti; double radelemall = 0.5; /* @@ -87,8 +101,8 @@ ComputePACE::ComputePACE(LAMMPS *lmp, int narg, char **arg) : */ //# of rank 1, rank > 1 functions int n_r1, n_rp = 0; - n_r1 = basis_set->total_basis_size_rank1[0]; - n_rp = basis_set->total_basis_size[0]; + n_r1 = acecimpl -> basis_set->total_basis_size_rank1[0]; + n_rp = acecimpl -> basis_set->total_basis_size[0]; int ncoeff = n_r1 + n_rp; //int nvalues = ncoeff; @@ -229,10 +243,10 @@ void ComputePACE::compute_array() SPECIES_TYPE *mus; NS_TYPE *ns; LS_TYPE *ls; - + int n_r1, n_rp = 0; - n_r1 = basis_set->total_basis_size_rank1[0]; - n_rp = basis_set->total_basis_size[0]; + n_r1 = acecimpl -> basis_set->total_basis_size_rank1[0]; + n_rp = acecimpl -> basis_set->total_basis_size[0]; const int inum = list->inum; const int* const ilist = list->ilist; @@ -271,21 +285,21 @@ void ComputePACE::compute_array() const int typeoffset_local = ndims_peratom*nvalues*(itype-1); const int typeoffset_global = nvalues*(itype-1); - ace = new ACECTildeEvaluator(*basis_set); + acecimpl -> ace = new ACECTildeEvaluator(*acecimpl -> basis_set); int n_r1, n_rp = 0; n_r1 = basis_set->total_basis_size_rank1[0]; n_rp = basis_set->total_basis_size[0]; int ncoeff = n_r1 + n_rp; - ace->element_type_mapping.init(ntypes+1); + acecimpl -> ace->element_type_mapping.init(ntypes+1); for (int ik = 1; ik <= ntypes; ik++) { for(int mu = 0; mu < basis_set->nelements; mu++){ if (mu != -1) { if (mu == ik - 1) { map[ik] = mu; - ace->element_type_mapping(ik) = mu; + acecimpl -> ace->element_type_mapping(ik) = mu; } - } + } } } @@ -320,18 +334,18 @@ void ComputePACE::compute_array() } // resize the neighbor cache after setting the basis - ace->resize_neighbours_cache(max_jnum); - ace->compute_atom(i, atom->x, atom->type, list->numneigh[i], list->firstneigh[i]); + acecimpl -> ace->resize_neighbours_cache(max_jnum); + acecimpl -> ace->compute_atom(i, atom->x, atom->type, list->numneigh[i], list->firstneigh[i]); Array1D Bs =ace->B_all; for (int jj = 0; jj < jnum; jj++) { const int j = jlist[jj]; //replace mapping of jj to j - if (!dgradflag) { + if (!dgradflag) { double *pacedi = pace_peratom[i]+typeoffset_local; double *pacedj = pace_peratom[j]+typeoffset_local; - Array3D fs = ace->neighbours_dB; + Array3D fs = acecimpl -> ace->neighbours_dB; //force array in (func_ind,neighbour_ind,xyz_ind) format // dimension: (n_descriptors,max_jnum,3) //example to access entries for neighbour jj after running compute_atom for atom i: @@ -348,7 +362,7 @@ void ComputePACE::compute_array() } } else { //printf("inside dBi/dRj logical : ncoeff = %d \n", ncoeff); - Array3D fs = ace->neighbours_dB; + Array3D fs = acecimpl -> ace->neighbours_dB; for (int iicoeff = 0; iicoeff < ncoeff; iicoeff++) { // add to pace array for this proc @@ -381,10 +395,10 @@ void ComputePACE::compute_array() pace[irow][k++] += Bs(icoeff); } } - delete ace; + delete acecimpl -> ace; } //group bit } // for ii loop - delete basis_set; + delete acecimpl -> basis_set; // accumulate force contributions to global array if (!dgradflag){ for (int itype = 0; itype < atom->ntypes; itype++) { diff --git a/src/ML-PACE/compute_pace.h b/src/ML-PACE/compute_pace.h index 44d92ca280..266b16c615 100644 --- a/src/ML-PACE/compute_pace.h +++ b/src/ML-PACE/compute_pace.h @@ -1,7 +1,7 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov + LAMMPS Development team: developers@lammps.org Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains @@ -21,9 +21,6 @@ ComputeStyle(pace,ComputePACE); #define LMP_COMPUTE_PACE_H #include "compute.h" -#include "ace-evaluator/ace_c_basis.h" -#include "ace-evaluator/ace_evaluator.h" -#include "ace-evaluator/ace_abstract_basis.h" namespace LAMMPS_NS { @@ -49,13 +46,12 @@ class ComputePACE : public Compute { int nelements, chemflag; int bikflag, bik_rows, dgradflag, dgrad_rows; double *cg; - class ACECTildeEvaluator *ace; - class ACECTildeBasisSet *basis_set; double cutmax; Compute *c_pe; Compute *c_virial; void dbdotr_compute(); + struct ACECimpl *acecimpl; }; } // namespace LAMMPS_NS