diff --git a/src/include/tra_subs.h b/src/include/tra_subs.h index 9aece525aa42b28f3ac933317c2b913c95269b6f..7038228c5018f97a3ec4a9165da969a04600fae6 100644 --- a/src/include/tra_subs.h +++ b/src/include/tra_subs.h @@ -107,7 +107,6 @@ void ffrt( * * \param nkv: `int` QUESTION: definition? * \param vkm: `double` QUESTION: definition? - * \param vkv: `double *` QUESTION: definition? * \param vknmx: `double` QUESTION: definition? * \param apfafa: `double` QUESTION: definition? * \param tra: `double` QUESTION: definition? @@ -118,12 +117,12 @@ void ffrt( * \param lmode: `int` QUESTION: definition? * \param pmf: `double` QUESTION: definition? * \param tt1: `Swap1 *` Pointer to first swap object. - * \param tt2: `fstream &` Handle to second temporary binary file. + * \param tt2: `Swap2 *` Pointer to second swap object. */ void frfmer( - int nkv, double vkm, double *vkv, double vknmx, double apfafa, double tra, + int nkv, double vkm, double vknmx, double apfafa, double tra, double spd, double rir, double ftcn, int le, int lmode, double pmf, - Swap1 *tt1, std::fstream &tt2 + Swap1 *tt1, Swap2 *tt2 ); /*! C++ porting of PWMALP diff --git a/src/libnptm/tfrfme.cpp b/src/libnptm/tfrfme.cpp index 675d90c4ccacd5297b60cce85d8a14772222670c..b126bbc7e051349d15af542b6465f99935fdf1b4 100644 --- a/src/libnptm/tfrfme.cpp +++ b/src/libnptm/tfrfme.cpp @@ -263,10 +263,10 @@ Swap2* Swap2::from_legacy(string file_name) { input.read(reinterpret_cast<char *>(&value), sizeof(double)); instance->set_vector_element(vj, value); } - for (int mi = 0; mi < _nkv; ,i++) { + for (int mi = 0; mi < _nkv; mi++) { for (int mj = 0; mj < _nkv; mj++) { input.read(reinterpret_cast<char *>(&value), sizeof(double)); - instance->set_matrix_element(vi, vj, value); + instance->set_matrix_element(mi, mj, value); } } input.read(reinterpret_cast<char *>(&value), sizeof(double)); @@ -432,7 +432,7 @@ void Swap2::write_hdf5(string file_name) { void Swap2::write_legacy(string file_name) { fstream output; - double value + double value; output.open(file_name.c_str(), ios::out | ios::binary); if (output.is_open()) { output.write(reinterpret_cast<char *>(&nkv), sizeof(int)); diff --git a/src/libnptm/tra_subs.cpp b/src/libnptm/tra_subs.cpp index e7a5287315f0c4b651a180e0f483f6ee783f841e..b87ea03d741eca41cfc0c016220582e7faaa6ad7 100644 --- a/src/libnptm/tra_subs.cpp +++ b/src/libnptm/tra_subs.cpp @@ -245,18 +245,18 @@ void ffrt( } void frfmer( - int nkv, double vkm, double *vkv, double vknmx, double apfafa, double tra, + int nkv, double vkm, double vknmx, double apfafa, double tra, double spd, double rir, double ftcn, int le, int lmode, double pmf, - Swap1 *tt1, std::fstream &tt2 + Swap1 *tt1, Swap2 *tt2 ) { const int nlemt = le * (le + 2) * 2; const complex<double> cc0(0.0, 0.0); double sq = vkm * vkm; for (int jy90 = 0; jy90 < nkv; jy90++) { - double vky = vkv[jy90]; + double vky = tt2->get_vector_element(jy90); double sqy = vky * vky; for (int jx80 = 0; jx80 < nkv; jx80++) { - double vkx = vkv[jx80]; + double vkx = tt2->get_vector_element(jx80); double sqx = vkx * vkx; double sqn = sqx + sqy; double vkn = sqrt(sqn); @@ -269,7 +269,8 @@ void frfmer( tt1.write(reinterpret_cast<char *>(&vreal), sizeof(double)); tt1.write(reinterpret_cast<char *>(&vimag), sizeof(double)); }*/ - tt2.write(reinterpret_cast<char *>(&vkz), sizeof(double)); + //tt2.write(reinterpret_cast<char *>(&vkz), sizeof(double)); + tt2->set_matrix_element(jx80, jy90, vkz); } else { // label 50 for (int j = 0; j < nlemt; j++) { //double vreal = 0.0; @@ -278,8 +279,9 @@ void frfmer( //tt1.write(reinterpret_cast<char *>(&vimag), sizeof(double)); tt1->set_element(j, cc0); } - double vkz = 0.0; - tt2.write(reinterpret_cast<char *>(&vkz), sizeof(double)); + //double vkz = 0.0; + //tt2.write(reinterpret_cast<char *>(&vkz), sizeof(double)); + tt2->set_matrix_element(jx80, jy90, 0.0); } } // jx80 loop } // jy90 loop diff --git a/src/trapping/cfrfme.cpp b/src/trapping/cfrfme.cpp index 7e2915171054ea250a6e7cb3ccbedb75798a0671..b99dd02d118014654fe39d364cc67089edcba212 100644 --- a/src/trapping/cfrfme.cpp +++ b/src/trapping/cfrfme.cpp @@ -44,9 +44,9 @@ void frfme(string data_file, string output_path) { string tfrfme_name = output_path + "/c_TFRFME.hd5"; TFRFME *tfrfme = NULL; Swap1 *tt1 = NULL; + Swap2 *tt2 = NULL; char namef[7]; char more; - double *vkv = NULL, **vkzm = NULL; complex<double> **w = NULL; const complex<double> cc0(0.0, 0.0); const complex<double> uim(0.0, 1.0); @@ -78,9 +78,9 @@ void frfme(string data_file, string output_path) { lmode = (int)tfrfme->get_param("lmode"); lm = (int)tfrfme->get_param("lm"); nkv = (int)tfrfme->get_param("nkv"); - nxv = (int)tfrfme->get_param("nkv"); - nyv = (int)tfrfme->get_param("nkv"); - nzv = (int)tfrfme->get_param("nkv"); + nxv = (int)tfrfme->get_param("nxv"); + nyv = (int)tfrfme->get_param("nyv"); + nzv = (int)tfrfme->get_param("nzv"); vk = tfrfme->get_param("vk"); exri = tfrfme->get_param("exri"); an = tfrfme->get_param("an"); @@ -89,33 +89,32 @@ void frfme(string data_file, string output_path) { spd = tfrfme->get_param("spd"); frsh = tfrfme->get_param("frsh"); exril = tfrfme->get_param("exril"); - vkv = new double[nkv](); - fstream temptape2; - string tempname2 = output_path + "/c_TEMPTAPE2"; - temptape2.open(tempname2.c_str(), ios::in | ios::binary); - if (temptape2.is_open()) { - for (int jx = 0; jx < nkv; jx++) temptape2.read(reinterpret_cast<char *>(&(vkv[jx])), sizeof(double)); + //fstream temptape2; + string tempname2 = output_path + "/c_TEMPTAPE2.hd5"; + //temptape2.open(tempname2.c_str(), ios::in | ios::binary); + if (tt2 == NULL) tt2 = Swap2::from_binary(tempname2, "HDF5"); + if (tt2 != NULL) { + /*for (int jx = 0; jx < nkv; jx++) temptape2.read(reinterpret_cast<char *>(&(vkv[jx])), sizeof(double)); vkzm = new double*[nkv]; for (int vki = 0; vki < nkv; vki++) vkzm[vki] = new double[nkv](); for (int jy10 = 0; jy10 < nkv; jy10++) { for (int jx10 = 0; jx10 < nkv; jx10++) { temptape2.read(reinterpret_cast<char *>(&(vkzm[jx10][jy10])), sizeof(double)); } //jx10 loop - } // jy10 loop - temptape2.read(reinterpret_cast<char *>(&apfafa), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&pmf), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&spd), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&rir), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&ftcn), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&fshmx), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&vxyzmx), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&delxyz), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&vknmx), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&delk), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&delks), sizeof(double)); - temptape2.read(reinterpret_cast<char *>(&nlmmt), sizeof(int)); - temptape2.read(reinterpret_cast<char *>(&nrvc), sizeof(int)); - temptape2.close(); + } // jy10 loop*/ + apfafa = tt2->get_param("apfafa"); + pmf = tt2->get_param("pmf"); + spd = tt2->get_param("spd"); + rir = tt2->get_param("rir"); + ftcn = tt2->get_param("ftcn"); + fshmx = tt2->get_param("fshmx"); + vxyzmx = tt2->get_param("vxyzmx"); + delxyz = tt2->get_param("delxyz"); + vknmx = tt2->get_param("vknmx"); + delk = tt2->get_param("delk"); + delks = tt2->get_param("delks"); + nlmmt = (int)tt2->get_param("nlmmt"); + nrvc = (int)tt2->get_param("nrvc"); } else { printf("ERROR: could not open TEMPTAPE2 file.\n"); } @@ -223,9 +222,10 @@ void frfme(string data_file, string output_path) { nks = nksh * 2; nkv = nks + 1; // Array initialization - vkv = new double[nkv](); + /*vkv = new double[nkv](); vkzm = new double*[nkv]; - for (int vi = 0; vi < nkv; vi++) vkzm[vi] = new double[nkv]; + for (int vi = 0; vi < nkv; vi++) vkzm[vi] = new double[nkv];*/ + tt2 = new Swap2(nkv); // End of array initialization double vkm = vk * exri; vknmx = vk * an; @@ -259,8 +259,8 @@ void frfme(string data_file, string output_path) { int nrvc = nxv * nyv * nzv; int nkshpo = nksh + 1; for (int i28 = nkshpo; i28 <= nks; i28++) { - vkv[i28] = vkv[i28 - 1] + delk; - vkv[nkv - i28 - 1] = -vkv[i28]; + tt2->set_vector_element(i28, tt2->get_vector_element(i28 - 1) + delk); + tt2->set_vector_element(nkv - i28 - 1, -tt2->get_vector_element(i28)); } // i28 loop if (tfrfme != NULL) { tfrfme->set_param("vk", vk); @@ -271,33 +271,33 @@ void frfme(string data_file, string output_path) { tfrfme->set_param("spd", spd); tfrfme->set_param("frsh", frsh); tfrfme->set_param("exril", exril); - fstream temptape1, temptape2; + //fstream temptape1, temptape2; string temp_name1 = output_path + "/c_TEMPTAPE1.hd5"; - string temp_name2 = output_path + "/c_TEMPTAPE2"; + string temp_name2 = output_path + "/c_TEMPTAPE2.hd5"; //temptape1.open(temp_name1.c_str(), ios::out | ios::binary); tt1 = new Swap1(lm); - temptape2.open(temp_name2.c_str(), ios::out | ios::binary); + /*temptape2.open(temp_name2.c_str(), ios::out | ios::binary); for (int jx = 0; jx < nkv; jx++) - temptape2.write(reinterpret_cast<char *>(&(vkv[jx])), sizeof(double)); - frfmer(nkv, vkm, vkv, vknmx, apfafa, tra, spd, rir, ftcn, lm, lmode, pmf, tt1, temptape2); + temptape2.write(reinterpret_cast<char *>(&(vkv[jx])), sizeof(double));*/ + frfmer(nkv, vkm, vknmx, apfafa, tra, spd, rir, ftcn, lm, lmode, pmf, tt1, tt2); //temptape1.close(); tt1->write_binary(temp_name1, "HDF5"); - temptape2.write(reinterpret_cast<char *>(&apfafa), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&pmf), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&spd), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&rir), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&ftcn), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&fshmx), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&vxyzmx), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&delxyz), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&vknmx), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&delk), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&delks), sizeof(double)); - temptape2.write(reinterpret_cast<char *>(&nlmmt), sizeof(int)); - temptape2.write(reinterpret_cast<char *>(&nrvc), sizeof(int)); - temptape2.close(); - temptape2.open("c_TEMPTAPE2", ios::in | ios::binary); - for (int jx = 0; jx < nkv; jx++) { + tt2->set_param("apfafa", apfafa); + tt2->set_param("pmf", pmf); + tt2->set_param("spd", spd); + tt2->set_param("rir", rir); + tt2->set_param("ftcn", ftcn); + tt2->set_param("fshmx", fshmx); + tt2->set_param("vxyzmx", vxyzmx); + tt2->set_param("delxyz", delxyz); + tt2->set_param("vknmx", vknmx); + tt2->set_param("delk", delk); + tt2->set_param("delks", delks); + tt2->set_param("nlmmt", 1.0 * nlmmt); + tt2->set_param("nrvc", 1.0 * nrvc); + tt2->write_binary(temp_name2, "HDF5"); + //temptape2.open("c_TEMPTAPE2", ios::in | ios::binary); + /*for (int jx = 0; jx < nkv; jx++) { double value = 0.0; temptape2.read(reinterpret_cast<char *>(&value), sizeof(double)); vkv[jx] = value; @@ -309,7 +309,7 @@ void frfme(string data_file, string output_path) { vkzm[jx40][jy40] = value; } } // jy40 loop - temptape2.close(); + temptape2.close();*/ for (int j80 = jlmf - 1; j80 < jlml; j80++) { // w matrix if (w != NULL) { @@ -344,16 +344,16 @@ void frfme(string data_file, string output_path) { ixyz++; complex<double> sumy = cc0; for (int jy60 = 0; jy60 < nkv; jy60++) { - double vky = vkv[jy60]; - double vkx = vkv[nkv - 1]; - double vkzf = vkzm[0][jy60]; - complex<double> phasf = exp(uim * (-vkx * x + vky * y +vkzf * z)); - double vkzl = vkzm[nkv - 1][jy60]; + double vky = tt2->get_vector_element(jy60); + double vkx = tt2->get_vector_element(nkv - 1); + double vkzf = tt2->get_matrix_element(0, jy60); + complex<double> phasf = exp(uim * (-vkx * x + vky * y + vkzf * z)); + double vkzl = tt2->get_matrix_element(nkv - 1, jy60); complex<double> phasl = exp(uim * (vkx * x + vky * y + vkzl * z)); complex<double> sumx = 0.5 * (w[0][jy60] * phasf + w[nkv - 1][jy60] * phasl); for (int jx55 = 2; jx55 <= nks; jx55++) { - vkx = vkv[jx55 - 1]; - double vkz = vkzm[jx55 - 1][jy60]; + vkx = tt2->get_vector_element(jx55 - 1); + double vkz = tt2->get_matrix_element(jx55 - 1, jy60); complex<double> phas = exp(uim * (vkx * x + vky * y + vkz * z)); sumx += (w[jx55 - 1][jy60] * phas); } // jx55 loop @@ -406,16 +406,12 @@ void frfme(string data_file, string output_path) { // label 45 if (tfrfme != NULL) delete tfrfme; delete[] file_lines; - if (vkv != NULL) delete[] vkv; - if (vkzm != NULL) { - for (int vki = nkv - 1; vki > -1; vki--) delete[] vkzm[vki]; - delete[] vkzm; - } + if (tt2 != NULL) delete tt2; if (w != NULL) { for (int wi = nkv - 1; wi > -1; wi--) delete[] w[wi]; delete[] w; } //if (wk != NULL) delete[] wk; if (tt1 != NULL) delete tt1; - printf("Done.\n"); + printf("FRFME: Done.\n"); } diff --git a/src/trapping/clffft.cpp b/src/trapping/clffft.cpp index 380e7e9e9a92d6685c6b3444ae36adeb6c3f7434..d44960b0f63580474d720ee2068f3f5de5be8ad2 100644 --- a/src/trapping/clffft.cpp +++ b/src/trapping/clffft.cpp @@ -442,5 +442,5 @@ void lffft(string data_file, string output_path) { delete cil; delete ccr; delete[] file_lines; - printf("Done.\n"); + printf("LFFT: Done.\n"); }