diff --git a/src/include/tfrfme.h b/src/include/tfrfme.h index d6538c7bac1e7427181c716c8a35243c9ad3b9b2..950118b67562e264a6111edd1a6d7f7d56477641 100644 --- a/src/include/tfrfme.h +++ b/src/include/tfrfme.h @@ -95,10 +95,10 @@ public: /*! \brief Calculate the necessary amount of memory to create a new instance. * * \param lm: `int` Maximum field expansion order. - * \param _nkv: `int` Number of vector coordinates. QUESTION: correct? + * \param nkv: `int` Number of vector coordinates. QUESTION: correct? * \return size: `long` The necessary memory size in bytes. */ - static long get_memory_requirement(int lm, int nkv); + static long get_size(int lm, int nkv); /*! \brief Bring the pointer to the next element at the start of vector. */ @@ -127,41 +127,39 @@ public: class Swap2 { protected: //! Index of the last vector element to be filled. - int last_vector; + int _last_vector; //! Index of the last matrix element to be filled. - int last_matrix; + int _last_matrix; //! Number of vector coordinates. QUESTION: correct? - int nkv; - //! QUESTION: definition? - double *vkv; - //! QUESTION: definition? - double **vkzm; + int _nkv; + //! Contiguous vector of VKZM matrix. + double *vec_vkzm; //! QUESTION: definition? - double apfafa; + double _apfafa; //! QUESTION: definition? - double pmf; + double _pmf; //! QUESTION: definition? - double spd; + double _spd; //! QUESTION: definition? - double rir; + double _rir; //! QUESTION: definition? - double ftcn; + double _ftcn; //! QUESTION: definition? - double fshmx; + double _fshmx; //! QUESTION: definition? - double vxyzmx; + double _vxyzmx; //! Cartesian displacement. QUESTION: correct? - double delxyz; + double _delxyz; //! QUESTION: definition? - double vknmx; + double _vknmx; //! QUESTION: definition? - double delk; + double _delk; //! QUESTION: definition? - double delks; + double _delks; //! NLMMT = LM * (LM + 2) * 2 - int nlmmt; + int _nlmmt; //! Number of radial vector coordinates. QUESTION: correct? - int nrvc; + int _nrvc; /*! \brief Load a Swap2 instance from a HDF5 binary file. * @@ -190,11 +188,48 @@ protected: void write_legacy(const std::string& file_name); public: + //! Read-only view onthe index of the last vector element to be filled. + const int &last_vector = _last_vector; + //! Read-only view on the index of the last matrix element to be filled. + const int &last_matrix = _last_matrix; + //! Read-only view on the number of vector coordinates. QUESTION: correct? + const int &nkv = _nkv; + //! QUESTION: definition? + double *vkv; + //! QUESTION: definition? + double **vkzm; + //! QUESTION: definition? + const double &apfafa = _apfafa; + //! QUESTION: definition? + const double &pmf = _pmf; + //! QUESTION: definition? + const double &spd = _spd; + //! QUESTION: definition? + const double &rir = _rir; + //! QUESTION: definition? + const double &ftcn = _ftcn; + //! QUESTION: definition? + const double &fshmx = _fshmx; + //! QUESTION: definition? + const double &vxyzmx = _vxyzmx; + //! Cartesian displacement. QUESTION: correct? + const double &delxyz = _delxyz; + //! QUESTION: definition? + const double &vknmx = _vknmx; + //! QUESTION: definition? + const double &delk = _delk; + //! QUESTION: definition? + const double &delks = _delks; + //! NLMMT = LM * (LM + 2) * 2 + const int &nlmmt = _nlmmt; + //! Number of radial vector coordinates. QUESTION: correct? + const int &nrvc = _nrvc; + /*! \brief Swap2 instance constructor. * - * \param _nkv: `int` Number of vector coordinates. QUESTION: correct? + * \param nkv: `int` Number of vector coordinates. QUESTION: correct? */ - Swap2(int _nkv); + Swap2(int nkv); /*! \brief Swap2 instance destroyer. */ @@ -217,17 +252,10 @@ public: /*! \brief Calculate the necessary amount of memory to create a new instance. * - * \param _nkv: `int` Number of radial vector coordinates. QUESTION: correct? + * \param nkv: `int` Number of radial vector coordinates. QUESTION: correct? * \return size: `long` The necessary memory size in bytes. */ - static long get_memory_requirement(int _nkv); - - /*! \brief Get a parameter by its name. - * - * \param param_name: `string` Name of the parameter. - * \return value: `double` The value of the requested parameter. - */ - double get_param(const std::string& param_name); + static long get_size(int nkv); /*! \brief Get the pointer to the VKV vector. * @@ -245,15 +273,15 @@ public: * * \param value: `double` The value to be pushed in the vector. */ - void push_vector(double value) { vkv[last_vector++] = value; } + void push_vector(double value) { vkv[_last_vector++] = value; } /*! \brief Bring the matrix pointer to the start of the array. */ - void reset_matrix() { last_matrix = 0; } + void reset_matrix() { _last_matrix = 0; } /*! \brief Bring the vector pointer to the start of the array. */ - void reset_vector() { last_vector = 0; } + void reset_vector() { _last_vector = 0; } /*! \brief Set a parameter by its name and value. * diff --git a/src/libnptm/tfrfme.cpp b/src/libnptm/tfrfme.cpp index 98455ef4f63b5be5e30bc604f5d3e88dc0a78921..d8958b95e23b13f81f2b205ce2dfaa9f4f041e88 100644 --- a/src/libnptm/tfrfme.cpp +++ b/src/libnptm/tfrfme.cpp @@ -123,7 +123,7 @@ Swap1* Swap1::from_legacy(const std::string& file_name) { return instance; } -long Swap1::get_memory_requirement(int lm, int nkv) { +long Swap1::get_size(int lm, int nkv) { long size = (long)(3 * sizeof(int)); size += (long)(sizeof(dcomplex) * 2 * lm * (lm + 2) * nkv * nkv); return size; @@ -218,18 +218,19 @@ bool Swap1::operator ==(Swap1 &other) { // >>> END OF Swap1 CLASS IMPLEMENTATION <<< // >>> START OF Swap2 CLASS IMPLEMENTATION <<< -Swap2::Swap2(int _nkv) { - nkv = _nkv; - vkv = new double[nkv](); +Swap2::Swap2(int nkv) { + _nkv = nkv; + vkv = new double[_nkv](); + vec_vkzm = new double[_nkv * _nkv](); vkzm = new double*[nkv]; - for (int vi = 0; vi < nkv; vi++) vkzm[vi] = new double[nkv](); - last_vector = 0; - last_matrix = 0; + for (int vi = 0; vi < _nkv; vi++) vkzm[vi] = vec_vkzm + vi * _nkv; + _last_vector = 0; + _last_matrix = 0; } Swap2::~Swap2() { delete[] vkv; - for (int vi = nkv - 1; vi > -1; vi--) delete[] vkzm[vi]; + delete[] vec_vkzm; delete[] vkzm; } @@ -252,15 +253,15 @@ Swap2* Swap2::from_hdf5(const std::string& file_name) { HDFFile *hdf_file = new HDFFile(file_name, flags); herr_t status = hdf_file->get_status(); string str_type; - int _nkv, _nlmmt, _nrvc; + int fnkv, fnlmmt, fnrvc; double value; if (status == 0) { - status = hdf_file->read("NKV", "INT32", &_nkv); - instance = new Swap2(_nkv); - str_type = "FLOAT64_(" + to_string(_nkv) + ")"; + status = hdf_file->read("NKV", "INT32", &fnkv); + instance = new Swap2(fnkv); + str_type = "FLOAT64_(" + to_string(fnkv) + ")"; status = hdf_file->read("VKV", str_type, instance->vkv); - str_type = "FLOAT64_(" + to_string(_nkv) + "," + to_string(_nkv) + ")"; - status = hdf_file->read("VKZM", str_type, instance->vkzm); + str_type = "FLOAT64_(" + to_string(fnkv * fnkv) + ")"; + status = hdf_file->read("VKZM", str_type, instance->vec_vkzm); status = hdf_file->read("APFAFA", "FLOAT64", &value); instance->set_param("apfafa", value); status = hdf_file->read("PMF", "FLOAT64", &value); @@ -283,10 +284,10 @@ Swap2* Swap2::from_hdf5(const std::string& file_name) { instance->set_param("delk", value); status = hdf_file->read("DELKS", "FLOAT64", &value); instance->set_param("delks", value); - status = hdf_file->read("NLMMT", "INT32", &_nlmmt); - instance->set_param("nlmmt", 1.0 * _nlmmt); - status = hdf_file->read("NRVC", "INT32", &_nrvc); - instance->set_param("nrvc", 1.0 * _nrvc); + status = hdf_file->read("NLMMT", "INT32", &fnlmmt); + instance->set_param("nlmmt", 1.0 * fnlmmt); + status = hdf_file->read("NRVC", "INT32", &fnrvc); + instance->set_param("nrvc", 1.0 * fnrvc); status = hdf_file->close(); delete hdf_file; } @@ -296,24 +297,24 @@ Swap2* Swap2::from_hdf5(const std::string& file_name) { Swap2* Swap2::from_legacy(const std::string& file_name) { fstream input; Swap2 *instance = NULL; - int _nkv, _nlmmt, _nrvc; - double **_vkzm = NULL; - double *_vkv = NULL; + int fnkv, fnlmmt, fnrvc; + double **fvkzm = NULL; + double *fvkv = NULL; double value; input.open(file_name.c_str(), ios::in | ios::binary); if (input.is_open()) { - input.read(reinterpret_cast<char *>(&_nkv), sizeof(int)); - instance = new Swap2(_nkv); - _vkzm = instance->get_matrix(); - _vkv = instance->get_vector(); - for (int vj = 0; vj < _nkv; vj++) { + input.read(reinterpret_cast<char *>(&fnkv), sizeof(int)); + instance = new Swap2(fnkv); + fvkzm = instance->get_matrix(); + fvkv = instance->get_vector(); + for (int vj = 0; vj < fnkv; vj++) { input.read(reinterpret_cast<char *>(&value), sizeof(double)); - _vkv[vj] = value; + fvkv[vj] = value; } - for (int mi = 0; mi < _nkv; mi++) { - for (int mj = 0; mj < _nkv; mj++) { + for (int mi = 0; mi < fnkv; mi++) { + for (int mj = 0; mj < fnkv; mj++) { input.read(reinterpret_cast<char *>(&value), sizeof(double)); - _vkzm[mi][mj] = value; + fvkzm[mi][mj] = value; } } input.read(reinterpret_cast<char *>(&value), sizeof(double)); @@ -338,10 +339,10 @@ Swap2* Swap2::from_legacy(const std::string& file_name) { instance->set_param("delk", value); input.read(reinterpret_cast<char *>(&value), sizeof(double)); instance->set_param("delks", value); - input.read(reinterpret_cast<char *>(&_nlmmt), sizeof(int)); - instance->set_param("nlmmt", 1.0 * _nlmmt); - input.read(reinterpret_cast<char *>(&_nrvc), sizeof(int)); - instance->set_param("nrvc", 1.0 * _nrvc); + input.read(reinterpret_cast<char *>(&fnlmmt), sizeof(int)); + instance->set_param("nlmmt", 1.0 * fnlmmt); + input.read(reinterpret_cast<char *>(&fnrvc), sizeof(int)); + instance->set_param("nrvc", 1.0 * fnrvc); input.close(); } else { printf("ERROR: could not open input file \"%s\"\n", file_name.c_str()); @@ -349,57 +350,34 @@ Swap2* Swap2::from_legacy(const std::string& file_name) { return instance; } -long Swap2::get_memory_requirement(int _nkv) { - long size = (long)(5 * sizeof(int) + 11 * sizeof(double)); - size += (long)(sizeof(double) * _nkv * (_nkv + 1)); +long Swap2::get_size(int nkv) { + long size = (long)(10 * sizeof(int) + 22 * sizeof(double)); + size += (long)(sizeof(double) * nkv * (nkv + 1)); return size; } -double Swap2::get_param(const std::string& param_name) { - double value; - if (param_name.compare("nkv") == 0) value = 1.0 * nkv; - else if (param_name.compare("apfafa") == 0) value = apfafa; - else if (param_name.compare("pmf") == 0) value = pmf; - else if (param_name.compare("spd") == 0) value = spd; - else if (param_name.compare("rir") == 0) value = rir; - else if (param_name.compare("ftcn") == 0) value = ftcn; - else if (param_name.compare("fshmx") == 0) value = fshmx; - else if (param_name.compare("vxyzmx") == 0) value = vxyzmx; - else if (param_name.compare("delxyz") == 0) value = delxyz; - else if (param_name.compare("vknmx") == 0) value = vknmx; - else if (param_name.compare("delk") == 0) value = delk; - else if (param_name.compare("delks") == 0) value = delks; - else if (param_name.compare("nlmmt") == 0) value = 1.0 * nlmmt; - else if (param_name.compare("nrvc") == 0) value = 1.0 * nrvc; - else { - string message = "Unrecognized parameter name \"" + param_name + "\""; - throw UnrecognizedParameterException(message); - } - return value; -} - void Swap2::push_matrix(double value) { - int col = last_matrix % (nkv - 1); - int row = last_matrix - (nkv * row); + int col = _last_matrix % (_nkv - 1); + int row = _last_matrix - (_nkv * row); vkzm[row][col] = value; - last_matrix++; + _last_matrix++; } void Swap2::set_param(const std::string& param_name, double value) { - if (param_name.compare("nkv") == 0) nkv = (int)value; - else if (param_name.compare("apfafa") == 0) apfafa = value; - else if (param_name.compare("pmf") == 0) pmf = value; - else if (param_name.compare("spd") == 0) spd = value; - else if (param_name.compare("rir") == 0) rir = value; - else if (param_name.compare("ftcn") == 0) ftcn = value; - else if (param_name.compare("fshmx") == 0) fshmx = value; - else if (param_name.compare("vxyzmx") == 0) vxyzmx = value; - else if (param_name.compare("delxyz") == 0) delxyz = value; - else if (param_name.compare("vknmx") == 0) vknmx = value; - else if (param_name.compare("delk") == 0) delk = value; - else if (param_name.compare("delks") == 0) delks = value; - else if (param_name.compare("nlmmt") == 0) nlmmt = (int)value; - else if (param_name.compare("nrvc") == 0) nrvc = (int)value; + if (param_name.compare("nkv") == 0) _nkv = (int)value; + else if (param_name.compare("apfafa") == 0) _apfafa = value; + else if (param_name.compare("pmf") == 0) _pmf = value; + else if (param_name.compare("spd") == 0) _spd = value; + else if (param_name.compare("rir") == 0) _rir = value; + else if (param_name.compare("ftcn") == 0) _ftcn = value; + else if (param_name.compare("fshmx") == 0) _fshmx = value; + else if (param_name.compare("vxyzmx") == 0) _vxyzmx = value; + else if (param_name.compare("delxyz") == 0) _delxyz = value; + else if (param_name.compare("vknmx") == 0) _vknmx = value; + else if (param_name.compare("delk") == 0) _delk = value; + else if (param_name.compare("delks") == 0) _delks = value; + else if (param_name.compare("nlmmt") == 0) _nlmmt = (int)value; + else if (param_name.compare("nrvc") == 0) _nrvc = (int)value; else { string message = "Unrecognized parameter name \"" + param_name + "\""; throw UnrecognizedParameterException(message); @@ -425,54 +403,54 @@ void Swap2::write_hdf5(const std::string& file_name) { string str_type; rec_name_list.set(0, "NKV"); rec_type_list.set(0, "INT32_(1)"); - rec_ptr_list.set(0, &nkv); + rec_ptr_list.set(0, &_nkv); rec_name_list.append("VKV"); - str_type = "FLOAT64_(" + to_string(nkv) + ")"; + str_type = "FLOAT64_(" + to_string(_nkv) + ")"; rec_type_list.append(str_type); rec_ptr_list.append(vkv); rec_name_list.append("VKZM"); - str_type = "FLOAT64_(" + to_string(nkv) + "," + to_string(nkv) + ")"; + str_type = "FLOAT64_(" + to_string(_nkv * _nkv) + ")"; rec_type_list.append(str_type); - rec_ptr_list.append(vkzm); + rec_ptr_list.append(vec_vkzm); rec_name_list.append("APFAFA"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&apfafa); + rec_ptr_list.append(&_apfafa); rec_name_list.append("PMF"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&pmf); + rec_ptr_list.append(&_pmf); rec_name_list.append("SPD"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&spd); + rec_ptr_list.append(&_spd); rec_name_list.append("RIR"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&rir); + rec_ptr_list.append(&_rir); rec_name_list.append("FTCN"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&ftcn); + rec_ptr_list.append(&_ftcn); rec_name_list.append("FSHMX"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&fshmx); + rec_ptr_list.append(&_fshmx); rec_name_list.append("VXYZMX"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&vxyzmx); + rec_ptr_list.append(&_vxyzmx); rec_name_list.append("delxyz"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&delxyz); + rec_ptr_list.append(&_delxyz); rec_name_list.append("VKNMX"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&vknmx); + rec_ptr_list.append(&_vknmx); rec_name_list.append("DELK"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&delk); + rec_ptr_list.append(&_delk); rec_name_list.append("DELKS"); rec_type_list.append("FLOAT64_(1)"); - rec_ptr_list.append(&delks); + rec_ptr_list.append(&_delks); rec_name_list.append("NLMMT"); rec_type_list.append("INT32_(1)"); - rec_ptr_list.append(&nlmmt); + rec_ptr_list.append(&_nlmmt); rec_name_list.append("NRVC"); rec_type_list.append("INT32_(1)"); - rec_ptr_list.append(&nrvc); + rec_ptr_list.append(&_nrvc); string *rec_names = rec_name_list.to_array(); string *rec_types = rec_type_list.to_array(); @@ -495,30 +473,30 @@ void Swap2::write_legacy(const std::string& file_name) { double value; output.open(file_name.c_str(), ios::out | ios::binary); if (output.is_open()) { - output.write(reinterpret_cast<char *>(&nkv), sizeof(int)); - for (int j = 0; j < nkv; j++){ + output.write(reinterpret_cast<char *>(&_nkv), sizeof(int)); + for (int j = 0; j < _nkv; j++){ value = vkv[j]; output.write(reinterpret_cast<const char*>(&value), sizeof(double)); } - for (int mi = 0; mi < nkv; mi++) { - for (int mj = 0; mj < nkv; mj++) { + for (int mi = 0; mi < _nkv; mi++) { + for (int mj = 0; mj < _nkv; mj++) { value = vkzm[mi][mj]; output.write(reinterpret_cast<const char*>(&value), sizeof(double)); } } - output.write(reinterpret_cast<const char*>(&apfafa), sizeof(double)); - output.write(reinterpret_cast<const char*>(&pmf), sizeof(double)); - output.write(reinterpret_cast<const char*>(&spd), sizeof(double)); - output.write(reinterpret_cast<const char*>(&rir), sizeof(double)); - output.write(reinterpret_cast<const char*>(&ftcn), sizeof(double)); - output.write(reinterpret_cast<const char*>(&fshmx), sizeof(double)); - output.write(reinterpret_cast<const char*>(&vxyzmx), sizeof(double)); - output.write(reinterpret_cast<const char*>(&delxyz), sizeof(double)); - output.write(reinterpret_cast<const char*>(&vknmx), sizeof(double)); - output.write(reinterpret_cast<const char*>(&delk), sizeof(double)); - output.write(reinterpret_cast<const char*>(&delks), sizeof(double)); - output.write(reinterpret_cast<const char*>(&nlmmt), sizeof(int)); - output.write(reinterpret_cast<const char*>(&nrvc), sizeof(int)); + output.write(reinterpret_cast<const char*>(&_apfafa), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_pmf), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_spd), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_rir), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_ftcn), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_fshmx), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_vxyzmx), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_delxyz), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_vknmx), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_delk), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_delks), sizeof(double)); + output.write(reinterpret_cast<const char*>(&_nlmmt), sizeof(int)); + output.write(reinterpret_cast<const char*>(&_nrvc), sizeof(int)); output.close(); } else { // Should never occur printf("ERROR: could not open output file \"%s\"\n", file_name.c_str()); @@ -526,55 +504,55 @@ void Swap2::write_legacy(const std::string& file_name) { } bool Swap2::operator ==(Swap2 &other) { - if (nlmmt != other.nlmmt) { + if (_nlmmt != other._nlmmt) { return false; } - if (nrvc != other.nrvc) { + if (_nrvc != other._nrvc) { return false; } - if (nkv != other.nkv) { + if (_nkv != other._nkv) { return false; } - if (apfafa != other.apfafa) { + if (_apfafa != other._apfafa) { return false; } - if (pmf != other.pmf) { + if (_pmf != other._pmf) { return false; } - if (spd != other.spd) { + if (_spd != other._spd) { return false; } - if (rir != other.rir) { + if (_rir != other._rir) { return false; } - if (ftcn != other.ftcn) { + if (_ftcn != other._ftcn) { return false; } - if (fshmx != other.fshmx) { + if (_fshmx != other._fshmx) { return false; } - if (vxyzmx != other.vxyzmx) { + if (_vxyzmx != other._vxyzmx) { return false; } - if (delxyz != other.delxyz) { + if (_delxyz != other._delxyz) { return false; } - if (vknmx != other.vknmx) { + if (_vknmx != other._vknmx) { return false; } - if (delk != other.delk) { + if (_delk != other._delk) { return false; } - if (delks != other.delks) { + if (_delks != other._delks) { return false; } - for (int vi = 0; vi < nkv; vi++) { + for (int vi = 0; vi < _nkv; vi++) { if (vkv[vi] != other.vkv[vi]) { return false; } } - for (int mi = 0; mi < nkv; mi++) { - for (int mj = 0; mj < nkv; mj++) { + for (int mi = 0; mi < _nkv; mi++) { + for (int mj = 0; mj < _nkv; mj++) { if (vkzm[mi][mj] != other.vkzm[mi][mj]) { return false; } diff --git a/src/libnptm/tra_subs.cpp b/src/libnptm/tra_subs.cpp index 59496de9b3d642b013c36d394db50e5989ce9017..1f331aef406dcec1e02d86ef16489b01638e565f 100644 --- a/src/libnptm/tra_subs.cpp +++ b/src/libnptm/tra_subs.cpp @@ -291,12 +291,9 @@ dcomplex *frfmer( double vkz = sqrt(sq - sqn); wamff(wk, vkx, vky, vkz, le, apfafa, tra, spd, rir, ftcn, lmode, pmf); for (int j = 0; j < nlemt; j++) tt1->append(wk[j]); - //tt2.write(reinterpret_cast<char *>(&vkz), sizeof(double)); _vkzm[jx80][jy90] = vkz; } else { // label 50 for (int j = 0; j < nlemt; j++) tt1->append(cc0); - //double vkz = 0.0; - //tt2.write(reinterpret_cast<char *>(&vkz), sizeof(double)); _vkzm[jx80][jy90] = 0.0; } } // jx80 loop