Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/source_pw/module_dfpt/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ addtest(
# Shared ctor/dtor stubs for the cell/spepot/Plus_U link closures.
dfpt_test_mocks.cpp
# Shared cubic-cell / stru_lib fixture.
dfpt_stru_fixture.cpp)
dfpt_stru_tool.cpp)

addtest(
TARGET MODULE_DFPT_kq_basis_test
Expand Down Expand Up @@ -60,4 +60,4 @@ addtest(
# Shared ctor/dtor stubs for the cell/spepot/charge/Plus_U closures.
dfpt_test_mocks.cpp
# Shared cubic-cell / stru_lib fixture.
dfpt_stru_fixture.cpp)
dfpt_stru_tool.cpp)
11 changes: 7 additions & 4 deletions source/source_pw/module_dfpt/test/dfpt_pw_data_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "source_cell/pseudo.h"
#include "source_cell/qlist.h"
#include "source_cell/unitcell.h"
#include "dfpt_stru_fixture.h"
#include "dfpt_stru_tool.h"
#include "source_base/global_variable.h"
#include "source_base/parallel_global.h"
#include "source_pw/module_dfpt/dfpt_pw_data.h"
Expand All @@ -33,9 +33,10 @@
* - per-(q, irrep) SCF ledger (B4: sunk from DFPT_IrrepData)
*/

class DFPT_PW_DataTest : public DFPTStruTestFixture
class DFPT_PW_DataTest : public ::testing::Test
{
protected:
UnitCell ucell;
ModuleCell::QList qlist;
ModuleDFPT::DFPT_PW_Data data;
std::ifstream ifs;
Expand All @@ -46,7 +47,8 @@ class DFPT_PW_DataTest : public DFPTStruTestFixture
// build a reduced 2x2x2 q-mesh (4 irreducible q-points for O_h)
void init_qlist()
{
construct_ucell(stru_lib[0]);
const dfpt_test::stru_ stru = dfpt_test::cubic_carbon_stru();
dfpt_test::construct_ucell(ucell, stru);
ofs_running.open("tmp_dfpt_qlist");
ModuleSymmetry::Symmetry symm;
const int cal_symm_repr[2] = {0, 6};
Expand All @@ -61,7 +63,8 @@ class DFPT_PW_DataTest : public DFPTStruTestFixture
{
data.clean();
ofs_running.close();
ClearUcell();
delete[] ucell.atoms;
ucell.atoms = nullptr;
remove("tmp_dfpt_qlist");
}
};
Expand Down
11 changes: 7 additions & 4 deletions source/source_pw/module_dfpt/test/dfpt_pw_run_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "source_cell/pseudo.h"
#include "source_cell/qlist.h"
#include "source_cell/unitcell.h"
#include "dfpt_stru_fixture.h"
#include "dfpt_stru_tool.h"
#include "source_base/global_variable.h"
#include "source_base/parallel_global.h"
#include "source_estate/module_charge/chg_mix.h"
Expand All @@ -33,16 +33,18 @@
* i.e. 3*nat entries for each q.
*/

class DFPT_PWRunTest : public DFPTStruTestFixture
class DFPT_PWRunTest : public ::testing::Test
{
protected:
UnitCell ucell;
ModuleDFPT::DFPT_PW dfpt;
std::ofstream ofs_running;
std::string output;

void SetUp() override
{
construct_ucell(stru_lib[0]);
const dfpt_test::stru_ stru = dfpt_test::cubic_carbon_stru();
dfpt_test::construct_ucell(ucell, stru);
ofs_running.open("tmp_dfpt_run");
ModuleSymmetry::Symmetry symm;
const int cal_symm_repr[2] = {0, 6};
Expand All @@ -55,7 +57,8 @@ class DFPT_PWRunTest : public DFPTStruTestFixture
void TearDown() override
{
ofs_running.close();
ClearUcell();
delete[] ucell.atoms;
ucell.atoms = nullptr;
remove("tmp_dfpt_run");
}
};
Expand Down
48 changes: 0 additions & 48 deletions source/source_pw/module_dfpt/test/dfpt_stru_fixture.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#include "dfpt_stru_fixture.h"
// Shared free-function utilities for the MPI-side DFPT tests,
// implementation (see dfpt_stru_tool.h).

#include "dfpt_stru_tool.h"

#include "source_base/mathzone.h"
#include "source_cell/unitcell.h"

namespace dfpt_test
{

DFPTStruTestFixture::DFPTStruTestFixture()
stru_ cubic_carbon_stru()
{
stru_lib.push_back(stru_{1,
"O_h",
"m-3m",
"Pm-3m",
std::vector<double>{1., 0., 0., 0., 1., 0., 0., 0., 1.},
std::vector<atomtype_>{atomtype_{"C",
std::vector<std::vector<double>>{
{0., 0., 0.},
}}}});
return stru_{1,
"O_h",
"m-3m",
"Pm-3m",
std::vector<double>{1., 0., 0., 0., 1., 0., 0., 0., 1.},
std::vector<atomtype_>{atomtype_{"C",
std::vector<std::vector<double>>{
{0., 0., 0.},
}}}};
}

void DFPTStruTestFixture::construct_ucell(stru_& stru)
void construct_ucell(UnitCell& ucell, const stru_& stru)
{
std::vector<atomtype_> coord = stru.all_type;
const std::vector<atomtype_>& coord = stru.all_type;
ucell.a1 = ModuleBase::Vector3<double>(stru.cell[0], stru.cell[1], stru.cell[2]);
ucell.a2 = ModuleBase::Vector3<double>(stru.cell[3], stru.cell[4], stru.cell[5]);
ucell.a3 = ModuleBase::Vector3<double>(stru.cell[6], stru.cell[7], stru.cell[8]);
Expand Down Expand Up @@ -66,7 +73,7 @@ void DFPTStruTestFixture::construct_ucell(stru_& stru)
}
// atom-index tables: real cells always carry them (iat2it/iat2ia map the
// running atom index to type and in-type index); populate them so any
// consumer (e.g. DFPT_Phon::apply_asr mass lookup) works on this fixture
// consumer (e.g. DFPT_Phon::apply_asr mass lookup) works on this cell
ucell.iat2it.resize(ucell.nat);
ucell.iat2ia.resize(ucell.nat);
int iat = 0;
Expand All @@ -81,7 +88,4 @@ void DFPTStruTestFixture::construct_ucell(stru_& stru)
}
}

void DFPTStruTestFixture::ClearUcell()
{
delete[] ucell.atoms;
}
} // namespace dfpt_test
52 changes: 52 additions & 0 deletions source/source_pw/module_dfpt/test/dfpt_stru_tool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef DFPT_STRU_TOOL_H
#define DFPT_STRU_TOOL_H

