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
29
30// Basic class for operator module,
31// it is designed for "O|psi>" and "<psi|O|psi>"
32// Operator "O" might have several different types, which should be calculated one by one.
33// In basic class , function add() is designed for combine all operators together with a chain.
34template <typename T, typename Device = base_device::DEVICE_CPU>
36{
37 public:
39 virtual ~Operator();
40
41 // this is the core function for Operator
42 // do H|psi> from input |psi> ,
47 typedef std::tuple<const psi::Psi<T, Device>*, const psi::Range, T*> hpsi_info;
48
49 virtual hpsi_info hPsi(hpsi_info& input) const;
50
51 virtual void init(const int ik_in);
52
53 virtual void add(Operator* next);
54
55 virtual int get_ik() const
56 {
57 return this->ik;
58 }
59
64 virtual void act(const int nbands,
65 const int nbasis,
66 const int npol,
67 const T* tmpsi_in,
68 T* tmhpsi,
69 const int ngk_ik = 0,
70 const bool is_first_node = false) const {};
71
74 // virtual void act(const psi::Psi<T, Device>& psi_in, psi::Psi<T, Device>& psi_out) const {};
75 virtual void act(const psi::Psi<T, Device>& psi_in,
76 psi::Psi<T, Device>& psi_out,
77 const int nbands) const {};
78
80 // virtual psi::Psi<T> act(const psi::Psi<T,Device>& psi_in) const { return psi_in; };
81
82 Operator* next_op = nullptr;
83
88 int get_act_type() const
89 {
90 return this->act_type;
91 }
92
94 {
95 return this->cal_type;
96 }
97
98 protected:
99 int ik = 0;
100 int act_type = 1;
101
102 mutable bool in_place = false;
103
104 // calculation type, only different type can be in main chain table
107 bool is_first_node = true;
108
109 // if this Operator is first node in chain table, hpsi would not be empty
110 mutable psi::Psi<T, Device>* hpsi = nullptr;
111
112 /*This function would analyze hpsi_info and choose how to arrange hpsi storage
113 In hpsi_info, if the third parameter hpsi_pointer is set, which indicates memory of hpsi is arranged by developer;
114 if hpsi_pointer is not set(nullptr), which indicates memory of hpsi is arranged by Operator, this case is rare.
115 two cases would occurred:
116 1. hpsi_pointer != nullptr && psi_pointer == hpsi_pointer , psi would be replaced by hpsi, hpsi need a temporary
117 memory
118 2. hpsi_pointer != nullptr && psi_pointer != hpsi_pointer , this is the commonly case
119 */
120 T* get_hpsi(const hpsi_info& info) const;
121
122 Device* ctx = {};
124};
125
126} // end namespace hamilt
127
128#endif
Definition operator.h:36
virtual ~Operator()
int act_type
determine which act() interface would be called in hPsi()
Definition operator.h:100
virtual int get_ik() const
Definition operator.h:55
Operator * next_sub_op
Definition operator.h:106
int get_act_type() const
Definition operator.h:88
psi::Psi< T, Device > * hpsi
Definition operator.h:110
int ik
Definition operator.h:99
Operator * next_op
interface type 3: return a Psi-type HPsi
Definition operator.h:82
std::tuple< const psi::Psi< T, Device > *, const psi::Range, T * > hpsi_info
Definition operator.h:47
enum calculation_type cal_type
Definition operator.h:105
virtual hpsi_info hPsi(hpsi_info &input) const
virtual void add(Operator *next)
calculation_type get_cal_type() const
Definition operator.h:93
T * get_hpsi(const hpsi_info &info) const
bool is_first_node
Definition operator.h:107
virtual void init(const int ik_in)
virtual void act(const psi::Psi< T, Device > &psi_in, psi::Psi< T, Device > &psi_out, const int nbands) const
Definition operator.h:75
Device * ctx
Definition operator.h:122
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:64
bool in_place
Definition operator.h:102
Definition psi.h:37
#define T
Definition exp.cpp:237
Definition hamilt.h:13
calculation_type
Definition operator.h:12
Definition memory_op.h:31
Definition psi.h:16