Skip to content

Commit 3aafc7d

Browse files
committed
change funcion setup ucell after vc
1 parent 8927103 commit 3aafc7d

File tree

14 files changed

+84
-81
lines changed

14 files changed

+84
-81
lines changed

source/module_cell/test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ AddTest(
122122
AddTest(
123123
TARGET cell_unitcell_test_setupcell
124124
LIBS parameter ${math_libs} base device cell_info
125-
SOURCES unitcell_test_setupcell.cpp ../../module_io/output.cpp
125+
SOURCES unitcell_test_setupcell.cpp ../../module_io/output.cpp
126+
../../module_cell/update_cell.cpp
126127
)
127128

128129
add_test(NAME cell_unitcell_test_parallel

source/module_cell/test/support/mock_unitcell.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ void UnitCell::print_stru_file(const std::string& fn,
6363
const bool& dpks_desc,
6464
const int& iproc) const {}
6565
void UnitCell::check_dtau() {}
66-
void UnitCell::setup_cell_after_vc(std::ofstream& log) {}
6766
void UnitCell::cal_nwfc(std::ofstream& log) {}
6867
void UnitCell::cal_meshx() {}
6968
void UnitCell::cal_natomwfc(std::ofstream& log) {}

source/module_cell/test/unitcell_test_setupcell.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include<valarray>
1212
#include <streambuf>
1313
#include "prepare_unitcell.h"
14-
14+
#include "module_cell/update_cell.h"
1515
#ifdef __LCAO
1616
#include "module_basis/module_ao/ORB_read.h"
1717
InfoNonlocal::InfoNonlocal(){}
@@ -146,7 +146,7 @@ TEST_F(UcellTest,SetupCellAfterVC)
146146
delete[] ucell->magnet.start_magnetization;
147147
ucell->magnet.start_magnetization = new double[ucell->ntype];
148148
ucell->setup_cell(fn,ofs_running);
149-
ucell->setup_cell_after_vc(ofs_running);
149+
setup_cell_after_vc(*ucell,ofs_running);
150150
ofs_running.close();
151151
remove("setup_cell.tmp");
152152
}

source/module_cell/unitcell.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -863,72 +863,6 @@ void UnitCell::cal_natomwfc(std::ofstream& log) {
863863
return;
864864
}
865865

866-
// LiuXh add a new function here,
867-
// 20180515
868-
void UnitCell::setup_cell_after_vc(std::ofstream& log) {
869-
ModuleBase::TITLE("UnitCell", "setup_cell_after_vc");
870-
assert(lat0 > 0.0);
871-
this->omega = std::abs(latvec.Det()) * this->lat0 * lat0 * lat0;
872-
if (this->omega <= 0) {
873-
ModuleBase::WARNING_QUIT("setup_cell_after_vc", "omega <= 0 .");
874-
} else {
875-
log << std::endl;
876-
ModuleBase::GlobalFunc::OUT(log, "Volume (Bohr^3)", this->omega);
877-
ModuleBase::GlobalFunc::OUT(log,
878-
"Volume (A^3)",
879-
this->omega
880-
* pow(ModuleBase::BOHR_TO_A, 3));
881-
}
882-
883-
lat0_angstrom = lat0 * 0.529177;
884-
tpiba = ModuleBase::TWO_PI / lat0;
885-
tpiba2 = tpiba * tpiba;
886-
887-
// lattice vectors in another form.
888-
a1.x = latvec.e11;
889-
a1.y = latvec.e12;
890-
a1.z = latvec.e13;
891-
892-
a2.x = latvec.e21;
893-
a2.y = latvec.e22;
894-
a2.z = latvec.e23;
895-
896-
a3.x = latvec.e31;
897-
a3.y = latvec.e32;
898-
a3.z = latvec.e33;
899-
900-
//==========================================================
901-
// Calculate recip. lattice vectors and dot products
902-
// latvec has the unit of lat0, but G has the unit 2Pi/lat0
903-
//==========================================================
904-
this->GT = latvec.Inverse();
905-
this->G = GT.Transpose();
906-
this->GGT = G * GT;
907-
this->invGGT = GGT.Inverse();
908-
909-
for (int it = 0; it < ntype; it++) {
910-
Atom* atom = &atoms[it];
911-
for (int ia = 0; ia < atom->na; ia++) {
912-
atom->tau[ia] = atom->taud[ia] * latvec;
913-
}
914-
}
915-
916-
#ifdef __MPI
917-
this->bcast_unitcell();
918-
#endif
919-
920-
log << std::endl;
921-
output::printM3(log,
922-
"Lattice vectors: (Cartesian coordinate: in unit of a_0)",
923-
latvec);
924-
output::printM3(
925-
log,
926-
"Reciprocal vectors: (Cartesian coordinate: in unit of 2 pi/a_0)",
927-
G);
928-
929-
return;
930-
}
931-
932866
// check if any atom can be moved
933867
bool UnitCell::if_atoms_can_move() const {
934868
for (int it = 0; it < this->ntype; it++) {

source/module_cell/unitcell.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ class UnitCell {
277277
const bool& dpks_desc = false,
278278
const int& iproc = 0) const;
279279
void check_dtau();
280-
void setup_cell_after_vc(std::ofstream& log); // LiuXh add 20180515
281-
282280
// for constrained vc-relaxation where type of lattice
283281
// is fixed, adjust the lattice vectors
284282

source/module_cell/update_cell.cpp

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,69 @@ void remake_cell(Lattice& lat)
278278
ModuleBase::WARNING_QUIT("UnitCell::read_atom_species",
279279
"latname not supported!");
280280
}
281-
}
281+
}
282+
283+
// LiuXh add a new function here,
284+
// 20180515
285+
void setup_cell_after_vc(UnitCell& ucell, std::ofstream& log) {
286+
ModuleBase::TITLE("UnitCell", "setup_cell_after_vc");
287+
assert(ucell.lat0 > 0.0);
288+
ucell.omega = std::abs(ucell.latvec.Det()) *
289+
ucell.lat0 * ucell.lat0 * ucell.lat0;
290+
if (ucell.omega <= 0) {
291+
ModuleBase::WARNING_QUIT("setup_cell_after_vc", "omega <= 0 .");
292+
} else {
293+
log << std::endl;
294+
ModuleBase::GlobalFunc::OUT(log, "Volume (Bohr^3)", ucell.omega);
295+
ModuleBase::GlobalFunc::OUT(log, "Volume (A^3)",
296+
ucell.omega * pow(ModuleBase::BOHR_TO_A, 3));
297+
}
298+
299+
ucell.lat0_angstrom = ucell.lat0 * 0.529177;
300+
ucell.tpiba = ModuleBase::TWO_PI / ucell.lat0;
301+
ucell.tpiba2 = ucell.tpiba * ucell.tpiba;
302+
303+
// lattice vectors in another form.
304+
ucell.a1.x = ucell.latvec.e11;
305+
ucell.a1.y = ucell.latvec.e12;
306+
ucell.a1.z = ucell.latvec.e13;
307+
308+
ucell.a2.x = ucell.latvec.e21;
309+
ucell.a2.y = ucell.latvec.e22;
310+
ucell.a2.z = ucell.latvec.e23;
311+
312+
ucell.a3.x = ucell.latvec.e31;
313+
ucell.a3.y = ucell.latvec.e32;
314+
ucell.a3.z = ucell.latvec.e33;
315+
316+
//==========================================================
317+
// Calculate recip. lattice vectors and dot products
318+
// latvec has the unit of lat0, but G has the unit 2Pi/lat0
319+
//==========================================================
320+
ucell.GT = ucell.latvec.Inverse();
321+
ucell.G = ucell.GT.Transpose();
322+
ucell.GGT = ucell.G * ucell.GT;
323+
ucell.invGGT = ucell.GGT.Inverse();
324+
325+
for (int it = 0; it < ucell.ntype; it++) {
326+
Atom* atom = &ucell.atoms[it];
327+
for (int ia = 0; ia < atom->na; ia++) {
328+
atom->tau[ia] = atom->taud[ia] * ucell.latvec;
329+
}
330+
}
331+
332+
#ifdef __MPI
333+
ucell.bcast_unitcell();
334+
#endif
335+
336+
log << std::endl;
337+
output::printM3(log,
338+
"Lattice vectors: (Cartesian coordinate: in unit of a_0)",
339+
ucell.latvec);
340+
output::printM3(
341+
log,
342+
"Reciprocal vectors: (Cartesian coordinate: in unit of 2 pi/a_0)",
343+
ucell.G);
344+
345+
return;
346+
}

