Commit b904e085c9e799f63e021975a96c7c136c710187
Exists in
master
and in
24 other branches
Merge branch 'FER_11000' into amdadev
Showing
6 changed files
with
47 additions
and
112 deletions
Show diff stats
CMakeLists.txt
... | ... | @@ -76,12 +76,15 @@ find_package(NetCDF REQUIRED) |
76 | 76 | find_package(DDClientCpp REQUIRED) |
77 | 77 | find_package(Geopack REQUIRED) |
78 | 78 | find_package(Maglib REQUIRED) |
79 | +find_package(Eigen REQUIRED) | |
79 | 80 | find_package(InternalField REQUIRED) |
80 | 81 | find_package(Con2020 REQUIRED) |
81 | 82 | find_package(KT17 REQUIRED) |
82 | 83 | find_package(Cainlib REQUIRED) |
83 | 84 | find_package(CSlim) |
84 | 85 | |
86 | +MESSAGE( STATUS "FER ${EIGENINCLUDE_DIR}") | |
87 | + | |
85 | 88 | get_filename_component(DDCLIENTLIB_DIR ${DDCLIENTLIBRARIES} PATH) |
86 | 89 | |
87 | 90 | # Apply configuration | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +FIND_PATH(EIGENINCLUDE_DIR Eigen | |
2 | + HINTS | |
3 | + ${USERLOCAL_ROOT}/include/eigen3/Eigen | |
4 | + NO_DEFAULT_PATH | |
5 | +) | |
6 | +mark_as_advanced(EIGENINCLUDE_DIR) | |
7 | + | |
8 | + | |
9 | + | |
10 | +include(FindPackageHandleStandardArgs) | |
11 | +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Eigen DEFAULT_MSG EIGENINCLUDE_DIR) | |
12 | + | |
13 | +if(EIGEN_FOUND) | |
14 | + set(EIGENINCLUDE_DIRS ${EIGENINCLUDE_DIR}) | |
15 | +endif() | |
16 | + | ... | ... |
src/ExternLib/Tetrahedron/characteristic/CMakeLists.txt
src/ExternLib/Tetrahedron/common/tetrahedron.cc
... | ... | @@ -2,13 +2,30 @@ |
2 | 2 | #include<iostream> |
3 | 3 | #include<cmath> |
4 | 4 | #include<algorithm> |
5 | +#include <Dense> | |
6 | +#include <vector> | |
7 | + | |
8 | +using Eigen::MatrixXd; | |
9 | +using Eigen::SelfAdjointEigenSolver; | |
5 | 10 | |
6 | 11 | using Vector = std::vector<double>; |
7 | 12 | using Matrix = std::vector<Vector>; |
8 | 13 | |
9 | -#ifdef DEBUG | |
10 | -void print_matrix(Matrix); | |
11 | -#endif | |
14 | + | |
15 | +Vector getEigenvalues(const Matrix& matrix) { | |
16 | + MatrixXd A(3, 3); | |
17 | + A << matrix[0][0], matrix[0][1], matrix[0][2], | |
18 | + matrix[1][0], matrix[1][1], matrix[1][2], | |
19 | + matrix[2][0], matrix[2][1], matrix[2][2]; | |
20 | + | |
21 | + SelfAdjointEigenSolver<MatrixXd> solver(A); | |
22 | + Vector eigenvalues(3); | |
23 | + eigenvalues[0] = solver.eigenvalues()[0]; | |
24 | + eigenvalues[1] = solver.eigenvalues()[1]; | |
25 | + eigenvalues[2] = solver.eigenvalues()[2]; | |
26 | + | |
27 | + return eigenvalues; | |
28 | +} | |
12 | 29 | |
13 | 30 | Matrix concatenate_vectors(Vector p1, Vector p2, Vector p3, Vector p4) { |
14 | 31 | Matrix mat; |
... | ... | @@ -46,7 +63,6 @@ Matrix matrix_multiply(Matrix mat1, Matrix mat2) { |
46 | 63 | Matrix mat2t = transpose(mat2); |
47 | 64 | Matrix r; |
48 | 65 | int n = mat1.size(); |
49 | - int m = mat1[0].size(); | |
50 | 66 | for(int i=0;i<n;i++) { |
51 | 67 | // new row |
52 | 68 | Vector row; |
... | ... | @@ -59,87 +75,6 @@ Matrix matrix_multiply(Matrix mat1, Matrix mat2) { |
59 | 75 | |
60 | 76 | } |
61 | 77 | |
62 | -#ifdef DEBUG | |
63 | -void print_vector(Vector vect) { | |
64 | - for(int i=0;i<(int)vect.size();i++) std::cout << vect[i] << " "; | |
65 | - std::cout << std::endl; | |
66 | -} | |
67 | - | |
68 | -void print_matrix(Matrix mat) { | |
69 | - for(int i=0;i<(int)mat.size();i++) { | |
70 | - print_vector(mat[i]); | |
71 | - } | |
72 | -} | |
73 | -#endif | |
74 | - | |
75 | -Vector vector_substract(Vector vect1, Vector vect2) { | |
76 | - Vector ans; | |
77 | - for(int i=0;i<(int)vect1.size();i++) { | |
78 | - ans.push_back(vect1[i] - vect2[i]); | |
79 | - } | |
80 | - return ans; | |
81 | -} | |
82 | - | |
83 | -Vector vector_projection(Vector v, Vector u) { | |
84 | - Vector ans; | |
85 | - double a = scalar_product(u,v); | |
86 | - double b = scalar_product(u,u); | |
87 | - for(int i=0;i<(int)v.size();i++) { | |
88 | - ans.push_back((a/b) * u[i]); | |
89 | - } | |
90 | - return ans; | |
91 | -} | |
92 | - | |
93 | -Vector vector_normalize(Vector vect) { | |
94 | - Vector ans; | |
95 | - double norm = scalar_product(vect, vect); | |
96 | - for(int i=0;i<(int)vect.size();i++) ans.push_back(vect[i] / sqrt(norm)); | |
97 | - return ans; | |
98 | -} | |
99 | - | |
100 | -Matrix gram_schmidt(Matrix mat) { | |
101 | - Matrix matt = transpose(mat); | |
102 | - Matrix basis; | |
103 | - Matrix Us; | |
104 | - for(int i=0;i<(int)mat.size();i++) { | |
105 | - // new basis vector | |
106 | - Vector nb = matt[i]; | |
107 | - for(int j=0;j<=i-1;j++) { | |
108 | - nb = vector_substract(nb, vector_projection(matt[i], Us[j])); | |
109 | - Vector vv = vector_projection(matt[i], Us[j]); | |
110 | - } | |
111 | - Us.push_back(nb); | |
112 | - nb = vector_normalize(nb); | |
113 | - basis.push_back(vector_normalize(nb)); | |
114 | - } | |
115 | - return transpose(basis); | |
116 | -} | |
117 | - | |
118 | -bool is_upper_triangular(Matrix mat) { | |
119 | - for(int i=0;i<(int)mat.size();i++) { | |
120 | - for(int j=0;j<i;j++) { | |
121 | - if(mat[i][j] > 1e-16) return false; | |
122 | - } | |
123 | - } | |
124 | - return true; | |
125 | -} | |
126 | - | |
127 | -Vector matrix_eigenvalues(Matrix mat) { | |
128 | - Matrix A = mat; | |
129 | - for(int k=0;k<1000000;k++) { | |
130 | - Matrix basis = gram_schmidt(A); | |
131 | - Matrix basisT = transpose(basis); | |
132 | - Matrix t1 = matrix_multiply(A, basis); | |
133 | - Matrix t2 = matrix_multiply(basisT, t1); | |
134 | - if(is_upper_triangular(t2)) break; | |
135 | - | |
136 | - A = t2; | |
137 | - } | |
138 | - Vector eig; | |
139 | - for(int i=0;i<(int)mat.size();i++) eig.push_back(A[i][i]); | |
140 | - return eig; | |
141 | -} | |
142 | - | |
143 | 78 | void compute_tetrahedron(Vector p1, Vector p2, Vector p3, Vector p4, double& elongation, double& planarity, double& characteristic) { |
144 | 79 | // make matrix by concatenating vectors |
145 | 80 | Matrix mat = concatenate_vectors(p1,p2,p3,p4); |
... | ... | @@ -149,35 +84,13 @@ void compute_tetrahedron(Vector p1, Vector p2, Vector p3, Vector p4, double& elo |
149 | 84 | // matrix product |
150 | 85 | Matrix pp = matrix_multiply(matt, mat); |
151 | 86 | |
152 | - Vector eig = matrix_eigenvalues(pp); | |
153 | - | |
87 | + // computing eigenvalues | |
88 | + Vector eig = getEigenvalues(pp); | |
89 | + | |
154 | 90 | // sort eigenvalues |
155 | 91 | sort(eig.begin(), eig.end()); |
156 | 92 | |
157 | 93 | planarity = 1. - sqrt(eig[0] / eig[1]); |
158 | 94 | elongation = 1. - sqrt(eig[1] / eig[2]); |
159 | 95 | characteristic = 2 * sqrt(eig[2]); |
160 | -} | |
161 | - | |
162 | -#ifdef DEBUG | |
163 | -Vector random_vector() { | |
164 | - Vector v; | |
165 | - for(int i=0;i<3;i++) v.push_back((double)(rand()%7)); | |
166 | - | |
167 | - return v; | |
168 | -} | |
169 | - | |
170 | -int main(int argc, char ** argv) { | |
171 | - // create some random data and compute the elongation | |
172 | - for(int i=0;i<1000000;i++) { | |
173 | - // generate twelve random numbers | |
174 | - Vector p1 = random_vector(); | |
175 | - Vector p2 = random_vector(); | |
176 | - Vector p3 = random_vector(); | |
177 | - Vector p4 = random_vector(); | |
178 | - std::cout << "Elongation " << elongation(p1,p2,p3,p4) << ", planarity: " << planarity(p1,p2,p3,p4) << std::endl; | |
179 | - } | |
180 | - return 0; | |
181 | -} | |
182 | -#endif | |
183 | - | |
96 | +} | |
184 | 97 | \ No newline at end of file | ... | ... |
src/ExternLib/Tetrahedron/elongation/CMakeLists.txt