Skip to content

Commit

Permalink
replaced C-style arrays with std::vector (#26)
Browse files Browse the repository at this point in the history
* replaced C-style arrays with std::vector

* fixed copy constructor
  • Loading branch information
JensWehner authored Jan 24, 2021
1 parent 5731482 commit e6aa13d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
8 changes: 3 additions & 5 deletions include/libecpint/bessel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<double>> K; ///< Bessel function values
std::vector<std::vector<std::vector<double>>> dK; ///< Bessel function derivatives
std::vector<double> C; ///< Coefficients of derivatives of the Bessel function

/**
* Pretabulates the Bessel function (and derivs) to a given accuracy.
Expand All @@ -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.
Expand Down
20 changes: 5 additions & 15 deletions src/lib/bessel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<double>>(N+1,std::vector<double>(lMax + TAYLOR_CUT + 1,0.0));
C=std::vector<double>(lMax+TAYLOR_CUT,0.0);
dK=std::vector<std::vector<std::vector<double>>>(N+1,std::vector<std::vector<double>>(lMax + TAYLOR_CUT + 1,std::vector<double>(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) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/ecp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit e6aa13d

Please sign in to comment.