Commit 3392d185 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Remove C1_AddOns::allocate_vectors() and fix vector memory leak

parent 4f25511e
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -208,19 +208,6 @@ protected:
  //! \brief Maximum expansion order plus one. QUESTION: correct?
  int lmpo;

  /*! \brief Allocate the necessary common vectors depending on configuration.
   *
   * The size of the vectors and matrices defined in various common
   * blocks, and particularly in C1, depends on many settings of the
   * problem configuration, such as the number of spheres, the number
   * of layers the spheres are made of, the field expansion order and
   * others. This function collects the calculations needed to infer
   * the necessary amount of memory for these configurable elements,
   * thus making the class constructor more compact and easier to handle.
   *
   * \param c4: `C4 *` Pointer to a C4 structure.
   */
  void allocate_vectors(C4 *c4);
public:
  //! \brief QUESTION: definition?
  dcomplex *vh;
+5 −16
Original line number Diff line number Diff line
@@ -132,6 +132,11 @@ C1_AddOns::C1_AddOns(C4 *c4) {
  }
  vintm = new dcomplex[16]();
  vintt = new dcomplex[16]();
  // This calculates the size of v3j0
  const int nv3j = c4->nv3j;
  v3j0 = new double[nv3j]();
  ind3j = new int*[lmpo];
  for (int ii = 0; ii < lmpo; ii++) ind3j[ii] = new int[c4->lm]();
  fsac = new dcomplex*[2];
  sac = new dcomplex*[2];
  fsacm = new dcomplex*[2];
@@ -144,7 +149,6 @@ C1_AddOns::C1_AddOns(C4 *c4) {
  ecscp = new dcomplex[2]();
  scscpm = new dcomplex[2]();
  ecscpm = new dcomplex[2]();
  allocate_vectors(c4);
  sscs = new double[nsph]();
  ecscm = new double[2]();
  scscm = new double[2]();
@@ -185,21 +189,6 @@ C1_AddOns::~C1_AddOns() {
  delete[] ecsc;
}

void C1_AddOns::allocate_vectors(C4 *c4) {
  // This calculates the size of v3j0
  int lm = (c4->li > c4->le) ? c4->li : c4->le;
  const int nv3j = c4->nv3j;
  v3j0 = new double[nv3j]();
  ind3j = new int*[lmpo];
  for (int ii = 0; ii < lmpo; ii++) ind3j[ii] = new int[c4->lm]();
  // This calculates the size of vyhj
  int ivy = (nsph * nsph - 1) * c4->litpos;
  vyhj = new dcomplex[ivy]();
  // This calculates the size of vyj0
  ivy = c4->lmtpos * c4->nsph;
  vyj0 = new dcomplex[ivy]();
}

C2::C2(int ns, int nl, int npnt, int npntts) {
  nsph = ns;
  int max_n = (npnt > npntts) ? npnt : npntts;