fermisurfer  2.0.0
fermisurfer
bz_lines.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 lines of BZ boundary
26 */
27 #include "basic_math.hpp"
28 #include "variable.hpp"
29 #include <wx/wx.h>
30 #if defined(HAVE_CONFIG_H)
31 #include <config.h>
32 #endif
33 #if defined(HAVE_GL_GL_H)
34 #include <GL/gl.h>
35 #elif defined(HAVE_OPENGL_GL_H)
36 #include <OpenGL/gl.h>
37 #endif
38 #include <cstdlib>
39 #include <cstdio>
40 #include <cmath>
41 
42 /**
43  @brief Judge wheser this line is the edge of 1st BZ
44 */
45 static int bragg_vert(
46  GLfloat bragg[26][3],
47  GLfloat brnrm[26],
48  int ibr, //!< [in] Index of a Bragg plane
49  int jbr, //!< [in] Index of a Bragg plane
50  int nbr, //!< [in]
51  GLfloat vert[3], //!< [in] start point of line
52  GLfloat vert2[3] //!< [in] end point of line
53 )
54 {
55  int kbr, i, lbr, nbr0;
56  GLfloat bmat[3][3], rhs[3], prod, thr, det;
57  /**/
58  nbr0 = nbr;
59  /**/
60  for (kbr = nbr0; kbr < 26; ++kbr) {
61  /**/
62  for (i = 0; i<3; ++i) bmat[0][i] = bragg[ibr][i];
63  for (i = 0; i<3; ++i) bmat[1][i] = bragg[jbr][i];
64  for (i = 0; i<3; ++i) bmat[2][i] = bragg[kbr][i];
65  /**/
66  rhs[0] = brnrm[ibr];
67  rhs[1] = brnrm[jbr];
68  rhs[2] = brnrm[kbr];
69  thr = sqrtf(rhs[0] * rhs[1] * rhs[2]) * 0.001f;
70  /*
71  if Bragg planes do not cross, roop next kbr
72  */
73  det = solve3(bmat, rhs);
74  if (fabsf(det) < thr) continue;
75  /*
76  if vert0 = vert1, roop next kbr
77  */
78  prod = (vert2[0] - rhs[0]) * (vert2[0] - rhs[0])
79  + (vert2[1] - rhs[1]) * (vert2[1] - rhs[1])
80  + (vert2[2] - rhs[2]) * (vert2[2] - rhs[2]);
81  if (prod < thr) continue;
82  /*
83  is corner really in 1st BZ ?
84  */
85  i = 0;
86  for (lbr = 0; lbr < 26; ++lbr) {
87  prod = bragg[lbr][0] * rhs[0]
88  + bragg[lbr][1] * rhs[1]
89  + bragg[lbr][2] * rhs[2];
90  /**/
91  if (prod > brnrm[lbr] + thr) {
92  i = 1;
93  break;
94  }
95  }
96  if (i == 1) {
97  }
98  else {
99  for (i = 0; i<3; ++i) vert[i] = rhs[i];
100  return kbr + 1;
101  }
102  }
103  /*
104  this line is not a BZ boundary
105  */
106  return 0;
107 }/* bragg_vert */
108 /**
109  @brief Compute real number of Bragg plane at 1st BZ
110 */
111 static void check_bragg()
112 {
113  int ibr, ibzl, ibzc;
114  int ii, kk, bzflag, nbzcorner, nn;
115  GLfloat thr = (GLfloat)0.0001, prod, bzc[676][3];
116  /*
117  First, compute real number of corners of 1st BZ
118  */
119  nbzcorner = 0;
120  for (ibzl = 0; ibzl < nbzl; ibzl++) {
121  for (ii = 0; ii < 2; ii++) {
122  bzflag = 0;
123 
124  for (ibzc = 0; ibzc < nbzcorner; ibzc++) {
125  prod = 0.0f;
126  for (kk = 0; kk < 3; kk++) prod += (bzl[ibzl][ii][kk] - bzc[ibzc][kk]) * (bzl[ibzl][ii][kk] - bzc[ibzc][kk]);
127  if (prod < thr) bzflag = 1;
128  }
129 
130  if (bzflag == 0) {
131  for (kk = 0; kk < 3; kk++) bzc[nbzcorner][kk] = bzl[ibzl][ii][kk];
132  nbzcorner += 1;
133  }
134 
135  }/*for (ii = 0; ii < 2; ii++)*/
136  }/*for (ibzl = 0; ibzl < nbzl; ibzl++)*/
137  *terminal << wxString::Format(wxT(" Number of corners of 1st BZ : %d\n"), nbzcorner);
138  /**@brief
139  Then, compute real number Bragg plane of 1st BZ (::nbragg),
140  Re-order ::bragg and ::brnrm
141  */
142  nbragg = 0;
143  for (ibr = 0; ibr < 26; ibr++) {
144  nn = 0;
145 
146  for (ibzc = 0; ibzc < nbzcorner; ibzc++) {
147  prod = bragg[ibr][0] * bzc[ibzc][0] + bragg[ibr][1] * bzc[ibzc][1] + bragg[ibr][2] * bzc[ibzc][2];
148  if (fabsf(prod - brnrm[ibr]) < thr) nn += 1;
149  }
150  if (nn >= 3) {
151  for (kk = 0; kk < 3; kk++) bragg[nbragg][kk] = bragg[ibr][kk];
152  brnrm[nbragg] = brnrm[ibr];
153  nbragg += 1;
154  }
155  }
156  *terminal << wxString::Format(wxT(" Number of plane of 1st BZ : %d\n"), nbragg);
157 }/*static void check_bragg*/
158 /**
159  @brief Compute Brillouin zone boundariy lines
160 
161  Modify : ::nbzl, ::bzl
162 */
163 void bz_lines()
164 {
165  /**/
166  int ibr, jbr, nbr, i, j, lvert;
167  GLfloat vert[2][3];
168  /**/
169  nbzl = 0;
170  /**/
171  for (ibr = 0; ibr < 26; ++ibr) {
172  for (jbr = 0; jbr < 26; ++jbr) {
173  /**/
174  for (i = 0; i<3; ++i) vert[1][i] = 0.0;
175  nbr = 0;
176  lvert = bragg_vert(bragg, brnrm, ibr, jbr, nbr, vert[0], vert[1]);
177  if (lvert == 0) continue;
178  nbr = lvert;
179  /**/
180  lvert = bragg_vert(bragg, brnrm, ibr, jbr, nbr, vert[1], vert[0]);
181  if (lvert == 0) continue;
182  /**/
183  for (i = 0; i < 2; ++i) for (j = 0; j < 3; ++j) bzl[nbzl][i][j] = vert[i][j];
184  nbzl = nbzl + 1;
185 
186  }/*for (jbr = 0; jbr < 26; ++jbr)*/
187  }/*for (ibr = 0; ibr < 26; ++ibr)*/
188 
189  check_bragg();
190 
191 }/*bz_lines*/
check_bragg
static void check_bragg()
Compute real number of Bragg plane at 1st BZ.
Definition: bz_lines.cpp:111
solve3
GLfloat solve3(GLfloat a[3][3], GLfloat b[3])
Solve linear system.
Definition: basic_math.cpp:58
basic_math.hpp
variable.hpp
Global variables.
bragg
GLfloat bragg[26][3]
Bragg plane vectors.
Definition: fermisurfer.cpp:129
bzl
GLfloat bzl[676][2][3]
Lines of 1st BZ [nbzl(max:26*26=676)][2][3].
Definition: fermisurfer.cpp:128
nbzl
int nbzl
The number of Lines of 1st Brillouin zone.
Definition: fermisurfer.cpp:127
brnrm
GLfloat brnrm[26]
Norms of Bragg plane vectors.
Definition: fermisurfer.cpp:130
bz_lines
void bz_lines()
Compute Brillouin zone boundariy lines.
Definition: bz_lines.cpp:163
terminal
wxTextCtrl * terminal
Definition: fermisurfer.cpp:237
bragg_vert
static int bragg_vert(GLfloat bragg[26][3], GLfloat brnrm[26], int ibr, int jbr, int nbr, GLfloat vert[3], GLfloat vert2[3])
Judge wheser this line is the edge of 1st BZ.
Definition: bz_lines.cpp:45
nbragg
int nbragg
Number of Bragg plane og 1st BZ.
Definition: fermisurfer.cpp:132