forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Make Hsolver_sdft a local variable in hamilt_to_density fun…
…ction (#4941) * Make Hsolver_sdft a temporary obj in hamilt_to_density function * fix bug * store emin and emax * [pre-commit.ci lite] apply automatic fixes * fix bug in mDFT * remove useless memory cost * fix init_psi should be store in sdft * update results --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
- Loading branch information
1 parent
111073b
commit b7ffff7
Showing
23 changed files
with
870 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
list(APPEND hamilt_stodft_srcs | ||
sto_iter.cpp | ||
sto_hchi.cpp | ||
sto_che.cpp | ||
sto_wf.cpp | ||
sto_func.cpp | ||
sto_forces.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "sto_che.h" | ||
#include "module_base/blas_connector.h" | ||
|
||
template <typename REAL> | ||
StoChe<REAL>::~StoChe() | ||
{ | ||
delete p_che; | ||
delete[] spolyv; | ||
} | ||
|
||
template <typename REAL> | ||
StoChe<REAL>::StoChe(const int& nche, const int& method, const REAL& emax_sto, const REAL& emin_sto) | ||
{ | ||
this->nche = nche; | ||
this->method_sto = method; | ||
p_che = new ModuleBase::Chebyshev<REAL>(nche); | ||
if (method == 1) | ||
{ | ||
spolyv = new REAL[nche]; | ||
} | ||
else | ||
{ | ||
spolyv = new REAL[nche * nche]; | ||
} | ||
|
||
this->emax_sto = emax_sto; | ||
this->emin_sto = emin_sto; | ||
} | ||
|
||
template class StoChe<double>; | ||
// template class StoChe<float>; | ||
|
||
double vTMv(const double* v, const double* M, const int n) | ||
{ | ||
const char normal = 'N'; | ||
const double one = 1; | ||
const int inc = 1; | ||
const double zero = 0; | ||
double* y = new double[n]; | ||
dgemv_(&normal, &n, &n, &one, M, &n, v, &inc, &zero, y, &inc); | ||
double result = BlasConnector::dot(n, y, 1, v, 1); | ||
delete[] y; | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef STO_CHE_H | ||
#define STO_CHE_H | ||
#include "module_base/math_chebyshev.h" | ||
|
||
template <typename REAL> | ||
class StoChe | ||
{ | ||
public: | ||
StoChe(const int& nche, const int& method, const REAL& emax_sto, const REAL& emin_sto); | ||
~StoChe(); | ||
|
||
public: | ||
int nche = 0; ///< order of Chebyshev expansion | ||
REAL* spolyv = nullptr; ///< coefficients of Chebyshev expansion | ||
int method_sto = 0; ///< method for the stochastic calculation | ||
|
||
// Chebyshev expansion | ||
// It stores the plan of FFTW and should be initialized at the beginning of the calculation | ||
ModuleBase::Chebyshev<REAL>* p_che = nullptr; | ||
|
||
REAL emax_sto = 0.0; ///< maximum energy for normalization | ||
REAL emin_sto = 0.0; ///< minimum energy for normalization | ||
}; | ||
|
||
/** | ||
* @brief calculate v^T*M*v | ||
* | ||
* @param v v | ||
* @param M M | ||
* @param n the dimension of v | ||
* @return double | ||
*/ | ||
double vTMv(const double* v, const double* M, const int n); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.