MCPcopy Create free account
hub / github.com/SZAILAB/MaterialDFT-Demo / dense_fallback

Function dense_fallback

cpp_core/src/rmmdiis.cpp:202–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202MatFreeRmmDiisResult dense_fallback(
203 const HamiltonianOp& h_op,
204 int n_pw,
205 int n_bands
206) {
207 std::vector<Complex> H(static_cast<std::size_t>(n_pw) * n_pw, Complex{0.0, 0.0});
208 std::vector<Complex> e_j(static_cast<std::size_t>(n_pw), Complex{0.0, 0.0});
209 std::vector<Complex> h_col(static_cast<std::size_t>(n_pw), Complex{0.0, 0.0});
210 for (int j = 0; j < n_pw; ++j) {
211 std::fill(e_j.begin(), e_j.end(), Complex{0.0, 0.0});
212 e_j[static_cast<std::size_t>(j)] = Complex{1.0, 0.0};
213 h_op(e_j.data(), h_col.data(), n_pw, 1);
214 for (int i = 0; i < n_pw; ++i) {
215 H[static_cast<std::size_t>(i + n_pw * j)] = h_col[static_cast<std::size_t>(i)];
216 }
217 }
218 const auto eig = diagonalize_hermitian_dense(H, n_pw);
219
220 MatFreeRmmDiisResult out;
221 out.n_pw = n_pw;
222 out.n_bands = n_bands;
223 out.converged = true;
224 out.iterations = 0;
225 out.n_matvec = n_pw;
226 out.max_residual_norm = 0.0;
227 out.method = "dense_fallback";
228 out.eigenvalues_ha.assign(eig.eigenvalues_ha.begin(), eig.eigenvalues_ha.begin() + n_bands);
229 out.eigenvectors_col_major.resize(static_cast<std::size_t>(n_pw) * n_bands);
230 for (int j = 0; j < n_bands; ++j) {
231 for (int i = 0; i < n_pw; ++i) {
232 out.eigenvectors_col_major[static_cast<std::size_t>(i + n_pw * j)] =
233 eig.eigenvectors_col_major[static_cast<std::size_t>(i + n_pw * j)];
234 }
235 }
236 return out;
237}
238
239} // namespace
240

Callers 1

rmm_diis_eigensolverFunction · 0.70

Calls 1

Tested by

no test coverage detected