Skip to content

Commit 46fe015

Browse files
authored
Refactor: Remove obsolete cross-device copy constructor in HamiltPW (#7418)
* Remove obsolete cross-device copy constructor in HamiltPW * Delete corresponding .h code
1 parent d33c34f commit 46fe015

2 files changed

Lines changed: 44 additions & 123 deletions

File tree

source/source_pw/module_pwdft/hamilt_pw.cpp

Lines changed: 31 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#include "hamilt_pw.h"
22

3-
#include "source_io/module_parameter/parameter.h"
4-
#include "source_base/global_function.h"
5-
#include "source_base/global_variable.h"
6-
#include "source_base/parallel_reduce.h"
7-
8-
#include "op_pw_veff.h"
93
#include "op_pw_ekin.h"
4+
#include "op_pw_exx.h"
105
#include "op_pw_meta.h"
116
#include "op_pw_nl.h"
127
#include "op_pw_proj.h"
13-
#include "op_pw_exx.h"
8+
#include "op_pw_veff.h"
9+
#include "source_base/global_function.h"
10+
#include "source_base/global_variable.h"
11+
#include "source_base/parallel_reduce.h"
1412
#include "source_hamilt/module_xc/exx_info.h" // use GlobalC::exx_info
13+
#include "source_io/module_parameter/parameter.h"
1514

1615
namespace hamilt
1716
{
@@ -22,7 +21,8 @@ HamiltPW<T, Device>::HamiltPW(elecstate::Potential* pot_in,
2221
K_Vectors* pkv,
2322
pseudopot_cell_vnl* nlpp,
2423
Plus_U* p_dftu, // mohan add 2025-11-06
25-
const UnitCell* ucell): ucell(ucell)
24+
const UnitCell* ucell)
25+
: ucell(ucell)
2626
{
2727
this->classname = "HamiltPW";
2828
this->ppcell = nlpp;
@@ -39,7 +39,7 @@ HamiltPW<T, Device>::HamiltPW(elecstate::Potential* pot_in,
3939
// Operator<double>* ekinetic = new Ekinetic<OperatorLCAO<double>>
4040
Operator<T, Device>* ekinetic
4141
= new Ekinetic<OperatorPW<T, Device>>(tpiba2, gk2, wfc_basis->nks, wfc_basis->npwk_max);
42-
if(this->ops == nullptr)
42+
if (this->ops == nullptr)
4343
{
4444
this->ops = ekinetic;
4545
}
@@ -59,7 +59,7 @@ HamiltPW<T, Device>::HamiltPW(elecstate::Potential* pot_in,
5959
{
6060
pot_register_in.push_back("hartree");
6161
}
62-
//no variable can choose xc, maybe it is necessary
62+
// no variable can choose xc, maybe it is necessary
6363
pot_register_in.push_back("xc");
6464
if (PARAM.inp.imp_sol)
6565
{
@@ -78,20 +78,21 @@ HamiltPW<T, Device>::HamiltPW(elecstate::Potential* pot_in,
7878
pot_register_in.push_back("ml_exx");
7979
}
8080
// DFT-1/2
81-
if (PARAM.inp.dfthalf_type == 1) {
81+
if (PARAM.inp.dfthalf_type == 1)
82+
{
8283
pot_register_in.push_back("dfthalf");
8384
}
84-
//only Potential is not empty, Veff and Meta are available
85-
if(pot_register_in.size()>0)
85+
// only Potential is not empty, Veff and Meta are available
86+
if (pot_register_in.size() > 0)
8687
{
87-
//register Potential by gathered operator
88+
// register Potential by gathered operator
8889
pot_in->pot_register(pot_register_in);
8990
Operator<T, Device>* veff = new Veff<OperatorPW<T, Device>>(isk,
9091
pot_in->get_veff_smooth_data<Real>(),
9192
pot_in->get_veff_smooth().nr,
9293
pot_in->get_veff_smooth().nc,
9394
wfc_basis);
94-
if(this->ops == nullptr)
95+
if (this->ops == nullptr)
9596
{
9697
this->ops = veff;
9798
}
@@ -110,9 +111,8 @@ HamiltPW<T, Device>::HamiltPW(elecstate::Potential* pot_in,
110111
}
111112
if (PARAM.inp.vnl_in_h)
112113
{
113-
Operator<T, Device>* nonlocal
114-
= new Nonlocal<OperatorPW<T, Device>>(isk, this->ppcell, ucell, wfc_basis);
115-
if(this->ops == nullptr)
114+
Operator<T, Device>* nonlocal = new Nonlocal<OperatorPW<T, Device>>(isk, this->ppcell, ucell, wfc_basis);
115+
if (this->ops == nullptr)
116116
{
117117
this->ops = nonlocal;
118118
}
@@ -121,11 +121,13 @@ HamiltPW<T, Device>::HamiltPW(elecstate::Potential* pot_in,
121121
this->ops->add(nonlocal);
122122
}
123123
}
124-
if(PARAM.inp.sc_mag_switch || PARAM.inp.dft_plus_u)
124+
if (PARAM.inp.sc_mag_switch || PARAM.inp.dft_plus_u)
125125
{
126-
Operator<T, Device>* onsite_proj
127-
= new OnsiteProj<OperatorPW<T, Device>>(isk, ucell, p_dftu,
128-
PARAM.inp.sc_mag_switch, (PARAM.inp.dft_plus_u>0));
126+
Operator<T, Device>* onsite_proj = new OnsiteProj<OperatorPW<T, Device>>(isk,
127+
ucell,
128+
p_dftu,
129+
PARAM.inp.sc_mag_switch,
130+
(PARAM.inp.dft_plus_u > 0));
129131
this->ops->add(onsite_proj);
130132
}
131133
if (GlobalC::exx_info.info_global.cal_exx)
@@ -144,97 +146,21 @@ HamiltPW<T, Device>::HamiltPW(elecstate::Potential* pot_in,
144146
return;
145147
}
146148

147-
template<typename T, typename Device>
149+
template <typename T, typename Device>
148150
HamiltPW<T, Device>::~HamiltPW()
149151
{
150-
if(this->ops!= nullptr)
152+
if (this->ops != nullptr)
151153
{
152154
delete this->ops;
153155
}
154156
}
155157

156-
template<typename T, typename Device>
158+
template <typename T, typename Device>
157159
void HamiltPW<T, Device>::updateHk(const int ik)
158160
{
159-
ModuleBase::TITLE("HamiltPW","updateHk");
161+
ModuleBase::TITLE("HamiltPW", "updateHk");
160162
this->ops->init(ik);
161-
ModuleBase::TITLE("HamiltPW","updateHk");
162-
}
163-
164-
template<typename T, typename Device>
165-
template<typename T_in, typename Device_in>
166-
HamiltPW<T, Device>::HamiltPW(const HamiltPW<T_in, Device_in> *hamilt)
167-
{
168-
this->classname = hamilt->classname;
169-
this->ppcell = hamilt->ppcell;
170-
this->qq_nt = hamilt->qq_nt;
171-
this->qq_so = hamilt->qq_so;
172-
this->vkb = hamilt->vkb;
173-
OperatorPW<std::complex<T_in>, Device_in> * node =
174-
reinterpret_cast<OperatorPW<std::complex<T_in>, Device_in> *>(hamilt->ops);
175-
176-
while(node != nullptr) {
177-
if (node->classname == "Ekinetic") {
178-
Operator<T, Device>* ekinetic =
179-
new Ekinetic<OperatorPW<T, Device>>(
180-
reinterpret_cast<const Ekinetic<OperatorPW<T_in, Device_in>>*>(node));
181-
if(this->ops == nullptr) {
182-
this->ops = ekinetic;
183-
}
184-
else {
185-
this->ops->add(ekinetic);
186-
}
187-
// this->ops = reinterpret_cast<Operator<T, Device>*>(node);
188-
}
189-
else if (node->classname == "Nonlocal") {
190-
Operator<T, Device>* nonlocal =
191-
new Nonlocal<OperatorPW<T, Device>>(
192-
reinterpret_cast<const Nonlocal<OperatorPW<T_in, Device_in>>*>(node));
193-
if(this->ops == nullptr) {
194-
this->ops = nonlocal;
195-
}
196-
else {
197-
this->ops->add(nonlocal);
198-
}
199-
}
200-
else if (node->classname == "Veff") {
201-
Operator<T, Device>* veff =
202-
new Veff<OperatorPW<T, Device>>(
203-
reinterpret_cast<const Veff<OperatorPW<T_in, Device_in>>*>(node));
204-
if(this->ops == nullptr) {
205-
this->ops = veff;
206-
}
207-
else {
208-
this->ops->add(veff);
209-
}
210-
}
211-
else if (node->classname == "Meta") {
212-
Operator<T, Device>* meta =
213-
new Meta<OperatorPW<T, Device>>(
214-
reinterpret_cast<const Meta<OperatorPW<T_in, Device_in>>*>(node));
215-
if(this->ops == nullptr) {
216-
this->ops = meta;
217-
}
218-
else {
219-
this->ops->add(meta);
220-
}
221-
}
222-
else if (node->classname == "OnsiteProj") {
223-
Operator<T, Device>* onsite_proj =
224-
new OnsiteProj<OperatorPW<T, Device>>(
225-
reinterpret_cast<const OnsiteProj<OperatorPW<T_in, Device_in>>*>(node));
226-
if(this->ops == nullptr) {
227-
this->ops = onsite_proj;
228-
}
229-
else {
230-
this->ops->add(onsite_proj);
231-
}
232-
}
233-
else {
234-
ModuleBase::WARNING_QUIT("HamiltPW", "Unrecognized Operator type!");
235-
}
236-
node = reinterpret_cast<OperatorPW<std::complex<T_in>, Device_in> *>(node->next_op);
237-
}
163+
ModuleBase::TITLE("HamiltPW", "updateHk");
238164
}
239165

240166
// This routine applies the S matrix to m wavefunctions psi and puts
@@ -390,8 +316,8 @@ void HamiltPW<T, Device>::sPsi(const T* psi_in, // psi
390316
}
391317
}
392318

393-
template<typename T, typename Device>
394-
void HamiltPW<T, Device>::set_exx_helper(Exx_Helper<T, Device> &exx_helper)
319+
template <typename T, typename Device>
320+
void HamiltPW<T, Device>::set_exx_helper(Exx_Helper<T, Device>& exx_helper)
395321
{
396322
auto op = this->ops;
397323
while (op != nullptr)
@@ -400,7 +326,6 @@ void HamiltPW<T, Device>::set_exx_helper(Exx_Helper<T, Device> &exx_helper)
400326
{
401327
exx_helper.op_exx = reinterpret_cast<OperatorEXXPW<T, Device>*>(op);
402328
exx_helper.set_op();
403-
404329
}
405330
op = op->next_op;
406331
}

source/source_pw/module_pwdft/hamilt_pw.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#ifndef HAMILTPW_H
22
#define HAMILTPW_H
33

4+
#include "source_base/kernels/math_kernel_op.h"
45
#include "source_base/macros.h"
56
#include "source_cell/klist.h"
6-
#include "source_estate/module_pot/potential_new.h"
77
#include "source_esolver/esolver_ks_pw.h"
8+
#include "source_estate/module_pot/potential_new.h"
89
#include "source_hamilt/hamilt.h"
9-
#include "source_pw/module_pwdft/vnl_pw.h"
10-
#include "source_base/kernels/math_kernel_op.h"
11-
#include "source_pw/module_pwdft/exx_helper.h"
1210
#include "source_lcao/module_dftu/dftu.h" // mohan add 2025-11-06
11+
#include "source_pw/module_pwdft/exx_helper.h"
12+
#include "source_pw/module_pwdft/vnl_pw.h"
1313

1414
namespace hamilt
1515
{
@@ -18,22 +18,18 @@ template <typename T, typename Device = base_device::DEVICE_CPU>
1818
class HamiltPW : public Hamilt<T, Device>
1919
{
2020
private:
21-
// Note GetTypeReal<T>::type will
22-
// return T if T is real type(float, double),
21+
// Note GetTypeReal<T>::type will
22+
// return T if T is real type(float, double),
2323
// otherwise return the real type of T(complex<float>, std::complex<double>)
2424
using Real = typename GetTypeReal<T>::type;
2525

2626
public:
27-
28-
HamiltPW(elecstate::Potential* pot_in,
29-
ModulePW::PW_Basis_K* wfc_basis,
30-
K_Vectors* p_kv,
31-
pseudopot_cell_vnl* nlpp,
32-
Plus_U *p_dftu, // mohan add 2025-11-06
33-
const UnitCell* ucell);
34-
35-
template<typename T_in, typename Device_in = Device>
36-
explicit HamiltPW(const HamiltPW<T_in, Device_in>* hamilt);
27+
HamiltPW(elecstate::Potential* pot_in,
28+
ModulePW::PW_Basis_K* wfc_basis,
29+
K_Vectors* p_kv,
30+
pseudopot_cell_vnl* nlpp,
31+
Plus_U* p_dftu, // mohan add 2025-11-06
32+
const UnitCell* ucell);
3733

3834
~HamiltPW();
3935

@@ -49,7 +45,7 @@ class HamiltPW : public Hamilt<T, Device>
4945

5046
void set_exx_helper(Exx_Helper<T, Device>& exx_helper_in);
5147

52-
protected:
48+
protected:
5349
// used in sPhi, which are calculated in hPsi or sPhi
5450
const pseudopot_cell_vnl* ppcell = nullptr;
5551
const UnitCell* const ucell = nullptr;

0 commit comments

Comments
 (0)