1#ifndef HS_SPARSE_IO_DETAIL_H
2#define HS_SPARSE_IO_DETAIL_H
37template <
typename Tdata>
40 const std::set<RCoordinate>& all_R_coor,
44 std::vector<long long> nonzero_num(all_R_coor.size(), 0);
49 if (iter != smat.end())
53 for (
const std::pair<const std::size_t, Tdata>& col_value: row_loop.second)
55 if (std::abs(col_value.second) >
threshold)
79 const std::string& filename,
80 const std::string& context)
99 return out_app_flag == 1 && istep > 0;
117 const std::string& spin_suffix,
120 const std::string& extension)
125 "File name prefix must not be empty.");
127 if (extension.empty() || extension[0] !=
'.')
130 "File extension must start with a dot.");
133 std::string name = prefix + spin_suffix;
134 if (numbered && istep >= 0)
136 name +=
"g" + std::to_string(istep + 1);
138 name +=
"_nao" + extension;
169 if (header.
ucell ==
nullptr)
172 "UnitCell pointer must not be null.");
174 if (header.
nspin <= 0)
177 "Number of spin directions must be positive.");
182 "Spin index must be within the spin range.");
187 "Number of localized basis functions must be positive.");
192 "Number of Bravais lattice vectors must not be negative.");
198 ofs <<
" " << header.
nspin <<
" # number of spin directions" << std::endl;
199 ofs <<
" " << header.
ispin <<
" # spin index";
202 ofs <<
", E_Fermi = " << std::setprecision(6) << header.
efermi_eV <<
" eV";
205 ofs <<
" " << header.
nbasis <<
" # number of localized basis" << std::endl;
206 ofs <<
" " << header.
number_of_R <<
" # number of Bravais lattice vector R" << std::endl;
232 const int number_of_R)
234 ofs.write(
reinterpret_cast<const char*
>(&step),
sizeof(
int));
235 ofs.write(
reinterpret_cast<const char*
>(&nbasis),
sizeof(
int));
236 ofs.write(
reinterpret_cast<const char*
>(&number_of_R),
sizeof(
int));
255 const bool leading_space)
259 if (nnz >
static_cast<long long>(std::numeric_limits<int>::max()))
262 "Too many non-zero elements for the binary R record.");
264 const int count =
static_cast<int>(nnz);
265 ofs.write(
reinterpret_cast<const char*
>(&rx),
sizeof(
int));
266 ofs.write(
reinterpret_cast<const char*
>(&ry),
sizeof(
int));
267 ofs.write(
reinterpret_cast<const char*
>(&rz),
sizeof(
int));
268 ofs.write(
reinterpret_cast<const char*
>(&count),
sizeof(
int));
276 ofs << rx <<
" " << ry <<
" " << rz <<
" " << nnz << std::endl;
Definition abfs_vector3_order.h:16
static void write_ucell(std::ofstream &ofs, const UnitCell *ucell)
Writes the unit cell information to a file.
Definition ucell_io.cpp:8
Provide the basic information about unitcell.
Definition unitcell.h:16
void WARNING_QUIT(const std::string &, const std::string &)
Combine the functions of WARNING and QUIT.
Definition test_delley.cpp:15
Definition hs_sparse_io_detail.h:28
void write_csr_text_header(std::ofstream &ofs, const CsrTextHeader &header)
Write the common self-describing header of a CSR text file.
Definition hs_sparse_io_detail.h:167
void write_R_record(std::ofstream &ofs, const int rx, const int ry, const int rz, const long long nnz, const bool binary, const bool leading_space)
Write the "Rx Ry Rz nnz" record that starts one R block.
Definition hs_sparse_io_detail.h:249
bool append_ionic_step(const int out_app_flag, const int istep)
Decide whether the current ionic step appends to an existing file.
Definition hs_sparse_io_detail.h:97
std::vector< long long > count_nonzeros_by_R(const SparseRMatrix< Tdata > &smat, const std::set< RCoordinate > &all_R_coor, const double threshold, const bool reduce)
Count non-zero elements per R-block of a sparse R-matrix.
Definition hs_sparse_io_detail.h:38
void write_csr_binary_header(std::ofstream &ofs, const int step, const int nbasis, const int number_of_R)
Write the three-integer binary CSR header.
Definition hs_sparse_io_detail.h:229
std::string make_sparse_R_filename(const std::string &prefix, const std::string &spin_suffix, const bool numbered, const int istep, const std::string &extension)
Build the "<prefix><spin suffix>[g<step>]_nao<ext>" name shared by every R-space sparse output.
Definition hs_sparse_io_detail.h:116
void check_output_file_open(const std::ofstream &ofs, const std::string &filename, const std::string &context)
Quit if a sparse-matrix output stream failed to open.
Definition hs_sparse_io_detail.h:78
Internal helpers shared by the R-space sparse text writers. Declared here (instead of duplicated in e...
Definition csr_reader.cpp:8
std::map< RCoordinate, SparseRBlock< T > > SparseRMatrix
Definition hs_sparse_io.h:22
std::string local_timestamp()
Definition provenance_header.h:16
std::map< size_t, std::map< size_t, T > > SparseRBlock
Definition hs_sparse_io.h:19
std::string prov_inline(const std::string &time_stamp)
Definition provenance_header.h:48
void write_csr_banner(std::ostream &ofs)
Write the CSR-format description banner used by every text CSR output (H(R)/S(R), DM(R),...
Definition sparse_matrix.cpp:84
void reduce_all(T &object)
reduce in all process
Definition depend_mock.cpp:14
#define threshold
Definition sph_bessel_rec_test.cpp:4