北京大学陈默涵课题组
飞书用户2166
ABACUS开发者文档
分享
Introduction to ABACUS: Path to PW calculation - Part 3
输入“/”快速插入内容
Introduction to ABACUS: Path to PW calculation - Part 3
作者:黄一珂,邮箱:
huangyk@aisi.ac.cn
审核:陈默涵,邮箱:
mohanchen@pku.edu.cn
📃
写在前面
1.
不脱离代码——避免读者看完手册后对代码没有一丁点概念
2.
不堆砌代码解释——避免平庸的代码解释,努力兼顾拉近读者和代码距离的同时,做到提纲挈领,不逐行复制代码后进行停留在代码语义上的解释
Driver
Driver::atomic_world()
Driver::driver_run()
多层
继承
:Init() functions in esolver class
Trigger: ESolver_FP::Init()
承接上篇中已经导入的结构信息,以及了解到构造函数及其伴随的变量初始化和ABACUS里应用到的
C++
多态编程,接下来即将(逐渐)步入ABACUS的核心内容。我们暂时跳过位于
source/driver_run.cpp:driver_run()
的:
代码块
C++
// 3. For these two types of calculations
// nothing else need to be initialized
if(GlobalV::CALCULATION == "test_neighbour" || GlobalV::CALCULATION == "test_memory")
{
p_esolver->Run(0, GlobalC::ucell);
ModuleBase::QUIT();
}
直接来到第44行,
ModuleESolver::ESolver::Init()
函数对
esolver
进行更多的设置:
代码块
C++
// driver_run.cpp: line 44
p_esolver->Init(INPUT, GlobalC::ucell);
然而查找该函数的定义和声明时,发现该函数在
module_esolver/esolver.h
被声明为纯虚函数,类似的还有
un()
,
cal_Energy()
,
cal_Force()
,
cal_Stress()
等。
代码块
C++
namespace ModuleESolver
{
class ESolver
{
public:
....
virtual void Init(Input& inp, UnitCell& cell) = 0;
virtual void Run(int istep, UnitCell& cell) = 0;
virtual void cal_Force(ModuleBase::matrix& force) = 0;
virtual void cal_Stress(ModuleBase::matrix& stress) = 0;
....
考虑到我们之前已经根据
basis_type
和
esolver_type
确定基类(
ESolver
)指针
p_esolver
所指向
内存
空间所存储变量为
ESolver_KS_PW<double, psi::DEVICE_CPU>
,因此我们首先只关注该纯虚函数在
esolver_ks_pw
的实例化。
查看
module_esolver/esolver_ks_pw.cpp
中该函数的定义:
代码块
C++
namespace ModuleESolver
{
....
template <typename FPTYPE, typename Device>
void ESolver_KS_PW<FPTYPE, Device>::Init(Input& inp, UnitCell& ucell)
{
ESolver_KS<FPTYPE, Device>::Init(inp, ucell);