|
ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
|
#include <complex>#include <cstdio>#include <iomanip>#include <sstream>#include <fstream>#include <iostream>#include <string>#include <vector>#include <map>#include "source_io/module_dm/write_dmk.h"#include "source_io/module_hs/dense_text_body.h"#include "source_base/global_variable.h"#include "prepare_unitcell.h"#include "gmock/gmock.h"#include "gtest/gtest.h"#include "source_base/module_external/scalapack_connector.h"#include "mpi.h"#include "source_base/module_parallel/para_mpi_func.h"Classes | |
| class | DMKTest |
| Fixture owning the Si UnitCell shared by most tests. More... | |
Functions | |
| template<typename T> | |
| void | expect_dmk_eq (const std::vector< std::vector< T > > &actual, const std::vector< std::vector< T > > &expected) |
| Element-wise near-equality check for two identically shaped buffers. | |
| void | expect_dmk_eq (const std::vector< std::vector< std::complex< double > > > &actual, const std::vector< std::vector< std::complex< double > > > &expected) |
| Complex overload: checks real and imaginary parts separately. | |
| void | init_pv (int nlocal, Parallel_Blkcyclic &pv) |
| template<typename T> | |
| void | gen_dmk (std::vector< std::vector< T > > &dmk, std::vector< double > &efs, int nspin, int nk, int nlocal, Parallel_Blkcyclic &pv) |
| void | init_kv (K_Vectors &kv, const double weight) |
| Fill the single-k-point K_Vectors metadata used by the writers. | |
| std::vector< double > | read_numbers (const std::string &fname) |
| Tokenize the numbers of the matrix body written at the end of a DMK file. | |
| template<typename T> | |
| void | fill_local_dmk (const std::vector< T > &probe, const int nlocal, const Parallel_Blkcyclic &pv, std::vector< std::vector< T > > &dmk) |
| Fill the local blocks of a single-k-point DM with a row-major probe, stored column-major as a column-major eigensolver would leave it. | |
| void | init_kv_multi (K_Vectors &kv, const int nspin, const int nk) |
| Fill the K_Vectors metadata for nspin spin channels and nk k-points. | |
| bool | copy_file (const std::string &src, const std::string &dst) |
| Copy a file inside the scratch directory. | |
| bool | drop_last_line (const std::string &fname) |
| Drop the final line of a text file to simulate a truncated write. | |
| TEST_F (DMKTest, GenFileName) | |
| TEST_F (DMKTest, WriteDMK) | |
| TEST_F (DMKTest, BodyIsRowMajorForColumnMajorStorage) | |
| TEST_F (DMKTest, Mode0FixedNameOverwrite) | |
| TEST_F (DMKTest, Mode2PerStepFile) | |
| TEST_F (DMKTest, ReadDMKRoundTripComplex) | |
| TEST_F (DMKTest, ReadDMKRoundTripGamma) | |
| TEST_F (DMKTest, ReadDMKRoundTripMultipleMatrices) | |
| TEST_F (DMKTest, ReadDMKMissingFileReturnsFalse) | |
| TEST_F (DMKTest, ReadDMKSplitCommunicatorStatus) | |
| Verify that split descriptor communicators keep their read status independent. | |
| TEST_F (DMKTest, ReadDMKMode2PerStepFile) | |
| TEST_F (DMKTest, ReadDMKMode1FrameSelection) | |
| bool | all_equal_to (const std::vector< std::vector< std::complex< double > > > &dmk, const std::complex< double > &sentinel) |
| Check that every block of a DM(k) buffer still holds the sentinel. | |
| TEST_F (DMKTest, ReadDMKPartialFailureKeepsCallerData) | |
| TEST_F (DMKTest, ReadDMKRejectsSpinMismatch) | |
| TEST_F (DMKTest, ReadDMKRejectsKPointMismatch) | |
| TEST_F (DMKTest, ReadDMKRejectsKVecMismatch) | |
| TEST_F (DMKTest, ReadDMKRejectsBasisMismatch) | |
| TEST_F (DMKTest, ReadDMKRejectsTruncatedFile) | |
| bool | rewrite_line (const std::string &fname, std::size_t target, const std::string &new_content) |
| Replace a specific line of a text file with new content. | |
| TEST_F (DMKTest, ReadDMKRejectsMalformedAtomCount) | |
| TEST_F (DMKTest, ReadDMKMode0RejectsMixedSteps) | |
| TEST_F (DMKTest, ReadDMKMode0AcceptsFilesWithoutStepMarker) | |
| TEST_F (DMKTest, DenseBufferIndexSelectsLayout) | |
| TEST_F (DMKTest, HeaderStatesConjFirstConvention) | |
| TEST_F (DMKTest, ReadDMKRoundTripRowMajorFlag) | |
| bool | patch_first_body_token (const std::string &fname, const std::string &token, const bool complex_body) |
| Overwrite the first matrix-body token of a written DM(k) file. | |
| TEST_F (DMKTest, ReadDMKRejectsOverflowingComplexComponent) | |
| TEST_F (DMKTest, ReadDMKRejectsNonFiniteRealComponent) | |
| int | main (int argc, char **argv) |
| bool all_equal_to | ( | const std::vector< std::vector< std::complex< double > > > & | dmk, |
| const std::complex< double > & | sentinel ) |
Check that every block of a DM(k) buffer still holds the sentinel.
| bool copy_file | ( | const std::string & | src, |
| const std::string & | dst ) |
Copy a file inside the scratch directory.
Used to build a file whose header contradicts the name the reader looks for, which cannot be produced through write_dmk itself.
| bool drop_last_line | ( | const std::string & | fname | ) |
Drop the final line of a text file to simulate a truncated write.
| void expect_dmk_eq | ( | const std::vector< std::vector< std::complex< double > > > & | actual, |
| const std::vector< std::vector< std::complex< double > > > & | expected ) |
Complex overload: checks real and imaginary parts separately.
| void expect_dmk_eq | ( | const std::vector< std::vector< T > > & | actual, |
| const std::vector< std::vector< T > > & | expected ) |
Element-wise near-equality check for two identically shaped buffers.
| void fill_local_dmk | ( | const std::vector< T > & | probe, |
| const int | nlocal, | ||
| const Parallel_Blkcyclic & | pv, | ||
| std::vector< std::vector< T > > & | dmk ) |
Fill the local blocks of a single-k-point DM with a row-major probe, stored column-major as a column-major eigensolver would leave it.
| void gen_dmk | ( | std::vector< std::vector< T > > & | dmk, |
| std::vector< double > & | efs, | ||
| int | nspin, | ||
| int | nk, | ||
| int | nlocal, | ||
| Parallel_Blkcyclic & | pv ) |
| void init_kv | ( | K_Vectors & | kv, |
| const double | weight ) |
Fill the single-k-point K_Vectors metadata used by the writers.
| void init_kv_multi | ( | K_Vectors & | kv, |
| const int | nspin, | ||
| const int | nk ) |
Fill the K_Vectors metadata for nspin spin channels and nk k-points.
write_dmk reads one k-point coordinate, weight and index per file, so a multi-k round trip needs real k-point arrays instead of the single-point metadata set up by init_kv.
| void init_pv | ( | int | nlocal, |
| Parallel_Blkcyclic & | pv ) |
| int main | ( | int | argc, |
| char ** | argv ) |
| bool patch_first_body_token | ( | const std::string & | fname, |
| const std::string & | token, | ||
| const bool | complex_body ) |
Overwrite the first matrix-body token of a written DM(k) file.
The complex body is the only section whose tokens contain '('; for the real body of a 2x2 matrix the whole body is the final line (8 values per line). Both fixtures used below keep the body free of comment markers, which the header and the UnitCell block never are on their numeric lines.
| std::vector< double > read_numbers | ( | const std::string & | fname | ) |
Tokenize the numbers of the matrix body written at the end of a DMK file.
The body is the trailing run of lines carrying complex pairs, so it is collected from the end of the file; taking the first "(" instead would hit the UnitCell header, and parsing the whole file would trip over the non-numeric metadata. Parentheses and commas become whitespace, so the value order (real, imaginary, real, ...) is preserved.
| bool rewrite_line | ( | const std::string & | fname, |
| std::size_t | target, | ||
| const std::string & | new_content ) |
Replace a specific line of a text file with new content.
| fname | Path of the file to rewrite (must exist). |
| target | Zero-based line index to replace; out-of-range returns false. |
| new_content | The replacement text, written with a trailing newline. |
| TEST_F | ( | DMKTest | , |
| BodyIsRowMajorForColumnMajorStorage | ) |
| TEST_F | ( | DMKTest | , |
| DenseBufferIndexSelectsLayout | ) |
| TEST_F | ( | DMKTest | , |
| GenFileName | ) |
| TEST_F | ( | DMKTest | , |
| HeaderStatesConjFirstConvention | ) |
| TEST_F | ( | DMKTest | , |
| Mode0FixedNameOverwrite | ) |
| TEST_F | ( | DMKTest | , |
| Mode2PerStepFile | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKMissingFileReturnsFalse | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKMode0AcceptsFilesWithoutStepMarker | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKMode0RejectsMixedSteps | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKMode1FrameSelection | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKMode2PerStepFile | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKPartialFailureKeepsCallerData | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRejectsBasisMismatch | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRejectsKPointMismatch | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRejectsKVecMismatch | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRejectsMalformedAtomCount | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRejectsNonFiniteRealComponent | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRejectsOverflowingComplexComponent | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRejectsSpinMismatch | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRejectsTruncatedFile | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRoundTripComplex | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRoundTripGamma | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRoundTripMultipleMatrices | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKRoundTripRowMajorFlag | ) |
| TEST_F | ( | DMKTest | , |
| ReadDMKSplitCommunicatorStatus | ) |
Verify that split descriptor communicators keep their read status independent.
| TEST_F | ( | DMKTest | , |
| WriteDMK | ) |