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

Function dense_generalized_fallback

cpp_core/src/davidson.cpp:175–220  ·  view source on GitHub ↗

Dense generalized fallback: build full H and S via callbacks, then use LAPACK.

Source from the content-addressed store, hash-verified

173
174// Dense generalized fallback: build full H and S via callbacks, then use LAPACK.
175MatFreeDavidsonResult dense_generalized_fallback(
176 const HamiltonianOp& h_op,
177 const HamiltonianOp& s_op,
178 int n_pw,
179 int n_bands
180) {
181 std::vector<Complex> H(static_cast<std::size_t>(n_pw) * n_pw, Complex{0.0, 0.0});
182 std::vector<Complex> S(static_cast<std::size_t>(n_pw) * n_pw, Complex{0.0, 0.0});
183 std::vector<Complex> e_j(static_cast<std::size_t>(n_pw), Complex{0.0, 0.0});
184 std::vector<Complex> h_col(static_cast<std::size_t>(n_pw), Complex{0.0, 0.0});
185 std::vector<Complex> s_col(static_cast<std::size_t>(n_pw), Complex{0.0, 0.0});
186 for (int j = 0; j < n_pw; ++j) {
187 std::fill(e_j.begin(), e_j.end(), Complex{0.0, 0.0});
188 e_j[static_cast<std::size_t>(j)] = Complex{1.0, 0.0};
189 h_op(e_j.data(), h_col.data(), n_pw, 1);
190 s_op(e_j.data(), s_col.data(), n_pw, 1);
191 for (int i = 0; i < n_pw; ++i) {
192 H[static_cast<std::size_t>(i + n_pw * j)] = h_col[static_cast<std::size_t>(i)];
193 S[static_cast<std::size_t>(i + n_pw * j)] = s_col[static_cast<std::size_t>(i)];
194 }
195 }
196
197 auto eig = diagonalize_hermitian_generalized_dense(H, S, n_pw);
198
199 MatFreeDavidsonResult result;
200 result.n_pw = n_pw;
201 result.n_bands = n_bands;
202 result.converged = true;
203 result.iterations = 0;
204 result.n_matvec = n_pw;
205 result.max_residual_norm = 0.0;
206 result.method = "dense_generalized_fallback";
207 result.stop_reason = "dense_generalized_fallback";
208 result.eigenvalues_ha.assign(
209 eig.eigenvalues_ha.begin(),
210 eig.eigenvalues_ha.begin() + n_bands
211 );
212 result.eigenvectors_col_major.resize(static_cast<std::size_t>(n_pw) * n_bands);
213 for (int band = 0; band < n_bands; ++band) {
214 for (int i = 0; i < n_pw; ++i) {
215 result.eigenvectors_col_major[static_cast<std::size_t>(i + n_pw * band)] =
216 eig.eigenvectors_col_major[static_cast<std::size_t>(i + n_pw * band)];
217 }
218 }
219 return result;
220}
221
222Complex s_inner_product(
223 const Complex* x,

Tested by

no test coverage detected