fermisurfer  2.0.0
fermisurfer
calc_nodeline.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 nodal lines
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 <cstdio>
37 #include <cstdlib>
38 #include <cmath>
39 #include <vector>
40 #include "basic_math.hpp"
41 #include "variable.hpp"
42 /**
43 @brief Compute node-line where \f$\Delta_{n k} = 0\f$
44 
45  Modify : ::nnl, ::kvnl, ::kvnl_rot
46 
47 */
49 {
50  int ib, itri, i, j, ithread, nnl0;
51  std::vector<std::vector<std::vector<std::vector<GLfloat> > > > kvnl_v;
52 
53  kvnl_v.resize(nthreads);
54 
55  *terminal << wxT(" band # of nodeline\n");
56  for (ib = 0; ib < nb; ib++) {
57 
58 #pragma omp parallel default(none) \
59 shared(nb,ib,matp,kvp,ntri,kvnl_v) \
60 private(itri,i,j,ithread)
61  {
62  int sw[3];
63  GLfloat a[3][3], matps[3];
64  std::vector<std::vector<GLfloat> > kvnl0;
65 
66  kvnl0.resize(2);
67  for (i = 0; i < 2; i++)kvnl0.at(i).resize(3);
68 
69  ithread = get_thread();
70  kvnl_v.at(ithread).resize(0);
71 
72 #pragma omp for
73  for (itri = 0; itri < ntri[ib]; ++itri) {
74 
75  for (i = 0; i < 3; ++i) matps[i] = matp[ib][itri][i][0];
76  eigsort(3, matps, sw);
77 
78  for (i = 0; i < 3; ++i) {
79  for (j = 0; j < 3; ++j) {
80  a[i][j] = (0.f - matp[ib][itri][sw[j]][0])
81  / (matp[ib][itri][sw[i]][0] - matp[ib][itri][sw[j]][0]);
82  }/*for (j = 0; j < 3; ++j)*/
83  }/*for (i = 0; i < 3; ++i)*/
84 
85  if (( matp[ib][itri][sw[0]][0] < 0.0 && 0.0 <= matp[ib][itri][sw[1]][0])
86  || (matp[ib][itri][sw[0]][0] <= 0.0 && 0.0 < matp[ib][itri][sw[1]][0])) {
87  for (i = 0; i < 3; ++i) {
88  kvnl0.at(0).at(i) = kvp[ib][itri][sw[0]][i] * a[0][1] + kvp[ib][itri][sw[1]][i] * a[1][0];
89  kvnl0.at(1).at(i) = kvp[ib][itri][sw[0]][i] * a[0][2] + kvp[ib][itri][sw[2]][i] * a[2][0];
90  }/*for (i = 0; i < 3; ++i)*/
91  kvnl_v.at(ithread).push_back(kvnl0);
92  }/*else if (matp[ib][itri][sw[0]] < 0.0 && 0.0 <= matp[ib][itri][sw[1]])*/
93  else if ((matp[ib][itri][sw[1]][0] < 0.0 && 0.0 <= matp[ib][itri][sw[2]][0])
94  || (matp[ib][itri][sw[1]][0] <= 0.0 && 0.0 < matp[ib][itri][sw[2]][0])) {
95  for (i = 0; i < 3; ++i) {
96  kvnl0.at(0).at(i) = kvp[ib][itri][sw[0]][i] * a[0][2] + kvp[ib][itri][sw[2]][i] * a[2][0];
97  kvnl0.at(1).at(i) = kvp[ib][itri][sw[1]][i] * a[1][2] + kvp[ib][itri][sw[2]][i] * a[2][1];
98  }/*for (i = 0; i < 3; ++i)*/
99  kvnl_v.at(ithread).push_back(kvnl0);
100  }/*else if (matp[ib][itri][sw[1]] < 0.0 && 0.0 <= matp[ib][itri][sw[2]])*/
101  }/*for (itri = 0; itri < ntri[ib]; ++itri)*/
102  }/* End of parallel region */
103  /*
104  Allocation of nodeline
105  */
106  nnl[ib] = 0;
107  for (ithread = 0; ithread < nthreads; ithread++)
108  nnl[ib] += kvnl_v.at(ithread).size();
109  *terminal << wxString::Format(wxT(" %d %d\n"), ib + 1, nnl[ib]);
110 
111  kvnl[ib] = new GLfloat * *[nnl[ib]];
112  kvnl_rot[ib] = new GLfloat[6 * nnl[ib]];
113  for (itri = 0; itri < nnl[ib]; ++itri) {
114  kvnl[ib][itri] = new GLfloat *[2];
115  for (i = 0; i < 2; ++i) {
116  kvnl[ib][itri][i] = new GLfloat[3];
117  }/*for (j = 0; j < 2; ++j)*/
118  }
119  /*
120  Input
121  */
122  nnl0 = 0;
123  for (ithread = 0; ithread < nthreads; ithread++){
124  for (itri = 0; itri < kvnl_v.at(ithread).size(); ++itri) {
125  for (i = 0; i < 2; ++i) {
126  for (j = 0; j < 3; j++) {
127  kvnl[ib][nnl0][i][j] = kvnl_v.at(ithread).at(itri).at(i).at(j);
128  }
129  }/*for (j = 0; j < 2; ++j)*/
130  nnl0 += 1;
131  }
132  }
133  }/*for (ib = 0; ib < nb; ib++)*/
134 }/*void calc_nodeline()*/
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
basic_math.hpp
variable.hpp
Global variables.
kvnl
GLfloat **** kvnl
-vector of nodeline [nb][nnl][2][3]
Definition: fermisurfer.cpp:155
calc_nodeline
void calc_nodeline()
Compute node-line where .
Definition: calc_nodeline.cpp:48
nb
int nb
The number of Bands.
Definition: fermisurfer.cpp:99
matp
GLfloat **** matp
Matrix elements of points [nb][ntri][3][3].
Definition: fermisurfer.cpp:145
kvnl_rot
GLfloat ** kvnl_rot
-vector of nodeline [nb][nnl*2*3]
Definition: fermisurfer.cpp:156
nnl
int * nnl
The number of nodeline.
Definition: fermisurfer.cpp:154
terminal
wxTextCtrl * terminal
Definition: fermisurfer.cpp:237
nthreads
int nthreads
Number of OpenMP threads.
Definition: fermisurfer.cpp:227