Skip to content

Commit ed29623

Browse files
committed
modify check_dtau
1 parent 74284f9 commit ed29623

File tree

9 files changed

+76
-85
lines changed

9 files changed

+76
-85
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ time.json
2323
__pycache__
2424
abacus.json
2525
*.npy
26+
*.sh
27+
*.py
28+
*.txt

source/module_cell/module_neighbor/test/sltk_atom_arrange_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "gmock/gmock.h"
1010
#include "gtest/gtest.h"
1111
#include "prepare_unitcell.h"
12-
12+
#include "module_cell/read_stru.h"
1313
#ifdef __LCAO
1414
InfoNonlocal::InfoNonlocal()
1515
{
@@ -108,7 +108,7 @@ TEST_F(SltkAtomArrangeTest, setsrNL)
108108

109109
TEST_F(SltkAtomArrangeTest, Search)
110110
{
111-
ucell->check_dtau();
111+
unitcell::check_dtau(ucell->atoms,ucell->ntype, ucell->lat0, ucell->latvec);
112112
Grid_Driver grid_d(PARAM.input.test_deconstructor, PARAM.input.test_grid);
113113
ofs.open("test.out");
114114
bool test_only = true;
@@ -124,7 +124,7 @@ TEST_F(SltkAtomArrangeTest, Search)
124124

125125
TEST_F(SltkAtomArrangeTest, Filteradjs)
126126
{
127-
ucell->check_dtau();
127+
unitcell::check_dtau(ucell->atoms,ucell->ntype, ucell->lat0, ucell->latvec);
128128
Grid_Driver grid_d(PARAM.input.test_deconstructor, PARAM.input.test_grid);
129129
ofs.open("test.out");
130130
bool test_only = true;

source/module_cell/module_neighbor/test/sltk_grid_test.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include "gmock/gmock.h"
22
#include "gtest/gtest.h"
3-
#define private public
4-
#include "module_parameter/parameter.h"
5-
#undef private
63

74
#define private public
85
#include "../sltk_grid.h"
96
#include "prepare_unitcell.h"
7+
#include "module_parameter/parameter.h"
108
#undef private
9+
#include "module_cell/read_stru.h"
1110
#ifdef __LCAO
1211
InfoNonlocal::InfoNonlocal()
1312
{
@@ -78,7 +77,7 @@ using SltkGridDeathTest = SltkGridTest;
7877
TEST_F(SltkGridTest, Init)
7978
{
8079
ofs.open("test.out");
81-
ucell->check_dtau();
80+
unitcell::check_dtau(ucell->atoms,ucell->ntype, ucell->lat0, ucell->latvec);
8281
test_atom_in = 2;
8382
PARAM.input.test_grid = 1;
8483
Grid LatGrid(PARAM.input.test_grid);
@@ -96,7 +95,7 @@ TEST_F(SltkGridTest, Init)
9695
TEST_F(SltkGridTest, InitSmall)
9796
{
9897
ofs.open("test.out");
99-
ucell->check_dtau();
98+
unitcell::check_dtau(ucell->atoms,ucell->ntype, ucell->lat0, ucell->latvec);
10099
test_atom_in = 2;
101100
PARAM.input.test_grid = 1;
102101
radius = 0.5;
@@ -129,7 +128,7 @@ TEST_F(SltkGridTest, InitSmall)
129128
TEST_F(SltkGridTest, InitNoExpand)
130129
{
131130
ofs.open("test.out");
132-
ucell->check_dtau();
131+
unitcell::check_dtau(ucell->atoms,ucell->ntype, ucell->lat0, ucell->latvec);
133132
test_atom_in = 2;
134133
PARAM.input.test_grid = 1;
135134
double radius = 1e-1000;

source/module_cell/read_atoms.cpp

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn
548548
// mohan add 2010-06-30
549549
//xiaohui modify 2015-03-15, cancel outputfile "STRU_READIN.xyz"
550550
//this->print_cell_xyz("STRU_READIN.xyz");
551-
this->check_dtau();
551+
unitcell::check_dtau(this->atoms,this->ntype, this->lat0, this->latvec);
552552

553553
if (unitcell::check_tau(this->atoms, this->ntype, this->lat0))
554554
{
@@ -680,77 +680,6 @@ int UnitCell::find_type(const std::string &label)
680680
}
681681
*/
682682

683-
void UnitCell::check_dtau() {
684-
for(int it=0; it<ntype; it++)
685-
{
686-
Atom* atom1 = &atoms[it];
687-
for(int ia=0; ia<atoms[it].na; ia++)
688-
{
689-
double dx2 = (atom1->taud[ia].x+10000) - int(atom1->taud[ia].x+10000);
690-
double dy2 = (atom1->taud[ia].y+10000) - int(atom1->taud[ia].y+10000);
691-
double dz2 = (atom1->taud[ia].z+10000) - int(atom1->taud[ia].z+10000);
692-
693-
// mohan add 2011-04-07
694-
while(dx2 >= 1)
695-
{
696-
GlobalV::ofs_warning << " dx2 is >=1 " << std::endl;
697-
dx2 -= 1.0;
698-
}
699-
while(dy2 >= 1)
700-
{
701-
GlobalV::ofs_warning << " dy2 is >=1 " << std::endl;
702-
dy2 -= 1.0;
703-
}
704-
while(dz2 >= 1)
705-
{
706-
GlobalV::ofs_warning << " dz2 is >=1 " << std::endl;
707-
dz2 -= 1.0;
708-
}
709-
// mohan add 2011-04-07
710-
while(dx2<0)
711-
{
712-
GlobalV::ofs_warning << " dx2 is <0 " << std::endl;
713-
dx2 += 1.0;
714-
}
715-
while(dy2<0)
716-
{
717-
GlobalV::ofs_warning << " dy2 is <0 " << std::endl;
718-
dy2 += 1.0;
719-
}
720-
while(dz2<0)
721-
{
722-
GlobalV::ofs_warning << " dz2 is <0 " << std::endl;
723-
dz2 += 1.0;
724-
}
725-
726-
atom1->taud[ia].x = dx2;
727-
atom1->taud[ia].y = dy2;
728-
atom1->taud[ia].z = dz2;
729-
730-
double cx2=0.0;
731-
double cy2=0.0;
732-
double cz2=0.0;
733-
734-
ModuleBase::Mathzone::Direct_to_Cartesian(
735-
atom1->taud[ia].x, atom1->taud[ia].y, atom1->taud[ia].z,
736-
latvec.e11, latvec.e12, latvec.e13,
737-
latvec.e21, latvec.e22, latvec.e23,
738-
latvec.e31, latvec.e32, latvec.e33,
739-
cx2, cy2, cz2);
740-
741-
atom1->tau[ia].x = cx2;
742-
atom1->tau[ia].y = cy2;
743-
atom1->tau[ia].z = cz2;
744-
745-
// std::cout << std::setw(15) << dx2 << std::setw(15) << dy2 << std::setw(15) << dz2
746-
// << std::setw(15) << cx2 << std::setw(15) << cy2 << std::setw(15) << cz2
747-
// << std::endl;
748-
749-
}
750-
}
751-
return;
752-
}
753-
754683
void UnitCell::read_orb_file(int it, std::string &orb_file, std::ofstream &ofs_running, Atom* atom)
755684
{
756685
// the maximum L is 9 like cc-pV9Z, according to the basissetexchange https://www.basissetexchange.org/

source/module_cell/read_stru.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "read_stru.h"
22
#include "module_base/timer.h"
33
#include "module_base/vector3.h"
4+
#include "module_base/mathzone.h"
5+
46

57
namespace unitcell
68
{
@@ -52,4 +54,58 @@ namespace unitcell
5254
ModuleBase::timer::tick("UnitCell","check_tau");
5355
return true;
5456
}
57+
58+
void check_dtau(Atom* atoms,
59+
const int& ntype,
60+
const double& lat0,
61+
ModuleBase::Matrix3& latvec)
62+
{
63+
for(int it=0; it<ntype; it++)
64+
{
65+
Atom* atom1 = &atoms[it];
66+
for(int ia=0; ia<atoms[it].na; ia++)
67+
{
68+
//fmod(x,1.0) set the result as [0,1),
69+
//if x=2.3,fmod(2.3,1.0)=0.3,fmod(2.3,1.0)+1=1.3,
70+
// fmod(fmod(2.3,1.0)+1,1.0)=0.3
71+
//if x=-0.7,fmod(-0.7,1.0)=-0.7 or 0.3,fmod(-0.7,1.0)+1=1.3,
72+
// fmod(fmod(-0.7,1.0)+1,1.0)=0.3
73+
double dx2 = fmod(fmod(atom1->taud[ia].x,1.0)+1.0,1.0);
74+
double dy2 = fmod(fmod(atom1->taud[ia].y,1.0)+1.0,1.0);
75+
double dz2 = fmod(fmod(atom1->taud[ia].z,1.0)+1.0,1.0);
76+
77+
atom1->taud[ia].x = dx2;
78+
atom1->taud[ia].y = dy2;
79+
atom1->taud[ia].z = dz2;
80+
81+
double cx2=0.0;
82+
double cy2=0.0;
83+
double cz2=0.0;
84+
85+
ModuleBase::Mathzone::Direct_to_Cartesian(
86+
atom1->taud[ia].x,
87+
atom1->taud[ia].y,
88+
atom1->taud[ia].z,
89+
latvec.e11,
90+
latvec.e12,
91+
latvec.e13,
92+
latvec.e21,
93+
latvec.e22,
94+
latvec.e23,
95+
latvec.e31,
96+
latvec.e32,
97+
latvec.e33,
98+
cx2,
99+
cy2,
100+
cz2);
101+
102+
atom1->tau[ia].x = cx2;
103+
atom1->tau[ia].y = cy2;
104+
atom1->tau[ia].z = cz2;
105+
106+
}
107+
}
108+
109+
}
110+
55111
}

source/module_cell/read_stru.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ namespace unitcell
88
bool check_tau(const Atom* atoms,
99
const int& ntype,
1010
const double& lat0);
11-
11+
void check_dtau(Atom* atoms,
12+
const int& ntype,
13+
const double& lat0,
14+
ModuleBase::Matrix3& latvec);
15+
1216
bool read_atom_species(std::ifstream& ifa,
1317
std::ofstream& ofs_running,
1418
UnitCell& ucell); // read in the atom information for each type of atom

source/module_cell/test/support/mock_unitcell.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ void UnitCell::print_stru_file(const std::string& fn,
4444
const bool& orb,
4545
const bool& dpks_desc,
4646
const int& iproc) const {}
47-
void UnitCell::check_dtau() {}
4847
void UnitCell::cal_nwfc(std::ofstream& log) {}
4948
void UnitCell::cal_meshx() {}
5049
void UnitCell::cal_natomwfc(std::ofstream& log) {}

source/module_cell/test/unitcell_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "module_base/mathzone.h"
1313
#include "prepare_unitcell.h"
1414
#include "module_cell/update_cell.h"
15+
#include "module_cell/read_stru.h"
1516
#include <streambuf>
1617
#include <valarray>
1718
#include <vector>
@@ -738,7 +739,7 @@ TEST_F(UcellTest, CheckDTau)
738739
UcellTestPrepare utp = UcellTestLib["C1H2-CheckDTau"];
739740
PARAM.input.relax_new = utp.relax_new;
740741
ucell = utp.SetUcellInfo();
741-
ucell->check_dtau();
742+
unitcell::check_dtau(ucell->atoms,ucell->ntype, ucell->lat0, ucell->latvec);
742743
for (int it = 0; it < utp.natom.size(); ++it)
743744
{
744745
for (int ia = 0; ia < utp.natom[it]; ++ia)

source/module_cell/unitcell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class UnitCell {
259259
const bool& orb = false,
260260
const bool& dpks_desc = false,
261261
const int& iproc = 0) const;
262-
void check_dtau();
262+
// void check_dtau();
263263
// for constrained vc-relaxation where type of lattice
264264
// is fixed, adjust the lattice vectors
265265

0 commit comments

Comments
 (0)