Skip to content

Commit

Permalink
update path6-8
Browse files Browse the repository at this point in the history
  • Loading branch information
Chentao168 committed Oct 5, 2023
1 parent 88892df commit 175682f
Show file tree
Hide file tree
Showing 53 changed files with 164 additions and 153 deletions.
2 changes: 1 addition & 1 deletion _book/abacus-candela.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-contribute.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-dcu.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-dpgen.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-gcc.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-hcp.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-intel.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-libri.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-md.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-nac1.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-nac2.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-nac3.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-namd.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-news.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-ofdft.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-phonopy.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-sdft.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-shengbte.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-sol.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-surface1.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-surface2.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-surface5.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-surface6.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-upf.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/abacus-uspex.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-C++.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-dox.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-format.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-input.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-issue.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-path1.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-path2.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-path3.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions _book/develop-path4.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-path5.html

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions _book/develop-path6.html

Large diffs are not rendered by default.

55 changes: 30 additions & 25 deletions _book/develop-path7.html

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions _book/develop-path8.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/develop-sm1.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _book/index.html

Large diffs are not rendered by default.

Binary file added _book/picture/fig_path7-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _book/picture/fig_path7-flow2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added _book/picture/fig_path8-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion _book/search_plus_index.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion develop-path4.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void PW_Basis:: initparameters(

❗ 注意:这里还完成了倒空间格点数量 `fftnx`, `fftny``fftnz` 的赋值。因为 FFT 变换前后的格点数量一般相同,因此 `fftnx = nx``fftny = ny`,...。

![ ](picture/fig_path4-1.png)
![](picture/fig_path4-1.png)

然后对平面波在 MPI 进程间进行分发:

Expand Down
19 changes: 9 additions & 10 deletions develop-path6.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
我们来到 `ModuleESolver::ESolver_KS::Init()`,在 `source/module_esolver/esolver_ks.cpp: line105`[link](https://github.com/abacusmodeling/abacus-develop/blob/develop/source/module_esolver/esolver_ks.cpp#L105)):

```cpp
template<typename FPTYPE, typename Device>
template<typename FPTYPE, typename Device>
void ESolver_KS<FPTYPE, Device>::Init(Input& inp, UnitCell& ucell)
{
....
Expand Down Expand Up @@ -67,12 +67,12 @@ namespace ModuleESolver
ModulePW::PW_Basis_K_Big* tmp = static_cast<ModulePW::PW_Basis_K_Big*>(pw_wfc);
```

因此对 `pw_wfc` 中成员函数的调用,和 `pw_rho` 类似地,此处会调用到其派生类 `PW_Basis_K_Big` 的对象 `tmp` 的成员函数。另一方面在 [Introduction to ABACUS: Path to PW calculation - Part 4](https://ucoyxk075n.feishu.cn/docx/R2b5dB0jKoMLwGxJERDcYpfanUb),我们对 `PW_Basis_Big::initgrids()` 在形参表中不包含 `nx`, `ny``nz` 的重载情况进行了介绍。当时使用 `ecutrho`,生成了 `nx`, `ny`, `nz``bx``by``bz` 及其组合,以及倒空间 `fftnx`, `fftny``fftnz`,然后分别将格点进行了实空间和倒空间的分发,为切片和“棍子”为分配基本单元,在 processors 间进行分发。
因此对 `pw_wfc` 中成员函数的调用,和 `pw_rho` 类似地,此处会调用到其派生类 `PW_Basis_K_Big` 的对象 `tmp` 的成员函数。另一方面在 [Introduction to ABACUS: Path to PW calculation - Part 4](develop-path4.md),我们对 `PW_Basis_Big::initgrids()` 在形参表中不包含 `nx`, `ny``nz` 的重载情况进行了介绍。当时使用 `ecutrho`,生成了 `nx`, `ny`, `nz``bx``by``bz` 及其组合,以及倒空间 `fftnx`, `fftny``fftnz`,然后分别将格点进行了实空间和倒空间的分发,为切片和“棍子”为分配基本单元,在 processors 间进行分发。

此处继续沿用依靠 `Input::ecutrho` 生成的 `nx`, `ny``nz`,调用包含 `nx`, `ny``nz` 在形参表中的 `PW_Basis_K::initgrids()` 函数(和 `PW_Basis_Big` 类不同,`PW_Basis_K_Big` 类并未重载 `initgrids()`),

```cpp
template<typename FPTYPE, typename Device>
template<typename FPTYPE, typename Device>
void ESolver_KS<FPTYPE, Device>::Init(Input& inp, UnitCell& ucell)
{
....
Expand All @@ -89,7 +89,7 @@ template<typename FPTYPE, typename Device>
> 🤔<strong>思考时间</strong>
> 这样做的结果是什么?让 ecutwfc 等于 ecutrho 的操作正确吗?
![](picture/fig_path6-1.png)
![update cutoff value based on factorized nx, ny and nz](picture/fig_path6-1.png)
`nx`, `ny` 和 `nz` 实空间格点数量增多的原因?→ 回顾 `nx`, `ny` 和 `nz` 的生成方式:在给定 ecutwfc 球半径后(通过 `ecutrho`),在可以分辨每个倒空间中点的情况下所确定出的最小格点数量。之后在给定的 ecutwfc 球中分别寻找可能达到的最大的 `x`/`y`/`z` 格点数,作为 `nx`, `ny` 和 `nz`,然后进行(2, 3, 5)-factorization,此处从
Expand Down Expand Up @@ -373,7 +373,7 @@ public:
之后反向更新 `ESolver_KS::K_Vectors::ngk` 中值:
```cpp
template<typename FPTYPE, typename Device>
template<typename FPTYPE, typename Device>
void ESolver_KS<FPTYPE, Device>::Init(Input& inp, UnitCell& ucell)
{
....
Expand Down Expand Up @@ -433,7 +433,7 @@ void PW_Basis_K::collect_local_pw()
##### GlobalC::Parallel_Grid::init()

```cpp
template<typename FPTYPE, typename Device>
template<typename FPTYPE, typename Device>
void ESolver_KS<FPTYPE, Device>::Init(Input& inp, UnitCell& ucell)
{
....
Expand Down Expand Up @@ -584,9 +584,8 @@ $$
V(\mathbf{G})=\int{d\mathbf{r} e^{i\mathbf{G}\cdot\mathbf{r}}
\sum_{\mathbf{T}}{
\sum_{\alpha}^{N}{
\sum_{i}^{n^\alpha}{
V^{\alpha}(\mathbf{r}-\mathbf{\tau}_{\alpha i}-\mathbf{T})
}
\sum_{i}^{n^\alpha}
{V^{\alpha}(\mathbf{r}-\mathbf{\tau}_{\alpha i}-\mathbf{T})}
}
}
}
Expand Down Expand Up @@ -691,7 +690,7 @@ $$\text{eigts}_1[i]=e^{i\mathbf{G}_1[i]\cdot\mathbf{\tau}_i}$$。
##### 电荷外推初始化:Charge_Extra::Init_CE()

```cpp
template<typename FPTYPE, typename Device>
template<typename FPTYPE, typename Device>
void ESolver_KS<FPTYPE, Device>::Init(Input& inp, UnitCell& ucell)
{
....
Expand Down
51 changes: 28 additions & 23 deletions develop-path7.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
> 1. 不脱离代码——避免读者看完手册后对代码没有一丁点概念
> 2. 不堆砌代码解释——避免平庸的代码解释,努力兼顾拉近读者和代码距离的同时,做到提纲挈领,不逐行复制代码后进行停留在代码语义上的解释
# Driver
<strong>Driver</strong>

## Driver::atomic_world()
<strong>Driver::atomic_world()<strong>

### Driver::driver_run()
<strong>Driver::driver_run()<strong>

#### 多层继承:Init() functions in esolver class
# 多层继承:Init() functions in esolver class

终于来到和原本 `p_esolver` 相同的类的成员函数 `Init()`

Expand Down Expand Up @@ -54,9 +54,9 @@ void ESolver_KS_PW<FPTYPE, Device>::Init(Input& inp, UnitCell& ucell)
}
```

##### Initialization of HSolverPW object
## Initialization of HSolverPW object

###### Constructor
### Constructor

首先来到按照注释划分的第一部分“Initialize HSolver”(line 6,HSolver 就是求解体系哈密顿量的求解器):

Expand Down Expand Up @@ -106,9 +106,9 @@ HSolverPW<FPTYPE, Device>::HSolverPW(ModulePW::PW_Basis_K* wfc_basis_in, wavefun

,即将 `ESolver_KS::pw_wfc` 复制进 HSolverPW 的数据成员 `wfc_basis``ESolver_KS::wf``HSolverPW::pwf`

##### Initialization of ElecState object
## Initialization of ElecState object

###### Constructor
### Constructor

接下来来到 `ESolver_KS_PW::Init()`“第二部分”中 `ElecState` 类对象的初始化。

Expand Down Expand Up @@ -141,7 +141,9 @@ ElecStatePW<FPTYPE, Device>::ElecStatePW(ModulePW::PW_Basis_K *wfc_basis_in, Cha

在该构造函数的函数体外初始化了成员变量 `basis``ESolver_KS::pw_wfc`。除了设置 `ElecStatePW::classname` 这一数据成员的具体值外,调用 `ElecState::init_ks()` 函数(显然继承自基类)。

###### ElecState::init_ks()
![](picture/fig_path7-flow.png)

### ElecState::init_ks()

```cpp
void ElecState::init_ks(Charge* chg_in, // pointer for class Charge
Expand All @@ -167,7 +169,7 @@ void ElecState::init_ks(Charge* chg_in, // pointer for class Charge
}
```
####### Link Charge* ElecState::charge to Charge ESolver_FP::chg
#### Link Charge* ElecState::charge to Charge ESolver_FP::chg
⚠ 注意在 `ElecState`/`ElecStatePW` 类中的数据成员 `charge` 是 `Charge` 类指针,被赋值为 `ESolver_FP` 类的 `Charge` 类对象,即使得 `ElecState` 类的 `Charge` 类指针指向 `ESolver_FP` 的 `chr` 数据成员。
Expand Down Expand Up @@ -202,6 +204,7 @@ void Charge::set_rhopw(ModulePW::PW_Basis* rhopw_in)
this->rhopw = rhopw_in;
}
```
> 🤔在变量命名过程中应当注意避免随意
| context | 用于展开电荷的 PW_Basis 类指针 | 包含 Big FFT grid 的用于电荷展开的 PW_Basis_Big 类指针 |
| ----------------------- | ------------------------------ | ------------------------------------------------------ |
Expand All @@ -211,9 +214,9 @@ void Charge::set_rhopw(ModulePW::PW_Basis* rhopw_in)
| `ESolver_FP` 数据成员 | `pw_rho` | `pw_big` |
| `Charge` 数据成员 | `rhopw` | |

####### Calculate numbers of electrons in different spin channels
#### Calculate numbers of electrons in different spin channels

`ElecState::init_nelec_spin()` 函数的调用为 `this->nelec_spin` 赋值,其中 `GlobalV::nupdown` 的意义已经在([Introduction to ABACUS: Path to PW calculation - Part 2](https://ucoyxk075n.feishu.cn/docx/JruadAi9FoipBAxkxWaczZoxnwg#GtbCdmMyHoArL7xb3IZcgti4nHb) )介绍,为 up 和 down spin 的差值:
`ElecState::init_nelec_spin()` 函数的调用为 `this->nelec_spin` 赋值,其中 `GlobalV::nupdown` 的意义已经在([Introduction to ABACUS: Path to PW calculation - Part 2](develop-path2.md) )介绍,为 up 和 down spin 的差值:

```cpp
void ElecState::init_nelec_spin()
Expand All @@ -228,7 +231,7 @@ void ElecState::init_nelec_spin()
}
```

####### Get number of bands to solve: ElecState::cal_nbands()
#### Get number of bands to solve: ElecState::cal_nbands()

`ElecState::cal_nbands()` 函数的调用为 `GlobalV::NBANDS`(需要计算的能带数量)这一全局变量赋值或对通过 `INPUT` 文件中 `nbands` 关键词进行赋值的值进行合理性检查。对于未在 `INPUT` 文件中进行赋值的情况,则在此函数之前仍然保持值为 0,之后的赋值策略为:

Expand Down Expand Up @@ -282,7 +285,7 @@ void ElecState::cal_nbands()
> 🤔<strong>思考时间</strong>
> Is there any differences bewteen the ways to assign default values for number of bands to calculate in ABACUS and Quantum ESPRESSO?
回溯:`GlobalV::nelec` 的值从 `ESolver_KS::Init()` 调用时确定(具体调用 `UnitCell::cal_nelec()`,[Introduction to ABACUS: Path to PW calculation - Part 5](https://ucoyxk075n.feishu.cn/docx/RCLSd2Of5oughUxmVDZcBhmqnDe#Tjg1dV3biorDVfxdl4vcmHNlnHh))。
回溯:`GlobalV::nelec` 的值从 `ESolver_KS::Init()` 调用时确定(具体调用 `UnitCell::cal_nelec()`,[Introduction to ABACUS: Path to PW calculation - Part 5](develop-path5.md))。
```cpp
//module_base/global_variable.cpp
Expand Down Expand Up @@ -320,6 +323,8 @@ void ElecState::cal_nbands()
Occupy::decision(INPUT.occupations, INPUT.smearing_method, INPUT.smearing_sigma);
```

![](picture/fig_path7-flow2.png)

`Occupy::gauss()` 的功能仅仅为:

```cpp
Expand Down Expand Up @@ -357,10 +362,10 @@ void ElecState::cal_nbands()
}
```

###### Others
### Others

```cpp
this->pelec->charge->allocate(GlobalV::NSPIN);
this->pelec->charge->allocate(GlobalV::NSPIN);
this->pelec->omega = GlobalC::ucell.omega;
```
Expand Down Expand Up @@ -415,7 +420,7 @@ void Charge::allocate(const int& nspin_in)
}
```

##### Initialization of Potential
## Initialization of Potential

```cpp
template <typename FPTYPE, typename Device>
Expand Down Expand Up @@ -493,7 +498,7 @@ class Potential : public PotBase
![](picture/fig_path7-3.png)
##### Initialization of rest parts of GlobalC
## Initialization of rest parts of GlobalC
`GlobalC` 和 `GlobalV` 是两个特殊的类,如第一版开发者文档所提到,此两种类的收益为避免过大的形参表,但负向收益为带来对两类中全局变量意外覆盖读写的隐患,因此在 ABACUS 的未来版本中,会逐步弃用 `GlobalC` 和 `GlobalV`,转而使用对象:利用高度且合理的封装方式,每次传入对象,对象包含各自相关的数据成员和函数。但就当前而言,`GlobalC` 提供了一些全局类。此处剩余的一些全局类申请内存空间、被初始化。
Expand Down Expand Up @@ -532,7 +537,7 @@ void ESolver_KS_PW<FPTYPE, Device>::Init_GlobalC(Input& inp, UnitCell& cell)
> 这里有一个有趣的东西是 `kspw_psi`(在求力部分还有 `__kspw_psi`)。有兴趣的读者可以自行查看对于 gpu 或者单精度情况,在调用的 `psi` 构造函数中发生了什么。
> 实际上,`kspw_psi` 支持了异构计算,而 `psi`,如 esolver_fp.h 声明中,实际上只为 `psi::Psi<std::complex<double>, Device = psi::DEVICE_CPU>*` 类指针。因此真正计算架构-dependent 的是 `kspw_psi``ESolver_KS_PW` 为支持异构计算,整个类为模板类。在 psi 被分配内存空间后,为 `kspw_psi` 赋予了其数据的可达性(accessibility),`reinterpret_cast` 或者复制内容。
###### Psi
### Psi

`Psi` 是 ABACUS 中一类特殊的数据结构,用于存储波函数(平面波基函数系数)信息。其包含如下数据成员:

Expand Down Expand Up @@ -572,7 +577,7 @@ template <typename T, typename Device = DEVICE_CPU> class Psi
}
```

####### Codes
#### Codes

我们首先阅读为 `Psi` 申请内存空间的代码

Expand Down Expand Up @@ -704,7 +709,7 @@ struct resize_memory_op<FPTYPE, psi::DEVICE_CPU>

因此 `Psi` 类对象最终使用 `resize_memory_op()` 来为 `Psi::psi` 数据成员进行内存申请,用于存储波函数信息/其同样是 3d-flatten,即申请的实际上是一级指针,规模为 `[ikpoint][iband][ibasis]`

####### Feature: struct with overloaded "()", extends the way of defining functions
#### Feature: struct with overloaded "()", extends the way of defining functions

`Psi` 申请内存时使用了在之前介绍的 ABACUS 代码中从未出现过的方式,即创建模板类结构体,之后在其中重载括号运算符,以调用函数的方式使用重载的括号。这种方式为 C++ 结构体所独有,是固定特性,对原本的函数实现方式实现了更大范围的拓展,结合 `using` 关键字,可以达到模板类实例化、封装、多态等效果。

Expand Down Expand Up @@ -839,9 +844,9 @@ this->kspw_psi = GlobalV::device_flag == "gpu" || GlobalV::precision_flag == "si
this->kspw_psi = reinterpret_cast<psi::Psi<std::complex<double>>*>(this->psi);
```

###### pseudopot_cell_vnl
### pseudopot_cell_vnl

####### Before init()
#### Before init()

我们之前没有特别关注过这个被声明在 `GlobalC` 里的全局类([line 278](https://github.com/abacusmodeling/abacus-develop/blob/develop/source/module_hamilt_pw/hamilt_pwdft/global.h#L284)),这里我们首先非常粗略回顾其顾名思义的非局域项的原理,之后在下一篇中对该类成员函数的一些细节进行详细说明(但仍然不会逐行逐句进行“翻译”)。该类的名字 `pseudopot_cell_vnl` 实际上是 pseudopotential_cell_V(potential)_nonlocal 的缩写。首先简单介绍 Kleinman-Bylander 方法([Phys. Rev. Lett. ](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.48.1425)<strong>48</strong>[, 1425(1982)](https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.48.1425))将 pseudopotential 分为完全非局域和局域部分:

Expand Down
Loading

0 comments on commit 175682f

Please sign in to comment.