Developers Manual:Double Grid

From OctopusWiki
Jump to: navigation, search

Results

Test system: CO molecule

Default spacing: 0.35 [b]

Convergence of the energy with the spacing

Converged spacing (0.1 [eV]) double grid: 0.35 [b]

Converged spacing (0.1 [eV]) single grid: 0.32 [b]

Co dg conv energy.png

Convergence of the forces with the spacing

Co dg conv forces.png

Eggbox effect in energy

To get the eggbox effect the molecule is displaced and the energy and forces are calculated for each displacement. The energy and forces shown in the graphs are the energy for each displacement minus the average over all the displacements, so they oscilate around zero.

Co dg eggbox energy.png

Eggbox effect in force

Co dg eggbox force.png

Co dg eggbox force dp.png

Energy v/s interatomic distance

This is the calculation of energy in function of the interatomic distance for the CO molecule. The zero of energy is at the minimum. Co dg dist energy.png

Force v/s interatomic distance

Co dg dist force.png

Method 1 (by Miguel)

It works on the following way. Imagine that you have two functions defined in two different grids, and that you want to calculate the integral of their product:


I = \sum_i \psi(r_i) v(r_i) dV\,

where v(r_i)\,\! is known in the fine grid, and \psi(r_i)\,\! in the coarse grid. v(r_i)\,\! in this case is the pseudopotential (including the angular momentum functions for the non-local part). To obtain the values of \psi(r_i)\,\! in all points of the fine grid r_i\,\!, we can interpolate from the known points in the coarse grid r_j\,\!:


\psi(r_i) = \sum_j c_{ij} \psi(r_j)\,

The simplest thing is to take, e. g., a bilinear interpolation. Inserting this into I\,\!


I = \sum_i \sum_j c_{ij} \psi(r_j) v(r_i) dV\,

and changing the order of the sums:


I = \sum_j \psi(r_j) DV \bigg(\sum_i c_{ij} v(r_i)\bigg) dV/DV\,

where dV\,\! is the volume element of the fine grid, and DV\,\! the volume element of the coarse grid. We now define a \bar v(r_j) = \sum_i c_{ij} v(r_i) dV/DV\,\!, so that


I = \sum_j \psi(r_j) \bar v(r_j) DV\,

This is the maths. In practice you have to do (cartesian grid for simplicity):

  • Choose a 3D interpolation routine. Let's assume that it is bilinear interpolation.
  • To calculate \bar v(r_j)\,\!, generate a fine grid around r_j\,\!. Odd numbers are easier, so let's imagine that you triple the box (reduce the mesh spacing by a factor of 3). For example, in 2D:
O X  X O X  X O
X X  X X X  X X
    +-----+
X X |7 4 1| X X
O X |8 5 2| X O
X X |9 6 3| X X
    +-----+
X X  X X X  X X
O X  X O X  X O

The points O are the points in the coarse grid (the standard grid of Octopus), and X are the finer grid. We will only be interested in the points inside the square (the neighbours)

If the grid is uniform, the positions of the points in the fine grid r_i\,\! relative to r_j\,\! are constant, and can be calculated once and for all. In this case, e. g.


d_1 = (h/3, h/3)\,\!

d_2 = (h/3, 0)\,\!

d_3 = (h/3, -h/3)\,\!

d_4 = (0, h/3)\,\!

\,\quad\vdots\,\!

d_9 = (-h/3, -h/3)\,\!

Interpolate \psi(r_i)\,\! to get the values in each one of this points. For example, defining:

p_1 = \psi(r_j + (h, h))\,\!

p_2 = \psi(r_j + (h, 0))\,\!

p_3 = \psi(r_j + (h, -h))\,\!

p_4 = \psi(r_j + (0, h))\,\!

p_5 = \psi(r_j + (0, 0))\,\!

p_6 = \psi(r_j + (0, -h))\,\!

p_7 = \psi(r_j + (-h, h))\,\!

p_8 = \psi(r_j + (-h, 0))\,\!

p_9 = \psi(r_j + (-h, -h))\,\!

i.e., these are the values of \psi(r_j)\,\! in the coarse grid in the neighboring points of r_j\,\!. For the interpolation we get

\psi(r_j+d_1) = \frac{2}{3} \left(\frac{2}{3} p_5 + \frac{1}{3} p_2\right) + \frac{1}{3} \left(\frac{2}{3} p_4 + \frac{1}{3} p_1\right)\,\!

\psi(r_j+d_2) = \frac{2}{3} p_5 + \frac{1}{3} p_2\,\!

\psi(r_j+d_3) = \frac{2}{3} \left(\frac{2}{3} p_5 + \frac{1}{3} p_2\right) + \frac{1}{3} \left(\frac{2}{3} p_6 + \frac{1}{3} p_3\right)\,\!

\psi(r_j+d_4) = \frac{2}{3} p_5 + \frac{1}{3} p_4\,\!

\psi(r_j+d_5) = p_5\,\!

\psi(r_j+d_6) = \frac{2}{3} p_5 + \frac{1}{3} p_6\,\!

