ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
test_write_dmk.cpp File Reference
#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"
Include dependency graph for test_write_dmk.cpp:

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)

Function Documentation

◆ all_equal_to()

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.

Here is the caller graph for this function:

◆ copy_file()

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.

Here is the caller graph for this function:

◆ drop_last_line()

bool drop_last_line ( const std::string & fname)

Drop the final line of a text file to simulate a truncated write.

Here is the caller graph for this function:

◆ expect_dmk_eq() [1/2]

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.

◆ expect_dmk_eq() [2/2]

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.

Here is the caller graph for this function:

◆ fill_local_dmk()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_dmk()

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 )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_kv()

void init_kv ( K_Vectors & kv,
const double weight )

Fill the single-k-point K_Vectors metadata used by the writers.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_kv_multi()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_pv()

void init_pv ( int nlocal,
Parallel_Blkcyclic & pv )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

◆ patch_first_body_token()

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.

Here is the caller graph for this function:

◆ read_numbers()

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.

Here is the caller graph for this function:

◆ rewrite_line()

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.

Parameters
fnamePath of the file to rewrite (must exist).
targetZero-based line index to replace; out-of-range returns false.
new_contentThe replacement text, written with a trailing newline.
Here is the caller graph for this function:

◆ TEST_F() [1/26]

TEST_F ( DMKTest ,
BodyIsRowMajorForColumnMajorStorage  )
Here is the call graph for this function:

◆ TEST_F() [2/26]

TEST_F ( DMKTest ,
DenseBufferIndexSelectsLayout  )
Here is the call graph for this function:

◆ TEST_F() [3/26]

TEST_F ( DMKTest ,
GenFileName  )
Here is the call graph for this function:

◆ TEST_F() [4/26]

TEST_F ( DMKTest ,
HeaderStatesConjFirstConvention  )
Here is the call graph for this function:

◆ TEST_F() [5/26]

TEST_F ( DMKTest ,
Mode0FixedNameOverwrite  )
Here is the call graph for this function:

◆ TEST_F() [6/26]

TEST_F ( DMKTest ,
Mode2PerStepFile  )
Here is the call graph for this function:

◆ TEST_F() [7/26]

TEST_F ( DMKTest ,
ReadDMKMissingFileReturnsFalse  )
Here is the call graph for this function:

◆ TEST_F() [8/26]

TEST_F ( DMKTest ,
ReadDMKMode0AcceptsFilesWithoutStepMarker  )
Here is the call graph for this function:

◆ TEST_F() [9/26]

TEST_F ( DMKTest ,
ReadDMKMode0RejectsMixedSteps  )
Here is the call graph for this function:

◆ TEST_F() [10/26]

TEST_F ( DMKTest ,
ReadDMKMode1FrameSelection  )
Here is the call graph for this function:

◆ TEST_F() [11/26]

TEST_F ( DMKTest ,
ReadDMKMode2PerStepFile  )
Here is the call graph for this function:

◆ TEST_F() [12/26]

TEST_F ( DMKTest ,
ReadDMKPartialFailureKeepsCallerData  )
Here is the call graph for this function:

◆ TEST_F() [13/26]

TEST_F ( DMKTest ,
ReadDMKRejectsBasisMismatch  )
Here is the call graph for this function:

◆ TEST_F() [14/26]

TEST_F ( DMKTest ,
ReadDMKRejectsKPointMismatch  )
Here is the call graph for this function:

◆ TEST_F() [15/26]

TEST_F ( DMKTest ,
ReadDMKRejectsKVecMismatch  )
Here is the call graph for this function:

◆ TEST_F() [16/26]

TEST_F ( DMKTest ,
ReadDMKRejectsMalformedAtomCount  )
Here is the call graph for this function:

◆ TEST_F() [17/26]

TEST_F ( DMKTest ,
ReadDMKRejectsNonFiniteRealComponent  )
Here is the call graph for this function:

◆ TEST_F() [18/26]

TEST_F ( DMKTest ,
ReadDMKRejectsOverflowingComplexComponent  )
Here is the call graph for this function:

◆ TEST_F() [19/26]

TEST_F ( DMKTest ,
ReadDMKRejectsSpinMismatch  )
Here is the call graph for this function:

◆ TEST_F() [20/26]

TEST_F ( DMKTest ,
ReadDMKRejectsTruncatedFile  )
Here is the call graph for this function:

◆ TEST_F() [21/26]

TEST_F ( DMKTest ,
ReadDMKRoundTripComplex  )
Here is the call graph for this function:

◆ TEST_F() [22/26]

TEST_F ( DMKTest ,
ReadDMKRoundTripGamma  )
Here is the call graph for this function:

◆ TEST_F() [23/26]

TEST_F ( DMKTest ,
ReadDMKRoundTripMultipleMatrices  )
Here is the call graph for this function:

◆ TEST_F() [24/26]

TEST_F ( DMKTest ,
ReadDMKRoundTripRowMajorFlag  )
Here is the call graph for this function:

◆ TEST_F() [25/26]

TEST_F ( DMKTest ,
ReadDMKSplitCommunicatorStatus  )

Verify that split descriptor communicators keep their read status independent.

Here is the call graph for this function:

◆ TEST_F() [26/26]

TEST_F ( DMKTest ,
WriteDMK  )
Here is the call graph for this function: