Skip to content

Commit 3c16456

Browse files
committed
Merge branch 'gint-omp' of https://github.com/dzzz2001/abacus-develop into gint-omp
2 parents a8b2504 + 8ea0d43 commit 3c16456

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+950
-554
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
- [out\_mat\_t](#out_mat_t)
154154
- [out\_mat\_dh](#out_mat_dh)
155155
- [out\_mat\_xc](#out_mat_xc)
156+
- [out\_mat\_xc2](#out_mat_xc2)
156157
- [out\_eband\_terms](#out_eband_terms)
157158
- [out\_hr\_npz/out\_dm\_npz](#out_hr_npzout_dm_npz)
158159
- [dm\_to\_rho](#dm_to_rho)
@@ -1799,6 +1800,13 @@ These variables are used to control the output of properties.
17991800
The band (KS orbital) energy for each (k-point, spin, band) will be printed in the file `OUT.${suffix}/vxc_out.dat`. If EXX is calculated, the local and EXX part of band energy will also be printed in `OUT.${suffix}/vxc_local_out.dat`and `OUT.${suffix}/vxc_exx_out.dat`, respectively. All the `vxc*_out.dat` files contains 3 integers (nk, nspin, nband) followed by nk\*nspin\*nband lines of energy Hartree and eV.
18001801
- **Default**: False
18011802

1803+
### out_mat_xc2
1804+
1805+
- **Type**: Boolean
1806+
- **Availability**: Numerical atomic orbital (NAO) basis
1807+
- **Description**: Whether to print the exchange-correlation matrices in **numerical orbital representation** (unit: Ry): $\braket{\phi_i|V_\text{xc}^\text{(semi-)local}+V_\text{exx}+V_\text{DFTU}|\phi_j}(\mathbf{R})$ in CSR format (the same format as [out_mat_hs2](../elec_properties/hs_matrix.md#out_mat_hs2)) in the directory `OUT.${suffix}`. (Note that currently DeePKS term is not included. ) The files are named `Vxc_R_spin$s`.
1808+
- **Default**: False
1809+
18021810
### out_eband_terms
18031811

18041812
- **Type**: Boolean

source/Makefile.Objects

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ OBJS_DEEPKS=LCAO_deepks.o\
208208
deepks_orbpre.o\
209209
deepks_vdelta.o\
210210
deepks_vdpre.o\
211-
deepks_hmat.o\
211+
deepks_vdrpre.o\
212212
deepks_pdm.o\
213213
deepks_phialpha.o\
214214
LCAO_deepks_io.o\
@@ -266,6 +266,7 @@ OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\
266266
lcao_after_scf.o\
267267
esolver_gets.o\
268268
lcao_others.o\
269+
esolver_dm2rho.o\
269270

270271
OBJS_GINT=gint.o\
271272
gint_gamma_env.o\

source/module_base/formatter.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,22 @@ class FmtTable
191191
*
192192
* @param titles titles, its size should be the same as the number of columns
193193
* @param nrows number of rows
194-
* @param aligns Alignments instance, can be constructed with initializer_list<char> like {'r', 'c'}, for right and center alignment for values and titles
194+
* @param fmts format strings for each column, its size should be the same as the number of columns
195+
* @param indent indent for each column, default is 0
196+
* @param aligns Alignments instance, for alignment of values and titles, e.g. {Align::LEFT, Align::RIGHT} for left alignment of values and right alignment of titles
195197
* @param frames Frames instance, can be constructed with initializer_list<char> like {'-', '-', '-', ' ', ' '}, for up, middle, down, left and right frames
196198
* @param delimiters Delimiters instance, can be constructed with initializer_list<char> like {'-', ' '}, for horizontal and vertical delimiters
197199
*/
198200
FmtTable(const std::vector<std::string>& titles,
199-
const size_t& nrows,
201+
const size_t nrows,
200202
const std::vector<std::string>& fmts,
203+
const size_t indent = 0,
201204
const Alignments& aligns = {},
202205
const Frames& frames = {},
203-
const Delimiters& delimiters = {}): titles_(titles), data_(nrows, titles.size()), fmts_(fmts), aligns_(aligns), frames_(frames), delimiters_(delimiters)
204-
{ assert(titles.size() == fmts.size()); };
206+
const Delimiters& delimiters = {}):
207+
titles_(titles), data_(nrows, titles.size()), // data
208+
fmts_(fmts), indent_(indent), aligns_(aligns), frames_(frames), delimiters_(delimiters) // styles
209+
{ assert(titles.size() == fmts.size()||titles.size() == 0); };
205210
~FmtTable() {};
206211
/**
207212
* @brief import data from std::vector
@@ -269,22 +274,24 @@ class FmtTable
269274
*/
270275
std::string concat_title(const std::vector<std::string>& titles) const
271276
{
272-
std::string dst;
277+
std::string dst = "";
273278
// first sum width of all titles
274279
size_t width = std::accumulate(titles.begin(), titles.end(), 0, [](const size_t& acc, const std::string& s) { return acc + s.size(); });
275280
// add width of delimiters
276281
width += titles.size() - 1;
277282
// add width of left and right frames
278283
width += 2;
279-
dst += std::string(width, frames_.up_) + "\n" + std::string(1, frames_.l_);
284+
dst += std::string(indent_, ' ') + std::string(width, frames_.up_) + "\n"; // first line: the upper frame
285+
dst += std::string(indent_, ' ') + std::string(1, frames_.l_); // second line: the left frame + titles + right frame
280286
for(size_t i = 0; i < titles.size(); i++)
281287
{
282288
dst += titles[i];
283289
if (i != titles.size() - 1) {
284290
dst += delimiters_.v_;
285291
}
286292
}
287-
dst += std::string(1, frames_.r_) + "\n" + std::string(width, frames_.mid_) + "\n";
293+
dst += std::string(1, frames_.r_) + "\n";
294+
dst += std::string(indent_, ' ') + std::string(width, frames_.mid_) + "\n"; // third line: the middle frame
288295
return dst;
289296
}
290297
/**
@@ -303,10 +310,10 @@ class FmtTable
303310
width += row.size() - 1;
304311
// for the left and right frame
305312
width += 2;
306-
if (pos == 't') {
307-
dst += std::string(width, frames_.up_) + "\n";
313+
if (pos == 't') { // 't' for top
314+
dst += std::string(indent_, ' ') + std::string(width, frames_.up_) + "\n";
308315
}
309-
dst += std::string(1, frames_.l_);
316+
dst += std::string(indent_, ' ') + std::string(1, frames_.l_);
310317
for(size_t i = 0; i < row.size(); i++)
311318
{
312319
dst += row[i];
@@ -315,8 +322,8 @@ class FmtTable
315322
}
316323
}
317324
dst += std::string(1, frames_.r_) + "\n";
318-
if (pos == 'b') {
319-
dst += std::string(width, frames_.dw_) + "\n";
325+
if (pos == 'b') { // 'b' for bottom
326+
dst += std::string(indent_, ' ') + std::string(width, frames_.dw_) + "\n"; // the last line
320327
}
321328
return dst;
322329
}
@@ -397,6 +404,7 @@ class FmtTable
397404
std::vector<std::string> titles_;
398405
NDArray<std::string> data_; // data
399406
std::vector<std::string> fmts_; // format strings for each column
407+
size_t indent_ = 0; // indent for each column
400408
};
401409

402410
#endif

source/module_base/test/formatter_test.cpp

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,28 @@ TEST(FormatterTest, FmtTableDefaultArgs)
217217
EXPECT_EQ(result, ref);
218218
}
219219

220+
TEST(FormatterTest, FmtTableHeadless)
221+
{
222+
const std::vector<std::string> titles = {"", "", ""};
223+
const std::vector<std::string> fmts = {"%s", "%d", "%f"};
224+
FmtTable table(titles, 5, fmts);
225+
const std::vector<std::string> col1 = {"row1", "row2", "row3", "row4", "row5"};
226+
const std::vector<int> col2 = {1, 2, 3, 4, 5};
227+
const std::vector<float> col3 = {1.1, 2.2, 3.3, 4.4, 5.5};
228+
table << col1 << col2 << col3;
229+
const std::string result = table.str();
230+
std::cout << result << std::endl;
231+
std::string ref = "";
232+
ref += "-----------------\n";
233+
ref += " row1 1 1.100000 \n";
234+
ref += " row2 2 2.200000 \n";
235+
ref += " row3 3 3.300000 \n";
236+
ref += " row4 4 4.400000 \n";
237+
ref += " row5 5 5.500000 \n";
238+
ref += "-----------------\n";
239+
EXPECT_EQ(result, ref);
240+
}
241+
220242
TEST(FormatterTest, FmtTableCustomArgsAlign)
221243
{
222244
// shared data
@@ -226,7 +248,7 @@ TEST(FormatterTest, FmtTableCustomArgsAlign)
226248
std::vector<int> col2 = {1, 2, 3, 4, 5};
227249
std::vector<float> col3 = {1.1, 2.2, 3.3, 4.4, 5.5};
228250
// align: l and l
229-
FmtTable table(titles, 5, fmts, {FmtTable::Align::LEFT, FmtTable::Align::LEFT});
251+
FmtTable table(titles, 5, fmts, 0, {FmtTable::Align::LEFT, FmtTable::Align::LEFT});
230252
table << col1 << col2 << col3;
231253
std::string result = table.str();
232254
std::cout << result << std::endl;
@@ -243,7 +265,7 @@ TEST(FormatterTest, FmtTableCustomArgsAlign)
243265
EXPECT_EQ(result, ref);
244266

245267
// align: r and r
246-
FmtTable table2(titles, 5, fmts, {FmtTable::Align::RIGHT, FmtTable::Align::RIGHT});
268+
FmtTable table2(titles, 5, fmts, 0, {FmtTable::Align::RIGHT, FmtTable::Align::RIGHT});
247269
table2 << col1 << col2 << col3;
248270
result = table2.str();
249271
std::cout << result << std::endl;
@@ -260,7 +282,7 @@ TEST(FormatterTest, FmtTableCustomArgsAlign)
260282
EXPECT_EQ(result, ref);
261283

262284
// align: l and r
263-
FmtTable table3(titles, 5, fmts, {FmtTable::Align::RIGHT, FmtTable::Align::LEFT});
285+
FmtTable table3(titles, 5, fmts, 0, {FmtTable::Align::RIGHT, FmtTable::Align::LEFT});
264286
table3 << col1 << col2 << col3;
265287
result = table3.str();
266288
std::cout << result << std::endl;
@@ -277,7 +299,7 @@ TEST(FormatterTest, FmtTableCustomArgsAlign)
277299
EXPECT_EQ(result, ref);
278300

279301
// align: r and l
280-
FmtTable table4(titles, 5, fmts, {FmtTable::Align::LEFT, FmtTable::Align::RIGHT});
302+
FmtTable table4(titles, 5, fmts, 0, {FmtTable::Align::LEFT, FmtTable::Align::RIGHT});
281303
table4 << col1 << col2 << col3;
282304
result = table4.str();
283305
std::cout << result << std::endl;
@@ -303,7 +325,12 @@ TEST(FormatterTest, FmtTableCustomArgsAlignFrame)
303325
std::vector<int> col2 = {1, 2, 3, 4, 5};
304326
std::vector<float> col3 = {1.1, 2.2, 3.3, 4.4, 5.5};
305327

306-
FmtTable table1(titles, 5, fmts, {FmtTable::Align::LEFT, FmtTable::Align::LEFT}, {'+', '?', '*', '.', '^'});
328+
FmtTable table1(titles,
329+
5,
330+
fmts,
331+
0,
332+
{FmtTable::Align::LEFT, FmtTable::Align::LEFT},
333+
{'+', '?', '*', '.', '^'});
307334
table1 << col1 << col2 << col3;
308335
std::string result = table1.str();
309336
std::cout << result << std::endl;
@@ -328,7 +355,10 @@ TEST(FormatterTest, FmtTableCustomArgsAlignFrameDelim)
328355
std::vector<std::string> col1 = {"row1", "row2", "row3", "row4", "row5"};
329356
std::vector<int> col2 = {1, 2, 3, 4, 5};
330357
std::vector<float> col3 = {1.1, 2.2, 3.3, 4.4, 5.5};
331-
FmtTable table1(titles, 5, fmts,
358+
FmtTable table1(titles,
359+
5,
360+
fmts,
361+
0,
332362
{FmtTable::Align::LEFT, FmtTable::Align::LEFT},
333363
{'=', '/', '&', '#', '%'},
334364
{'"', ']'});
@@ -348,6 +378,30 @@ TEST(FormatterTest, FmtTableCustomArgsAlignFrameDelim)
348378
EXPECT_EQ(result, ref);
349379
}
350380

381+
TEST(FormatterTest, FmtTableCustomIndent)
382+
{
383+
const std::vector<std::string> titles = {"title1", "t i t l e 2", "t-i-t-l-e-3"};
384+
const std::vector<std::string> fmts = {"%s", "%d", "%f"};
385+
FmtTable table(titles, 5, fmts, 4);
386+
const std::vector<std::string> col1 = {"row1", "row2", "row3", "row4", "row5"};
387+
const std::vector<int> col2 = {1, 2, 3, 4, 5};
388+
const std::vector<float> col3 = {1.1, 2.2, 3.3, 4.4, 5.5};
389+
table << col1 << col2 << col3;
390+
const std::string result = table.str();
391+
std::cout << result << std::endl;
392+
std::string ref = "";
393+
ref += " --------------------------------\n";
394+
ref += " title1 t i t l e 2 t-i-t-l-e-3 \n";
395+
ref += " --------------------------------\n";
396+
ref += " row1 1 1.100000 \n";
397+
ref += " row2 2 2.200000 \n";
398+
ref += " row3 3 3.300000 \n";
399+
ref += " row4 4 4.400000 \n";
400+
ref += " row5 5 5.500000 \n";
401+
ref += " --------------------------------\n";
402+
EXPECT_EQ(result, ref);
403+
}
404+
351405
int main(int argc, char** argv) {
352406
::testing::InitGoogleTest(&argc, argv);
353407
return RUN_ALL_TESTS();

source/module_base/timer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ void timer::print_all(std::ofstream &ofs)
300300

301301
std::vector<std::string> titles = {"CLASS_NAME", "NAME", "TIME/s", "CALLS", "AVG/s", "PER/%"};
302302
std::vector<std::string> formats = {"%-10s", "%-10s", "%6.2f", "%8d", "%6.2f", "%6.2f"};
303-
FmtTable time_statistics(titles, pers.size(), formats, {FmtTable::Align::LEFT, FmtTable::Align::CENTER});
303+
FmtTable time_statistics(/*titles=*/titles,
304+
/*nrows=*/pers.size(),
305+
/*formats=*/formats,
306+
/*indent=*/0,
307+
/*align=*/{/*value*/FmtTable::Align::LEFT, /*title*/FmtTable::Align::CENTER});
304308
time_statistics << class_names << names << times << calls << avgs << pers;
305309
const std::string table = "TIME STATISTICS\n" + time_statistics.str();
306310
std::cout<<table<<std::endl;

source/module_elecstate/elecstate_lcao.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,6 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d
2323
ModuleBase::TITLE("ElecStateLCAO", "psiToRho");
2424
ModuleBase::timer::tick("ElecStateLCAO", "psiToRho");
2525

26-
// // the calculations of dm, and dm -> rho are, technically, two separate
27-
// // functionalities, as we cannot rule out the possibility that we may have a
28-
// // dm from other sources, such as read from file. However, since we are not
29-
// // separating them now, I opt to add a flag to control how dm is obtained as
30-
// // of now
31-
// if (!PARAM.inp.dm_to_rho)
32-
// {
33-
// ModuleBase::GlobalFunc::NOTE("Calculate the density matrix.");
34-
35-
// // this part for calculating DMK in 2d-block format, not used for charge
36-
// // now
37-
// // psi::Psi<std::complex<double>> dm_k_2d();
38-
39-
// if (PARAM.inp.ks_solver == "genelpa" || PARAM.inp.ks_solver == "elpa" || PARAM.inp.ks_solver ==
40-
// "scalapack_gvx" || PARAM.inp.ks_solver == "lapack"
41-
// || PARAM.inp.ks_solver == "cusolver" || PARAM.inp.ks_solver == "cusolvermp"
42-
// || PARAM.inp.ks_solver == "cg_in_lcao") // Peize Lin test 2019-05-15
43-
// {
44-
// elecstate::cal_dm_psi(this->DM->get_paraV_pointer(),
45-
// this->wg,
46-
// psi,
47-
// *(this->DM));
48-
// this->DM->cal_DMR();
49-
// }
50-
// }
51-
5226
for (int is = 0; is < PARAM.inp.nspin; is++)
5327
{
5428
ModuleBase::GlobalFunc::ZEROS(this->charge->rho[is],

source/module_elecstate/elecstate_print.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,11 @@ void print_etot(const Magnetism& magnet,
430430
std::transform(energies_Ry.begin(), energies_Ry.end(), energies_eV.begin(), [](double ener) {
431431
return ener * ModuleBase::Ry_to_eV;
432432
});
433-
FmtTable table({"Energy", "Rydberg", "eV"},
434-
titles.size(),
435-
{"%-14s", "%20.10f", "%20.10f"},
436-
{FmtTable::Align::LEFT, FmtTable::Align::CENTER});
433+
FmtTable table(/*titles=*/{"Energy", "Rydberg", "eV"},
434+
/*nrows=*/titles.size(),
435+
/*formats=*/{"%-14s", "%20.10f", "%20.10f"},
436+
/*indents=*/0,
437+
/*align=*/{/*value*/FmtTable::Align::LEFT, /*title*/FmtTable::Align::CENTER});
437438
table << titles << energies_Ry << energies_eV;
438439
GlobalV::ofs_running << table.str() << std::endl;
439440
if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m") // xiaohui add 'm' option, 2015-09-16

source/module_esolver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ if(ENABLE_LCAO)
2020
lcao_after_scf.cpp
2121
esolver_gets.cpp
2222
lcao_others.cpp
23+
esolver_dm2rho.cpp
2324
)
2425
endif()
2526

source/module_esolver/esolver.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "module_base/module_device/device.h"
66
#include "module_parameter/parameter.h"
77
#ifdef __LCAO
8+
#include "esolver_dm2rho.h"
89
#include "esolver_gets.h"
910
#include "esolver_ks_lcao.h"
1011
#include "esolver_ks_lcao_tddft.h"
@@ -204,11 +205,25 @@ ESolver* init_esolver(const Input_para& inp, UnitCell& ucell)
204205
}
205206
else if (PARAM.inp.nspin < 4)
206207
{
207-
return new ESolver_KS_LCAO<std::complex<double>, double>();
208+
if (PARAM.inp.dm_to_rho)
209+
{
210+
return new ESolver_DM2rho<std::complex<double>, double>();
211+
}
212+
else
213+
{
214+
return new ESolver_KS_LCAO<std::complex<double>, double>();
215+
}
208216
}
209217
else
210218
{
211-
return new ESolver_KS_LCAO<std::complex<double>, std::complex<double>>();
219+
if (PARAM.inp.dm_to_rho)
220+
{
221+
return new ESolver_DM2rho<std::complex<double>, std::complex<double>>();
222+
}
223+
else
224+
{
225+
return new ESolver_KS_LCAO<std::complex<double>, std::complex<double>>();
226+
}
212227
}
213228
}
214229
else if (esolver_type == "ksdft_lcao_tddft")

0 commit comments

Comments
 (0)