fermisurfer  2.0.0
fermisurfer
kumo.cpp
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 Copyright (c) 2014 Mitsuaki KAWAMURA
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 /**@file
25 @brief Compute @f$\varepsilon_{n k}, \Delta_{n k}@f$ on
26 denser @f$k@f$-grid with French-curve (Kumo) interpolation
27 */
28 #if defined(HAVE_CONFIG_H)
29 #include <config.h>
30 #endif
31 #if defined(HAVE_GL_GL_H)
32 #include <GL/gl.h>
33 #elif defined(HAVE_OPENGL_GL_H)
34 #include <OpenGL/gl.h>
35 #endif
36 #include <wx/wx.h>
37 #include <cstdlib>
38 #include <cstdio>
39 #include "basic_math.hpp"
40 #include "variable.hpp"
41 /**
42  @brief Compute coefficient for the French-curve (Kumo) interpolation
43  @f[
44  A^{\rm intp} = \sum_{i = 1}^4 C_i A_i^{\rm orig}
45  @f]
46 */
47 static void kumo_coef(
48  int j, //!< [in] Interpolated grid index
49  GLfloat *coef, //!< [out] Coefficient of interpolation @f$C_i@f$
50  int interpol
51 ) {
52  GLfloat x, mx;
53  x = (GLfloat)j / (GLfloat)interpol;
54  mx = 1.0f - x;
55  coef[0] = -0.5f * x * mx * mx;
56  coef[1] = mx * (mx*mx + 3.0f* x*mx + 0.5f* x* x);
57  coef[2] = x * ( x* x + 3.0f*mx* x + 0.5f*mx*mx);
58  coef[3] = -0.5f * x * x * mx;
59 }
60 /**
61  @brief Interpolation of energy and matrix
62  with the French-curve (Kumo) interpolation.
63 
64  Modify : ::eig, ::mat
65 */
67 {
68  int ib, i0, i1, i2, ii;
69 
70  *terminal << wxT(" Interpolating ... ");
71  /*
72  Reallocate
73  */
74  for (ib = 0; ib < nb; ib++) {
75  for (i0 = 0; i0 < ng[0]; i0++) {
76  for (i1 = 0; i1 < ng[1]; i1++) {
77  for (i2 = 0; i2 < ng[2]; i2++) {
78  delete[] vf[ib][i0][i1][i2];
79  delete[] mat[ib][i0][i1][i2];
80  }
81  delete[] eig[ib][i0][i1];
82  delete[] mat[ib][i0][i1];
83  delete[] vf[ib][i0][i1];
84  }/*for (i1 = 0; i1 < ng[1]; i1++)*/
85  delete[] eig[ib][i0];
86  delete[] mat[ib][i0];
87  delete[] vf[ib][i0];
88  }/*for (i0 = 0; i0 < ng[0]; i0++)*/
89  delete[] eig[ib];
90  delete[] mat[ib];
91  delete[] vf[ib];
92  }/*for (ib = 0; ib < nb; ib++)*/
93  for (ii = 0; ii < 3; ii++)ng[ii] = ng0[ii] * interpol;
94  /**/
95  for (ib = 0; ib < nb; ib++) {
96  eig[ib] = new GLfloat**[ng[0]];
97  mat[ib] = new GLfloat***[ng[0]];
98  vf[ib] = new GLfloat***[ng[0]];
99  for (i0 = 0; i0 < ng[0]; i0++) {
100  eig[ib][i0] = new GLfloat*[ng[1]];
101  mat[ib][i0] = new GLfloat**[ng[1]];
102  vf[ib][i0] = new GLfloat**[ng[1]];
103  for (i1 = 0; i1 < ng[1]; i1++) {
104  eig[ib][i0][i1] = new GLfloat[ng[2]];
105  mat[ib][i0][i1] = new GLfloat*[ng[2]];
106  vf[ib][i0][i1] = new GLfloat*[ng[2]];
107  for (i2 = 0; i2 < ng[2]; i2++) {
108  mat[ib][i0][i1][i2] = new GLfloat[3];
109  vf[ib][i0][i1][i2] = new GLfloat[3];
110  }
111  }/*for (i1 = 0; i1 < ng[1]; i1++)*/
112  }/*for (i0 = 0; i0 < ng[0]; i0++)*/
113  }/*for (ib = 0; ib < nb; ib++)*/
114  /*
115  3rd order - three dimensional Kumo interpolation
116  */
117 #pragma omp parallel default(none) \
118  shared(nb,ng0,ng,eig,eig0,mat,mat0,interpol) \
119  private (ib,i0,i1,i2,ii)
120  {
121  int j0, j1, j2, jj;
122  GLfloat coef[4],
123  mat1[4][4][4][3], mat2[4][4][3], mat3[4][3],
124  eig1[4][4][4], eig2[4][4], eig3[4];
125 
126  for (ib = 0; ib < nb; ib++) {
127 # pragma omp for nowait
128  for (i0 = 0; i0 < ng0[0]; i0++) {
129  //if (ith == 1) continue;
130  for (i1 = 0; i1 < ng0[1]; i1++) {
131  for (i2 = 0; i2 < ng0[2]; i2++) {
132  for (j0 = 0; j0 < 4; j0++) {
133  for (j1 = 0; j1 < 4; j1++) {
134  for (j2 = 0; j2 < 4; j2++) {
135  eig1[j0][j1][j2] = eig0[ib][modulo(i0 + j0 - 1, ng0[0])]
136  [modulo(i1 + j1 - 1, ng0[1])]
137  [modulo(i2 + j2 - 1, ng0[2])];
138  for (jj = 0; jj < 3; jj++) {
139  mat1[j0][j1][j2][jj] = mat0[ib][modulo(i0 + j0 - 1, ng0[0])]
140  [modulo(i1 + j1 - 1, ng0[1])]
141  [modulo(i2 + j2 - 1, ng0[2])][jj];
142  }
143  }/*for (j2 = 0; j2 < 4; j2++)*/
144  }/*for (j1 = 0; j1 < 4; j1++)*/
145  }/*for (i2 = 0; i2 < ng0[2]; i2++)*/
146  for (j0 = 0; j0 < interpol; j0++) {
147  kumo_coef(j0, &coef[0], interpol);
148  for (j1 = 0; j1 < 4; j1++) {
149  for (j2 = 0; j2 < 4; j2++) {
150  eig2[j1][j2] = 0.0;
151  for (jj = 0; jj < 3; jj++) mat2[j1][j2][jj] = 0.0;
152  for (ii = 0; ii < 4; ii++) {
153  eig2[j1][j2] += coef[ii] * eig1[ii][j1][j2];
154  for (jj = 0; jj < 3; jj++)
155  mat2[j1][j2][jj] += coef[ii] * mat1[ii][j1][j2][jj];
156  }/*for (ii = 0; ii < 4; ii++)*/
157  }/*for (j2 = 0; j2 < 4; j2++)*/
158  }/*for (j1 = 0; j1 < 4; j1++)*/
159  for (j1 = 0; j1 < interpol; j1++) {
160  kumo_coef(j1, &coef[0], interpol);
161  for (j2 = 0; j2 < 4; j2++) {
162  eig3[j2] = 0.0;
163  for (jj = 0; jj < 3; jj++) mat3[j2][jj] = 0.0;
164  for (ii = 0; ii < 4; ii++) {
165  eig3[j2] += coef[ii] * eig2[ii][j2];
166  for (jj = 0; jj < 3; jj++)
167  mat3[j2][jj] += coef[ii] * mat2[ii][j2][jj];
168  }/*for (ii = 0; ii < 4; ii++)*/
169  }/*for (j2 = 0; j2 < 4; j2++)*/
170  for (j2 = 0; j2 < interpol; j2++) {
171  kumo_coef(j2, &coef[0], interpol);
172  eig[ib][i0*interpol + j0]
173  [i1*interpol + j1]
174  [i2*interpol + j2] = 0.0;
175  for (jj = 0; jj < 3; jj++)
176  mat[ib][i0*interpol + j0]
177  [i1*interpol + j1]
178  [i2*interpol + j2][jj] = 0.0;
179  for (ii = 0; ii < 4; ii++) {
180  eig[ib][i0*interpol + j0]
181  [i1*interpol + j1]
182  [i2*interpol + j2] += coef[ii] * eig3[ii];
183  for (jj = 0; jj < 3; jj++)
184  mat[ib][i0*interpol + j0]
185  [i1*interpol + j1]
186  [i2*interpol + j2][jj] += coef[ii] * mat3[ii][jj];
187  }/*for (ii = 0; ii < 4; ii++)*/
188  }/*for (j2 = 0; j2 < interpol; j2++)*/
189  }/*for (j1 = 0; j1 < interpol; j1++)*/
190  }/*for (j0 = 0; j0 < interpol; j0++)*/
191  }/*for (i2 = 0; i2 < ng0[2]; i2++)*/
192  }/*for (i1 = 0; i1 < ng0[1]; i1++)*/
193  }/*for (i0 = 0; i0 < ng0[0]; i0++)*/
194  }/*for (ib = 0; ib < nb; ib++)*/
195  }/*End of parallel region*/
196  /*
197  Fermi velocity
198  */
199 #pragma omp parallel default(none) \
200  shared(nb,ng,eig,vf,avec) \
201  private (ib,i0,i1,i2,ii)
202  {
203  int i0p, i0m, i1p, i1m, i2p, i2m;
204  GLfloat de[3];
205 
206  for (ib = 0; ib < nb; ib++) {
207  for (i0 = 0; i0 < ng[0]; i0++) {
208  i0p = modulo(i0 + 1, ng[0]);
209  i0m = modulo(i0 - 1, ng[0]);
210  for (i1 = 0; i1 < ng[1]; i1++) {
211  i1p= modulo(i1 + 1, ng[1]);
212  i1m = modulo(i1 - 1, ng[1]);
213  for (i2 = 0; i2 < ng[2]; i2++) {
214  i2p = modulo(i2 + 1, ng[2]);
215  i2m = modulo(i2 - 1, ng[2]);
216 
217  de[0] = eig[ib][i0p][i1][i2] - eig[ib][i0m][i1][i2];
218  de[1] = eig[ib][i0][i1p][i2] - eig[ib][i0][i1m][i2];
219  de[2] = eig[ib][i0][i1][i2p] - eig[ib][i0][i1][i2m];
220  for (ii = 0; ii < 3; ii++)de[ii] *= 0.5f * (GLfloat)ng[ii];
221  for (ii = 0; ii < 3; ii++) vf[ib][i0][i1][i2][ii] =
222  avec[0][ii] * de[0] + avec[1][ii] * de[1] + avec[2][ii] * de[2];
223 
224  }/*for (i2 = 0; i2 < ng[2]; i2++)*/
225  }/*for (i1 = 0; i1 < ng[1]; i1++)*/
226  }/*for (i0 = 0; i0 < ng[0]; i0++)*/
227  }/*for (ib = 0; ib < nb; ib++)*/
228  }/*End of parallel region*/
229  *terminal << wxT("Done\n\n");
230 }/*void interpol_energy() */
interpol_energy
void interpol_energy()
Interpolation of energy and matrix with the French-curve (Kumo) interpolation.
Definition: kumo.cpp:66
eig0
GLfloat **** eig0
Eigenvalues [nb][ng0[0]][ng0[1]][ng0[2]].
Definition: fermisurfer.cpp:102
kumo_coef
static void kumo_coef(int j, GLfloat *coef, int interpol)
Compute coefficient for the French-curve (Kumo) interpolation.
Definition: kumo.cpp:47
mat0
GLfloat ***** mat0
Matrix element [nb][ng0[0]][ng0[1]][ng0[2]][3].
Definition: fermisurfer.cpp:103
interpol
int interpol
Ratio of interpolation.
Definition: fermisurfer.cpp:111
avec
GLfloat avec[3][3]
Direct lattice vector.
Definition: fermisurfer.cpp:100
basic_math.hpp
variable.hpp
Global variables.
modulo
int modulo(int i, int n)
Work as Modulo function of fortran.
Definition: basic_math.cpp:46
nb
int nb
The number of Bands.
Definition: fermisurfer.cpp:99
mat
GLfloat ***** mat
Matrix element [nb][ng[0]][ng[1]][ng[2]][3].
Definition: fermisurfer.cpp:109
eig
GLfloat **** eig
Eigenvalues [nb][ng[0]][ng[1]][ng[2]].
Definition: fermisurfer.cpp:108
vf
GLfloat ***** vf
Matrix element [nb][ng[0]][ng[1]][ng[2]][3].
Definition: fermisurfer.cpp:110
ng
int ng[3]
Interpolated -grids
Definition: fermisurfer.cpp:107
terminal
wxTextCtrl * terminal
Definition: fermisurfer.cpp:237
ng0
int ng0[3]
-point grid in the input file
Definition: fermisurfer.cpp:97