// Shared free-function utilities for the MPI-side DFPT tests
// (dfpt_pw_data_test / dfpt_pw_run_test): building a minimal UnitCell
// from a hand-written structure table (abbreviated from
// module_symmetry/test/symm_test.cpp and klist_test.cpp), in the
// free-function test-tool pattern of module_pw's test/test_tool (a
// serial-side counterpart for test_serial/ is pending review and not
// part of this change). Every test file derives its own fixture from
// ::testing::Test, owns its UnitCell and calls these functions; there
// is no shared fixture base class on this side.

#include <string>
#include <vector>

class UnitCell;

namespace dfpt_test
{

/// one atom species: label + cartesian coordinates of its sites
struct atomtype_
{
std::string atomname;
std::vector<std::vector<double>> coordinate;
};

/// hand-written structure table consumed by construct_ucell
struct stru_
{
int ibrav;
std::string point_group; // Schoenflies symbol
std::string point_group_hm; // Hermann-Mauguin notation
std::string space_group;
std::vector<double> cell; // a1 | a2 | a3 (cartesian, row-major)
std::vector<atomtype_> all_type;
};

/// The default test structure: a cubic 1x1x1 carbon cell (O_h / Pm-3m,
/// single atom at the origin).
stru_ cubic_carbon_stru();

/// Build the UnitCell from the structure table: lattice vectors and
/// latvec / G / GT, per-type tau / taud (cartesian -> direct through
/// Mathzone), and the iat2it / iat2ia running-index tables real cells
/// always carry. The caller owns the UnitCell (and its atoms array).
void construct_ucell(UnitCell& ucell, const stru_& stru);

} // namespace dfpt_test

#endif // DFPT_STRU_TOOL_H
Loading