Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/source_base/module_container/base/utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define BASE_CORE_LOGGING_H_

#include <base/macros/macros.h>
#include <cstdio>
#include <cstdlib>

namespace base {
namespace utils {
Expand All @@ -19,4 +21,4 @@ inline static void check_exit_impl(const char* func, const char* file, uint32_t

} // namespace logging
} // namespace base
#endif // BASE_CORE_LOGGING_H_
#endif // BASE_CORE_LOGGING_H_
44 changes: 17 additions & 27 deletions source/source_hamilt/hamilt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <complex>
#include <vector>

#include "hamilt_base.h"
#include "matrixblock.h"
#include "source_psi/psi.h"
#include "operator.h"
#include "hamilt_base.h"
#include "source_psi/psi.h"

namespace hamilt
{
Expand All @@ -16,7 +16,7 @@ template <typename T, typename Device = base_device::DEVICE_CPU>
class Hamilt : public HamiltBase
{
public:
virtual ~Hamilt(){};
virtual ~Hamilt() {};

/// for target K point, update consequence of hPsi() and matrix()
void updateHk(const int ik) override { return; }
Expand All @@ -28,46 +28,36 @@ class Hamilt : public HamiltBase
std::string get_classname() const override { return classname; }

/// get the operator chain
void* get_ops() override { return static_cast<void*>(ops); }
void *get_ops() override { return static_cast<void *>(ops); }

/// core function: for solving eigenvalues of Hamiltonian with iterative method
virtual void hPsi(
const T* psi_in,
T* hpsi,
const size_t size) const
{
return;
}

virtual void sPsi(const T* psi_in, // psi
T* spsi, // spsi
const int nrow, // dimension of spsi: nbands * nrow
const int npw, // number of plane waves
const int nbands // number of bands
virtual void hPsi(const T *psi_in, T *hpsi, const size_t size) const { return; }

virtual void sPsi(
const T *psi_in, // psi
T *spsi, // spsi
const int nrow, // dimension of spsi: nbands * nrow
const int npw, // number of plane waves
const int nbands // number of bands
) const
{
syncmem_op()(spsi, psi_in, static_cast<size_t>(nbands * nrow));
}

/// core function: return H(k) and S(k) matrixs for direct solving eigenvalues.
virtual void matrix(
MatrixBlock<std::complex<double>> &hk_in,
MatrixBlock<std::complex<double>> &sk_in){return;}
virtual void matrix(MatrixBlock<std::complex<double>> &hk_in, MatrixBlock<std::complex<double>> &sk_in) { return; }

virtual void matrix(
MatrixBlock<double> &hk_in,
MatrixBlock<double> &sk_in){return;}
virtual void matrix(MatrixBlock<double> &hk_in, MatrixBlock<double> &sk_in) { return; }

virtual std::vector<T> matrix() { return std::vector<T>(); }

std::string classname = "none";

/// first node operator, add operations from each operators
Operator<T, Device>* ops = nullptr;

protected:
Operator<T, Device> *ops = nullptr;

Device* ctx = {};
protected:
Device *ctx = {};
using syncmem_op = base_device::memory::synchronize_memory_op<T, Device, Device>;
};

Expand Down
2 changes: 1 addition & 1 deletion source/source_hamilt/hamilt_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HamiltBase
*
* @return pointer to operator chain
*/
virtual void* get_ops() { return nullptr; }
virtual void *get_ops() { return nullptr; }
};

} // namespace hamilt
Expand Down
30 changes: 17 additions & 13 deletions source/source_hamilt/hamilt_hs_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ template <typename T, typename Device = base_device::DEVICE_CPU>
class HamiltHSOperator : public hsolver::HSOperator<T, Device>
{
public:
HamiltHSOperator(Hamilt<T, Device>* hm, const ModulePW::PW_Basis_K* wfc_basis) : hm_(hm), wfc_basis_(wfc_basis)
{
}
HamiltHSOperator(Hamilt<T, Device> *hm, const ModulePW::PW_Basis_K *wfc_basis) : hm_(hm), wfc_basis_(wfc_basis) {}

void update_k(const int ik) override
{
Expand All @@ -33,26 +31,34 @@ class HamiltHSOperator : public hsolver::HSOperator<T, Device>
npw_ = wfc_basis_->npwk[ik];
}

void hpsi(const T* x, T* hx, const int ld, const int nvec) const override
void hpsi(
const T *x,
T *hx,
const int ld,
const int nvec) const override
{
if (hm_->ops == nullptr)
{
ModuleBase::WARNING_QUIT("HamiltHSOperator::hpsi", "Operators in Hamilt are not allocated yet");
}
// non-owning view of x: one k point, nvec bands, leading dimension ld, npw valid rows
psi::Psi<T, Device> x_view(const_cast<T*>(x), 1, nvec, ld, npw_);
psi::Psi<T, Device> x_view(const_cast<T *>(x), 1, nvec, ld, npw_);
typename Operator<T, Device>::hpsi_info info(&x_view, psi::Range(true, 0, 0, nvec - 1), hx);
hm_->ops->hPsi(info);
}

void spsi(const T* x, T* sx, const int ld, const int nvec) const override
void spsi(
const T *x,
T *sx,
const int ld,
const int nvec) const override
{
hm_->sPsi(x, sx, ld, npw_, nvec);
}

protected:
Hamilt<T, Device>* hm_ = nullptr;
const ModulePW::PW_Basis_K* wfc_basis_ = nullptr;
Hamilt<T, Device> *hm_ = nullptr;
const ModulePW::PW_Basis_K *wfc_basis_ = nullptr;
int ik_ = 0; ///< k point set by the last update_k()
int npw_ = 0; ///< number of plane waves of that k point (without npol)
};
Expand All @@ -65,18 +71,16 @@ template <typename T>
class HamiltHSMatrix : public hsolver::HSMatrix<T>
{
public:
explicit HamiltHSMatrix(Hamilt<T>* hm) : hm_(hm)
{
}
explicit HamiltHSMatrix(Hamilt<T> *hm) : hm_(hm) {}

void hs_at_k(const int ik, ModuleBase::MatrixBlock<T>& hk, ModuleBase::MatrixBlock<T>& sk) override
void hs_at_k(const int ik, ModuleBase::MatrixBlock<T> &hk, ModuleBase::MatrixBlock<T> &sk) override
{
hm_->updateHk(ik);
hm_->matrix(hk, sk);
}

private:
Hamilt<T>* hm_ = nullptr;
Hamilt<T> *hm_ = nullptr;
};

} // namespace hamilt
Expand Down
6 changes: 3 additions & 3 deletions source/source_hamilt/hs_matrix_k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace hamilt
{
template class HS_Matrix_K<double>;
template class HS_Matrix_K<std::complex<double>>;
}
template class HS_Matrix_K<double>;
template class HS_Matrix_K<std::complex<double>>;
} // namespace hamilt
50 changes: 25 additions & 25 deletions source/source_hamilt/hs_matrix_k.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,40 @@
#include <vector>
namespace hamilt
{
template <typename TK>
class HS_Matrix_K
{

public:
HS_Matrix_K(const Parallel_Orbitals* paraV, bool no_s=false){
hk.resize(paraV->para_2d().size());
if(!no_s)
{
sk.resize(paraV->para_2d().size());
}
this->pv = paraV;
}
template <typename TK>
class HS_Matrix_K
{

TK* get_hk() {return hk.data();}
public:
HS_Matrix_K(const Parallel_Orbitals *paraV, bool no_s = false)
{
hk.resize(paraV->para_2d().size());
if (!no_s)
{
sk.resize(paraV->para_2d().size());
}
this->pv = paraV;
}

TK* get_sk() {return sk.data();}
TK *get_hk() { return hk.data(); }

int get_size() {return hk.size();}
TK *get_sk() { return sk.data(); }

void set_zero_hk() {hk.assign(hk.size(), 0);}
int get_size() { return hk.size(); }

void set_zero_sk() {sk.assign(sk.size(), 0);}
void set_zero_hk() { hk.assign(hk.size(), 0); }

const Parallel_Orbitals* get_pv() const {return this->pv;}
void set_zero_sk() { sk.assign(sk.size(), 0); }

private:
const Parallel_Orbitals *get_pv() const { return this->pv; }

std::vector<TK> hk;
private:
std::vector<TK> hk;

std::vector<TK> sk;
std::vector<TK> sk;

const Parallel_Orbitals* pv = nullptr;
};
}
const Parallel_Orbitals *pv = nullptr;
};
} // namespace hamilt

#endif
Loading
Loading