From e6aa13d67e00158486f8eeea8f102f8cbaeb8da5 Mon Sep 17 00:00:00 2001 From: Jens Date: Mon, 25 Jan 2021 00:25:46 +0100 Subject: [PATCH] replaced C-style arrays with std::vector (#26) * replaced C-style arrays with std::vector * fixed copy constructor --- include/libecpint/bessel.hpp | 8 +++----- src/lib/bessel.cpp | 20 +++++--------------- src/lib/ecp.cpp | 1 + 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/include/libecpint/bessel.hpp b/include/libecpint/bessel.hpp index bbb0ac9..2420cef 100644 --- a/include/libecpint/bessel.hpp +++ b/include/libecpint/bessel.hpp @@ -51,9 +51,9 @@ namespace libecpint { int order; ///< Order to which the Bessel series is expanded double scale; ///< N/16.0 - double **K; ///< Bessel function values - double ***dK; ///< Bessel function derivatives - double *C; ///< Coefficients of derivatives of the Bessel function + std::vector> K; ///< Bessel function values + std::vector>> dK; ///< Bessel function derivatives + std::vector C; ///< Coefficients of derivatives of the Bessel function /** * Pretabulates the Bessel function (and derivs) to a given accuracy. @@ -69,8 +69,6 @@ namespace libecpint { /// Specified constructor. Will call init with given arguments. BesselFunction(int lMax, int N, int order, double accuracy); - /// Destructor, cleans up K and C - ~BesselFunction(); /** * Initialises and pretabulates the BesselFunction up to the given angular momentum. diff --git a/src/lib/bessel.cpp b/src/lib/bessel.cpp index 5cf83eb..9e30ea2 100644 --- a/src/lib/bessel.cpp +++ b/src/lib/bessel.cpp @@ -45,25 +45,15 @@ namespace libecpint { scale = N/16.0; // Allocate arrays - K = new double*[N+1]; - dK = new double**[N+1]; - for (int i = 0; i < N+1; i++) { - K[i] = new double[lMax + TAYLOR_CUT + 1]; - dK[i] = new double*[TAYLOR_CUT + 1]; - for (int j = 0; j < TAYLOR_CUT + 1; j++) - dK[i][j] = new double[lMax + TAYLOR_CUT + 1]; - } - C = new double[lMax+TAYLOR_CUT]; - + + K=std::vector>(N+1,std::vector(lMax + TAYLOR_CUT + 1,0.0)); + C=std::vector(lMax+TAYLOR_CUT,0.0); + dK=std::vector>>(N+1,std::vector>(lMax + TAYLOR_CUT + 1,std::vector(lMax + TAYLOR_CUT + 1,0.0))); // Tabulate values tabulate(accuracy); } - BesselFunction::~BesselFunction() { - free(K); - free(dK); - free(C); - } + // Tabulate the bessel function values int BesselFunction::tabulate(const double accuracy) { diff --git a/src/lib/ecp.cpp b/src/lib/ecp.cpp index c775cbf..d0c38ec 100644 --- a/src/lib/ecp.cpp +++ b/src/lib/ecp.cpp @@ -67,6 +67,7 @@ namespace libecpint { gaussians = other.gaussians; N = other.N; L = other.L; + atom_id=other.atom_id; min_exp = other.min_exp; for (int i = 0; i < LIBECPINT_MAX_L + 1; i++) { min_exp_l[i] = other.min_exp_l[i];