From f333d5d5eda2e0ac7ca63302dae4a6d6b9add5aa Mon Sep 17 00:00:00 2001 From: Giovanni La Mura <giovanni.lamura@inaf.it> Date: Wed, 16 Apr 2025 12:21:34 +0200 Subject: [PATCH] Create read-only view of Swap1::wk vector --- src/include/tfrfme.h | 9 +++------ src/libnptm/tfrfme.cpp | 9 +++------ src/libnptm/tra_subs.cpp | 6 +++--- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/include/tfrfme.h b/src/include/tfrfme.h index be6ac562..ded5377a 100644 --- a/src/include/tfrfme.h +++ b/src/include/tfrfme.h @@ -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; } diff --git a/src/libnptm/tfrfme.cpp b/src/libnptm/tfrfme.cpp index df999983..37b872e2 100644 --- a/src/libnptm/tfrfme.cpp +++ b/src/libnptm/tfrfme.cpp @@ -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 { diff --git a/src/libnptm/tra_subs.cpp b/src/libnptm/tra_subs.cpp index 8d04f447..59496de9 100644 --- a/src/libnptm/tra_subs.cpp +++ b/src/libnptm/tra_subs.cpp @@ -269,9 +269,9 @@ void ffrt(dcomplex *ac, dcomplex *ws, double *ffte, double *ffts, CIL *cil) { } dcomplex *frfmer( - int nkv, double vkm, double vknmx, double apfafa, double tra, - double spd, double rir, double ftcn, int le, int lmode, double pmf, - Swap1 *tt1, Swap2 *tt2 + int nkv, double vkm, double vknmx, double apfafa, double tra, + double spd, double rir, double ftcn, int le, int lmode, double pmf, + Swap1 *tt1, Swap2 *tt2 ) { const int nlemt = le * (le + 2) * 2; const dcomplex cc0 = 0.0 + 0.0 * I; -- GitLab