Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
GramSchmidt.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_GRAMSCHMIDT_H_
9#define model_GRAMSCHMIDT_H_
10
11#include <iostream>
12#include <iomanip>
13#include <vector>
14#include <Eigen/Dense>
15
16namespace model
17{
18
20 {
25
26
27
28 /********************************************************************/
29 template <int dim>
30 static void orthoNormalize(std::vector<Eigen::Matrix<double,dim,1>>& NV,
31 const double& tol=Eigen::NumTraits<double>::dummy_precision())
32 {/*
33 * Ref:
34 * Giraud, L., Langou, J., & Rozloznik, M. (2005). The loss of
35 * orthogonality in the Gram-Schmidt orthogonalization process.
36 * Computers & Mathematics with Applications, 50(7), 1069–1075.
37 */
38 typedef Eigen::Matrix<double,dim,1> VectorDim;
39 typedef std::vector<VectorDim> VectorOfNormalsType;
40 VectorOfNormalsType NV_new;
41
42 for (size_t i=0;i<NV.size();++i)
43 {
44 VectorDim temp=NV[i];
45
46 for (int r=0;r<2;++r) // 2 is the number or reorthogonalizations
47 {
48 for (size_t j=0;j<NV_new.size();++j)
49 {
50 //temp-= NV[i].dot(NV_new[j]))*NV_new[j]; // classical GS (CGM)
51 temp -= (temp.dot(NV_new[j])*NV_new[j]).eval(); //modified GS (MGS)
52
53 }
54 }
55
56 const double tempNorm(temp.norm());
57 if (tempNorm>tol)
58 {
59 NV_new.push_back(temp/tempNorm);
60 }
61 }
62
63 if(NV_new.size()>dim)
64 {
65 std::cout<<"GramSchmidt FAILED. Input vectors:"<<std::endl;
66 for(const auto& v : NV)
67 {
68 std::cout<<std::setprecision(15)<<std::scientific<<v.transpose()<<std::endl;
69 }
70 std::cout<<"orthonormal vectors:"<<std::endl;
71 for(const auto& v : NV_new)
72 {
73 std::cout<<std::setprecision(15)<<std::scientific<<v.transpose()<<std::endl;
74 }
75 std::cout<<"tol="<<tol<<std::endl;
76 assert(0 && "GramSchmidt failed.");
77 }
78
79 NV=NV_new; // overwrite
80 }
81
82// /**********************************************************************/
83// static void makeUnique(std::deque<const LatticePlane*>& NV)
84// {
85//
86// std::deque<const LatticePlane*> temp;
87//
88// for (size_t i=0;i<NV.size();++i)
89// {
90// bool unique=true;
91// for (size_t j=0;j<temp.size();++j)
92// {
93// unique*=(temp[j]->n.cross(NV[i]->n).squaredNorm());
94// }
95//
96// if (unique)
97// {
98// temp.push_back(NV[i]);
99// }
100//
101// if(temp.size()>=3)
102// {
103// break;
104// }
105// }
106//
124//
125// NV=temp; // overwrite
126// }
127
128 };
129
130}
131#endif
static void orthoNormalize(std::vector< Eigen::Matrix< double, dim, 1 > > &NV, const double &tol=Eigen::NumTraits< double >::dummy_precision())
A class template that performs a modified Gram-Schmidt (MGS) orthonormalization (with reorthogonaliza...
Definition GramSchmidt.h:30
int j
int i
vertex temp
REAL v[4]