Skip to content

Commit 23271d2

Browse files
authored
Update the outputs of geometry relaxation (#6387)
* update the output formats of rt-TDDFT * update the output formats of rt-TDDFT * fix a bug * update initialized velocities * found some output information is still lacking in MD module * update output information * remove some global variables in relax_driver * update outputs * update relaxation outputs * update relaxation output messages * update tests of print info * fix a test * fix cg outputs * udpate cg test * update relax tests * update LCAO output stress format * change update_cell.cpp algorithm, when the ion move is larger than the cell length, it is fine to proceed the relaxation calculations * fix tests for unitcells * update cell
1 parent 7aa668a commit 23271d2

23 files changed

+307
-232
lines changed

source/source_cell/atom_spec.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class Atom
3838
std::vector<ModuleBase::Vector3<double>> taud; // Direct coordinates of each atom in this type.
3939
std::vector<ModuleBase::Vector3<double>> vel; // velocities of each atom in this type.
4040
std::vector<ModuleBase::Vector3<double>> force; // force acting on each atom in this type.
41-
std::vector<ModuleBase::Vector3<double>>
42-
lambda; // Lagrange multiplier for each atom in this type. used in deltaspin
41+
std::vector<ModuleBase::Vector3<double>> lambda; // Lagrange multiplier for each atom in this type. used in deltaspin
4342
std::vector<ModuleBase::Vector3<int>> constrain; // constrain for each atom in this type. used in deltaspin
4443
std::string label_orb = "\0"; // atomic Element symbol in the orbital file of lcao
4544

source/source_cell/test/unitcell_test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ TEST_F(UcellDeathTest, RemakeCellWarnings)
603603
}
604604
else
605605
{
606-
EXPECT_THAT(output, testing::HasSubstr("latname not supported!"));
606+
EXPECT_THAT(output, testing::HasSubstr("latname type not supported!"));
607607
}
608608
}
609609
}
@@ -804,6 +804,9 @@ TEST_F(UcellTest, SelectiveDynamics)
804804
EXPECT_TRUE(ucell->if_atoms_can_move());
805805
}
806806

807+
808+
// mohan comment out 2025-07-14
809+
/*
807810
TEST_F(UcellDeathTest, PeriodicBoundaryAdjustment1)
808811
{
809812
UcellTestPrepare utp = UcellTestLib["C1H2-PBA"];
@@ -816,6 +819,7 @@ TEST_F(UcellDeathTest, PeriodicBoundaryAdjustment1)
816819
std::string output = testing::internal::GetCapturedStdout();
817820
EXPECT_THAT(output, testing::HasSubstr("the movement of atom is larger than the length of cell"));
818821
}
822+
*/
819823

820824
TEST_F(UcellTest, PeriodicBoundaryAdjustment2)
821825
{

source/source_cell/update_cell.cpp

Lines changed: 84 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "update_cell.h"
22
#include "bcast_cell.h"
33
#include "source_base/global_function.h"
4+
45
namespace unitcell
56
{
7+
68
void remake_cell(Lattice& lat)
79
{
810
ModuleBase::TITLE("Lattice", "rmake_cell");
@@ -13,18 +15,20 @@ void remake_cell(Lattice& lat)
1315
std::string& latName = lat.latName;
1416
ModuleBase::Matrix3& latvec = lat.latvec;
1517

16-
if (latName == "none") {
17-
ModuleBase::WARNING_QUIT("UnitCell",
18-
"to use fixed_ibrav, latname must be provided");
19-
} else if (latName == "sc") // ibrav = 1
18+
if (latName == "none")
2019
{
20+
ModuleBase::WARNING_QUIT("UnitCell", "to use fixed_ibrav, latname must be provided");
21+
}
22+
else if (latName == "sc") // ibrav = 1
23+
{
2124
double celldm = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
2225
+ pow(latvec.e13, 2));
2326

2427
latvec.Zero();
2528
latvec.e11 = latvec.e22 = latvec.e33 = celldm;
26-
} else if (latName == "fcc") // ibrav = 2
27-
{
29+
}
30+
else if (latName == "fcc") // ibrav = 2
31+
{
2832
double celldm = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
2933
+ pow(latvec.e13, 2)) / std::sqrt(2.0);
3034

@@ -37,8 +41,9 @@ void remake_cell(Lattice& lat)
3741
latvec.e31 = -celldm;
3842
latvec.e32 = celldm;
3943
latvec.e33 = 0.0;
40-
} else if (latName == "bcc") // ibrav = 3
41-
{
44+
}
45+
else if (latName == "bcc") // ibrav = 3
46+
{
4247
double celldm = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
4348
+ pow(latvec.e13, 2))
4449
/ std::sqrt(3.0);
@@ -52,9 +57,10 @@ void remake_cell(Lattice& lat)
5257
latvec.e31 = -celldm;
5358
latvec.e32 = -celldm;
5459
latvec.e33 = celldm;
55-
} else if (latName == "hexagonal") // ibrav = 4
56-
{
57-
double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
60+
}
61+
else if (latName == "hexagonal") // ibrav = 4
62+
{
63+
double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
5864
+ pow(latvec.e13, 2));
5965
double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2)
6066
+ pow(latvec.e33, 2));
@@ -69,19 +75,21 @@ void remake_cell(Lattice& lat)
6975
latvec.e31 = 0.0;
7076
latvec.e32 = 0.0;
7177
latvec.e33 = celldm3;
72-
} else if (latName == "trigonal") // ibrav = 5
73-
{
74-
double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
78+
}
79+
else if (latName == "trigonal") // ibrav = 5
80+
{
81+
double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
7582
+ pow(latvec.e13, 2));
7683
double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2)
7784
+ pow(latvec.e23, 2));
7885
double celldm12 = (latvec.e11 * latvec.e21 + latvec.e12 * latvec.e22
7986
+ latvec.e13 * latvec.e23);
8087
double cos12 = celldm12 / celldm1 / celldm2;
8188

