2021-02-16 10:49:15 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include "hdf5/serial/hdf5.h"
|
|
|
|
#include "H5Cpp.h"
|
|
|
|
|
|
|
|
#include "../SM_MaponiA3.hpp"
|
|
|
|
#include "../Helpers.hpp"
|
|
|
|
|
|
|
|
using namespace H5;
|
|
|
|
#define DEBUG 1
|
|
|
|
|
2021-02-24 18:41:48 +01:00
|
|
|
const H5std_string FILE_NAME( "datasets.small.hdf5" );
|
2021-02-16 10:49:15 +01:00
|
|
|
|
|
|
|
void read_int(H5File file, std::string key, unsigned int * data) {
|
|
|
|
DataSet ds = file.openDataSet(key);
|
|
|
|
ds.read(data, PredType::STD_U32LE);
|
|
|
|
ds.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void read_double(H5File file, std::string key, double * data) {
|
|
|
|
DataSet ds = file.openDataSet(key);
|
|
|
|
ds.read(data, PredType::IEEE_F64LE);
|
|
|
|
ds.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_cycle(H5File file, int cycle) {
|
|
|
|
|
|
|
|
/* Read the data */
|
|
|
|
|
|
|
|
std::string group = "cycle_" + std::to_string(cycle);
|
|
|
|
|
2021-02-24 18:41:48 +01:00
|
|
|
unsigned int dim, nupdates, col, i, j;
|
2021-02-16 10:49:15 +01:00
|
|
|
read_int(file, group + "/slater_matrix_dim", &dim);
|
|
|
|
read_int(file, group + "/nupdates", &nupdates);
|
|
|
|
|
|
|
|
double * slater_matrix = new double[dim*dim];
|
|
|
|
read_double(file, group + "/slater_matrix", slater_matrix);
|
|
|
|
|
|
|
|
double * slater_inverse = new double[dim*dim];
|
|
|
|
read_double(file, group + "/slater_inverse", slater_inverse);
|
2021-02-24 18:41:48 +01:00
|
|
|
slater_inverse = transpose(slater_inverse, dim);
|
2021-02-16 10:49:15 +01:00
|
|
|
|
|
|
|
unsigned int * col_update_index = new unsigned int[nupdates];
|
|
|
|
read_int(file, group + "/col_update_index", col_update_index);
|
|
|
|
|
|
|
|
double * updates = new double[nupdates*dim];
|
|
|
|
read_double(file, group + "/updates", updates);
|
|
|
|
|
|
|
|
/* Test */
|
|
|
|
#ifdef DEBUG
|
|
|
|
showMatrix(slater_matrix, dim, "Slater");
|
|
|
|
#endif
|
|
|
|
|
2021-02-24 18:41:48 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
showMatrix(slater_inverse, dim, "Inverse");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (j = 0; j < nupdates; j++) {
|
|
|
|
for (i = 0; i < dim; i++) {
|
|
|
|
col = col_update_index[j];
|
|
|
|
slater_matrix[i*dim + (col - 1)] += updates[i + j*dim];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 10:51:07 +01:00
|
|
|
MaponiA3(slater_inverse, dim, nupdates, updates, col_update_index);
|
2021-02-16 10:49:15 +01:00
|
|
|
|
2021-02-24 18:41:48 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
showMatrix(slater_matrix, dim, "Slater");
|
|
|
|
#endif
|
|
|
|
|
2021-02-16 10:49:15 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
showMatrix(slater_inverse, dim, "Inverse");
|
|
|
|
#endif
|
|
|
|
|
2021-02-24 18:41:48 +01:00
|
|
|
double * res = matMul2(slater_matrix, slater_inverse, dim);
|
2021-02-16 10:49:15 +01:00
|
|
|
bool ok = is_identity(res, dim, 1.0e-8);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
showMatrix(res, dim, "Result");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
delete [] res, updates, col_update_index, slater_matrix, slater_inverse;
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
if (argc != 2) {
|
2021-02-22 10:51:07 +01:00
|
|
|
std::cerr << "usage: ./test <cycle>" << std::endl;
|
2021-02-16 10:49:15 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int cycle = std::stoi(argv[1]);
|
|
|
|
H5File file(FILE_NAME, H5F_ACC_RDONLY);
|
|
|
|
|
2021-02-22 18:18:00 +01:00
|
|
|
bool ok = test_cycle(file, cycle);
|
2021-02-16 10:49:15 +01:00
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
std::cerr << "ok -- cycle " << std::to_string(cycle) << std::endl;
|
2021-02-24 18:41:48 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-02-16 10:49:15 +01:00
|
|
|
std::cerr << "failed -- cycle " << std::to_string(cycle) << std::endl;
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|