Skip to content
Open
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: 1 addition & 1 deletion source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ OBJS_ELECSTAT=elecstate.o\
efield.o\
gatefield.o\
potential_new.o\
potential_types.o\
potential_factory.o\
pot_sep.o\
pot_local.o\
H_Hartree_pw.o\
Expand Down
10 changes: 2 additions & 8 deletions source/source_esolver/esolver_double_xc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//-----HSolver ElecState Hamilt--------
#include "source_estate/elecstate_lcao.h"
#include "source_estate/elecstate_tools.h"
#include "source_estate/module_pot/potential_new.h"
#include "source_lcao/hamilt_lcao.h"
#include "source_hsolver/hsolver_lcao.h"
#include "source_io/module_parameter/parameter.h"
Expand Down Expand Up @@ -95,14 +96,7 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(UnitCell& ucell, const Input_p
// 11) initialize the potential
if (this->pelec_base->pot == nullptr)
{
this->pelec_base->pot = new elecstate::Potential(this->pw_rhod,
this->pw_rho,
&ucell,
&(this->locpp.vloc),
&(this->sf),
&(this->solvent),
&(this->pelec_base->f_en.etxc),
&(this->pelec_base->f_en.vtxc));
this->pelec_base->pot = new elecstate::Potential(this->pw_rhod, this->pw_rho, &ucell);
}

ModuleBase::timer::end("ESolver_DoubleXC", "before_all_runners");
Expand Down
28 changes: 16 additions & 12 deletions source/source_esolver/esolver_of_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "source_estate/module_pot/gatefield.h"
#include "source_io/module_parameter/parameter.h"
#include "source_estate/cal_ux.h"
#include "source_estate/module_pot/potential_new.h"
#include "source_estate/module_pot/potential_factory.h"

namespace ModuleESolver
{
Expand All @@ -22,15 +24,8 @@ void ESolver_OF::init_elecstate(UnitCell& ucell)
}

delete this->pelec->pot;
this->pelec->pot = new elecstate::Potential(this->pw_rhod,
this->pw_rho,
&ucell,
&(this->locpp.vloc),
&(this->sf),
&(this->solvent),
&(this->pelec->f_en.etxc),
&(this->pelec->f_en.vtxc));
// There is no Operator in ESolver_OF, register Potentials here!
this->pelec->pot = new elecstate::Potential(this->pw_rhod, this->pw_rho, &ucell);

std::vector<std::string> pot_register_in;
if (PARAM.inp.vion_in_h)
{
Expand Down Expand Up @@ -58,11 +53,20 @@ void ESolver_OF::init_elecstate(UnitCell& ucell)
{
pot_register_in.push_back("ml_exx");
}
// only Potential is not empty, Veff and Meta are available

if (pot_register_in.size() > 0)
{
// register Potential by gathered operator
this->pelec->pot->pot_register(pot_register_in);
elecstate::PotentialFactory factory(&this->locpp.vloc,
&this->sf,
this->pw_rhod,
&(this->pelec->f_en.etxc),
&(this->pelec->f_en.vtxc),
this->pelec->pot->get_eff_vofk(),
&this->solvent,
nullptr,
&ucell);
auto components = factory.create_components(pot_register_in);
this->pelec->pot->set_components(std::move(components));
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/source_estate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ list(APPEND objects
module_pot/pot_xc.cpp
module_pot/pot_local.cpp
module_pot/potential_new.cpp
module_pot/potential_types.cpp
module_pot/potential_factory.cpp
module_pot/pot_ml_exx.cpp
module_pot/pot_ml_exx_label.cpp
module_pot/pot_sep.cpp
Expand Down
4 changes: 2 additions & 2 deletions source/source_estate/module_pot/pot_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class PotLocal : public PotBase
PotLocal(const ModuleBase::matrix* vloc_in, // local pseduopotentials
const ModuleBase::ComplexMatrix* sf_in,
const ModulePW::PW_Basis* rho_basis_in,
double& vl_of_0)
: vloc_(vloc_in), sf_(sf_in), vl_of_0_(&vl_of_0)
double* vl_of_0_ptr)
: vloc_(vloc_in), sf_(sf_in), vl_of_0_(vl_of_0_ptr)
{
assert(this->vloc_->nr == this->sf_->nr);
this->rho_basis_ = rho_basis_in;
Expand Down
165 changes: 165 additions & 0 deletions source/source_estate/module_pot/potential_factory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#include "potential_factory.h"
#include "H_Hartree_pw.h"
#include "efield.h"
#include "gatefield.h"
#include "pot_local.h"
#include "pot_surchem.hpp"
#include "pot_xc.h"
#include "pot_sep.h"
#include "source_base/global_function.h"
#include "source_base/global_variable.h"
#include "source_base/tool_quit.h"
#include "source_io/module_parameter/parameter.h"
#ifdef __LCAO
#include "H_TDDFT_pw.h"
#endif
#ifdef __MLALGO
#include "pot_ml_exx.h"
#endif

namespace elecstate
{

PotentialFactory::PotentialFactory(const ModuleBase::matrix* vloc_in,
Structure_Factor* structure_factors_in,
const ModulePW::PW_Basis* rho_basis_in,
double* etxc_in,
double* vtxc_in,
ModuleBase::matrix& vofk_eff_out,
surchem* solvent_in,
VSep* vsep_cell_in,
const UnitCell* ucell_in)
: vloc_(vloc_in),
structure_factors_(structure_factors_in),
rho_basis_(rho_basis_in),
etxc_(etxc_in),
vtxc_(vtxc_in),
vofk_eff_(vofk_eff_out),
solvent_(solvent_in),
vsep_cell_(vsep_cell_in),
ucell_(ucell_in)
{
}

std::vector<PotBase*> PotentialFactory::create_components(const std::vector<std::string>& components_list)
{
ModuleBase::TITLE("PotentialFactory", "create_components");
std::vector<PotBase*> components;

for (const auto& pot_type : components_list)
{
PotBase* tmp = nullptr;
if (pot_type == "local")
{
tmp = create_pot_local();
}
else if (pot_type == "hartree")
{
tmp = create_pot_hartree();
}
else if (pot_type == "xc")
{
tmp = create_pot_xc();
}
else if (pot_type == "surchem")
{
tmp = create_pot_surchem();
}
else if (pot_type == "efield")
{
tmp = create_pot_efield();
}
else if (pot_type == "gatefield")
{
tmp = create_pot_gatefield();
}
#ifdef __LCAO
else if (pot_type == "tddft")
{
tmp = create_pot_tddft();
}
#endif
#ifdef __MLALGO
else if (pot_type == "ml_exx")
{
tmp = create_pot_ml_exx();
}
#endif
else if (pot_type == "dfthalf")
{
tmp = create_pot_dfthalf();
}
else
{
ModuleBase::WARNING_QUIT("PotentialFactory::create_components",
"Unknown potential type: " + pot_type);
}

if (tmp != nullptr)
{
components.push_back(tmp);
}
}

return components;
}

PotBase* PotentialFactory::create_pot_local()
{
return new PotLocal(this->vloc_,
&(this->structure_factors_->strucFac),
this->rho_basis_,
nullptr);
}

PotBase* PotentialFactory::create_pot_hartree()
{
return new PotHartree(this->rho_basis_);
}

PotBase* PotentialFactory::create_pot_xc()
{
return new PotXC(this->rho_basis_, this->etxc_, this->vtxc_, &(this->vofk_eff_));
}

PotBase* PotentialFactory::create_pot_surchem()
{
return new PotSurChem(this->rho_basis_,
this->structure_factors_,
nullptr,
this->solvent_);
}

PotBase* PotentialFactory::create_pot_efield()
{
return new PotEfield(this->rho_basis_,
this->ucell_,
this->solvent_,
PARAM.inp.dip_cor_flag);
}

PotBase* PotentialFactory::create_pot_gatefield()
{
return new PotGate(this->rho_basis_, this->ucell_);
}

#ifdef __LCAO
PotBase* PotentialFactory::create_pot_tddft()
{
return new H_TDDFT_pw(this->rho_basis_, this->ucell_);
}
#endif

#ifdef __MLALGO
PotBase* PotentialFactory::create_pot_ml_exx()
{
return new PotML_EXX(this->rho_basis_, this->ucell_);
}
#endif

PotBase* PotentialFactory::create_pot_dfthalf()
{
return new PotSep(&(this->structure_factors_->strucFac), this->rho_basis_, this->vsep_cell_);
}

} // namespace elecstate
59 changes: 59 additions & 0 deletions source/source_estate/module_pot/potential_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef POTENTIAL_FACTORY_H
#define POTENTIAL_FACTORY_H

#include <string>
#include <vector>
#include "pot_base.h"
#include "source_pw/module_pwdft/structure_factor.h"

class UnitCell;
class surchem;
class VSep;

namespace elecstate
{

class PotentialFactory
{
public:
PotentialFactory(const ModuleBase::matrix* vloc_in,
Structure_Factor* structure_factors_in,
const ModulePW::PW_Basis* rho_basis_in,
double* etxc_in,
double* vtxc_in,
ModuleBase::matrix& vofk_eff_out,
surchem* solvent_in,
VSep* vsep_cell_in,
const UnitCell* ucell_in);

std::vector<PotBase*> create_components(const std::vector<std::string>& components_list);

private:
PotBase* create_pot_local();
PotBase* create_pot_hartree();
PotBase* create_pot_xc();
PotBase* create_pot_surchem();
PotBase* create_pot_efield();
PotBase* create_pot_gatefield();
#ifdef __LCAO
PotBase* create_pot_tddft();
#endif
#ifdef __MLALGO
PotBase* create_pot_ml_exx();
#endif
PotBase* create_pot_dfthalf();

const ModuleBase::matrix* vloc_ = nullptr;
Structure_Factor* structure_factors_ = nullptr;
const ModulePW::PW_Basis* rho_basis_ = nullptr;
double* etxc_ = nullptr;
double* vtxc_ = nullptr;
ModuleBase::matrix& vofk_eff_;
surchem* solvent_ = nullptr;
VSep* vsep_cell_ = nullptr;
const UnitCell* ucell_ = nullptr;
};

} // namespace elecstate

#endif
Loading
Loading