Skip to content
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
8 changes: 6 additions & 2 deletions source/module_ri/Exx_LRI_interface.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#ifndef EXX_LRI_INTERFACE_H
#define EXX_LRI_INTERFACE_H

#include "Exx_LRI.h"
#include "module_ri/Mix_DMk_2D.h"
#include <memory>
Expand Down Expand Up @@ -55,4 +57,6 @@ class Exx_LRI_Interface
int two_level_step = 0;
};

#include "Exx_LRI_interface.hpp"
#include "Exx_LRI_interface.hpp"

#endif
61 changes: 37 additions & 24 deletions source/module_ri/Exx_LRI_interface.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#ifndef EXX_LRI_INTERFACE_HPP
#define EXX_LRI_INTERFACE_HPP

#include "Exx_LRI_interface.h"
#include "module_ri/exx_abfs-jle.h"
#include "module_ri/exx_opt_orb.h"
#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h"
#include "module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.h"

#include <sys/time.h>

template<typename T, typename Tdata>
void Exx_LRI_Interface<T, Tdata>::write_Hexxs(const std::string& file_name) const
{
Expand Down Expand Up @@ -32,13 +37,9 @@ void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const K_Vectors& kv, const Charg
if ( GlobalC::exx_info.info_global.cal_exx )
{
if (GlobalC::ucell.atoms[0].ncpp.xc_func == "HF" || GlobalC::ucell.atoms[0].ncpp.xc_func == "PBE0" || GlobalC::ucell.atoms[0].ncpp.xc_func == "HSE")
{
XC_Functional::set_xc_type("pbe");
}
else if (GlobalC::ucell.atoms[0].ncpp.xc_func == "SCAN0")
{
XC_Functional::set_xc_type("scan");
}

this->exx_ptr->cal_exx_ions();
}
Expand All @@ -57,13 +58,9 @@ void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const K_Vectors& kv, const Charg
{
this->mix_DMk_2D.set_nks(kv.nks, GlobalV::GAMMA_ONLY_LOCAL);
if(GlobalC::exx_info.info_global.separate_loop)
{
this->mix_DMk_2D.set_mixing(nullptr);
}
else
{
this->mix_DMk_2D.set_mixing(chgmix.mixing);
}
}
// for exx two_level scf
this->two_level_step = 0;
Expand Down Expand Up @@ -139,25 +136,28 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
}
else
{
hamilt::Operator<std::complex<double>>* exx;
if(GlobalV::NSPIN < 4)
{
hamilt::HamiltLCAO<std::complex<double>, double>* hamilt_lcao =
dynamic_cast<hamilt::HamiltLCAO<std::complex<double>, double>*>(&hamilt);
exx = new hamilt::OperatorEXX<hamilt::OperatorLCAO<std::complex<double>, double>>(&lm,
hamilt_lcao->getHR(),
&(hamilt_lcao->getHk(&lm)),
kv);
hamilt::HamiltLCAO<std::complex<double>, double>* hamilt_lcao
= dynamic_cast<hamilt::HamiltLCAO<std::complex<double>, double>*>(&hamilt);
hamilt::Operator<std::complex<double>>* exx
= new hamilt::OperatorEXX<hamilt::OperatorLCAO<std::complex<double>, double>>(
&lm,
hamilt_lcao->getHR(),
&(hamilt_lcao->getHk(&lm)),
kv);
hamilt_lcao->getOperator()->add(exx);
}
else
{
hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>* hamilt_lcao =
dynamic_cast<hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>*>(&hamilt);
exx = new hamilt::OperatorEXX<hamilt::OperatorLCAO<std::complex<double>, std::complex<double>>>(&lm,
hamilt_lcao->getHR(),
&(hamilt_lcao->getHk(&lm)),
kv);
hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>* hamilt_lcao
= dynamic_cast<hamilt::HamiltLCAO<std::complex<double>, std::complex<double>>*>(&hamilt);
hamilt::Operator<std::complex<double>>* exx
= new hamilt::OperatorEXX<hamilt::OperatorLCAO<std::complex<double>, std::complex<double>>>(
&lm,
hamilt_lcao->getHR(),
&(hamilt_lcao->getHk(&lm)),
kv);
hamilt_lcao->getOperator()->add(exx);
}
}
Expand Down Expand Up @@ -207,6 +207,9 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
XC_Functional::set_xc_type(GlobalC::ucell.atoms[0].ncpp.xc_func);
}

std::cout << " Updating EXX " << std::flush;
timeval t_start; gettimeofday(&t_start, NULL);

const bool flag_restart = (this->two_level_step == 0) ? true : false;
this->mix_DMk_2D.mix(dm.get_DMK_vector(), flag_restart);

Expand All @@ -217,10 +220,20 @@ bool Exx_LRI_Interface<T, Tdata>::exx_after_converge(
: RI_2D_Comm::split_m2D_ktoR<Tdata>(*this->exx_ptr->p_kv, this->mix_DMk_2D.get_DMk_k_out(), *dm.get_paraV_pointer());
this->exx_ptr->cal_exx_elec(Ds, *dm.get_paraV_pointer());
iter = 0;
std::cout << " Updating EXX and rerun SCF" << std::endl;
this->two_level_step++;

timeval t_end; gettimeofday(&t_end, NULL);
std::cout << "and rerun SCF\t"
<< std::setprecision(3) << std::setiosflags(std::ios::scientific)
<< (double)(t_end.tv_sec-t_start.tv_sec) + (double)(t_end.tv_usec-t_start.tv_usec)/1000000.0
<< std::defaultfloat << " (s)" << std::endl;
return false;
}
}
return true;
}
else
{
return true;
}
}

#endif