Skip to content

Commit e29103d

Browse files
author
abacus_fixer
committed
fix: wrap member function definitions in namespace hamilt for -Wdtor-name
Move Nonlocal and Overlap member function definitions inside `namespace hamilt` blocks and drop redundant `hamilt::` qualifiers. This resolves the ISO C++ warning: warning: ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~' [-Wdtor-name] Affected files: - source/source_lcao/module_operator_lcao/nonlocal.cpp - source/source_lcao/module_operator_lcao/overlap.cpp
1 parent 2992ed3 commit e29103d

2 files changed

Lines changed: 55 additions & 45 deletions

File tree

source/source_lcao/module_operator_lcao/nonlocal.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
#include <unordered_set>
1010
#endif
1111

12+
namespace hamilt
13+
{
14+
1215
template <typename TK, typename TR>
13-
hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::Nonlocal(
16+
Nonlocal<OperatorLCAO<TK, TR>>::Nonlocal(
1417
HS_Matrix_K<TK>* hsk_in,
1518
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
16-
hamilt::HContainer<TR>* hR_in,
19+
HContainer<TR>* hR_in,
1720
const UnitCell* ucell_in,
1821
const std::vector<double>& orb_cutoff,
1922
const Grid_Driver* GridD_in,
2023
const TwoCenterIntegrator* intor)
21-
: hamilt::OperatorLCAO<TK, TR>(hsk_in, kvec_d_in, hR_in), orb_cutoff_(orb_cutoff), intor_(intor)
24+
: OperatorLCAO<TK, TR>(hsk_in, kvec_d_in, hR_in), orb_cutoff_(orb_cutoff), intor_(intor)
2225
{
2326
this->cal_type = calculation_type::lcao_fixed;
2427
this->ucell = ucell_in;
@@ -35,7 +38,7 @@ hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::Nonlocal(
3538

3639
// destructor
3740
template <typename TK, typename TR>
38-
hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::~Nonlocal()
41+
Nonlocal<OperatorLCAO<TK, TR>>::~Nonlocal()
3942
{
4043
if (this->allocated)
4144
{
@@ -45,7 +48,7 @@ hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::~Nonlocal()
4548

4649
// initialize_HR()
4750
template <typename TK, typename TR>
48-
void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driver* GridD)
51+
void Nonlocal<OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driver* GridD)
4952
{
5053
ModuleBase::TITLE("Nonlocal", "initialize_HR");
5154
ModuleBase::timer::start("Nonlocal", "initialize_HR");
@@ -98,7 +101,7 @@ void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Dr
98101
{
99102
continue;
100103
}
101-
hamilt::AtomPair<TR> tmp(iat1,
104+
AtomPair<TR> tmp(iat1,
102105
iat2,
103106
R_index2.x - R_index1.x,
104107
R_index2.y - R_index1.y,
@@ -115,7 +118,7 @@ void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Dr
115118
}
116119

117120
template <typename TK, typename TR>
118-
void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
121+
void Nonlocal<OperatorLCAO<TK, TR>>::calculate_HR()
119122
{
120123
ModuleBase::TITLE("Nonlocal", "calculate_HR");
121124
ModuleBase::timer::start("Nonlocal", "calculate_HR");
@@ -205,7 +208,7 @@ void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
205208
ModuleBase::Vector3<int> R_vector(R_index2[0] - R_index1[0],
206209
R_index2[1] - R_index1[1],
207210
R_index2[2] - R_index1[2]);
208-
hamilt::BaseMatrix<TR>* tmp
211+
BaseMatrix<TR>* tmp
209212
= this->HR_fixed->find_matrix(iat1, iat2, R_vector[0], R_vector[1], R_vector[2]);
210213
// if not found , skip this pair of atoms
211214
if (tmp != nullptr)
@@ -224,7 +227,7 @@ void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
224227

225228
// cal_HR_IJR()
226229
template <typename TK, typename TR>
227-
void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::cal_HR_IJR(
230+
void Nonlocal<OperatorLCAO<TK, TR>>::cal_HR_IJR(
228231
const int& iat1,
229232
const int& iat2,
230233
const int& T0,
@@ -284,15 +287,15 @@ void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::cal_HR_IJR(
284287

285288
// set_HR_fixed()
286289
template <typename TK, typename TR>
287-
void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::set_HR_fixed(void* HR_fixed_in)
290+
void Nonlocal<OperatorLCAO<TK, TR>>::set_HR_fixed(void* HR_fixed_in)
288291
{
289-
this->HR_fixed = static_cast<hamilt::HContainer<TR>*>(HR_fixed_in);
292+
this->HR_fixed = static_cast<HContainer<TR>*>(HR_fixed_in);
290293
this->allocated = false;
291294
}
292295

293296
// contributeHR()
294297
template <typename TK, typename TR>
295-
void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
298+
void Nonlocal<OperatorLCAO<TK, TR>>::contributeHR()
296299
{
297300
ModuleBase::TITLE("Nonlocal", "contributeHR");
298301
ModuleBase::timer::start("Nonlocal", "contributeHR");
@@ -301,7 +304,7 @@ void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
301304
// if this Operator is the first node of the sub_chain, then HR_fixed is nullptr
302305
if (this->HR_fixed == nullptr)
303306
{
304-
this->HR_fixed = new hamilt::HContainer<TR>(*this->hR);
307+
this->HR_fixed = new HContainer<TR>(*this->hR);
305308
this->HR_fixed->set_zero();
306309
this->allocated = true;
307310
}
@@ -323,6 +326,8 @@ void hamilt::Nonlocal<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
323326
return;
324327
}
325328

326-
template class hamilt::Nonlocal<hamilt::OperatorLCAO<double, double>>;
327-
template class hamilt::Nonlocal<hamilt::OperatorLCAO<std::complex<double>, double>>;
328-
template class hamilt::Nonlocal<hamilt::OperatorLCAO<std::complex<double>, std::complex<double>>>;
329+
template class Nonlocal<OperatorLCAO<double, double>>;
330+
template class Nonlocal<OperatorLCAO<std::complex<double>, double>>;
331+
template class Nonlocal<OperatorLCAO<std::complex<double>, std::complex<double>>>;
332+
333+
} // namespace hamilt

source/source_lcao/module_operator_lcao/overlap.cpp

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ void populate_atom_pairs(hamilt::HContainer<TR>* container,
9090

9191
} // anonymous namespace
9292

93+
namespace hamilt
94+
{
95+
9396
template <typename TK, typename TR>
94-
hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::Overlap(HS_Matrix_K<TK>* hsk_in,
97+
Overlap<OperatorLCAO<TK, TR>>::Overlap(HS_Matrix_K<TK>* hsk_in,
9598
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
96-
hamilt::HContainer<TR>* hR_in,
97-
hamilt::HContainer<TR>* SR_in,
99+
HContainer<TR>* hR_in,
100+
HContainer<TR>* SR_in,
98101
const UnitCell* ucell_in,
99102
const std::vector<double>& orb_cutoff,
100103
const Grid_Driver* GridD_in,
101104
const TwoCenterIntegrator* intor)
102-
: hamilt::OperatorLCAO<TK, TR>(hsk_in, kvec_d_in, hR_in), orb_cutoff_(orb_cutoff), intor_(intor), gridD(GridD_in)
105+
: OperatorLCAO<TK, TR>(hsk_in, kvec_d_in, hR_in), orb_cutoff_(orb_cutoff), intor_(intor), gridD(GridD_in)
103106
{
104107
this->cal_type = calculation_type::lcao_overlap;
105108
this->ucell = ucell_in;
@@ -116,12 +119,12 @@ hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::Overlap(HS_Matrix_K<TK>* hsk_in,
116119
}
117120

118121
template <typename TK, typename TR>
119-
hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::~Overlap()
122+
Overlap<OperatorLCAO<TK, TR>>::~Overlap()
120123
{
121124
}
122125

123126
template <typename TK, typename TR>
124-
void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::initialize_SR(const Grid_Driver* GridD)
127+
void Overlap<OperatorLCAO<TK, TR>>::initialize_SR(const Grid_Driver* GridD)
125128
{
126129
ModuleBase::TITLE("OverlapNew", "initialize_SR");
127130
ModuleBase::timer::start("OverlapNew", "initialize_SR");
@@ -132,7 +135,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::initialize_SR(const Grid_Dri
132135
}
133136

134137
template <typename TK, typename TR>
135-
void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::calculate_SR()
138+
void Overlap<OperatorLCAO<TK, TR>>::calculate_SR()
136139
{
137140
ModuleBase::TITLE("Overlap", "calculate_SR");
138141
ModuleBase::timer::start("Overlap", "calculate_SR");
@@ -141,7 +144,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::calculate_SR()
141144
#endif
142145
for (int iap = 0; iap < this->SR->size_atom_pairs(); ++iap)
143146
{
144-
hamilt::AtomPair<TR>& tmp = this->SR->get_atom_pair(iap);
147+
AtomPair<TR>& tmp = this->SR->get_atom_pair(iap);
145148
const int iat1 = tmp.get_atom_i();
146149
const int iat2 = tmp.get_atom_j();
147150
const Parallel_Orbitals* paraV = tmp.get_paraV();
@@ -165,7 +168,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::calculate_SR()
165168

166169
// cal_SR_IJR()
167170
template <typename TK, typename TR>
168-
void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::cal_SR_IJR(const int& iat1,
171+
void Overlap<OperatorLCAO<TK, TR>>::cal_SR_IJR(const int& iat1,
169172
const int& iat2,
170173
const Parallel_Orbitals* paraV,
171174
const ModuleBase::Vector3<double>& dtau,
@@ -234,7 +237,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::cal_SR_IJR(const int& iat1,
234237

235238
// contributeHR()
236239
template <typename TK, typename TR>
237-
void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
240+
void Overlap<OperatorLCAO<TK, TR>>::contributeHR()
238241
{
239242
if (this->SR_fixed_done)
240243
{
@@ -246,7 +249,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
246249

247250
// contributeHk()
248251
template <>
249-
void hamilt::Overlap<hamilt::OperatorLCAO<double, double>>::contributeHk(int ik)
252+
void Overlap<OperatorLCAO<double, double>>::contributeHk(int ik)
250253
{
251254
//! if k vector is not changed, then do nothing and return, only for gamma_only case
252255
if (this->kvec_d[ik] == this->kvec_d_old)
@@ -261,12 +264,12 @@ void hamilt::Overlap<hamilt::OperatorLCAO<double, double>>::contributeHk(int ik)
261264
if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver))
262265
{
263266
const int nrow = this->SR->get_atom_pair(0).get_paraV()->get_row_size();
264-
hamilt::folding_HR(*this->SR, this->hsk->get_sk(), this->kvec_d[ik], nrow, 1);
267+
folding_HR(*this->SR, this->hsk->get_sk(), this->kvec_d[ik], nrow, 1);
265268
}
266269
else
267270
{
268271
const int ncol = this->SR->get_atom_pair(0).get_paraV()->get_col_size();
269-
hamilt::folding_HR(*this->SR, this->hsk->get_sk(), this->kvec_d[ik], ncol, 0);
272+
folding_HR(*this->SR, this->hsk->get_sk(), this->kvec_d[ik], ncol, 0);
270273
}
271274

272275
// update kvec_d_old
@@ -275,7 +278,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<double, double>>::contributeHk(int ik)
275278
ModuleBase::timer::end("Overlap", "contributeHk");
276279
}
277280
template <typename TK, typename TR>
278-
void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::contributeHk(int ik)
281+
void Overlap<OperatorLCAO<TK, TR>>::contributeHk(int ik)
279282
{
280283
ModuleBase::TITLE("Overlap", "contributeHk");
281284
ModuleBase::timer::start("Overlap", "contributeHk");
@@ -291,7 +294,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::contributeHk(int ik)
291294
}
292295
else
293296
{
294-
hamilt::folding_HR(*this->SR, this->hsk->get_sk(), this->kvec_d[ik], nrow, 1);
297+
folding_HR(*this->SR, this->hsk->get_sk(), this->kvec_d[ik], nrow, 1);
295298
}
296299
}
297300
else
@@ -303,7 +306,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::contributeHk(int ik)
303306
}
304307
else
305308
{
306-
hamilt::folding_HR(*this->SR, this->hsk->get_sk(), this->kvec_d[ik], ncol, 0);
309+
folding_HR(*this->SR, this->hsk->get_sk(), this->kvec_d[ik], ncol, 0);
307310
}
308311
}
309312

@@ -313,7 +316,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::contributeHk(int ik)
313316
ModuleBase::timer::end("Overlap", "contributeHk");
314317
}
315318
template <typename TK, typename TR>
316-
TK* hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::getSk()
319+
TK* Overlap<OperatorLCAO<TK, TR>>::getSk()
317320
{
318321
if (this->hsk != nullptr)
319322
{
@@ -329,7 +332,7 @@ TK* hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::getSk()
329332
//==============================================================================
330333

331334
template <typename TK, typename TR>
332-
hamilt::HContainer<TR>* hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::calculate_SR_async(const UnitCell& ucell_in,
335+
HContainer<TR>* Overlap<OperatorLCAO<TK, TR>>::calculate_SR_async(const UnitCell& ucell_in,
333336
const double md_dt,
334337
const Parallel_Orbitals* paraV)
335338
{
@@ -338,7 +341,7 @@ hamilt::HContainer<TR>* hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::calculate
338341

339342
// Initialize SR_async for Hefei-NAMD asynchronous overlap calculation
340343
// This is done here to use the exact dtau with velocity shifts
341-
hamilt::HContainer<TR>* SR_async = new hamilt::HContainer<TR>(paraV);
344+
HContainer<TR>* SR_async = new HContainer<TR>(paraV);
342345

343346
// Define velocity shift modifier for dtau
344347
// This shifts atom1 backward to its position at (t - dt),
@@ -361,7 +364,7 @@ hamilt::HContainer<TR>* hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::calculate
361364
#endif
362365
for (int iap = 0; iap < SR_async->size_atom_pairs(); ++iap)
363366
{
364-
hamilt::AtomPair<TR>& atom_pair = SR_async->get_atom_pair(iap);
367+
AtomPair<TR>& atom_pair = SR_async->get_atom_pair(iap);
365368
const int iat1 = atom_pair.get_atom_i();
366369
const int iat2 = atom_pair.get_atom_j();
367370
const Parallel_Orbitals* paraV_local = atom_pair.get_paraV();
@@ -399,8 +402,8 @@ hamilt::HContainer<TR>* hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::calculate
399402
}
400403

401404
template <typename TK, typename TR>
402-
void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::output_SR_async_csr(const int istep,
403-
hamilt::HContainer<TR>* SR_async,
405+
void Overlap<OperatorLCAO<TK, TR>>::output_SR_async_csr(const int istep,
406+
HContainer<TR>* SR_async,
404407
const int precision)
405408
{
406409
if (SR_async == nullptr)
@@ -419,10 +422,10 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::output_SR_async_csr(const in
419422
serial_paraV.set_serial(nbasis, nbasis);
420423
serial_paraV.set_atomic_trace(this->ucell->get_iat2iwt(), this->ucell->nat, nbasis);
421424

422-
hamilt::HContainer<TR> SR_async_serial(&serial_paraV);
423-
hamilt::gatherParallels(*SR_async, &SR_async_serial, 0);
425+
HContainer<TR> SR_async_serial(&serial_paraV);
426+
gatherParallels(*SR_async, &SR_async_serial, 0);
424427
#else
425-
hamilt::HContainer<TR>& SR_async_serial = *SR_async;
428+
HContainer<TR>& SR_async_serial = *SR_async;
426429
#endif
427430

428431
// Only rank 0 writes the output file
@@ -448,7 +451,7 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::output_SR_async_csr(const in
448451

449452
// Write matrix data in CSR format
450453
const double sparse_threshold = 1e-10;
451-
hamilt::Output_HContainer<TR> output_handler(&SR_async_serial, ofs, sparse_threshold, precision);
454+
Output_HContainer<TR> output_handler(&SR_async_serial, ofs, sparse_threshold, precision);
452455
output_handler.write();
453456

454457
ofs.close();
@@ -457,6 +460,8 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::output_SR_async_csr(const in
457460
ModuleBase::timer::end("OverlapNew", "output_SR_async_csr");
458461
}
459462

460-
template class hamilt::Overlap<hamilt::OperatorLCAO<double, double>>;
461-
template class hamilt::Overlap<hamilt::OperatorLCAO<std::complex<double>, double>>;
462-
template class hamilt::Overlap<hamilt::OperatorLCAO<std::complex<double>, std::complex<double>>>;
463+
template class Overlap<OperatorLCAO<double, double>>;
464+
template class Overlap<OperatorLCAO<std::complex<double>, double>>;
465+
template class Overlap<OperatorLCAO<std::complex<double>, std::complex<double>>>;
466+
467+
} // namespace hamilt

0 commit comments

Comments
 (0)