\psi(r_j+d_7) = \frac{2}{3} \left(\frac{2}{3} p_5 + \frac{1}{3} p_8\right) + \frac{1}{3} \left(\frac{2}{3} p_4 + \frac{1}{3} p_7\right)\,\!

\psi(r_j+d_8) = \frac{2}{3} p_5 + \frac{1}{3} p_8\,\!

\psi(r_j+d_9) = \frac{2}{3} \left(\frac{2}{3} p_5 + \frac{1}{3} p_8\right) + \frac{1}{3} \left(\frac{2}{3} p_6 + \frac{1}{3} p_9\right)\,\!

(this is much harder in 3D).

Now I collect all coefficients for p. The loop would look like

\bar v \leftarrow 0\,\!

\mathrm{for}\quad j \leftarrow 1, \ldots, N\quad\mathrm{do}

    r_1 \leftarrow r_j + (h, h)\,\!
    r_2 \leftarrow r_j + (h, 0)\,\!
    \vdots\,\!
    \bar v(r_1) \leftarrow \bar v(r_1) +  \frac{1}{3}\cdot\frac{1}{3} v(r_1)\,\!
    \bar v(r_2) \leftarrow \bar v(r_2) +  \frac{2}{3}\cdot\frac{1}{3} v(r_1) + \frac{1}{3} v(r_2) + \frac{2}{3}\cdot\frac{1}{3} v(r_3)\,\!
    \bar v(r_3) \leftarrow \bar v(r_3) +  \frac{1}{3}\cdot\frac{1}{3} v(r_3)\,\!
    \bar v(r_4) \leftarrow \bar v(r_4) +  \frac{1}{3}\cdot\frac{2}{3} v(r_1) + \frac{1}{3} v(r_4) + \frac{1}{3}\cdot\frac{2}{3} v(r_7)\,\!
    \bar v(r_5) \leftarrow \bar v(r_5) +  \frac{2}{3}\cdot\frac{2}{3} v(r_1) + \frac{2}{3} v(r_2) + \frac{2}{3}\cdot\frac{2}{3} v(r_3) + \frac{2}{3} v(r_4) + v(r_5) + \frac{2}{3} v(r_6) + \frac{2}{3}\cdot\frac{2}{3} v(r_7) + \frac{2}{3} v(r_8) + \frac{2}{3}\cdot\frac{2}{3} v(r_9)\,\!
    \bar v(r_6) \leftarrow \bar v(r_6) +  \frac{1}{3}\cdot\frac{2}{3} v(r_3) + \frac{1}{3} v(r_6) + \frac{1}{3}\cdot\frac{2}{3} v(r_9)\,\!
    \bar v(r_7) \leftarrow \bar v(r_7) +  \frac{1}{3}\cdot\frac{1}{3} v(r_7)\,\!
    \bar v(r_8) \leftarrow \bar v(r_8) +  \frac{1}{3}\cdot\frac{2}{3} v(r_7) + \frac{1}{3} v(r_8) + \frac{1}{3}\cdot\frac{2}{3} v(r_9)\,\!
    \bar v(r_9) \leftarrow \bar v(r_9) + \frac{1}{3}\cdot\frac{1}{3} v(r_9)\,\!

\mathrm{done}

\bar v \leftarrow \bar v \,\mathrm{d}V/\mathrm{D}V\,\!


I remember I managed to get general formulas for an order n interpolation. Probably it is best to stay with odd numbers, as for an even increase of the grid points (for example grid doubling), there will be some points in the fine grid that will be shared.

Method 2

Fine grid h/3\,\!, 1D.

Interpolation:


F_{3p+i}=\sum_{k=-n}^{n-1}C_kF_{3p+3i(k-1)},\  i=-1,0,1


\sum_{k=-n}^{n-1}C_k=1

Coefficients:


V_{3p+3i(k-1)}\,+=\,C_kV_{3p+i}\,

Coefficients 2:


\sum_jV_jF_j = \sum_{p}V_{3p}F_{3p}+\sum_{i=-1,\ i\neq0}^{i=1}V_{3p+i}F_{3p+i}\,


\sum_jV_jF_j = \sum_{p}V_{3p}F_{3p}+\sum_{i=-1,\ i\neq0}^{i=1}V_{3p+i}\sum_{k=n}^{n-1}C_kF_{3p+3i(k-1)}\,


\sum_jV_jF_j = \sum_{p}V_{3p}F_{3p}+\sum_{i=-1,\ i\neq0}^{i=1}\sum_{k=n}^{n-1}C_kV_{3p-i(3k+2)}F_{3p}\,


\sum_jV_jF_j = \sum_{p}F_{3p}\sum_{i=-1}^{i=1}\sum_{k=n}^{n-1}C_kV_{3p-i(3k+2)}\,



\sum_jV_jF_j = \sum_{p}F_{3p}W_{3p}\,


W_{3p}=\sum_{i=-1}^{i=1}\sum_{k=n}^{n-1}C_k V_{3p-i(3k+2)}\,