Skip to content

Commit 50f4d68

Browse files
committed
C++11 compatibility
1 parent abb06b4 commit 50f4d68

3 files changed

Lines changed: 94 additions & 89 deletions

File tree

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
9595
const auto wfc_extrap_method = ModuleExtrap::wfc_extrap_method_from_string(inp.wfc_extrap);
9696
if (wfc_extrap_method != ModuleExtrap::WfcExtrapMethod::None)
9797
{
98-
this->wf_history_lcao_ = std::make_unique<ModuleExtrap::WfHistoryLCAO<TK>>(wfc_extrap_method);
98+
this->wf_history_lcao_.reset(new ModuleExtrap::WfHistoryLCAO<TK>(wfc_extrap_method));
9999
GlobalV::ofs_running << " WFN extrapolation method: "
100100
<< ModuleExtrap::to_string(wfc_extrap_method) << std::endl;
101101
}
@@ -215,7 +215,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
215215
}
216216
else if(PARAM.inp.esolver_type!="tddft")//initialize DMR from WFN history if required
217217
{
218-
if constexpr (std::is_same<TK, double>::value)
218+
if (std::is_same<TK, double>::value)
219219
{
220220
if (this->wf_history_lcao_ != nullptr)
221221
{

source/source_lcao/module_extrap/wf_history_lcao.cpp

Lines changed: 90 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -89,106 +89,111 @@ bool WfHistoryLCAO<TK>::latest_snapshot(WfSnapshotLCAO<TK>& snapshot) const
8989
}
9090

9191
template <typename TK>
92-
WfExtrapApplyResult WfHistoryLCAO<TK>::try_use_prev_wf_gamma(const double* current_overlap,
93-
const Parallel_Orbitals& pv,
94-
psi::Psi<double>& psi,
95-
const ModuleBase::matrix& wg_now,
96-
const double pivot_threshold,
97-
const double check_tolerance)
92+
WfExtrapApplyResult WfHistoryLCAO<TK>::try_use_prev_wf_gamma(const TK*,
93+
const Parallel_Orbitals&,
94+
psi::Psi<TK>&,
95+
const ModuleBase::matrix&,
96+
const double,
97+
const double)
9898
{
9999
WfExtrapApplyResult result;
100+
result.status = WfcExtrapStatus::Unsupported;
101+
return result;
102+
}
103+
104+
template <>
105+
WfExtrapApplyResult WfHistoryLCAO<double>::try_use_prev_wf_gamma(const double* current_overlap,
106+
const Parallel_Orbitals& pv,
107+
psi::Psi<double>& psi,
108+
const ModuleBase::matrix& wg_now,
109+
const double pivot_threshold,
110+
const double check_tolerance)
111+
{
112+
WfExtrapApplyResult result;
113+
114+
if (this->method_ != WfcExtrapMethod::UsePrevWf)
115+
{
116+
result.status = WfcExtrapStatus::Disabled;
117+
return result;
118+
}
119+
120+
if (this->snapshots_.empty())
121+
{
122+
result.status = WfcExtrapStatus::EmptyHistory;
123+
return result;
124+
}
125+
126+
if (current_overlap == nullptr || !(pivot_threshold >= 0.0) || !(check_tolerance > 0.0))
127+
{
128+
result.status = WfcExtrapStatus::InvalidInput;
129+
return result;
130+
}
100131

101-
if constexpr (!std::is_same<TK, double>::value)
132+
// The first PR only supports the real Gamma-only path. In this path the
133+
// first Psi dimension may label spin channels, but not physical k-points.
134+
if (!psi.get_k_first())
102135
{
103136
result.status = WfcExtrapStatus::Unsupported;
104137
return result;
105138
}
106-
else
139+
140+
const WfSnapshotLCAO<double>& snapshot = this->snapshots_.back();
141+
result.snapshot_istep = snapshot.istep;
142+
143+
if (!snapshot.compatible_with(psi, wg_now))
144+
{
145+
result.status = WfcExtrapStatus::DimensionMismatch;
146+
return result;
147+
}
148+
149+
// Work on an owned trial Psi first. The caller's Psi is not overwritten
150+
// unless the stored WFN can be loaded and reorthonormalized successfully.
151+
psi::Psi<double> psi_trial(psi);
152+
ModuleBase::timer::start("WFN_Extrap", "restore_snapshot");
153+
const bool snapshot_loaded = snapshot.load_to(psi_trial);
154+
ModuleBase::timer::end("WFN_Extrap", "restore_snapshot");
155+
if (!snapshot_loaded)
107156
{
108-
if (this->method_ != WfcExtrapMethod::UsePrevWf)
109-
{
110-
result.status = WfcExtrapStatus::Disabled;
111-
return result;
112-
}
113-
114-
if (this->snapshots_.empty())
115-
{
116-
result.status = WfcExtrapStatus::EmptyHistory;
117-
return result;
118-
}
119-
120-
if (current_overlap == nullptr || !(pivot_threshold >= 0.0) || !(check_tolerance > 0.0))
121-
{
122-
result.status = WfcExtrapStatus::InvalidInput;
123-
return result;
124-
}
125-
126-
// The first PR only supports the real Gamma-only path. In this path the
127-
// first Psi dimension may label spin channels, but not physical k-points.
128-
if (!psi.get_k_first())
129-
{
130-
result.status = WfcExtrapStatus::Unsupported;
131-
return result;
132-
}
133-
134-
const WfSnapshotLCAO<TK>& snapshot = this->snapshots_.back();
135-
result.snapshot_istep = snapshot.istep;
136-
137-
if (!snapshot.compatible_with(psi, wg_now))
138-
{
139-
result.status = WfcExtrapStatus::DimensionMismatch;
140-
return result;
141-
}
142-
143-
// Work on an owned trial Psi first. The caller's Psi is not overwritten
144-
// unless the stored WFN can be loaded and reorthonormalized successfully.
145-
psi::Psi<double> psi_trial(psi);
146-
ModuleBase::timer::start("WFN_Extrap", "restore_snapshot");
147-
const bool snapshot_loaded = snapshot.load_to(psi_trial);
148-
ModuleBase::timer::end("WFN_Extrap", "restore_snapshot");
149-
if (!snapshot_loaded)
150-
{
151-
result.status = WfcExtrapStatus::DimensionMismatch;
152-
return result;
153-
}
154-
155-
ModuleBase::timer::start("WFN_Extrap", "orthonormalize");
156-
const WfOrthonormalizeResult orth_result = reorthonormalize_gamma_lcao(current_overlap,
157-
pv,
158-
psi_trial,
159-
snapshot.wg,
160-
1.0e-12,
161-
pivot_threshold,
162-
check_tolerance);
163-
ModuleBase::timer::end("WFN_Extrap", "orthonormalize");
164-
if (!orth_result.ok())
165-
{
166-
result.status = orth_result.status;
167-
result.failed_state = orth_result.failed_state;
168-
result.failed_pivot_index = orth_result.failed_pivot_index;
169-
result.failed_pivot = orth_result.failed_pivot;
170-
result.min_metric_diag = orth_result.min_metric_diag;
171-
result.max_metric_diag = orth_result.max_metric_diag;
172-
result.max_metric_abs = orth_result.max_metric_abs;
173-
result.max_metric_asymmetry = orth_result.max_metric_asymmetry;
174-
result.nstate = orth_result.nstate;
175-
result.nbands = orth_result.nbands;
176-
result.nbasis = orth_result.nbasis;
177-
result.nactive_bands = orth_result.nactive_bands;
178-
result.max_orthonormality_deviation = orth_result.max_deviation;
179-
return result;
180-
}
181-
182-
psi = psi_trial;
183-
result.status = WfcExtrapStatus::Success;
184-
result.failed_state = -1;
157+
result.status = WfcExtrapStatus::DimensionMismatch;
158+
return result;
159+
}
160+
161+
ModuleBase::timer::start("WFN_Extrap", "orthonormalize");
162+
const WfOrthonormalizeResult orth_result = reorthonormalize_gamma_lcao(current_overlap,
163+
pv,
164+
psi_trial,
165+
snapshot.wg,
166+
1.0e-12,
167+
pivot_threshold,
168+
check_tolerance);
169+
ModuleBase::timer::end("WFN_Extrap", "orthonormalize");
170+
if (!orth_result.ok())
171+
{
172+
result.status = orth_result.status;
173+
result.failed_state = orth_result.failed_state;
174+
result.failed_pivot_index = orth_result.failed_pivot_index;
175+
result.failed_pivot = orth_result.failed_pivot;
176+
result.min_metric_diag = orth_result.min_metric_diag;
177+
result.max_metric_diag = orth_result.max_metric_diag;
178+
result.max_metric_abs = orth_result.max_metric_abs;
179+
result.max_metric_asymmetry = orth_result.max_metric_asymmetry;
185180
result.nstate = orth_result.nstate;
186181
result.nbands = orth_result.nbands;
187182
result.nbasis = orth_result.nbasis;
188183
result.nactive_bands = orth_result.nactive_bands;
189184
result.max_orthonormality_deviation = orth_result.max_deviation;
190185
return result;
191186
}
187+
188+
psi = psi_trial;
189+
result.status = WfcExtrapStatus::Success;
190+
result.failed_state = -1;
191+
result.nstate = orth_result.nstate;
192+
result.nbands = orth_result.nbands;
193+
result.nbasis = orth_result.nbasis;
194+
result.nactive_bands = orth_result.nactive_bands;
195+
result.max_orthonormality_deviation = orth_result.max_deviation;
196+
return result;
192197
}
193198

194199
template <typename TK>

source/source_lcao/module_extrap/wf_history_lcao.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ class WfHistoryLCAO
7272
* complex WFN snapshots, per-k S(k), and phase/convention handling, and should be
7373
* added in a separate path instead of silently reusing this helper.
7474
*/
75-
WfExtrapApplyResult try_use_prev_wf_gamma(const double* current_overlap,
75+
WfExtrapApplyResult try_use_prev_wf_gamma(const TK* current_overlap,
7676
const Parallel_Orbitals& pv,
77-
psi::Psi<double>& psi,
77+
psi::Psi<TK>& psi,
7878
const ModuleBase::matrix& wg_now,
7979
double pivot_threshold = 1.0e-14,
8080
double check_tolerance = 1.0e-8);

0 commit comments

Comments
 (0)