Skip to content

Commit

Permalink
Refactor:Move the relaxation part of the ucell function (#5767)
Browse files Browse the repository at this point in the history
* udpate ucell cell-relax

* change funcion setup ucell after vc

* [pre-commit.ci lite] apply automatic fixes

* fix bug in relax test

* [pre-commit.ci lite] apply automatic fixes

* add namespace for unitcell

* add unittest for the setcell_after_vc

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
A-006 and pre-commit-ci-lite[bot] authored Dec 28, 2024
1 parent 68735ed commit 5e8bc21
Show file tree
Hide file tree
Showing 20 changed files with 455 additions and 373 deletions.
1 change: 1 addition & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ OBJS_CELL=atom_pseudo.o\
klist.o\
cell_index.o\
check_atomic_stru.o\
update_cell.o\

OBJS_DEEPKS=LCAO_deepks.o\
deepks_force.o\
Expand Down
1 change: 1 addition & 0 deletions source/module_cell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_library(
parallel_kpoints.cpp
cell_index.cpp
check_atomic_stru.cpp
update_cell.cpp
)

if(ENABLE_COVERAGE)
Expand Down
5 changes: 3 additions & 2 deletions source/module_cell/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ add_test(NAME cell_parallel_kpoints_test
AddTest(
TARGET cell_unitcell_test
LIBS parameter ${math_libs} base device cell_info symmetry
SOURCES unitcell_test.cpp ../../module_io/output.cpp ../../module_elecstate/cal_ux.cpp
SOURCES unitcell_test.cpp ../../module_io/output.cpp ../../module_elecstate/cal_ux.cpp ../update_cell.cpp

)

Expand All @@ -122,7 +122,8 @@ AddTest(
AddTest(
TARGET cell_unitcell_test_setupcell
LIBS parameter ${math_libs} base device cell_info
SOURCES unitcell_test_setupcell.cpp ../../module_io/output.cpp
SOURCES unitcell_test_setupcell.cpp ../../module_io/output.cpp
../../module_cell/update_cell.cpp
)

add_test(NAME cell_unitcell_test_parallel
Expand Down
2 changes: 1 addition & 1 deletion source/module_cell/test/prepare_unitcell.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class UcellTestPrepare
ucell->latvec.e13 = this->latvec[2];
ucell->latvec.e21 = this->latvec[3];
ucell->latvec.e22 = this->latvec[4];
ucell->latvec.e23 = this->latvec[5];
ucell->latvec.e23 = this->latvec[5];
ucell->latvec.e31 = this->latvec[6];
ucell->latvec.e32 = this->latvec[7];
ucell->latvec.e33 = this->latvec[8];
Expand Down
2 changes: 0 additions & 2 deletions source/module_cell/test/support/mock_unitcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ void UnitCell::print_stru_file(const std::string& fn,
const bool& dpks_desc,
const int& iproc) const {}
void UnitCell::check_dtau() {}
void UnitCell::setup_cell_after_vc(std::ofstream& log) {}
void UnitCell::remake_cell() {}
void UnitCell::cal_nwfc(std::ofstream& log) {}
void UnitCell::cal_meshx() {}
void UnitCell::cal_natomwfc(std::ofstream& log) {}
Expand Down
6 changes: 3 additions & 3 deletions source/module_cell/test/unitcell_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#define private public
#include "module_parameter/parameter.h"
#undef private
#include "module_cell/unitcell.h"
#include "module_elecstate/cal_ux.h"
#include "module_elecstate/read_pseudo.h"

#include "memory"
#include "module_base/global_variable.h"
#include "module_base/mathzone.h"
#include "prepare_unitcell.h"
#include "module_cell/update_cell.h"
#include <streambuf>
#include <valarray>
#include <vector>
Expand Down Expand Up @@ -346,7 +346,7 @@ TEST_F(UcellTest, RemakeCell)
ucell->latvec.e32 = 0.00;
ucell->latvec.e33 = 10.0;
ucell->latName = latname_in[i];
ucell->remake_cell();
unitcell::remake_cell(ucell->lat);
if (latname_in[i] == "sc")
{
double celldm
Expand Down Expand Up @@ -591,7 +591,7 @@ TEST_F(UcellDeathTest, RemakeCellWarnings)
ucell->latvec.e33 = 10.0;
ucell->latName = latname_in[i];
testing::internal::CaptureStdout();
EXPECT_EXIT(ucell->remake_cell(), ::testing::ExitedWithCode(1), "");
EXPECT_EXIT(unitcell::remake_cell(ucell->lat), ::testing::ExitedWithCode(1), "");
std::string output = testing::internal::GetCapturedStdout();
if (latname_in[i] == "none")
{
Expand Down
43 changes: 41 additions & 2 deletions source/module_cell/test/unitcell_test_setupcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include<valarray>
#include <streambuf>
#include "prepare_unitcell.h"

#include "module_cell/update_cell.h"
#ifdef __LCAO
#include "module_basis/module_ao/ORB_read.h"
InfoNonlocal::InfoNonlocal(){}
Expand Down Expand Up @@ -145,8 +145,47 @@ TEST_F(UcellTest,SetupCellAfterVC)
ucell->ntype = 2;
delete[] ucell->magnet.start_magnetization;
ucell->magnet.start_magnetization = new double[ucell->ntype];


ucell->setup_cell(fn,ofs_running);
ucell->setup_cell_after_vc(ofs_running);
ucell->lat0 = 1.0;
ucell->latvec.Zero();
ucell->latvec.e11 = 10.0;
ucell->latvec.e22 = 10.0;
ucell->latvec.e33 = 10.0;
for (int i =0;i<ucell->ntype;i++)
{
ucell->atoms[i].na = 1;
ucell->atoms[i].taud.resize(ucell->atoms[i].na);
ucell->atoms[i].tau.resize(ucell->atoms[i].na);
ucell->atoms[i].taud[0].x = 0.1;
ucell->atoms[i].taud[0].y = 0.1;
ucell->atoms[i].taud[0].z = 0.1;
}

unitcell::setup_cell_after_vc(*ucell,ofs_running);
EXPECT_EQ(ucell->lat0_angstrom,0.529177);
EXPECT_EQ(ucell->tpiba,ModuleBase::TWO_PI);
EXPECT_EQ(ucell->tpiba2,ModuleBase::TWO_PI*ModuleBase::TWO_PI);
EXPECT_EQ(ucell->a1.x ,10.0);
EXPECT_EQ(ucell->a2.y ,10.0);
EXPECT_EQ(ucell->a3.z ,10.0);
EXPECT_EQ(ucell->omega,1000.0);
EXPECT_EQ(ucell->GT.e11,0.1);
EXPECT_EQ(ucell->GT.e22,0.1);
EXPECT_EQ(ucell->GT.e33,0.1);
EXPECT_EQ(ucell->G.e11,0.1);
EXPECT_EQ(ucell->G.e22,0.1);
EXPECT_EQ(ucell->G.e33,0.1);

for (int it = 0; it < ucell->ntype; it++) {
Atom* atom = &ucell->atoms[it];
for (int ia = 0; ia < atom->na; ia++) {
EXPECT_EQ(atom->tau[ia].x,1);
EXPECT_EQ(atom->tau[ia].y,1);
EXPECT_EQ(atom->tau[ia].z,1);
}
}
ofs_running.close();
remove("setup_cell.tmp");
}
Expand Down
Loading

0 comments on commit 5e8bc21

Please sign in to comment.