Select Git revision
egg.cpython-310.pyc
-
Akke Esa Tapio Viitanen authoredAkke Esa Tapio Viitanen authored
tfrfme.cpp 33.08 KiB
/*! \file tfrfme.cpp
*
* \brief Implementation of the trapping calculation objects.
*/
#include <complex>
#include <exception>
#include <fstream>
#include <hdf5.h>
#include <string>
#ifndef INCLUDE_ERRORS_H_
#include "../include/errors.h"
#endif
#ifndef INCLUDE_LIST_H_
#include "../include/List.h"
#endif
#ifndef INCLUDE_TFRFME_H_
#include "../include/tfrfme.h"
#endif
#ifndef INCLUDE_FILE_IO_H_
#include "../include/file_io.h"
#endif
using namespace std;
// >>> START OF Swap1 CLASS IMPLEMENTATION <<<
Swap1::Swap1(int lm, int _nkv) {
nkv = _nkv;
nlmmt = 2 * lm * (lm + 2);
const int size = nkv * nkv * nlmmt;
wk = new complex<double>[size]();
last_index = 0;
}
Swap1* Swap1::from_binary(string file_name, string mode) {
Swap1 *instance = NULL;
if (mode.compare("LEGACY") == 0) {
instance = from_legacy(file_name);
} else if (mode.compare("HDF5") == 0) {
instance = from_hdf5(file_name);
} else {
string message = "Unknown format mode: \"" + mode + "\"";
throw UnrecognizedFormatException(message);
}
return instance;
}
Swap1* Swap1::from_hdf5(string file_name) {
Swap1 *instance = NULL;
unsigned int flags = H5F_ACC_RDONLY;
HDFFile *hdf_file = new HDFFile(file_name, flags);
herr_t status = hdf_file->get_status();
double *elements;
string str_type;
int _nlmmt, _nkv, lm, num_elements, index;
complex<double> value;
complex<double> *_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) + ")";