fermisurfer  2.0.0
fermisurfer
equator.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 <vector>
37 #include <cstdio>
38 #include <cstdlib>
39 #include <cmath>
40 #include "basic_math.hpp"
41 #include "variable.hpp"
42 /**
43 @brief Compute equator \f$\{\bf v}_{n k} \cdot {\bf k} = 0\f$
44 
45  Modify : ::nequator, ::kveq, ::kveq_rot
46 */
47 void equator() {
48  int ib, itri, i, j, ithread, nequator0;
49  std::vector<std::vector<std::vector<std::vector<GLfloat> > > > kveq_v;
50 
51  kveq_v.resize(nthreads);
52 
53  *terminal << wxT(" band # of equator\n");
54  for (ib = 0; ib < nb; ib++) {
55 
56 #pragma omp parallel default(none) \
57  shared(nb,ib,nmlp,kvp,ntri,eqvec,kveq_v) \
58  private(itri,i,j,ithread)
59  {
60  int sw[3];
61  GLfloat a[3][3], prod[3];
62  std::vector<std::vector<GLfloat> > kveq_0;
63 
64  kveq_0.resize(2);
65  for (i = 0; i < 2; i++) kveq_0.at(i).resize(3);
66 
67  ithread = get_thread();
68  kveq_v.at(ithread).resize(0);
69 
70 #pragma omp for
71  for (itri = 0; itri < ntri[ib]; ++itri) {
72 
73  for (i = 0; i < 3; ++i) {
74  prod[i] = 0.0f;
75  for (j = 0; j < 3; ++j) prod[i] += eqvec[j] * nmlp[ib][itri][i][j];
76  }/*for (i = 0; i < 3; ++i)*/
77 
78  eigsort(3, prod, sw);
79  for (i = 0; i < 3; ++i) {
80  for (j = 0; j < 3; ++j) {
81  a[i][j] = (0.f - prod[sw[j]]) / (prod[sw[i]] - prod[sw[j]]);
82  }/*for (j = 0; j < 3; ++j)*/
83  }/*for (i = 0; i < 3; ++i)*/
84 
85  if ((prod[sw[0]] < 0.0 && 0.0 <= prod[sw[1]])
86  || (prod[sw[0]] <= 0.0 && 0.0 < prod[sw[1]])) {
87  for (i = 0; i < 3; ++i) {
88  kveq_0.at(0).at(i) = kvp[ib][itri][sw[0]][i] * a[0][1] + kvp[ib][itri][sw[1]][i] * a[1][0];
89  kveq_0.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  kveq_v.at(ithread).push_back(kveq_0);
92  }/*else if (prod[sw[0]] < 0.0 && 0.0 <= prod[sw[1]])*/
93  else if ((prod[sw[1]] < 0.0 && 0.0 <= prod[sw[2]])
94  || (prod[sw[1]] <= 0.0 && 0.0 < prod[sw[2]])) {
95  for (i = 0; i < 3; ++i) {
96  kveq_0.at(0).at(i) = kvp[ib][itri][sw[0]][i] * a[0][2] + kvp[ib][itri][sw[2]][i] * a[2][0];
97  kveq_0.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  kveq_v.at(ithread).push_back(kveq_0);
100  }/*else if (prod[sw[1]] < 0.0 && 0.0 <= prod[sw[2]])*/
101  }/*for (itri = 0; itri < ntri[ib]; ++itri)*/
102  }/* End of parallel region */
103  /*
104  Sum node-lines in all threads
105  */
106  nequator[ib] = 0;
107  for (ithread = 0; ithread < nthreads; ithread++)
108  nequator[ib] += kveq_v.at(ithread).size();
109  *terminal << wxString::Format(wxT(" %d %d\n"), ib + 1, nequator[ib]);
110  /*
111  Allocate
112  */
113  kveq[ib] = new GLfloat * *[nequator[ib]];
114  kveq_rot[ib] = new GLfloat[6 * nequator[ib]];
115  for (itri = 0; itri < nequator[ib]; ++itri) {
116  kveq[ib][itri] = new GLfloat * [2];
117  for (i = 0; i < 2; ++i)
118  kveq[ib][itri][i] = new GLfloat[3];
119  }
120  /*
121  Input
122  */
123  nequator0 = 0;
124  for (ithread = 0; ithread < nthreads; ithread++) {
125  for (itri = 0; itri < kveq_v.at(ithread).size(); ++itri) {
126  for (i = 0; i < 2; ++i) {
127  for (j = 0; j < 3; ++j) {
128  kveq[ib][nequator0][i][j] = kveq_v.at(ithread).at(itri).at(i).at(j);
129  }
130  }
131  nequator0 += 1;
132  }
133  }
134  }/*for (ib = 0; ib < nb; ib++)*/
135 }/*void equator()*/
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
kveq_rot
GLfloat ** kveq_rot
-vector of equator [nb][nequator*2*3]
Definition: fermisurfer.cpp:177
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
equator
void equator()
Compute equator .
Definition: equator.cpp:47
basic_math.hpp
nmlp
GLfloat **** nmlp
Normal vector of patchs [nb][ntri][3][3].
Definition: fermisurfer.cpp:139
variable.hpp
Global variables.
kveq
GLfloat **** kveq
-vector of equator [nb][nequator][2][3]
Definition: fermisurfer.cpp:176
nb
int nb
The number of Bands.
Definition: fermisurfer.cpp:99
eqvec
GLfloat eqvec[3]
-vector for equator
Definition: fermisurfer.cpp:173
terminal
wxTextCtrl * terminal
Definition: fermisurfer.cpp:237
nthreads
int nthreads
Number of OpenMP threads.
Definition: fermisurfer.cpp:227
nequator
int * nequator
The number of equator.
Definition: fermisurfer.cpp:175