82-
if (cos12 <= -0.5 || cos12 >= 1.0) {
83-
ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!");
84-
}
89+
if (cos12 <= -0.5 || cos12 >= 1.0)
90+
{
91+
ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!");
92+
}
8593
double t1 = sqrt(1.0 + 2.0 * cos12);
8694
double t2 = sqrt(1.0 - cos12);
8795

@@ -99,8 +107,9 @@ void remake_cell(Lattice& lat)
99107
latvec.e31 = -e11;
100108
latvec.e32 = e12;
101109
latvec.e33 = e13;
102-
} else if (latName == "st") // ibrav = 6
103-
{
110+
}
111+
else if (latName == "st") // ibrav = 6
112+
{
104113
double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
105114
+ pow(latvec.e13, 2));
106115
double celldm3 = std::sqrt(pow(latvec.e31, 2) + pow(latvec.e32, 2)
@@ -114,8 +123,9 @@ void remake_cell(Lattice& lat)
114123
latvec.e31 = 0.0;
115124
latvec.e32 = 0.0;
116125
latvec.e33 = celldm3;
117-
} else if (latName == "bct") // ibrav = 7
118-
{
126+
}
127+
else if (latName == "bct") // ibrav = 7
128+
{
119129
double celldm1 = std::abs(latvec.e11);
120130
double celldm2 = std::abs(latvec.e13);
121131

@@ -128,8 +138,9 @@ void remake_cell(Lattice& lat)
128138
latvec.e31 = -celldm1;
129139
latvec.e32 = -celldm1;
130140
latvec.e33 = celldm2;
131-
} else if (latName == "so") // ibrav = 8
132-
{
141+
}
142+
else if (latName == "so") // ibrav = 8
143+
{
133144
double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
134145
+ pow(latvec.e13, 2));
135146
double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2)
@@ -146,8 +157,9 @@ void remake_cell(Lattice& lat)
146157
latvec.e31 = 0.0;
147158
latvec.e32 = 0.0;
148159
latvec.e33 = celldm3;
149-
} else if (latName == "baco") // ibrav = 9
150-
{
160+
}
161+
else if (latName == "baco") // ibrav = 9
162+
{
151163
double celldm1 = std::abs(latvec.e11);
152164
double celldm2 = std::abs(latvec.e22);
153165
double celldm3 = std::abs(latvec.e33);
@@ -161,8 +173,9 @@ void remake_cell(Lattice& lat)
161173
latvec.e31 = 0.0;
162174
latvec.e32 = 0.0;
163175
latvec.e33 = celldm3;
164-
} else if (latName == "fco") // ibrav = 10
165-
{
176+
}
177+
else if (latName == "fco") // ibrav = 10
178+
{
166179
double celldm1 = std::abs(latvec.e11);
167180
double celldm2 = std::abs(latvec.e22);
168181
double celldm3 = std::abs(latvec.e33);
@@ -176,8 +189,9 @@ void remake_cell(Lattice& lat)
176189
latvec.e31 = 0.0;
177190
latvec.e32 = celldm2;
178191
latvec.e33 = celldm3;
179-
} else if (latName == "bco") // ibrav = 11
180-
{
192+
}
193+
else if (latName == "bco") // ibrav = 11
194+
{
181195
double celldm1 = std::abs(latvec.e11);
182196
double celldm2 = std::abs(latvec.e12);
183197
double celldm3 = std::abs(latvec.e13);
@@ -191,8 +205,9 @@ void remake_cell(Lattice& lat)
191205
latvec.e31 = -celldm1;
192206
latvec.e32 = -celldm2;
193207
latvec.e33 = celldm3;
194-
} else if (latName == "sm") // ibrav = 12
195-
{
208+
}
209+
else if (latName == "sm") // ibrav = 12
210+
{
196211
double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
197212
+ pow(latvec.e13, 2));
198213
double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2)
@@ -215,16 +230,18 @@ void remake_cell(Lattice& lat)
215230
latvec.e31 = 0.0;
216231
latvec.e32 = 0.0;
217232
latvec.e33 = celldm3;
218-
} else if (latName == "bacm") // ibrav = 13
219-
{
233+
}
234+
else if (latName == "bacm") // ibrav = 13
235+
{
220236
double celldm1 = std::abs(latvec.e11);
221237
double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2)
222238
+ pow(latvec.e23, 2));
223239
double celldm3 = std::abs(latvec.e13);
224240

