ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
ModuleIO::detail Namespace Reference

Classes

struct  CsrTextHeader
 Metadata shared by every self-describing CSR text writer. More...

Functions

template<typename Tdata>
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.
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.
bool append_ionic_step (const int out_app_flag, const int istep)
 Decide whether the current ionic step appends to an existing file.
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.
void write_csr_text_header (std::ofstream &ofs, const CsrTextHeader &header)
 Write the common self-describing header of a CSR text file.
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.
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.
bool lat_r_nonempty (const int nonzero_num[3])
void assemble_csr (const std::string &output_filename, const std::string &payload_filename, int step, int nlocal, int output_R_number, bool binary, bool append, const std::string &axis, const UnitCell *ucell, const std::string &context)
 Assemble one r(R) component file from its temporary block payload.

Function Documentation

◆ append_ionic_step()

bool ModuleIO::detail::append_ionic_step ( const int out_app_flag,
const int istep )
inline

Decide whether the current ionic step appends to an existing file.

Mode 1 appends all ionic steps after the first written one; mode 0 and mode 2 always start a fresh stream (mode 2 embeds the step in the file name). Single-point runs pass istep <= 0 and truncate.

Parameters
out_app_flagOutput append mode from INPUT.
istepZero-based ionic step index.
Returns
True when the stream must be opened in append mode.
Here is the caller graph for this function:

◆ assemble_csr()

void ModuleIO::detail::assemble_csr ( const std::string & output_filename,
const std::string & payload_filename,
int step,
int nlocal,
int output_R_number,
bool binary,
bool append,
const std::string & axis,
const UnitCell * ucell,
const std::string & context )

Assemble one r(R) component file from its temporary block payload.

Text output uses the same self-describing header and CSR banner as H(R)/S(R)/dH(R) files, while binary output keeps the three-integer header followed by the raw block records.

Parameters
output_filenameFinal file name of this Cartesian component.
payload_filenameTemporary file holding the CSR block records.
stepOne-based ionic step written into the header.
nlocalNumber of localized basis functions.
output_R_numberNumber of Bravais lattice vectors written.
binaryWhether the payload and output are binary.
appendWhether to append to the existing output file.
axisCartesian component label ("x", "y" or "z").
ucellUnit cell written into the text header; must not be null.
contextCaller name used in diagnostics.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_output_file_open()

void ModuleIO::detail::check_output_file_open ( const std::ofstream & ofs,
const std::string & filename,
const std::string & context )
inline

Quit if a sparse-matrix output stream failed to open.

Parameters
ofsStream to check.
filenameFilename for the error message.
contextCaller tag for the error message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ count_nonzeros_by_R()

template<typename Tdata>
std::vector< long long > ModuleIO::detail::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.

Parameters
smatSparse matrix keyed by R-coordinate.
all_R_coorOrdered set of R-coordinates to scan.
thresholdMagnitude below which an element is treated as zero.
reduceIf true, allreduce the per-R counts across MPI ranks.
Returns
Per-R nonzero counts aligned with all_R_coor order.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lat_r_nonempty()

bool ModuleIO::detail::lat_r_nonempty ( const int nonzero_num[3])
Here is the caller graph for this function:

◆ make_sparse_R_filename()

std::string ModuleIO::detail::make_sparse_R_filename ( const std::string & prefix,
const std::string & spin_suffix,
const bool numbered,
const int istep,
const std::string & extension )
inline

Build the "<prefix><spin suffix>[g<step>]_nao<ext>" name shared by every R-space sparse output.

Centralizing the suffix order keeps H(R), S(R), DM(R), dH/dR, r(R), T(R), Vxc(R) and L(R) file names consistent and avoids one writer drifting from the others.

Parameters
prefixProperty prefix without spin or step, e.g. "dhrx", "rrx".
spin_suffixSpin token appended to the prefix ("s1", "1") or empty when the quantity is spin independent.
numberedWhether to embed the one-based ionic step.
istepZero-based ionic step index.
extensionFile extension including the leading dot.
Returns
Assembled file name without any directory prefix.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_csr_binary_header()

void ModuleIO::detail::write_csr_binary_header ( std::ofstream & ofs,
const int step,
const int nbasis,
const int number_of_R )
inline

Write the three-integer binary CSR header.

Parameters
ofsOutput binary stream.
stepOne-based ionic step.
nbasisNumber of localized basis functions.
number_of_RNumber of R blocks actually written.
Here is the caller graph for this function:

◆ write_csr_text_header()

void ModuleIO::detail::write_csr_text_header ( std::ofstream & ofs,
const CsrTextHeader & header )
inline

Write the common self-describing header of a CSR text file.

Parameters
ofsOutput text stream.
headerHeader fields; ucell must not be null.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_R_record()

void ModuleIO::detail::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 )
inline

Write the "Rx Ry Rz nnz" record that starts one R block.

Parameters
ofsOutput stream.
rxFirst Bravais lattice vector component.
rySecond Bravais lattice vector component.
rzThird Bravais lattice vector component.
nnzNumber of non-zero elements in the block.
binaryWhether the stream uses the binary record layout.
leading_spacePrefix the text record with a space (save_sparse layout).
Here is the call graph for this function:
Here is the caller graph for this function: