9 #ifndef _COMPADRE_LINEAR_ALGEBRA_DEFINITIONS_HPP_
10 #define _COMPADRE_LINEAR_ALGEBRA_DEFINITIONS_HPP_
15 namespace GMLS_LinearAlgebra {
17 KOKKOS_INLINE_FUNCTION
20 Kokkos::single(Kokkos::PerTeam(teamMember), [&] () {
22 double maxRange = 100;
26 double eigenvalue_relative_tolerance = 1e-6;
29 double v[3] = {rand_gen.drand(maxRange),rand_gen.drand(maxRange),rand_gen.drand(maxRange)};
30 double v_old[3] = {v[0], v[1], v[2]};
35 while (error > eigenvalue_relative_tolerance) {
38 v[0] = PtP(0,0)*tmp1 + PtP(0,1)*v[1];
39 if (dimensions>2) v[0] += PtP(0,2)*v[2];
42 v[1] = PtP(1,0)*tmp1 + PtP(1,1)*tmp2;
43 if (dimensions>2) v[1] += PtP(1,2)*v[2];
46 v[2] = PtP(2,0)*tmp1 + PtP(2,1)*tmp2 + PtP(2,2)*v[2];
48 norm_v = v[0]*v[0] + v[1]*v[1];
49 if (dimensions>2) norm_v += v[2]*v[2];
50 norm_v = std::sqrt(norm_v);
54 if (dimensions>2) v[2] = v[2] / norm_v;
56 error = (v[0]-v_old[0])*(v[0]-v_old[0]) + (v[1]-v_old[1])*(v[1]-v_old[1]);
57 if (dimensions>2) error += (v[2]-v_old[2])*(v[2]-v_old[2]);
58 error = std::sqrt(error);
64 if (dimensions>2) v_old[2] = v[2];
73 for (
int i=0; i<2; ++i) {
78 V(1,0) = 1.0; V(1,1) = 1.0;
79 dot_product = V(0,0)*V(1,0) + V(0,1)*V(1,1);
80 V(1,0) -= dot_product*V(0,0);
81 V(1,1) -= dot_product*V(0,1);
83 norm = std::sqrt(V(1,0)*V(1,0) + V(1,1)*V(1,1));
89 for (
int i=0; i<3; ++i) {
91 for (
int j=0; j<3; ++j) {
92 PtP(i,j) -= norm_v*v[i]*v[j];
97 v[0] = rand_gen.drand(maxRange); v[1] = rand_gen.drand(maxRange); v[2] = rand_gen.drand(maxRange);
98 v_old[0] = v[0]; v_old[1] = v[1]; v_old[2] =v[2];
99 while (error > eigenvalue_relative_tolerance) {
102 v[0] = PtP(0,0)*tmp1 + PtP(0,1)*v[1] + PtP(0,2)*v[2];
105 v[1] = PtP(1,0)*tmp1 + PtP(1,1)*tmp2 + PtP(1,2)*v[2];
107 v[2] = PtP(2,0)*tmp1 + PtP(2,1)*tmp2 + PtP(2,2)*v[2];
109 norm_v = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
111 v[0] = v[0] / norm_v;
112 v[1] = v[1] / norm_v;
113 v[2] = v[2] / norm_v;
115 error = std::sqrt((v[0]-v_old[0])*(v[0]-v_old[0]) + (v[1]-v_old[1])*(v[1]-v_old[1]) + (v[2]-v_old[2])*(v[2]-v_old[2])) / norm_v;
122 for (
int i=0; i<3; ++i) {
127 dot_product = V(0,0)*V(1,0) + V(0,1)*V(1,1) + V(0,2)*V(1,2);
129 V(1,0) -= dot_product*V(0,0);
130 V(1,1) -= dot_product*V(0,1);
131 V(1,2) -= dot_product*V(0,2);
133 norm = std::sqrt(V(1,0)*V(1,0) + V(1,1)*V(1,1) + V(1,2)*V(1,2));
139 V(2,0) = V(0,1)*V(1,2) - V(1,1)*V(0,2);
140 V(2,1) = V(1,0)*V(0,2) - V(0,0)*V(1,2);
141 V(2,2) = V(0,0)*V(1,1) - V(1,0)*V(0,1);
144 norm = std::sqrt(V(2,0)*V(2,0) + V(2,1)*V(2,1) + V(2,2)*V(2,2));
151 random_number_pool.free_state(rand_gen);
pool_type::generator_type generator_type
team_policy::member_type member_type
KOKKOS_INLINE_FUNCTION void largestTwoEigenvectorsThreeByThreeSymmetric(const member_type &teamMember, scratch_matrix_right_type V, scratch_matrix_right_type PtP, const int dimensions, pool_type &random_number_pool)
Calculates two eigenvectors corresponding to two dominant eigenvalues.
Kokkos::View< double **, layout_right, Kokkos::MemoryTraits< Kokkos::Unmanaged > > scratch_matrix_right_type
Kokkos::Random_XorShift64_Pool pool_type