1#ifndef CSR_TEST_HELPERS_H
2#define CSR_TEST_HELPERS_H
14#include "gmock/gmock.h"
15#include "gtest/gtest.h"
33std::string read_file(
const std::string& filename)
35 std::ifstream ifs(filename.c_str());
36 std::ostringstream oss;
41std::vector<int> read_binary_ints(
const std::string& filename,
const size_t count)
43 std::ifstream ifs(filename.c_str(), std::ios::binary);
44 std::vector<int> values(count, 0);
45 for (
size_t i = 0;
i < count; ++
i)
47 ifs.read(
reinterpret_cast<char*
>(&values[i]),
sizeof(
int));
53T read_binary_value(std::ifstream& ifs)
56 ifs.read(
reinterpret_cast<char*
>(&value),
sizeof(
T));
60struct NativeDoubleRBlock
65 std::vector<double> values;
66 std::vector<int> columns;
67 std::vector<long long> row_ptr;
70struct NativeDoubleRecord
73 int format_version = 0;
76 std::vector<NativeDoubleRBlock> blocks;
79NativeDoubleRecord read_native_double_record(std::ifstream& ifs)
81 NativeDoubleRecord record;
82 record.magic = read_binary_value<int>(ifs);
83 record.format_version = read_binary_value<int>(ifs);
84 record.step = read_binary_value<int>(ifs);
85 record.nbasis = read_binary_value<int>(ifs);
86 const int nR = read_binary_value<int>(ifs);
87 record.blocks.resize(nR);
88 for (NativeDoubleRBlock& block: record.blocks)
90 block.rx = read_binary_value<int>(ifs);
91 block.ry = read_binary_value<int>(ifs);
92 block.rz = read_binary_value<int>(ifs);
93 const int nnz = read_binary_value<int>(ifs);
94 block.values.resize(nnz);
95 block.columns.resize(nnz);
96 block.row_ptr.resize(record.nbasis + 1);
97 for (
double& value: block.values)
99 value = read_binary_value<double>(ifs);
101 for (
int& column: block.columns)
103 column = read_binary_value<int>(ifs);
105 for (
long long& pointer: block.row_ptr)
107 pointer = read_binary_value<long long>(ifs);
113std::vector<std::string> read_lines(
const std::string& filename)
115 std::ifstream ifs(filename.c_str());
116 std::vector<std::string> lines;
118 while (std::getline(ifs, line))
120 lines.push_back(line);
125int count_substr(
const std::string& text,
const std::string& pattern)
128 std::string::size_type pos = 0;
129 while ((pos = text.find(pattern, pos)) != std::string::npos)
132 pos += pattern.size();
139 ucell.
latName =
"user_defined_lattice";
184void init_sparse_output_globals()
189void remove_derivative_files(
const std::string& fileflag,
int step = -1)
191 std::vector<std::string> filenames;
192 const std::string suffix = (step >= 0) ? (
"g" + std::to_string(step + 1) +
"_nao.csr") :
"_nao.csr";
194 const bool spin_suffix = (fileflag ==
"h");
195 for (
const char axis : {
'x',
'y',
'z'})
199 for (
int ispin = 1; ispin <= 2; ++ispin)
201 filenames.push_back(
"d" + fileflag +
"r" + axis +
"s" + std::to_string(ispin) + suffix);
206 filenames.push_back(
"d" + fileflag +
"r" + axis + suffix);
208 for (
int ispin = 1; ispin <= 2; ++ispin)
210 filenames.push_back(
"d" + fileflag +
"r" + axis +
"s" + std::to_string(ispin) + suffix);
214 for (
const std::string& filename: filenames)
216 std::remove(filename.c_str());
220bool starts_with(
const std::string& text,
const std::string& prefix)
222 return text.find(prefix) == 0;
Atom class for storing atom information.
Definition atom_spec.h:14
int na
Number of atoms in this type.
Definition atom_spec.h:44
int nw
number of local orbitals (l,n,m) of this type
Definition atom_spec.h:36
std::string label
atomic symbol
Definition atom_spec.h:51
std::vector< ModuleBase::Vector3< double > > taud
Direct coordinates of each atom in this type.
Definition atom_spec.h:54
double e11
element e_ij: i_row, j_column
Definition matrix3.h:22
double e33
Definition matrix3.h:22
double e22
Definition matrix3.h:22
3 elements vector
Definition vector3.h:21
void set_serial(const int nrglb, const int ncglb)
Definition parallel_blkcyc.cpp:239
Definition parallel_orbitals.h:16
Parallel_Blkcyclic & para_2d()
Definition parallel_orbitals.h:24
std::vector< int > atom_begin_col
Definition parallel_orbitals.h:117
std::vector< int > atom_begin_row
Definition parallel_orbitals.h:116
Provide the basic information about unitcell.
Definition unitcell.h:16
int ntype
number of atom species in UnitCell
Definition unitcell.h:154
Atom * atoms
Definition unitcell.h:165
double & lat0
Definition unitcell.h:135
ModuleBase::Matrix3 & latvec
Definition unitcell.h:142
bool set_atom_flag
added on 2009-3-8 by mohan
Definition unitcell.h:215
int nat
total number of atoms of all species in unitcell
Definition unitcell.h:155
std::string & latName
Definition unitcell.h:134
Definition atom_pair.h:45
Definition hcontainer.h:147
#define T
Definition exp.cpp:237
int DRANK
Definition global_variable.cpp:28
int4 i[880]
Definition sincos.cpp:28
const std::string matrix
Definition para_tag.h:35