source/module_cell/update_cell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
#define UPDATE_CELL_H
33

44
#include "unitcell_data.h"
5+
#include "module_cell/unitcell.h"
56
// for constrained vc-relaxation where type of lattice
67
// is fixed, adjust the lattice vectors
78
void remake_cell(Lattice& lat);
89

10+
void setup_cell_after_vc(UnitCell& ucell, std::ofstream& log);
911
#endif

source/module_md/msst.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "msst.h"
22

3+
#include "module_cell/update_cell.h"
34
#include "md_func.h"
45
#ifdef __MPI
56
#include "mpi.h"
@@ -256,7 +257,7 @@ void MSST::rescale(std::ofstream& ofs, const double& volume)
256257
ucell.latvec.e22 *= dilation[1];
257258
ucell.latvec.e33 *= dilation[2];
258259

259-
ucell.setup_cell_after_vc(ofs);
260+
setup_cell_after_vc(ucell,ofs);
260261

261262
/// rescale velocity
262263
for (int i = 0; i < ucell.nat; ++i)

source/module_md/nhchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "mpi.h"
66
#endif
77
#include "module_base/timer.h"
8-
8+
#include "module_cell/update_cell.h"
99
Nose_Hoover::Nose_Hoover(const Parameter& param_in, UnitCell& unit_in) : MD_base(param_in, unit_in)
1010
{
1111
const double unit_transform = ModuleBase::HARTREE_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8;
@@ -809,7 +809,7 @@ void Nose_Hoover::update_volume(std::ofstream& ofs)
809809
}
810810

811811
/// reset ucell and pos due to change of lattice
812-
ucell.setup_cell_after_vc(ofs);
812+
setup_cell_after_vc(ucell,ofs);
813813
}
814814

815815
void Nose_Hoover::target_stress()

source/module_md/test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ AddTest(
8888
SOURCES nhchain_test.cpp
8989
../md_base.cpp
9090
../nhchain.cpp
91+
../../module_cell/update_cell.cpp
92+
../../module_io/output.cpp
9193
${depend_files}
9294
)
9395

@@ -97,6 +99,8 @@ AddTest(
9799
SOURCES msst_test.cpp
98100
../md_base.cpp
99101
../msst.cpp
102+
../../module_cell/update_cell.cpp
103+
../../module_io/output.cpp
100104
${depend_files}
101105
)
102106

0 commit comments

Comments
 (0)