Skip to content

Commit e461ffd

Browse files
authored
Refactor: Remove obsolete cg_in_lcao code (deepmodeling#7870)
* Refactor: Remove obsolete `cg_in_lcao` code * Make glob_fn_each2 header self-contained
1 parent 74dcbdf commit e461ffd

10 files changed

Lines changed: 205 additions & 256 deletions

File tree

source/source_base/glob_fn_each2.h

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef GLOB_FN_EACH2_H
55
#define GLOB_FN_EACH2_H
66

7+
#include <cstddef>
78
#include <functional>
89
#include <map>
910
#include <vector>
@@ -12,45 +13,37 @@ namespace ModuleBase
1213
{
1314
namespace GlobalFunc
1415
{
15-
16-
template<typename Ti, typename... T_tail>
17-
void FUNC_EACH_2(
18-
Ti & tA,
19-
const Ti & tB,
20-
std::function< void( Ti&, const Ti&, T_tail... ) > func,
21-
const T_tail&... t_tail )
16+
17+
template <typename Ti, typename... T_tail>
18+
void FUNC_EACH_2(Ti& tA, const Ti& tB, std::function<void(Ti&, const Ti&, T_tail...)> func, const T_tail&... t_tail)
2219
{
23-
func( tA, tB, t_tail... );
20+
func(tA, tB, t_tail...);
2421
}
2522

26-
27-
template<typename Tv, typename Ti, typename... T_tail>
28-
void FUNC_EACH_2(
29-
std::vector<Tv> & tA,
30-
const std::vector<Tv> & tB,
31-
std::function< void( Ti&, const Ti&, T_tail... ) > func,
32-
const T_tail&... t_tail )
23+
template <typename Tv, typename Ti, typename... T_tail>
24+
void FUNC_EACH_2(std::vector<Tv>& tA,
25+
const std::vector<Tv>& tB,
26+
std::function<void(Ti&, const Ti&, T_tail...)> func,
27+
const T_tail&... t_tail)
3328
{
34-
for( size_t i=0; i!=tA.size(); ++i )
35-
{
36-
FUNC_EACH_2( tA[i], tB[i], func, t_tail... );
37-
}
29+
for (std::size_t i = 0; i != tA.size(); ++i)
30+
{
31+
FUNC_EACH_2(tA[i], tB[i], func, t_tail...);
32+
}
3833
}
3934

40-
41-
template<typename T1, typename T2, typename Ti, typename... T_tail>
42-
void FUNC_EACH_2(
43-
std::map<T1,T2> & tA,
44-
const std::map<T1,T2> & tB,
45-
std::function< void( Ti&, const Ti&, T_tail... ) > func,
46-
const T_tail&... t_tail )
35+
template <typename T1, typename T2, typename Ti, typename... T_tail>
36+
void FUNC_EACH_2(std::map<T1, T2>& tA,
37+
const std::map<T1, T2>& tB,
38+
std::function<void(Ti&, const Ti&, T_tail...)> func,
39+
const T_tail&... t_tail)
4740
{
48-
for( auto & ta : tA )
49-
{
50-
FUNC_EACH_2( ta.second, tB.at(ta.first), func, t_tail... );
51-
}
41+
for (auto& ta: tA)
42+
{
43+
FUNC_EACH_2(ta.second, tB.at(ta.first), func, t_tail...);
44+
}
5245
}
5346

54-
}
55-
}
47+
} // namespace GlobalFunc
48+
} // namespace ModuleBase
5649
#endif // GLOB_FN_EACH2_H

source/source_base/global_function.h

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef GLOBAL_FUNCTION_H
22
#define GLOBAL_FUNCTION_H
33

4-
#include "module_external/blas_connector.h"
54
#include "glob_fn_each2.h" // Peize Lin add 2016-09-07
65
#include "global_variable.h"
6+
#include "module_external/blas_connector.h"
77
#include "tool_check.h" // mohan add 2021-05-08
88
#include "tool_quit.h" // mohan add 2021-05-07
99
#include "tool_title.h" // mohan add 2021-05-05
@@ -146,37 +146,34 @@ static void READ_VALUE(std::ifstream& ifs, T& v)
146146
}
147147

