diff --git a/source/api_cc/include/DeepPot.h b/source/api_cc/include/DeepPot.h index 1c252938f6..0e61b03ce9 100644 --- a/source/api_cc/include/DeepPot.h +++ b/source/api_cc/include/DeepPot.h @@ -480,7 +480,7 @@ class DeepPotModelDevi { **/ double cutoff() const { assert(inited); - return rcut; + return dps[0].cutoff(); }; /** * @brief Get the number of types. @@ -488,7 +488,7 @@ class DeepPotModelDevi { **/ int numb_types() const { assert(inited); - return ntypes; + return dps[0].numb_types(); }; /** * @brief Get the number of types with spin. @@ -496,7 +496,7 @@ class DeepPotModelDevi { **/ int numb_types_spin() const { assert(inited); - return ntypes_spin; + return dps[0].numb_types_spin(); }; /** * @brief Get the dimension of the frame parameter. @@ -504,7 +504,7 @@ class DeepPotModelDevi { **/ int dim_fparam() const { assert(inited); - return dfparam; + return dps[0].dim_fparam(); }; /** * @brief Get the dimension of the atomic parameter. @@ -512,7 +512,7 @@ class DeepPotModelDevi { **/ int dim_aparam() const { assert(inited); - return daparam; + return dps[0].dim_aparam(); }; /** * @brief Compute the average energy. @@ -590,7 +590,7 @@ class DeepPotModelDevi { **/ bool is_aparam_nall() const { assert(inited); - return aparam_nall; + return dps[0].is_aparam_nall(); }; private: diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index 5f379a7693..528fe33f16 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -1242,22 +1242,10 @@ DeepPotModelDevi::DeepPotModelDevi( const int& gpu_rank, const std::vector& file_contents) : inited(false), init_nbor(false), numb_models(0) { - try { - init(models, gpu_rank, file_contents); - } catch (...) { - // Clean up and rethrow, as the destructor will not be called - for (unsigned ii = 0; ii < numb_models; ++ii) { - delete graph_defs[ii]; - } - throw; - } + init(models, gpu_rank, file_contents); } -DeepPotModelDevi::~DeepPotModelDevi() { - for (unsigned ii = 0; ii < numb_models; ++ii) { - delete graph_defs[ii]; - } -} +DeepPotModelDevi::~DeepPotModelDevi() {} void DeepPotModelDevi::init(const std::vector& models, const int& gpu_rank, @@ -1269,6 +1257,9 @@ void DeepPotModelDevi::init(const std::vector& models, return; } numb_models = models.size(); + if (numb_models == 0) { + throw deepmd::deepmd_exception("no model is specified"); + } for (unsigned int ii = 0; ii < numb_models; ++ii) { dps[ii] = DeepPot(models[ii], gpu_rank, file_contents[ii]); }