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

Function should_stop_vasp_like

cpp_core/src/davidson.cpp:630–694  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

628};
629
630bool should_stop_vasp_like(
631 const std::vector<double>& current_ritz_values_ha,
632 int n_bands,
633 const MatFreeDavidsonOptions& opts,
634 EigenvalueBreakState* state,
635 double* max_eigenvalue_change_ha_out
636) {
637 if (max_eigenvalue_change_ha_out != nullptr) {
638 *max_eigenvalue_change_ha_out = 0.0;
639 }
640 if (!opts.use_vasp_like_stop || state == nullptr || n_bands <= 0) {
641 return false;
642 }
643
644 if (!state->have_previous) {
645 state->previous_ritz_values_ha.assign(
646 current_ritz_values_ha.begin(),
647 current_ritz_values_ha.begin() + n_bands
648 );
649 state->have_previous = true;
650 return false;
651 }
652
653 std::vector<double> deltas_ha(static_cast<std::size_t>(n_bands), 0.0);
654 double max_delta_ha = 0.0;
655 for (int j = 0; j < n_bands; ++j) {
656 const double delta_ha = std::abs(
657 current_ritz_values_ha[static_cast<std::size_t>(j)]
658 - state->previous_ritz_values_ha[static_cast<std::size_t>(j)]
659 );
660 deltas_ha[static_cast<std::size_t>(j)] = delta_ha;
661 max_delta_ha = std::max(max_delta_ha, delta_ha);
662 }
663 if (max_eigenvalue_change_ha_out != nullptr) {
664 *max_eigenvalue_change_ha_out = max_delta_ha;
665 }
666
667 if (!state->have_first_step_delta) {
668 state->first_step_delta_ha = deltas_ha;
669 state->have_first_step_delta = true;
670 }
671
672 int n_satisfied = 0;
673 for (int j = 0; j < n_bands; ++j) {
674 const double delta_ha = deltas_ha[static_cast<std::size_t>(j)];
675 const bool abs_ok = opts.eigenvalue_abs_break_ha > 0.0
676 && delta_ha <= opts.eigenvalue_abs_break_ha;
677
678 bool rel_ok = false;
679 if (opts.eigenvalue_rel_break > 0.0 && state->have_first_step_delta) {
680 const double first_delta_ha = state->first_step_delta_ha[static_cast<std::size_t>(j)];
681 rel_ok = delta_ha <= opts.eigenvalue_rel_break * first_delta_ha;
682 }
683
684 if (abs_ok || rel_ok) {
685 ++n_satisfied;
686 }
687 }

Callers 2

davidson_eigensolverFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected