Skip to content

Commit 1b3baf0

Browse files
authored
Fix: Initialize LCAO LDOS DMR independently (deepmodeling#7874)
1 parent e461ffd commit 1b3baf0

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

source/source_estate/module_dm/density_matrix_io.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "source_base/tool_title.h"
88
#include "source_cell/klist.h"
99

10+
#include <cstddef>
11+
#include <stdexcept>
12+
1013
namespace elecstate
1114
{
1215

@@ -185,9 +188,14 @@ void DensityMatrix<TK, TR>::init_DMR(const hamilt::HContainer<TRShift>& DMR_in)
185188
template <typename TK, typename TR>
186189
hamilt::HContainer<TR>* DensityMatrix<TK, TR>::get_DMR_pointer(const int ispin) const
187190
{
188-
#ifdef __DEBUG
189-
assert(ispin > 0 && ispin <= this->_nspin);
190-
#endif
191+
if (ispin <= 0 || ispin > this->_nspin)
192+
{
193+
throw std::out_of_range("DensityMatrix::get_DMR_pointer: DMR spin index is out of range");
194+
}
195+
if (this->_DMR.size() != static_cast<std::size_t>(this->_nspin))
196+
{
197+
throw std::logic_error("DensityMatrix::get_DMR_pointer: DMR has not been initialized");
198+
}
191199
return this->_DMR[ispin - 1];
192200
}
193201

@@ -443,4 +451,4 @@ template class DensityMatrix<double, double>; // Gamma-Only case
443451
template class DensityMatrix<std::complex<double>, double>; // Multi-k case
444452
template class DensityMatrix<std::complex<double>, std::complex<double>>; // For EXX in future
445453

446-
} // namespace elecstate
454+
} // namespace elecstate

source/source_io/module_ctrl/ctrl_runner_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void ctrl_runner_lcao(UnitCell& ucell, // unitcell
5151
if (inp.out_ldos[0])
5252
{
5353
ModuleIO::Cal_ldos<TK>::cal_ldos_lcao(pelec->eferm, chr, dmat, kv,
54-
pelec->ekb, pelec->wg, psi[0], pgrid, ucell);
54+
pelec->ekb, pelec->wg, psi[0], pgrid, gd, ucell);
5555
}
5656

5757
// 3) print out exchange-correlation potential

source/source_io/module_dos/cal_ldos.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void Cal_ldos<T>::cal_ldos_lcao(
2222
const ModuleBase::matrix &wg, // mohan add 2025-11-02
2323
const psi::Psi<T>& psi,
2424
const Parallel_Grid& pgrid,
25+
const Grid_Driver& grid_driver,
2526
const UnitCell& ucell)
2627
{
2728
for (int ie = 0; ie < PARAM.inp.stm_bias[2]; ie++)
@@ -55,7 +56,7 @@ void Cal_ldos<T>::cal_ldos_lcao(
5556
kv.get_nks() / nspin_dm);
5657

5758
elecstate::cal_dm_psi(dmat.dm->get_paraV_pointer(), weight, psi, dm_ldos);
58-
dm_ldos.init_DMR(*(dmat.dm->get_DMR_pointer(1)));
59+
dm_ldos.init_DMR(&grid_driver, &ucell);
5960
dm_ldos.cal_DMR();
6061

6162
// allocate ldos space

source/source_io/module_dos/cal_ldos.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "source_estate/module_charge/charge.h" // chr
99
#include "source_lcao/setup_dm.h" // Setup_DM
1010
#include "source_cell/klist.h" // K_Vectors
11+
#include "source_cell/module_neighbor/sltk_grid_driver.h" // Grid_Driver
1112
#include "source_base/matrix.h" // matrix
1213

1314
namespace ModuleIO
@@ -28,6 +29,7 @@ class Cal_ldos
2829
const ModuleBase::matrix &wg, // mohan add 2025-11-02
2930
const psi::Psi<T>& psi,
3031
const Parallel_Grid& pgrid,
32+
const Grid_Driver& grid_driver,
3133
const UnitCell& ucell);
3234

3335
}; // namespace Cal_ldos

0 commit comments

Comments
 (0)