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