148148
//-------------------------------------------------------------
149-
//! The `SCAN_BEGIN` function efficiently searches
150-
//! text files for specified keywords
149+
//! The `SCAN_BEGIN` function efficiently searches
150+
//! text files for specified keywords
151151
//-------------------------------------------------------------
152-
bool SCAN_BEGIN(std::ifstream& ifs,
153-
const std::string& TargetName,
154-
const bool restart = true,
155-
const bool ifwarn = true);
152+
bool SCAN_BEGIN(std::ifstream& ifs, const std::string& TargetName, const bool restart = true, const bool ifwarn = true);
156153

157154
//-------------------------------------------------------------
158-
// The `SCAN_LINE_BEGIN` function efficiently searches
155+
// The `SCAN_LINE_BEGIN` function efficiently searches
159156
// text files for specified keywords while ignoring comment
160-
// lines and whitespace. It skips any line starting with '#'
157+
// lines and whitespace. It skips any line starting with '#'
161158
//-------------------------------------------------------------
162-
bool SCAN_LINE_BEGIN(std::ifstream& ifs,
163-
const std::string& TargetName,
164-
const bool restart = true,
165-
const bool ifwarn = true);
159+
bool SCAN_LINE_BEGIN(std::ifstream& ifs, const std::string& TargetName, const bool restart = true, const bool ifwarn = true);
166160

167161
void SCAN_END(std::ifstream& ifs, const std::string& TargetName, const bool ifwarn = true);
168162