225241
double cos12 = latvec.e21 / celldm2;
226-
if (cos12 >= 1.0) {
227-
ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!");
242+
if (cos12 >= 1.0)
243+
{
244+
ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!");
228245
}
229246

230247
double e21 = celldm2 * cos12;
@@ -239,8 +256,9 @@ void remake_cell(Lattice& lat)
239256
latvec.e31 = celldm1;
240257
latvec.e32 = 0.0;
241258
latvec.e33 = celldm3;
242-
} else if (latName == "triclinic") // ibrav = 14
243-
{
259+
}
260+
else if (latName == "triclinic") // ibrav = 14
261+
{
244262
double celldm1 = std::sqrt(pow(latvec.e11, 2) + pow(latvec.e12, 2)
245263
+ pow(latvec.e13, 2));
246264
double celldm2 = std::sqrt(pow(latvec.e21, 2) + pow(latvec.e22, 2)
@@ -258,8 +276,9 @@ void remake_cell(Lattice& lat)
258276
double cos23 = celldm23 / celldm2 / celldm3;
259277

260278
double sin12 = std::sqrt(1.0 - cos12 * cos12);
261-
if (cos12 >= 1.0) {
262-
ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!");
279+
if (cos12 >= 1.0)
280+
{
281+
ModuleBase::WARNING_QUIT("unitcell", "wrong cos12!");
263282
}
264283

265284
latvec.e11 = celldm1;
@@ -278,15 +297,16 @@ void remake_cell(Lattice& lat)
278297
else
279298
{
280299
std::cout << "latname is : " << latName << std::endl;
281-
ModuleBase::WARNING_QUIT("UnitCell::remake_cell",
282-
"latname not supported!");
300+
ModuleBase::WARNING_QUIT("unitcell::remake_cell",
301+
"latname type not supported!");
283302
}
284303
}
285304

286305
// LiuXh add a new function here,
287306
// 20180515
288-
void setup_cell_after_vc(UnitCell& ucell, std::ofstream& log) {
289-
ModuleBase::TITLE("UnitCell", "setup_cell_after_vc");
307+
void setup_cell_after_vc(UnitCell& ucell, std::ofstream& log)
308+
{
309+
ModuleBase::TITLE("unitcell", "setup_cell_after_vc");
290310
assert(ucell.lat0 > 0.0);
291311
ucell.omega = std::abs(ucell.latvec.Det()) *
292312
pow(ucell.lat0, 3);
@@ -325,9 +345,11 @@ void setup_cell_after_vc(UnitCell& ucell, std::ofstream& log) {
325345
ucell.GGT = ucell.G * ucell.GT;
326346
ucell.invGGT = ucell.GGT.Inverse();
327347

328-
for (int it = 0; it < ucell.ntype; it++) {
329-
Atom* atom = &ucell.atoms[it];
330-
for (int ia = 0; ia < atom->na; ia++) {
348+
for (int it = 0; it < ucell.ntype; it++)
349+
{
350+
Atom* atom = &ucell.atoms[it];
351+
for (int ia = 0; ia < atom->na; ia++)
352+
{
331353
atom->tau[ia] = atom->taud[ia] * ucell.latvec;
332354
}
333355
}
@@ -354,10 +376,13 @@ void update_pos_tau(const Lattice& lat,
354376
Atom* atoms)
355377
{
356378
int iat = 0;
357-
for (int it = 0; it < ntype; it++) {
358-
Atom* atom = &atoms[it];
359-
for (int ia = 0; ia < atom->na; ia++) {
360-
for (int ik = 0; ik < 3; ++ik) {
379+
for (int it = 0; it < ntype; it++)
380+
{
381+
Atom* atom = &atoms[it];
382+
for (int ia = 0; ia < atom->na; ia++)
383+
{
384+
for (int ik = 0; ik < 3; ++ik)
385+
{
361386
if (atom->mbl[ia][ik])
362387
{
363388
atom->dis[ia][ik] = pos[3 * iat + ik] / lat.lat0 - atom->tau[ia][ik];
@@ -454,9 +479,11 @@ void periodic_boundary_adjustment(Atom* atoms,
454479
// first adjust direct coordinates,
455480
// then update them into cartesian coordinates,
456481
//----------------------------------------------
457-
for (int it = 0; it < ntype; it++) {
458-
Atom* atom = &atoms[it];
459-
for (int ia = 0; ia < atom->na; ia++) {
482+
for (int it = 0; it < ntype; it++)
483+
{
484+
Atom* atom = &atoms[it];
485+
for (int ia = 0; ia < atom->na; ia++)
486+
{
460487
// mohan update 2011-03-21
461488
for (int ik = 0; ik < 3; ik++)
462489
{
@@ -476,12 +503,12 @@ void periodic_boundary_adjustment(Atom* atoms,
476503
|| atom->taud[ia].y >= 1.0
477504
|| atom->taud[ia].z >= 1.0)
478505
{
479-
GlobalV::ofs_warning << " it=" << it + 1 << " ia=" << ia + 1 << std::endl;
480-
GlobalV::ofs_warning << "d=" << atom->taud[ia].x << " "
506+
GlobalV::ofs_warning << " atom type=" << it + 1 << " atom index=" << ia + 1 << std::endl;
507+
GlobalV::ofs_warning << " direct coordinate=" << atom->taud[ia].x << " "
481508
<< atom->taud[ia].y << " "
482509
<< atom->taud[ia].z << std::endl;
483-
ModuleBase::WARNING_QUIT("Ions_Move_Basic::move_ions",
484-
"the movement of atom is larger than the length of cell.");
510+
ModuleBase::WARNING_QUIT("unitcell::periodic_boundary_adjustment",
511+
"Movement of atom is larger than the cell length");
485512
}
486513

487514
atom->tau[ia] = atom->taud[ia] * latvec;

source/source_io/print_info.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ void print_wfcfft(const Input_para& inp, ModulePW::PW_Basis_K& pw_wfc, std::ofst
344344

345345
void print_screen(const int& stress_step, const int& force_step, const int& istep)
346346
{
347-
std::cout << " ======================================================================" << std::endl;
348-
GlobalV::ofs_running << " ======================================================================" << std::endl;
347+
std::cout << "\n ================================================================" << std::endl;
348+
GlobalV::ofs_running << " ================================================================" << std::endl;
349349

350350
if(PARAM.inp.calculation=="scf")
351351
{
@@ -366,20 +366,22 @@ void print_screen(const int& stress_step, const int& force_step, const int& iste
366366
{
367367
if(PARAM.inp.calculation=="relax")
368368
{
369-
std::cout << " STEP OF ION RELAXATION: " << unsigned(istep) << std::endl;
370-
GlobalV::ofs_running << " STEP OF ION RELAXATION : " << unsigned(istep) << std::endl;
369+
std::cout << " RELAX STEP: " << unsigned(istep) << std::endl;
370+
GlobalV::ofs_running << " RELAX STEP: " << unsigned(istep) << std::endl;
371371
}
372372
else if(PARAM.inp.calculation=="cell-relax")
373373
{
374-
std::cout << " RELAX CELL : " << unsigned(stress_step) << std::endl;
375-
std::cout << " RELAX IONS : " << unsigned(force_step) << " (in total: " << unsigned(istep) << ")" << std::endl;
376-
GlobalV::ofs_running << " RELAX CELL : " << unsigned(stress_step) << std::endl;
377-
GlobalV::ofs_running << " RELAX IONS : " << unsigned(force_step) << " (in total: " << unsigned(istep) << ")" << std::endl;
374+
std::cout << " RELAX STEP: " << unsigned(istep);
375+
std::cout << " (CELL_CHANGE# " << unsigned(stress_step);
376+
std::cout << " IONS_CHANGE# " << unsigned(force_step) << ")" << std::endl;
377+
GlobalV::ofs_running << " RELAX STEP: " << unsigned(istep);
378+
GlobalV::ofs_running << " (CELL_CHANGE# " << unsigned(stress_step);
379+
GlobalV::ofs_running << " IONS_CHANGE# " << unsigned(force_step) << ")" << std::endl;
378380
}
379381
}
380382

381-
std::cout << " ======================================================================" << std::endl;
382-
GlobalV::ofs_running << " ======================================================================" << std::endl;
383+
std::cout << " ================================================================" << std::endl;
384+
GlobalV::ofs_running << " ================================================================" << std::endl;
383385
}
384386

385387
} // namespace ModuleIO

0 commit comments

Comments
 (0)