ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
operator.h
Go to the documentation of this file.
1#ifndef OPERATOR_H
2#define OPERATOR_H
3
4#include "source_psi/psi.h"
5
6#include <complex>
7
8namespace hamilt
9{
10
35
36// Basic class for operator module,
37// it is designed for "O|psi>" and "<psi|O|psi>"
38// Operator "O" might have several different types, which should be calculated one by one.
39// In basic class , function add() is designed for combine all operators together with a chain.
40template <typename T, typename Device = base_device::DEVICE_CPU>
42{
43 public:
44 Operator();
45 virtual ~Operator();
46
53 typedef std::tuple<const psi::Psi<T, Device> *, const psi::Range, T *> hpsi_info;
54
83 virtual hpsi_info hPsi(hpsi_info &input) const;
84
85 virtual void init(const int ik_in);
86
87 virtual void add(Operator *next);
88
89 virtual int get_ik() const { return this->ik; }
90
95 virtual void act(
96 const int nbands,
97 const int nbasis,
98 const int npol,
99 const T *tmpsi_in,
100 T *tmhpsi,
101 const int ngk_ik = 0,
102 const bool is_first_node = false) const {};
103
106 // virtual void act(const psi::Psi<T, Device>& psi_in, psi::Psi<T, Device>& psi_out) const {};
107 virtual void act(const psi::Psi<T, Device> &psi_in, psi::Psi<T, Device> &psi_out, const int nbands) const {};
108
110 // virtual psi::Psi<T> act(const psi::Psi<T,Device>& psi_in) const { return psi_in; };
111
112 Operator *next_op = nullptr;
113
118 int get_act_type() const { return this->act_type; }
119
120 calculation_type get_cal_type() const { return this->cal_type; }
121
122 protected:
123 int ik = 0;
124 int act_type = 1;
125
126 mutable bool in_place = false;
127
128 // calculation type, only different type can be in main chain table
131 bool is_first_node = true;
132
133 // if this Operator is first node in chain table, hpsi would not be empty
134 mutable psi::Psi<T, Device> *hpsi = nullptr;
135
136 /*This function would analyze hpsi_info and choose how to arrange hpsi storage
137 In hpsi_info, if the third parameter hpsi_pointer is set, which indicates memory of hpsi is arranged by developer;
138 if hpsi_pointer is not set(nullptr), which indicates memory of hpsi is arranged by Operator, this case is rare.
139 two cases would occurred:
140 1. hpsi_pointer != nullptr && psi_pointer == hpsi_pointer , psi would be replaced by hpsi, hpsi need a temporary
141 memory
142 2. hpsi_pointer != nullptr && psi_pointer != hpsi_pointer , this is the commonly case
143 */
144 T *get_hpsi(const hpsi_info &info) const;
145
146 Device *ctx = {};
148};
149
150} // end namespace hamilt
151
152#endif
int act_type
determine which act() interface would be called in hPsi()
Definition operator.h:124
virtual int get_ik() const
Definition operator.h:89
Operator * next_sub_op
Definition operator.h:130
int get_act_type() const
Definition operator.h:118
psi::Psi< T, Device > * hpsi
Definition operator.h:134
int ik
Definition operator.h:123
Operator * next_op
interface type 3: return a Psi-type HPsi
Definition operator.h:112
virtual ~Operator()
Definition operator.cpp:14
enum calculation_type cal_type
Definition operator.h:129
T * get_hpsi(const hpsi_info &info) const
Definition operator.cpp:156
virtual void add(Operator *next)
Definition operator.cpp:117
std::tuple< const psi::Psi< T, Device > *, const psi::Range, T * > hpsi_info
input type of hPsi: (psi_input, range, hpsi_pointer)
Definition operator.h:53
virtual void init(const int ik_in)
Definition operator.cpp:107
calculation_type get_cal_type() const
Definition operator.h:120
bool is_first_node
Definition operator.h:131
virtual hpsi_info hPsi(hpsi_info &input) const
Core hot-path: compute H|psi> by traversing the operator chain.
Definition operator.cpp:46
virtual void act(const psi::Psi< T, Device > &psi_in, psi::Psi< T, Device > &psi_out, const int nbands) const
Definition operator.h:107
base_device::memory::set_memory_op< T, Device > set_memory_op
Definition operator.h:147
Operator()
Definition operator.cpp:9
Device * ctx
Definition operator.h:146
virtual void act(const int nbands, const int nbasis, const int npol, const T *tmpsi_in, T *tmhpsi, const int ngk_ik=0, const bool is_first_node=false) const
Definition operator.h:95
bool in_place
Definition operator.h:126
Definition psi.h:37
#define T
Definition exp.cpp:237
Definition wf_op.cpp:6
calculation_type
Definition operator.h:12
@ pw_ekinetic_td
Definition operator.h:15
@ pw_veff
Definition operator.h:17
@ pw_onsite
Definition operator.h:19
@ lcao_sc_lambda
Definition operator.h:27
@ lr_dmtrans_exx
Definition operator.h:32
@ pw_ekinetic
Definition operator.h:14
@ lcao_gint
Definition operator.h:23
@ pw_nonlocal
Definition operator.h:16
@ lr_dmdiff_hxc
Definition operator.h:31
@ lr_dmtrans_hxc
Definition operator.h:29
@ lcao_fixed
Definition operator.h:22
@ no
Definition operator.h:13
@ lcao_tddft_periodic
Definition operator.h:28
@ lcao_overlap
Definition operator.h:21
@ pw_meta
Definition operator.h:18
@ lcao_dftu
Definition operator.h:26
@ lcao_exx
Definition operator.h:25
@ lcao_deepks
Definition operator.h:24
@ lr_dmdiff_exx
Definition operator.h:33
@ lr_dmtrans_gxc
Definition operator.h:30
@ pw_exx
Definition operator.h:20
Definition memory_op.h:31
Definition psi.h:16
Input_para input
Definition test_io_sys_var.cpp:58