Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Hubbard U+V non magnetic case #788

Merged
merged 6 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/density/occupation_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ Occupation_matrix::add_k_point_contribution(K_point<T>& kp__)
}
} // ispn
}

PROFILE_STOP("sirius::Occupation_matrix::add_k_point_contribution");
}

template void Occupation_matrix::add_k_point_contribution<double>(K_point<double>& kp__);
Expand Down
18 changes: 5 additions & 13 deletions src/dft/energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ewald_energy(const Simulation_context& ctx, const sddk::Gvec& gvec, const Unit_c

for (int ia = 0; ia < unit_cell.num_atoms(); ia++) {
rho += ctx.gvec_phase_factor(gvec.gvec<sddk::index_domain_t::local>(igloc), ia) *
static_cast<double>(unit_cell.atom(ia).zn());
static_cast<double>(unit_cell.atom(ia).zn());
}

ewald_g += std::pow(std::abs(rho), 2) * std::exp(-g2 / 4 / alpha) / g2;
Expand Down Expand Up @@ -165,18 +165,13 @@ total_energy(Simulation_context const& ctx, K_point_set const& kset, Density con

case electronic_structure_method_t::pseudopotential: {
tot_en = (kset.valence_eval_sum() - energy_vxc(density, potential) - energy_bxc(density, potential) -
potential.PAW_one_elec_energy(density)) -
potential.PAW_one_elec_energy(density) - one_electron_energy_hubbard(density, potential)) -
0.5 * energy_vha(potential) + energy_exc(density, potential) + potential.PAW_total_energy() +
ewald_energy + kset.entropy_sum();
ewald_energy + kset.entropy_sum() + ::sirius::hubbard_energy(density);
break;
}
}

if (ctx.hubbard_correction()) {
tot_en += ::sirius::energy(density.occupation_matrix());
tot_en -= ::sirius::one_electron_energy_hubbard(density, potential);
}

return tot_en;
}

Expand Down Expand Up @@ -210,11 +205,8 @@ one_electron_energy_hubbard(Density const& density, Potential const& potential)
double
energy_potential(Density const& density, Potential const& potential)
{
double e =
energy_veff(density, potential) + energy_bxc(density, potential) + potential.PAW_one_elec_energy(density);
if (potential.ctx().hubbard_correction()) {
e += ::sirius::energy(density.occupation_matrix());
}
const double e = energy_veff(density, potential) + energy_bxc(density, potential) +
potential.PAW_one_elec_energy(density) + ::sirius::hubbard_energy(density);
return e;
}

Expand Down
50 changes: 25 additions & 25 deletions src/hubbard/hubbard_potential_energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ generate_potential_collinear_nonlocal(Simulation_context const& ctx__, const int
um__.zero();

double v_ij = nl.V() / ha2ev;
int il = nl.l()[0];
int jl = nl.l()[1];
int il = nl.l()[0];
int jl = nl.l()[1];
um__.zero();
// second term of Eq. 2
for (int is = 0; is < ctx__.num_spins(); is++) {
Expand Down Expand Up @@ -142,22 +142,14 @@ generate_potential_collinear_local(Simulation_context const& ctx__, Atom_type co
for (int m1 = 0; m1 < lmax_at; m1++) {

/* dc contribution */
um__(m1, m1, is) += hub_wf.J() * n_updown[is] +
0.5 * (hub_wf.U() - hub_wf.J()) - hub_wf.U() * n_total;
um__(m1, m1, is) += hub_wf.J() * n_updown[is] + 0.5 * (hub_wf.U() - hub_wf.J()) - hub_wf.U() * n_total;

// the u contributions
for (int m2 = 0; m2 < lmax_at; m2++) {
for (int m3 = 0; m3 < lmax_at; m3++) {
for (int m4 = 0; m4 < lmax_at; m4++) {

/* non-magnetic case */
if (ctx__.num_mag_dims() == 0) {
um__(m1, m2, is) += 2.0 * hub_wf.hubbard_matrix(m1, m3, m2, m4) * om__(m3, m4, is);
} else {
/* collinear case */
for (int is2 = 0; is2 < ctx__.num_spins(); is2++) {
um__(m1, m2, is) += hub_wf.hubbard_matrix(m1, m3, m2, m4) * om__(m3, m4, is2);
}
for (int is2 = 0; is2 < ctx__.num_spins(); is2++) {
um__(m1, m2, is) += hub_wf.hubbard_matrix(m1, m3, m2, m4) * om__(m3, m4, is2);
}

um__(m1, m2, is) -= hub_wf.hubbard_matrix(m1, m3, m4, m2) * om__(m3, m4, is);
Expand Down Expand Up @@ -188,6 +180,11 @@ calculate_energy_collinear_nonlocal(Simulation_context const& ctx__, const int i
}
}

// non magnetic case
if (ctx__.num_spins() == 1) {
hubbard_energy *= 2.0;
}

return -0.5 * hubbard_energy;
}

Expand Down Expand Up @@ -248,8 +245,7 @@ calculate_energy_collinear_local(Simulation_context const& ctx__, Atom_type cons
hubbard_energy += sign * hub_wf.beta() * om__(m1, m1, is).real();

for (int m2 = 0; m2 < lmax_at; m2++) {
hubbard_energy +=
0.5 * hub_wf.J0() * (om__(m2, m1, is) * om__(m1, m2, s_opposite)).real();
hubbard_energy += 0.5 * hub_wf.J0() * (om__(m2, m1, is) * om__(m1, m2, s_opposite)).real();
}
}
}
Expand Down Expand Up @@ -289,8 +285,8 @@ calculate_energy_collinear_local(Simulation_context const& ctx__, Atom_type cons
}

hubbard_energy_dc_contribution +=
0.5 * (hub_wf.U() * n_total * (n_total - 1.0) -
hub_wf.J() * n_total * (0.5 * n_total - 1.0) - hub_wf.J() * magnetization * 0.5);
0.5 * (hub_wf.U() * n_total * (n_total - 1.0) - hub_wf.J() * n_total * (0.5 * n_total - 1.0) -
hub_wf.J() * magnetization * 0.5);

/* now hubbard contribution */

Expand Down Expand Up @@ -617,20 +613,24 @@ one_electron_energy_hubbard(Hubbard_matrix const& om__, Hubbard_matrix const& pm

for (int i = 0; i < static_cast<int>(ctx.cfg().hubbard().nonlocal().size()); i++) {
auto nl = ctx.cfg().hubbard().nonlocal(i);
int il = nl.l()[0];
int jl = nl.l()[1];
int il = nl.l()[0];
int jl = nl.l()[1];

const auto &n1 = om__.nonlocal(i);
const auto &n2 = pm__.nonlocal(i);
const auto& n1 = om__.nonlocal(i);
const auto& n2 = pm__.nonlocal(i);

for (int is = 0; is < ctx.num_spins(); is++) {
for (int m2 = 0; m2 < 2 * jl + 1; m2++) {
for (int m1 = 0; m1 < 2 * il + 1; m1++) {
tmp += std::conj(n2(m1, m2, is)) * n1(m1, m2, is);
for (int m2 = 0; m2 < 2 * jl + 1; m2++) {
for (int m1 = 0; m1 < 2 * il + 1; m1++) {
tmp += std::conj(n2(m1, m2, is)) * n1(m1, m2, is);
}
}
}
}
}

if (ctx.num_spins() == 1) {
tmp *= 2.0;
}
return std::real(tmp);
}
return 0.0;
Expand Down
Loading