Commit f333d5d5 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Create read-only view of Swap1::wk vector

parent 7a890ae7
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -63,6 +63,9 @@ protected:
  void write_legacy(const std::string& file_name);

public:
  //! \brief Read only view on WK.
  const dcomplex *vec_wk;
  
  /*! \brief Swap1 instance constructor.
   *
   * \param lm: `int` Maximum field expansion order.
@@ -97,12 +100,6 @@ public:
   */
  static long get_memory_requirement(int lm, int _nkv);
  
  /*! \brief Get the pointer to the WK vector.
   *
   * \return value: `complex double *` Memory address of the WK vector.
   */
  dcomplex *get_vector() { return wk; }

  /*! \brief Bring the pointer to the next element at the start of vector.
   */
  void reset() { last_index = 0; }
+3 −6
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ Swap1::Swap1(int lm, int _nkv) {
  nlmmt = 2 * lm * (lm + 2);
  const int size = nkv * nkv * nlmmt;
  wk = new dcomplex[size]();
  vec_wk = wk;
  last_index = 0;
}

@@ -77,21 +78,19 @@ Swap1* Swap1::from_hdf5(const std::string& file_name) {
  string str_type;
  int _nlmmt, _nkv, lm, num_elements, index;
  dcomplex value;
  dcomplex *_wk = NULL;
  if (status == 0) {
    status = hdf_file->read("NLMMT", "INT32", &_nlmmt);
    status = hdf_file->read("NKV", "INT32", &_nkv);
    lm = (int)((-2.0 + sqrt(4.0 + 2.0 * _nlmmt)) / 2.0);
    num_elements = 2 * _nlmmt * _nkv * _nkv;
    instance = new Swap1(lm, _nkv);
    _wk = instance->get_vector();
    elements = new double[num_elements]();
    str_type = "FLOAT64_(" + to_string(num_elements) + ")";
    status = hdf_file->read("WK", str_type, elements);
    for (int wi = 0; wi < num_elements / 2; wi++) {
      index = 2 * wi;
      value = elements[index] + elements[index + 1] * I;
      _wk[wi] = value;
      instance->wk[wi] = value;
    } // wi loop
    delete[] elements;
    status = hdf_file->close();
@@ -103,7 +102,6 @@ Swap1* Swap1::from_hdf5(const std::string& file_name) {
Swap1* Swap1::from_legacy(const std::string& file_name) {
  fstream input;
  Swap1 *instance = NULL;
  dcomplex *_wk = NULL;
  int _nlmmt, _nkv, lm;
  double rval, ival;
  input.open(file_name.c_str(), ios::in | ios::binary);
@@ -112,12 +110,11 @@ Swap1* Swap1::from_legacy(const std::string& file_name) {
    lm = (int)((-2.0 + sqrt(4.0 + 2.0 * _nlmmt)) / 2.0);
    input.read(reinterpret_cast<char *>(&_nkv), sizeof(int));
    instance = new Swap1(lm, _nkv);
    _wk = instance->get_vector();
    int num_elements = _nlmmt * _nkv * _nkv;
    for (int j = 0; j < num_elements; j++) {
      input.read(reinterpret_cast<char *>(&rval), sizeof(double));
      input.read(reinterpret_cast<char *>(&ival), sizeof(double));
      _wk[j] = rval + ival * I;
      instance->wk[j] = rval + ival * I;
    }
    input.close();
  } else {
+3 −3

File changed.

Contains only whitespace changes.