169163
template <class T>
170164
static inline void DCOPY(const T& a, T& b, const int& dim)
171165
{
172-
for (int i = 0; i < dim; ++i) {
166+
for (int i = 0; i < dim; ++i)
167+
{
173168
b[i] = a[i];
174169
}
175170
}
176171

177172
template <typename T>
178-
inline void DCOPY(const T* a, T* b, const int& dim) {
179-
for (int i = 0; i < dim; ++i) {
173+
inline void DCOPY(const T* a, T* b, const int& dim)
174+
{
175+
for (int i = 0; i < dim; ++i)
176+
{
180177
b[i] = a[i];
181178
}
182179
}
@@ -236,7 +233,7 @@ static inline const T* VECTOR_TO_PTR(const std::valarray<T>& v)
236233
// Peize Lin add 2016-07-18
237234
//==========================================================
238235
template <typename T>
239-
std::string TO_STRING(const T& t, const int n=20) // n=20 since LDBL_EPSILON is 1E-16 or 1E-19
236+
std::string TO_STRING(const T& t, const int n = 20) // n=20 since LDBL_EPSILON is 1E-16 or 1E-19
240237
{
241238
std::stringstream newstr;
242239
newstr << std::setprecision(n) << t;
@@ -255,7 +252,8 @@ template <typename T_map, typename T_key1>
255252
inline void* MAP_EXIST(T_map& ms, const T_key1& key1)
256253
{
257254
auto ms1 = ms.find(key1);
258-
if (ms1 == ms.end()) {
255+
if (ms1 == ms.end())
256+
{
259257
return nullptr;
260258
}
261259
return static_cast<void*>(&ms1->second);
@@ -265,7 +263,8 @@ template <typename T_map, typename T_key1, typename... T_key_tail>
265263
inline void* MAP_EXIST(T_map& ms, const T_key1& key1, const T_key_tail&... key_tail)
266264
{
267265
auto ms1 = ms.find(key1);
268-
if (ms1 == ms.end()) {
266+
if (ms1 == ms.end())
267+
{
269268
return nullptr;
270269
}
271270
return MAP_EXIST(ms1->second, key_tail...);
@@ -275,7 +274,8 @@ template <typename T_map, typename T_key1>
275274
inline const void* MAP_EXIST(const T_map& ms, const T_key1& key1)
276275
{
277276
auto ms1 = ms.find(key1);
278-
if (ms1 == ms.end()) {
277+
if (ms1 == ms.end())
278+
{
279279
return nullptr;
280280
}
281281
return static_cast<const void*>(&ms1->second);
@@ -285,7 +285,8 @@ template <typename T_map, typename T_key1, typename... T_key_tail>
285285
inline const void* MAP_EXIST(const T_map& ms, const T_key1& key1, const T_key_tail&... key_tail)
286286
{
287287
auto ms1 = ms.find(key1);
288-
if (ms1 == ms.end()) {
288+
if (ms1 == ms.end())
289+
{
289290
return nullptr;
290291
}
291292
return MAP_EXIST(ms1->second, key_tail...);
@@ -323,7 +324,8 @@ static inline void DELETE_MUL_PTR(T_element* v)
323324
template <typename T_element, typename T_N_first, typename... T_N_tail>
324325
static inline void DELETE_MUL_PTR(T_element* v, const T_N_first N_first, const T_N_tail... N_tail)
325326
{
326-
for (T_N_first i = 0; i < N_first; ++i) {
327+
for (T_N_first i = 0; i < N_first; ++i)
328+
{
327329
DELETE_MUL_PTR(v[i], N_tail...);
328330
}
329331
delete[] v;
@@ -353,7 +355,8 @@ static inline void FREE_MUL_PTR(T_element* v)
353355
template <typename T_element, typename T_N_first, typename... T_N_tail>
354356
static inline void FREE_MUL_PTR(T_element* v, const T_N_first N_first, const T_N_tail... N_tail)
355357
{
356-
for (T_N_first i = 0; i < N_first; ++i) {
358+
for (T_N_first i = 0; i < N_first; ++i)
359+
{
357360
FREE_MUL_PTR(v[i], N_tail...);
358361
}
359362
free(v);
@@ -371,7 +374,7 @@ T ddot_real(const int& dim, const std::complex<T>* psi_L, const std::complex<T>*
371374
static inline bool IS_COLUMN_MAJOR_KS_SOLVER(std::string ks_solver)
372375
{
373376
return ks_solver == "genelpa" || ks_solver == "elpa" || ks_solver == "scalapack_gvx" || ks_solver == "cusolver"
374-
|| ks_solver == "cusolvermp" || ks_solver == "cg_in_lcao" || ks_solver == "pexsi" || ks_solver == "lapack";
377+
|| ks_solver == "cusolvermp" || ks_solver == "pexsi" || ks_solver == "lapack";
375378
}
376379

377380
} // namespace GlobalFunc

source/source_estate/elecstate_print.cpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "elecstate.h"
2+
#include "occupy.h"
23
#include "source_base/formatter.h"
34
#include "source_base/global_variable.h"
45
#include "source_base/parallel_common.h"
5-
#include "source_estate/module_pot/h_hartree_pw.h"
66
#include "source_estate/module_pot/efield.h"
77
#include "source_estate/module_pot/gatefield.h"
8+
#include "source_estate/module_pot/h_hartree_pw.h"
89
#include "source_hamilt/module_xc/xc_functional.h"
910
#include "source_io/module_parameter/parameter.h"
10-
#include "occupy.h"
1111
namespace elecstate
1212
{
1313
/**
@@ -49,7 +49,6 @@ void print_scf_iterinfo(const std::string& ks_solver,
4949
{
5050
std::map<std::string, std::string> iter_header_dict
5151
= {{"cg", "CG"},
52-
{"cg_in_lcao", "CG"},
5352
{"lapack", "LA"},
5453
{"genelpa", "GE"},
5554
{"elpa", "EL"},
@@ -127,10 +126,7 @@ void print_scf_iterinfo(const std::string& ks_solver,
127126
values = {double(istep), mag[0], mag[1], mag[2], mag[3], etot, ediff, drho[0]};
128127
break;
129128
default:
130-
titles = {"ITER",
131-
FmtCore::center("ETOT/eV", wener),
132-
FmtCore::center("EDIFF/eV", wener),
133-
FmtCore::center("DRHO", wrho)};
129+
titles = {"ITER", FmtCore::center("ETOT/eV", wener), FmtCore::center("EDIFF/eV", wener), FmtCore::center("DRHO", wrho)};
134130
values = {double(istep), etot, ediff, drho[0]};
135131
break;
136132
}
@@ -163,7 +159,6 @@ void print_scf_iterinfo(const std::string& ks_solver,
163159
std::cout << buf << std::flush;
164160
}
165161

166-
167162
/// @brief print total free energy and other energies
168163
/// @param ucell: unit cell
169164
/// @param converged: if converged
@@ -204,10 +199,10 @@ void print_etot(const Magnetism& magnet,
204199
std::vector<double> energies_Ry;
205200
std::vector<double> energies_eV;
206201

207-
if( (iter % PARAM.inp.out_freq_elec == 0) || converged || iter == PARAM.inp.scf_nmax )
208-
{
202+
if ((iter % PARAM.inp.out_freq_elec == 0) || converged || iter == PARAM.inp.scf_nmax)
203+
{
209204
int n_order = std::max(0, Occupy::gaussian_type);
210-
205+
211206
//! Kohn-Sham functional energy
212207
titles.push_back("E_KohnSham");
213208
energies_Ry.push_back(elec.f_en.etot);
@@ -271,11 +266,11 @@ void print_etot(const Magnetism& magnet,
271266
}
272267

273268
// mohan add 20251108
274-
if (PARAM.inp.dft_plus_u)
275-
{
269+
if (PARAM.inp.dft_plus_u)
270+
{
276271
titles.push_back("E_plusU");
277272
energies_Ry.push_back(elec.f_en.edftu);
278-
}
273+
}
279274

280275
//! hybrid functional energy
281276
titles.push_back("E_exx");
@@ -296,7 +291,7 @@ void print_etot(const Magnetism& magnet,
296291
titles.push_back("E_efield");
297292
energies_Ry.push_back(elecstate::Efield::etotefield);
298293
}
299-
294+
300295
//! gate energy
301296
if (PARAM.inp.gate_flag)
302297
{
@@ -354,23 +349,19 @@ void print_etot(const Magnetism& magnet,
354349
energies_Ry.push_back(elec.bandgap_dw);
355350
}
356351
energies_eV.resize(energies_Ry.size());
357-
std::transform(energies_Ry.begin(), energies_Ry.end(), energies_eV.begin(), [](double ener) {
358-
return ener * ModuleBase::Ry_to_eV;
359-
});
352+
std::transform(energies_Ry.begin(), energies_Ry.end(), energies_eV.begin(), [](double ener) { return ener * ModuleBase::Ry_to_eV; });
360353

361354
// for each SCF step, we print out energy
362355
FmtTable table(/*titles=*/{"Energy", "Rydberg", "eV"},
363356
/*nrows=*/titles.size(),
364-
/*formats=*/{"%-14s", "%20.10f", "%20.10f"},
357+
/*formats=*/{"%-14s", "%20.10f", "%20.10f"},
365358
/*indents=*/1,
366-
/*align=*/{/*value*/FmtTable::Align::LEFT, /*title*/FmtTable::Align::CENTER});
359+
/*align=*/{/*value*/ FmtTable::Align::LEFT, /*title*/ FmtTable::Align::CENTER});
367360
// print out the titles
368361
table << titles << energies_Ry << energies_eV;
369362

370363
GlobalV::ofs_running << table.str() << std::endl;
371364

372-
373-
374365
if (PARAM.inp.out_level == "ie" || PARAM.inp.out_level == "m")
375366
{
376367
std::vector<double> mag;
@@ -380,10 +371,7 @@ void print_etot(const Magnetism& magnet,
380371
mag = {magnet.tot_mag, magnet.abs_mag};
381372
break;
382373
case 4:
383-
mag = {magnet.tot_mag_nc[0],
384-
magnet.tot_mag_nc[1],
385-
magnet.tot_mag_nc[2],
386-
magnet.abs_mag};
374+
mag = {magnet.tot_mag_nc[0], magnet.tot_mag_nc[1], magnet.tot_mag_nc[2], magnet.abs_mag};
387375
break;
388376
default:
389377
mag = {};
@@ -396,9 +384,7 @@ void print_etot(const Magnetism& magnet,
396384
}
397385
// Pure SDFT (nbands=0) uses Chebyshev trace (CT) since no H diagonalization is performed.
398386
// Mixed SDFT (nbands>0) still diagonalizes KS orbitals, so use the actual ks_solver label.
399-
const std::string iter_label = (PARAM.inp.esolver_type == "sdft" && PARAM.inp.nbands == 0)
400-
? "sdft"
401-
: PARAM.inp.ks_solver;
387+
const std::string iter_label = (PARAM.inp.esolver_type == "sdft" && PARAM.inp.nbands == 0) ? "sdft" : PARAM.inp.ks_solver;
402388
elecstate::print_scf_iterinfo(iter_label,
403389
iter,
404390
4,
@@ -422,8 +408,7 @@ void print_etot(const Magnetism& magnet,
422408
void print_format(const std::string& name, const double& value)
423409
{
424410
GlobalV::ofs_running << std::setiosflags(std::ios::showpos);
425-
GlobalV::ofs_running << " " << std::setw(16) << name << std::setw(30) << value << std::setw(30)
426-
<< value * ModuleBase::Ry_to_eV << std::endl;
411+
GlobalV::ofs_running << " " << std::setw(16) << name << std::setw(30) << value << std::setw(30) << value * ModuleBase::Ry_to_eV << std::endl;
427412
GlobalV::ofs_running << std::resetiosflags(std::ios::showpos);
428413
return;
429414
}

0 commit comments

Comments
 (0)