ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
mixing_data.h
Go to the documentation of this file.
1#ifndef MIXING_DATA_H_
2#define MIXING_DATA_H_
3#include <vector>
4
6namespace Base_Mixing
7{
8
14{
15 public:
16 Mixing_Data() = default;
25 Mixing_Data(const int& ndim, const std::size_t& length, const size_t& type_size);
26
32
41 void resize(const int& ndim, const std::size_t& length, const size_t& type_size);
42
47 template <typename FPTYPE>
48 void push(const FPTYPE* data_in)
49 {
50 this->start = (this->start + 1) % this->ndim_tot;
51 this->ndim_use = std::min(this->ndim_use + 1, this->ndim_tot);
52 ++this->ndim_history;
53 FPTYPE* FP_startdata = static_cast<FPTYPE*>(this->data) + this->start * this->length;
54#ifdef _OPENMP
55#pragma omp parallel for schedule(static, 4096/sizeof(FPTYPE))
56#endif
57 for (std::size_t i = 0; i < length; ++i)
58 {
59 FP_startdata[i] = data_in[i];
60 }
61 }
62
67 void reset()
68 {
69 this->ndim_use = 0;
70 this->ndim_history = 0;
71 this->start = -1;
72 }
73
78 int index_move(const int& n) const
79 {
80 return (n + this->start + ndim_tot) % ndim_tot;
81 }
82
83 public:
84 // Tensor pointer to store the data
85 void* data = nullptr;
86 // the number of vectors for mixing
87 int ndim_tot = 0;
88 // the length of each vector
89 std::size_t length = 0;
90 // the start index for vector: start = this->index_move(0)
91 int start = -1;
92 // the number of used vectors for mixing
93 int ndim_use = 0;
94 // the number of history vectors
95 int ndim_history = 0;
96};
97
98} // namespace Base_Mixing
99#endif
data for Mixing class
Definition mixing_data.h:14
int index_move(const int &n) const
get the index of i-th vector
Definition mixing_data.h:78
void resize(const int &ndim, const std::size_t &length, const size_t &type_size)
resize the data
Definition mixing_data.cpp:23
int start
Definition mixing_data.h:91
int ndim_tot
Definition mixing_data.h:87
void * data
Definition mixing_data.h:85
int ndim_history
Definition mixing_data.h:95
~Mixing_Data()
Destroy the Mixing_Data object.
Definition mixing_data.cpp:16
void push(const FPTYPE *data_in)
push data to the tensor
Definition mixing_data.h:48
void reset()
reset mixing
Definition mixing_data.h:67
int ndim_use
Definition mixing_data.h:93
std::size_t length
Definition mixing_data.h:89
Definition broyden_mixing.cpp:9