fermisurfer  2.0.0
fermisurfer
fermi_patch.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 Functions for computing patch of Fermi surface
26 */
27 #if defined(HAVE_CONFIG_H)
28 #include <config.h>
29 #endif
30 #if defined(HAVE_GL_GL_H)
31 #include <GL/gl.h>
32 #elif defined(HAVE_OPENGL_GL_H)
33 #include <OpenGL/gl.h>
34 #endif
35 #include <wx/wx.h>
36 #include <vector>
37 #include <cstdlib>
38 #include <cstdio>
39 #include <cmath>
40 #include "basic_math.hpp"
41 #include "variable.hpp"
42 /**
43  @brief Store triangle patch
44 
45  Modify : ::matp, ::kvp
46 
47  For the 1st BZ mode, this routine cuts triangle recursivly at the
48  BZ boundary (Bragg plane).
49 
50  - DO @f${\bf l}@f$ in Bragg vector
51  - @f${p_i = {\bf l}\cdot{\bf k}}@f$
52  - Sort : @f$p_0<p_1<p_2@f$
53  - @f[
54  a_{i j} \equiv \frac{-p_j}{p_i - p_j}
55  @f]
56  - if (@f$|{\bf l}| < p_0@f$)
57  - This patch is not in the 1st BZ
58  - if (@f$p_0 < |{\bf l}| < p_1@f$)
59  - @f${\bf k}'_0 = {\bf k}_0@f$
60  - @f${\bf k}'_1 = {\bf k}_0 a_{0 1} + {\bf k}_1 a_{1 0}@f$
61  - @f${\bf k}'_2 = {\bf k}_0 a_{0 2} + {\bf k}_2 a_{2 0}@f$
62  - if (@f$p_1 < |{\bf l}| < p_2@f$)
63  - @f${\bf k}'_0 = {\bf k}_0@f$
64  - @f${\bf k}'_1 = {\bf k}_1@f$
65  - @f${\bf k}'_2 = {\bf k}_0 a_{0 2} + {\bf k}_2 a_{2 0}@f$
66  - and
67  - @f${\bf k}'_0 = {\bf k}_1 a_{1 2} + {\bf k}_2 a_{2 1}@f$
68  - @f${\bf k}'_1 = {\bf k}_1@f$
69  - @f${\bf k}'_2 = {\bf k}_0 a_{0 2} + {\bf k}_2 a_{2 0}@f$
70  - if (@f$p_2 < |{\bf l}| < p_3@f$)
71  - @f${\bf k}'_0 = {\bf k}_0@f$
72  - @f${\bf k}'_1 = {\bf k}_1@f$
73  - @f${\bf k}'_2 = {\bf k}_2@f$
74  - END DO
75 */
76 static void triangle(
77  int nbr, //!<[in] Bragg plane
78  GLfloat mat1[3][3], //!<[in] The matrix element
79  GLfloat kvec1[3][3], //!<[in] @f$k@f$-vector of corners
80  GLfloat vf1[3][3], //!<[in] @f$v_f@f$-vector of corners
81  std::vector<std::vector<std::vector<GLfloat> > > &kvp_v,
82  std::vector<std::vector<std::vector<GLfloat> > > &matp_v,
83  std::vector<std::vector<std::vector<GLfloat> > > &nmlp_v
84  )
85 {
86  int ibr, i, j, sw[3];
87  GLfloat prod[3], thr, thr2 = 0.001f, mat2[3][3], kvec2[3][3],
88  vf2[3][3], a[3][3], bshift, vfave[3], norm[3];
89  std::vector<std::vector<GLfloat> > kvp_0, matp_0, nmlp_0;
90 
91  kvp_0.resize(3);
92  matp_0.resize(3);
93  nmlp_0.resize(3);
94  for (i = 0; i < 3; i++) {
95  kvp_0.at(i).resize(3);
96  matp_0.at(i).resize(3);
97  nmlp_0.at(i).resize(3);
98  }
99  /*
100  If the area is nearly 0, it is ignored.
101  */
102  for (i = 0; i < 3; i++)norm[i] = 0.0f;
103  for (i = 0; i < 3; i++) {
104  norm[0] += (kvec1[1][i] - kvec1[2][i])*(kvec1[1][i] - kvec1[2][i]);
105  norm[1] += (kvec1[2][i] - kvec1[0][i])*(kvec1[2][i] - kvec1[0][i]);
106  norm[2] += (kvec1[0][i] - kvec1[1][i])*(kvec1[0][i] - kvec1[1][i]);
107  }
108  for (i = 0; i < 3; i++) {
109  if (norm[i] < 1.0e-10f*brnrm_min) return;
110  }
111  /*
112  For 1st BZ, it is cut at the BZ boundary.
113  */
114  if (fbz == 1) {
115  /**/
116  for (ibr = 0; ibr < nbragg; ++ibr) {
117 
118  thr = brnrm[ibr] * 0.001f;
119  /**/
120  for (i = 0; i < 3; ++i)
121  prod[i] = bragg[ibr][0] * kvec1[i][0]
122  + bragg[ibr][1] * kvec1[i][1]
123  + bragg[ibr][2] * kvec1[i][2];
124  eigsort(3, prod, sw);
125  for (i = 0; i < 3; ++i) {
126  for (j = 0; j < 3; ++j) {
127  a[i][j] = (brnrm[ibr] - prod[sw[j]]) / (prod[sw[i]] - prod[sw[j]]);
128  }/*for (j = 0; j < 3; ++j)*/
129  }/*for (i = 0; i < 3; ++i)*/
130  i = (int)(0.5f * ((prod[sw[2]] / brnrm[ibr]) + 1.0f));
131  bshift = -2.0f *(GLfloat)i;
132 
133  if (brnrm[ibr] + thr > prod[sw[2]]) continue;
134 
135  if (brnrm[ibr] < prod[sw[0]]) {
136  /*
137  All corners are outside of the Bragg plane
138  */
139  for (i = 0; i < 3; ++i) {
140  for (j = 0; j < 3; ++j) {
141  kvec2[i][j] = kvec1[sw[i]][j] + bshift * bragg[ibr][j];
142  mat2[i][j] = mat1[sw[i]][j];
143  vf2[i][j] = vf1[sw[i]][j];
144  }
145  }
146  triangle(ibr + 1, mat2, kvec2, vf2, kvp_v, matp_v, nmlp_v);
147  return;
148  }
149  else if (brnrm[ibr] < prod[sw[1]]) {
150  /*
151  Single corner (#0) is inside of the Bragg plane
152  */
153  for (i = 0; i < 3; ++i) {
154  kvec2[0][i] = kvec1[sw[0]][i];
155  kvec2[1][i] = kvec1[sw[0]][i] * a[0][1] + kvec1[sw[1]][i] * a[1][0];
156  kvec2[2][i] = kvec1[sw[0]][i] * a[0][2] + kvec1[sw[2]][i] * a[2][0];
157 
158  mat2[0][i] = mat1[sw[0]][i];
159  mat2[1][i] = mat1[sw[0]][i] * a[0][1] + mat1[sw[1]][i] * a[1][0];
160  mat2[2][i] = mat1[sw[0]][i] * a[0][2] + mat1[sw[2]][i] * a[2][0];
161 
162  vf2[0][i] = vf1[sw[0]][i];
163  vf2[1][i] = vf1[sw[0]][i] * a[0][1] + vf1[sw[1]][i] * a[1][0];
164  vf2[2][i] = vf1[sw[0]][i] * a[0][2] + vf1[sw[2]][i] * a[2][0];
165  }/*for (i = 0; i < 3; ++i)*/
166  triangle(ibr + 1, mat2, kvec2, vf2, kvp_v, matp_v, nmlp_v);
167 
168  for (i = 0; i < 3; ++i) {
169  kvec2[0][i] = kvec1[sw[0]][i] * a[0][1] + kvec1[sw[1]][i] * a[1][0];
170  kvec2[1][i] = kvec1[sw[1]][i];
171  kvec2[2][i] = kvec1[sw[0]][i] * a[0][2] + kvec1[sw[2]][i] * a[2][0];
172 
173  mat2[0][i] = mat1[sw[0]][i] * a[0][1] + mat1[sw[1]][i] * a[1][0];
174  mat2[1][i] = mat1[sw[1]][i];
175  mat2[2][i] = mat1[sw[0]][i] * a[0][2] + mat1[sw[2]][i] * a[2][0];
176 
177  vf2[0][i] = vf1[sw[0]][i] * a[0][1] + vf1[sw[1]][i] * a[1][0];
178  vf2[1][i] = vf1[sw[1]][i];
179  vf2[2][i] = vf1[sw[0]][i] * a[0][2] + vf1[sw[2]][i] * a[2][0];
180  }/*for (i = 0; i < 3; ++i)*/
181  for (i = 0; i < 3; ++i) for (j = 0; j < 3; ++j)
182  kvec2[i][j] += bshift * bragg[ibr][j];
183  triangle(ibr + 1, mat2, kvec2, vf2, kvp_v, matp_v, nmlp_v);
184 
185  for (i = 0; i < 3; ++i) {
186  kvec2[0][i] = kvec1[sw[2]][i];
187  kvec2[1][i] = kvec1[sw[1]][i];
188  kvec2[2][i] = kvec1[sw[0]][i] * a[0][2] + kvec1[sw[2]][i] * a[2][0];
189 
190  mat2[0][i] = mat1[sw[2]][i];
191  mat2[1][i] = mat1[sw[1]][i];
192  mat2[2][i] = mat1[sw[0]][i] * a[0][2] + mat1[sw[2]][i] * a[2][0];
193 
194  vf2[0][i] = vf1[sw[2]][i];
195  vf2[1][i] = vf1[sw[1]][i];
196  vf2[2][i] = vf1[sw[0]][i] * a[0][2] + vf1[sw[2]][i] * a[2][0];
197  }/*for (i = 0; i < 3; ++i)*/
198  for (i = 0; i < 3; ++i) for (j = 0; j < 3; ++j)
199  kvec2[i][j] += bshift * bragg[ibr][j];
200  triangle(ibr + 1, mat2, kvec2, vf2, kvp_v, matp_v, nmlp_v);
201  return;
202  }
203  else if (brnrm[ibr] < prod[sw[2]]) {
204  /*
205  Two corners (#0, #1) are inside of the Bragg plane
206  */
207  for (i = 0; i < 3; ++i) {
208  kvec2[0][i] = kvec1[sw[0]][i] * a[0][2] + kvec1[sw[2]][i] * a[2][0];
209  kvec2[1][i] = kvec1[sw[1]][i] * a[1][2] + kvec1[sw[2]][i] * a[2][1];
210  kvec2[2][i] = kvec1[sw[2]][i];
211 
212  mat2[0][i] = mat1[sw[0]][i] * a[0][2] + mat1[sw[2]][i] * a[2][0];
213  mat2[1][i] = mat1[sw[1]][i] * a[1][2] + mat1[sw[2]][i] * a[2][1];
214  mat2[2][i] = mat1[sw[2]][i];
215 
216  vf2[0][i] = vf1[sw[0]][i] * a[0][2] + vf1[sw[2]][i] * a[2][0];
217  vf2[1][i] = vf1[sw[1]][i] * a[1][2] + vf1[sw[2]][i] * a[2][1];
218  vf2[2][i] = vf1[sw[2]][i];
219  }/*for (i = 0; i < 3; ++i)*/
220  for (i = 0; i < 3; ++i) for (j = 0; j < 3; ++j)
221  kvec2[i][j] += bshift * bragg[ibr][j];
222  triangle(ibr + 1, mat2, kvec2, vf2, kvp_v, matp_v, nmlp_v);
223 
224  for (i = 0; i < 3; ++i) {
225  kvec2[0][i] = kvec1[sw[0]][i];
226  kvec2[1][i] = kvec1[sw[1]][i];
227  kvec2[2][i] = kvec1[sw[0]][i] * a[0][2] + kvec1[sw[2]][i] * a[2][0];
228 
229  mat2[0][i] = mat1[sw[0]][i];
230  mat2[1][i] = mat1[sw[1]][i];
231  mat2[2][i] = mat1[sw[0]][i] * a[0][2] + mat1[sw[2]][i] * a[2][0];
232 
233  vf2[0][i] = vf1[sw[0]][i];
234  vf2[1][i] = vf1[sw[1]][i];
235  vf2[2][i] = vf1[sw[0]][i] * a[0][2] + vf1[sw[2]][i] * a[2][0];
236  }/*for (i = 0; i < 3; ++i)*/
237  triangle(ibr + 1, mat2, kvec2, vf2, kvp_v, matp_v, nmlp_v);
238 
239  for (i = 0; i < 3; ++i) {
240  kvec2[0][i] = kvec1[sw[1]][i] * a[1][2] + kvec1[sw[2]][i] * a[2][1];
241  kvec2[1][i] = kvec1[sw[1]][i];
242  kvec2[2][i] = kvec1[sw[0]][i] * a[0][2] + kvec1[sw[2]][i] * a[2][0];
243 
244  mat2[0][i] = mat1[sw[1]][i] * a[1][2] + mat1[sw[2]][i] * a[2][1];
245  mat2[1][i] = mat1[sw[1]][i];
246  mat2[2][i] = mat1[sw[0]][i] * a[0][2] + mat1[sw[2]][i] * a[2][0];
247 
248  vf2[0][i] = vf1[sw[1]][i] * a[1][2] + vf1[sw[2]][i] * a[2][1];
249  vf2[1][i] = vf1[sw[1]][i];
250  vf2[2][i] = vf1[sw[0]][i] * a[0][2] + vf1[sw[2]][i] * a[2][0];
251  }/*for (i = 0; i < 3; ++i)*/
252  triangle(ibr + 1, mat2, kvec2, vf2, kvp_v, matp_v, nmlp_v);
253  return;
254  }
255  else {
256  /*
257  All corners are inside of the Bragg plane
258  */
259  } /* brnrm[ibr] + thr < prod */
260  } /* for ibr = 1; ibr < nbragg*/
261  } /* if fbz == 1 */
262  /*
263  Store patch
264  */
265  normal_vec(kvec1[0], kvec1[1], kvec1[2], norm);
266  for (i = 0; i < 3; ++i) {
267  vfave[i] = 0.0f;
268  for (j = 0; j < 3; ++j) vfave[i] += vf1[j][i];
269  }
270  prod[0] = 0.0f;
271  for (i = 0; i < 3; ++i) prod[0] += vfave[i] * norm[i];
272 
273  if (prod[0] < 0.0f) {
274  for (i = 0; i < 3; ++i) {
275  for (j = 0; j < 3; ++j) {
276  kvp_0.at(i).at(j) = kvec1[2 - i][j];
277  matp_0.at(i).at(j) = mat1[2 - i][j];
278  nmlp_0.at(i).at(j) = vf1[2 - i][j];
279  }
280  }/*for (i = 0; i < 3; ++i)*/
281  }
282  else {
283  for (i = 0; i < 3; ++i) {
284  for (j = 0; j < 3; ++j) {
285  kvp_0.at(i).at(j) = kvec1[i][j];
286  matp_0.at(i).at(j) = mat1[i][j];
287  nmlp_0.at(i).at(j) = vf1[i][j];
288  }
289  }/*for (i = 0; i < 3; ++i)*/
290  }
291  kvp_v.push_back(kvp_0);
292  matp_v.push_back(matp_0);
293  nmlp_v.push_back(nmlp_0);
294 }/* triangle */
295 /**
296 @brief Cut triangle patch with the tetrahedron method.
297 
298  - Sort : @f$\varepsilon_0<\varepsilon_1<\varepsilon_2<\varepsilon_3@f$
299  - @f[
300  a_{i j} \equiv \frac{-\varepsilon_j}{\varepsilon_i - \varepsilon_j}
301  @f]
302  - if (@f$\varepsilon_0 < 0 < \varepsilon_1@f$)
303  - @f${\bf k}'_0 = {\bf k}_0 a_{0 1} + {\bf k}_1 a_{1 0}@f$
304  - @f${\bf k}'_1 = {\bf k}_0 a_{0 2} + {\bf k}_2 a_{2 0}@f$
305  - @f${\bf k}'_2 = {\bf k}_0 a_{0 3} + {\bf k}_3 a_{3 0}@f$
306  - if (@f$\varepsilon_1 < 0 < \varepsilon_2@f$)
307  - @f${\bf k}'_0 = {\bf k}_0 a_{0 2} + {\bf k}_2 a_{2 0}@f$
308  - @f${\bf k}'_1 = {\bf k}_0 a_{0 3} + {\bf k}_3 a_{3 0}@f$
309  - @f${\bf k}'_2 = {\bf k}_1 a_{1 2} + {\bf k}_2 a_{2 1}@f$
310  - and
311  - @f${\bf k}'_0 = {\bf k}_1 a_{1 3} + {\bf k}_3 a_{3 1}@f$
312  - @f${\bf k}'_1 = {\bf k}_0 a_{0 3} + {\bf k}_3 a_{3 0}@f$
313  - @f${\bf k}'_2 = {\bf k}_1 a_{1 2} + {\bf k}_2 a_{2 1}@f$
314  - if (@f$\varepsilon_2 < 0 < \varepsilon_3@f$)
315  - @f${\bf k}'_0 = {\bf k}_3 a_{3 0} + {\bf k}_0 a_{0 3}@f$
316  - @f${\bf k}'_1 = {\bf k}_3 a_{3 1} + {\bf k}_1 a_{1 3}@f$
317  - @f${\bf k}'_2 = {\bf k}_3 a_{3 2} + {\bf k}_2 a_{2 3}@f$
318 */
319 static void tetrahedron(
320  GLfloat eig1[8], //!< [in] Orbital energies @f$\varepsilon_{n k}@f$
321  GLfloat mat1[8][3], //!< [in] Matrix elements @f$\Delta_{n k}@f$
322  GLfloat kvec1[8][3], //!< [in] @f$k@f$-vectors
323  GLfloat vf1[8][3], //!< [in] @f$v_f@f$-vectors
324  std::vector<std::vector<std::vector<GLfloat> > > &kvp_v,
325  std::vector<std::vector<std::vector<GLfloat> > > &matp_v,
326  std::vector<std::vector<std::vector<GLfloat> > > &nmlp_v
327 )
328 {
329  int it, i, j, sw[4];
330  GLfloat eig2[4], mat2[4][3], kvec2[4][3], vf2[4][3], a[4][4],
331  kvec3[3][3], mat3[3][3], vf3[3][3], vol, thr = 0.000f;
332 
333  for (it = 0; it < 6; ++it) {
334  /*
335  Define corners of the tetrahedron
336  */
337  for (i = 0; i < 4; ++i) {
338  eig2[i] = eig1[corner[it][i]];
339  for (j = 0; j < 3; ++j) {
340  mat2[i][j] = mat1[corner[it][i]][j];
341  vf2[i][j] = vf1[corner[it][i]][j];
342  }
343  /*
344  Fractional -> Cartecian
345  */
346  for (j = 0; j < 3; ++j)
347  kvec2[i][j] = bvec[0][j] * kvec1[corner[it][i]][0]
348  + bvec[1][j] * kvec1[corner[it][i]][1]
349  + bvec[2][j] * kvec1[corner[it][i]][2];
350  }/*for (i = 0; i < 4; ++i)*/
351  eigsort(4, eig2, sw);
352 
353  for (i = 0; i < 4; ++i) {
354  for (j = 0; j < 4; ++j) {
355  a[i][j] = (0.0f - eig2[sw[j]]) / (eig2[sw[i]] - eig2[sw[j]]);
356  }/*for (j = 0; j < 4; ++j)*/
357  }/*for (i = 0; i < 4; ++i)*/
358  /*
359  Draw triangle in each cases
360  */
361  if (eig2[sw[0]] <= 0.0 && 0.0 < eig2[sw[1]]) {
362  for (i = 0; i < 3; ++i) {
363  kvec3[0][i] = kvec2[sw[0]][i] * a[0][1] + kvec2[sw[1]][i] * a[1][0];
364  kvec3[1][i] = kvec2[sw[0]][i] * a[0][2] + kvec2[sw[2]][i] * a[2][0];
365  kvec3[2][i] = kvec2[sw[0]][i] * a[0][3] + kvec2[sw[3]][i] * a[3][0];
366 
367  mat3[0][i] = mat2[sw[0]][i] * a[0][1] + mat2[sw[1]][i] * a[1][0];
368  mat3[1][i] = mat2[sw[0]][i] * a[0][2] + mat2[sw[2]][i] * a[2][0];
369  mat3[2][i] = mat2[sw[0]][i] * a[0][3] + mat2[sw[3]][i] * a[3][0];
370 
371  vf3[0][i] = vf2[sw[0]][i] * a[0][1] + vf2[sw[1]][i] * a[1][0];
372  vf3[1][i] = vf2[sw[0]][i] * a[0][2] + vf2[sw[2]][i] * a[2][0];
373  vf3[2][i] = vf2[sw[0]][i] * a[0][3] + vf2[sw[3]][i] * a[3][0];
374  }
375 
376  vol = a[1][0] * a[2][0] * a[3][0];
377  triangle(0, mat3, kvec3, vf3, kvp_v, matp_v, nmlp_v);
378  }
379  else if (eig2[sw[1]] <= 0.0 && 0.0 < eig2[sw[2]]) {
380  for (i = 0; i < 3; ++i) {
381  kvec3[0][i] = kvec2[sw[0]][i] * a[0][2] + kvec2[sw[2]][i] * a[2][0];
382  kvec3[1][i] = kvec2[sw[0]][i] * a[0][3] + kvec2[sw[3]][i] * a[3][0];
383  kvec3[2][i] = kvec2[sw[1]][i] * a[1][2] + kvec2[sw[2]][i] * a[2][1];
384 
385  mat3[0][i] = mat2[sw[0]][i] * a[0][2] + mat2[sw[2]][i] * a[2][0];
386  mat3[1][i] = mat2[sw[0]][i] * a[0][3] + mat2[sw[3]][i] * a[3][0];
387  mat3[2][i] = mat2[sw[1]][i] * a[1][2] + mat2[sw[2]][i] * a[2][1];
388 
389  vf3[0][i] = vf2[sw[0]][i] * a[0][2] + vf2[sw[2]][i] * a[2][0];
390  vf3[1][i] = vf2[sw[0]][i] * a[0][3] + vf2[sw[3]][i] * a[3][0];
391  vf3[2][i] = vf2[sw[1]][i] * a[1][2] + vf2[sw[2]][i] * a[2][1];
392  }
393 
394  vol = a[1][2] * a[2][0] * a[3][0];
395  triangle(0, mat3, kvec3, vf3, kvp_v, matp_v, nmlp_v);
396  /**/
397  for (i = 0; i < 3; ++i) {
398  kvec3[0][i] = kvec2[sw[1]][i] * a[1][3] + kvec2[sw[3]][i] * a[3][1];
399  kvec3[1][i] = kvec2[sw[0]][i] * a[0][3] + kvec2[sw[3]][i] * a[3][0];
400  kvec3[2][i] = kvec2[sw[1]][i] * a[1][2] + kvec2[sw[2]][i] * a[2][1];
401 
402  mat3[0][i] = mat2[sw[1]][i] * a[1][3] + mat2[sw[3]][i] * a[3][1];
403  mat3[1][i] = mat2[sw[0]][i] * a[0][3] + mat2[sw[3]][i] * a[3][0];
404  mat3[2][i] = mat2[sw[1]][i] * a[1][2] + mat2[sw[2]][i] * a[2][1];
405 
406  vf3[0][i] = vf2[sw[1]][i] * a[1][3] + vf2[sw[3]][i] * a[3][1];
407  vf3[1][i] = vf2[sw[0]][i] * a[0][3] + vf2[sw[3]][i] * a[3][0];
408  vf3[2][i] = vf2[sw[1]][i] * a[1][2] + vf2[sw[2]][i] * a[2][1];
409  }
410 
411  vol = a[1][3] * a[3][0] * a[2][1];
412  triangle(0, mat3, kvec3, vf3, kvp_v, matp_v, nmlp_v);
413  }
414  else if (eig2[sw[2]] <= 0.0 && 0.0 < eig2[sw[3]]) {
415  for (i = 0; i < 3; ++i) {
416  kvec3[0][i] = kvec2[sw[3]][i] * a[3][0] + kvec2[sw[0]][i] * a[0][3];
417  kvec3[1][i] = kvec2[sw[3]][i] * a[3][1] + kvec2[sw[1]][i] * a[1][3];
418  kvec3[2][i] = kvec2[sw[3]][i] * a[3][2] + kvec2[sw[2]][i] * a[2][3];
419 
420  mat3[0][i] = mat2[sw[3]][i] * a[3][0] + mat2[sw[0]][i] * a[0][3];
421  mat3[1][i] = mat2[sw[3]][i] * a[3][1] + mat2[sw[1]][i] * a[1][3];
422  mat3[2][i] = mat2[sw[3]][i] * a[3][2] + mat2[sw[2]][i] * a[2][3];
423 
424  vf3[0][i] = vf2[sw[3]][i] * a[3][0] + vf2[sw[0]][i] * a[0][3];
425  vf3[1][i] = vf2[sw[3]][i] * a[3][1] + vf2[sw[1]][i] * a[1][3];
426  vf3[2][i] = vf2[sw[3]][i] * a[3][2] + vf2[sw[2]][i] * a[2][3];
427  }
428 
429  vol = a[0][3] * a[1][3] * a[2][3];
430  triangle(0, mat3, kvec3, vf3, kvp_v, matp_v, nmlp_v);
431  }
432  else {
433  }
434  }/*for (it = 0; it < 6; ++it)*/
435 }/* tetrahedron */
436 /**
437  @brief Compute patches for Fermi surfaces
438 
439  Modify : ::ntri, nmlp, ::matp, ::kvp, ::clr, ::nmlp_rot, ::kvp_rot
440 */
441 void fermi_patch()
442 {
443  int ntri0, ib, i0, i1, j0, start[3], last[3];
444  int ithread;
445  std::vector < std::vector<std::vector<std::vector<GLfloat> > > > kvp_v, matp_v, nmlp_v;
446 
447  kvp_v.resize(nthreads);
448  matp_v.resize(nthreads);
449  nmlp_v.resize(nthreads);
450  /**/
451  if (fbz == 1) {
452  *terminal << wxT("\n");
453  *terminal << wxT(" ## First Brillouin zone mode #######\n");
454  for (i0 = 0; i0 < 3; ++i0) {
455  start[i0] = ng[i0] / 2 - ng[i0];
456  last[i0] = ng[i0] / 2;
457  }
458  }
459  else {
460  *terminal << wxT("\n");
461  *terminal << wxT(" ## Premitive Brillouin zone mode #######\n");
462  for (i0 = 0; i0 < 3; ++i0) {
463  start[i0] = 0;
464  last[i0] = ng[i0];
465  }
466  }
467  *terminal << wxT(" Computing patch ...\n");
468  *terminal << wxT(" band # of patchs\n");
469  /**/
470  for (ib = 0; ib < nb; ++ib) {
471 
472 #pragma omp parallel default(none) \
473 shared(nb,start,last,ng,ng0,eig,vf,EF,mat,shiftk,kvp_v,matp_v,nmlp_v, \
474 corner, bvec, fbz, nbragg, bragg, brnrm, brnrm_min,ib) \
475 private(j0,i0,i1,ithread)
476  {
477  int i, j, i2, j1, j2, ii0, ii1, ii2;
478  GLfloat kvec1[8][3], mat1[8][3], eig1[8], vf1[8][3];
479 
480  ithread = get_thread();
481  kvp_v.at(ithread).resize(0);
482  matp_v.at(ithread).resize(0);
483  nmlp_v.at(ithread).resize(0);
484 
485 #pragma omp for nowait schedule(static, 1)
486  for (j0 = start[0]; j0 < last[0]; ++j0) {
487  for (j1 = start[1]; j1 < last[1]; ++j1) {
488  for (j2 = start[2]; j2 < last[2]; ++j2) {
489  /**/
490  i0 = j0;
491  i1 = j1;
492  i2 = j2;
493  ii0 = j0 + 1;
494  ii1 = j1 + 1;
495  ii2 = j2 + 1;
496  /**/
497  kvec1[0][0] = (GLfloat)i0 / (GLfloat)ng[0];
498  kvec1[1][0] = (GLfloat)i0 / (GLfloat)ng[0];
499  kvec1[2][0] = (GLfloat)i0 / (GLfloat)ng[0];
500  kvec1[3][0] = (GLfloat)i0 / (GLfloat)ng[0];
501  kvec1[4][0] = (GLfloat)ii0 / (GLfloat)ng[0];
502  kvec1[5][0] = (GLfloat)ii0 / (GLfloat)ng[0];
503  kvec1[6][0] = (GLfloat)ii0 / (GLfloat)ng[0];
504  kvec1[7][0] = (GLfloat)ii0 / (GLfloat)ng[0];
505  /**/
506  kvec1[0][1] = (GLfloat)i1 / (GLfloat)ng[1];
507  kvec1[1][1] = (GLfloat)i1 / (GLfloat)ng[1];
508  kvec1[2][1] = (GLfloat)ii1 / (GLfloat)ng[1];
509  kvec1[3][1] = (GLfloat)ii1 / (GLfloat)ng[1];
510  kvec1[4][1] = (GLfloat)i1 / (GLfloat)ng[1];
511  kvec1[5][1] = (GLfloat)i1 / (GLfloat)ng[1];
512  kvec1[6][1] = (GLfloat)ii1 / (GLfloat)ng[1];
513  kvec1[7][1] = (GLfloat)ii1 / (GLfloat)ng[1];
514  /**/
515  kvec1[0][2] = (GLfloat)i2 / (GLfloat)ng[2];
516  kvec1[1][2] = (GLfloat)ii2 / (GLfloat)ng[2];
517  kvec1[2][2] = (GLfloat)i2 / (GLfloat)ng[2];
518  kvec1[3][2] = (GLfloat)ii2 / (GLfloat)ng[2];
519  kvec1[4][2] = (GLfloat)i2 / (GLfloat)ng[2];
520  kvec1[5][2] = (GLfloat)ii2 / (GLfloat)ng[2];
521  kvec1[6][2] = (GLfloat)i2 / (GLfloat)ng[2];
522  kvec1[7][2] = (GLfloat)ii2 / (GLfloat)ng[2];
523  /**/
524  for (i = 0; i < 8; i++)
525  for (j = 0; j < 3; j++)
526  kvec1[i][j] = kvec1[i][j] + (GLfloat)shiftk[j] / (GLfloat)(2 * ng0[j]);
527  /**/
528  i0 = modulo(i0, ng[0]);
529  i1 = modulo(i1, ng[1]);
530  i2 = modulo(i2, ng[2]);
531  ii0 = modulo(ii0, ng[0]);
532  ii1 = modulo(ii1, ng[1]);
533  ii2 = modulo(ii2, ng[2]);
534  /**/
535  eig1[0] = eig[ib][i0][i1][i2] - EF;
536  eig1[1] = eig[ib][i0][i1][ii2] - EF;
537  eig1[2] = eig[ib][i0][ii1][i2] - EF;
538  eig1[3] = eig[ib][i0][ii1][ii2] - EF;
539  eig1[4] = eig[ib][ii0][i1][i2] - EF;
540  eig1[5] = eig[ib][ii0][i1][ii2] - EF;
541  eig1[6] = eig[ib][ii0][ii1][i2] - EF;
542  eig1[7] = eig[ib][ii0][ii1][ii2] - EF;
543  /**/
544  for (j = 0; j < 3; j++) {
545  mat1[0][j] = mat[ib][i0][i1][i2][j];
546  mat1[1][j] = mat[ib][i0][i1][ii2][j];
547  mat1[2][j] = mat[ib][i0][ii1][i2][j];
548  mat1[3][j] = mat[ib][i0][ii1][ii2][j];
549  mat1[4][j] = mat[ib][ii0][i1][i2][j];
550  mat1[5][j] = mat[ib][ii0][i1][ii2][j];
551  mat1[6][j] = mat[ib][ii0][ii1][i2][j];
552  mat1[7][j] = mat[ib][ii0][ii1][ii2][j];
553  /**/
554  vf1[0][j] = vf[ib][i0][i1][i2][j];
555  vf1[1][j] = vf[ib][i0][i1][ii2][j];
556  vf1[2][j] = vf[ib][i0][ii1][i2][j];
557  vf1[3][j] = vf[ib][i0][ii1][ii2][j];
558  vf1[4][j] = vf[ib][ii0][i1][i2][j];
559  vf1[5][j] = vf[ib][ii0][i1][ii2][j];
560  vf1[6][j] = vf[ib][ii0][ii1][i2][j];
561  vf1[7][j] = vf[ib][ii0][ii1][ii2][j];
562  }/*for (j = 0; j < 3; j++)*/
563  /**/
564  tetrahedron(eig1, mat1, kvec1, vf1,
565  kvp_v.at(ithread), matp_v.at(ithread), nmlp_v.at(ithread));
566  }/*for (j0 = start[0]; j0 < ng[0]; ++j0)*/
567  }/*for (j1 = start[1]; j1 < ng[1]; ++j1)*/
568  }/*for (j0 = start[0]; j0 < ng[0]; ++j0)*/
569  } /* End of parallel region */
570  /*
571  Sum patches in all threads
572  */
573  ntri[ib] = 0;
574  for (ithread = 0; ithread < nthreads; ithread++)
575  ntri[ib] += kvp_v.at(ithread).size();
576  *terminal << wxString::Format(wxT(" %d %d\n"), ib + 1, ntri[ib]);
577  /*
578  Allocation of triangler patches
579  */
580  matp[ib] = new GLfloat * *[ntri[ib]];
581  clr[ib] = new GLfloat[12 * ntri[ib]];
582  kvp[ib] = new GLfloat * *[ntri[ib]];
583  nmlp[ib] = new GLfloat * *[ntri[ib]];
584  arw[ib] = new GLfloat * **[ntri[ib]];
585  kvp_rot[ib] = new GLfloat[9 * ntri[ib]];
586  nmlp_rot[ib] = new GLfloat[9 * ntri[ib]];
587  arw_rot[ib] = new GLfloat[18 * ntri[ib]];
588  for (i0 = 0; i0 < ntri[ib]; ++i0) {
589  matp[ib][i0] = new GLfloat * [3];
590  kvp[ib][i0] = new GLfloat * [3];
591  nmlp[ib][i0] = new GLfloat * [3];
592  arw[ib][i0] = new GLfloat * *[3];
593  for (i1 = 0; i1 < 3; ++i1) {
594  matp[ib][i0][i1] = new GLfloat[3];
595  kvp[ib][i0][i1] = new GLfloat[3];
596  nmlp[ib][i0][i1] = new GLfloat[3];
597  arw[ib][i0][i1] = new GLfloat * [2];
598  for (j0 = 0; j0 < 2; ++j0)
599  arw[ib][i0][i1][j0] = new GLfloat[3];
600  }/*for (i1 = 0; i1 < 3; ++i1)*/
601  }/*for (i0 = 0; i0 < ntri[ib]; ++i0)*/
602  /*
603  Input
604  */
605  ntri0 = 0;
606  for (ithread = 0; ithread < nthreads; ithread++) {
607  for (i0 = 0; i0 < kvp_v.at(ithread).size(); ++i0) {
608  for (i1 = 0; i1 < 3; ++i1) {
609  for (j0 = 0; j0 < 3; ++j0){
610  kvp[ib][ntri0][i1][j0] = kvp_v.at(ithread).at(i0).at(i1).at(j0);
611  matp[ib][ntri0][i1][j0] = matp_v.at(ithread).at(i0).at(i1).at(j0);
612  nmlp[ib][ntri0][i1][j0] = nmlp_v.at(ithread).at(i0).at(i1).at(j0);
613  }
614  }
615  ntri0 += 1;
616  }
617  }
618  }/*for (ib = 0; ib < nb; ++ib)*/
619  *terminal << wxT(" ... Done\n");
620 } /* fermi_patch */
kvp
GLfloat **** kvp
-vectors of points [nb][ntri][3][3]
Definition: fermisurfer.cpp:140
get_thread
int get_thread()
OpenMP wrapper, get the number of threads.
Definition: basic_math.cpp:139
ntri
int * ntri
The number of triangle patch [nb].
Definition: fermisurfer.cpp:136
eigsort
void eigsort(int n, GLfloat *key, int *swap)
Simple sort.
Definition: basic_math.cpp:88
EF
GLfloat EF
Fermi energy.
Definition: fermisurfer.cpp:218
normal_vec
void normal_vec(GLfloat in1[3], GLfloat in2[3], GLfloat in3[3], GLfloat out[3])
Calculate normal vector from corners of triangle.
Definition: basic_math.cpp:114
basic_math.hpp
arw_rot
GLfloat ** arw_rot
Definition: fermisurfer.cpp:144
nmlp
GLfloat **** nmlp
Normal vector of patchs [nb][ntri][3][3].
Definition: fermisurfer.cpp:139
variable.hpp
Global variables.
kvp_rot
GLfloat ** kvp_rot
-vectors of points [nb][ntri*3*3]
Definition: fermisurfer.cpp:143
bragg
GLfloat bragg[26][3]
Bragg plane vectors.
Definition: fermisurfer.cpp:129
clr
GLfloat ** clr
Colors of points [nb][ntri*3*4].
Definition: fermisurfer.cpp:146
arw
GLfloat ***** arw
Definition: fermisurfer.cpp:141
fbz
int fbz
Switch for 1st Brillouin zone mode.
Definition: fermisurfer.cpp:116
fermi_patch
void fermi_patch()
nmlp_rot
GLfloat ** nmlp_rot
Normal vector of patchs [nb][ntri*3*3].
Definition: fermisurfer.cpp:142
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
brnrm_min
GLfloat brnrm_min
Minimum scale of the reciplocal space.
Definition: fermisurfer.cpp:131
matp
GLfloat **** matp
Matrix elements of points [nb][ntri][3][3].
Definition: fermisurfer.cpp:145
corner
int corner[6][4]
Corners of tetrahedron.
Definition: fermisurfer.cpp:217
eig
GLfloat **** eig
Eigenvalues [nb][ng[0]][ng[1]][ng[2]].
Definition: fermisurfer.cpp:108
bvec
GLfloat bvec[3][3]
Reciprocal lattice vector.
Definition: fermisurfer.cpp:101
vf
GLfloat ***** vf
Matrix element [nb][ng[0]][ng[1]][ng[2]][3].
Definition: fermisurfer.cpp:110
brnrm
GLfloat brnrm[26]
Norms of Bragg plane vectors.
Definition: fermisurfer.cpp:130
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
nthreads
int nthreads
Number of OpenMP threads.
Definition: fermisurfer.cpp:227
nbragg
int nbragg
Number of Bragg plane og 1st BZ.
Definition: fermisurfer.cpp:132
shiftk
int shiftk[3]
Wherether -grid is shifted or not.
Definition: fermisurfer.cpp:98