degen.resize(0);//empty the vector which will hold the multiplicities of the degenerate curved directions. This will be in an inverted order due to the storage order of the eigendirections as they are found.
BlockDims.resize(0);
//Creating auxiliary generic matrix...
unsignedintadim=d2V[0][0].size()-NIC;//Number of independent couplings
vector<double>randvec(adim,0);// generic random coupling vector
for(size_ta=0;a<adim;++a){
randvec[a]=r(-1,1);//creating random couplings...
if(d2V.Mag[a+NIC]!=0)
randvec[a]/=d2V.Mag[a+NIC];//Using typical scale of matrix elements for this matrix to re-scale random number
}
////filling generic matrix through the linear combination...
for(size_tk=0;k!=d2V.size();++k){
Agen[k*d2V.size()+k]=0e0;//Set diagonal element to zero
for(size_ta=0;a!=adim;++a)//filling diagonal element through linear combination
Agen[j*d2V.size()+k]=0e0;//Set off-diagonal element to zero
for(size_ta=0;a!=adim;++a)
Agen[j*d2V.size()+k]+=d2V[j][k][orderdV[a+NIC]]*randvec[a];//filling off-diagonal element
Agen[k*d2V.size()+j]=Agen[j*d2V.size()+k];//Use that matrices are symmetric to get transposed term
}
}
//Compute the eigenvalues of the reference matrix in this basis
EigenSystemRsym(d2V.size(),Agen,MtestOut);
doubleScaleEigen=1;//Variable to hold a scale for the eigenvalues, to test for null eigenvalues.
if(abs(MtestOut[d2V.size()-1])!=0)
ScaleEigen=MtestOut[d2V.size()-1];//If not all eigenvalues are zero, use largest one to set the scale.
for(size_tdummy=0;dummy<d2V.size();++dummy){//Loop to detect all flat directions
if(abs(MtestOut[kflat]/ScaleEigen)<epsilon){//Flat direction detected!
kflat++;//increase counter of accepted flat directions
for(size_tj=0;j!=d2V.size();++j){//And store vector at the end of the k range (accepted flat directions are stored from the end of Mbasis as they are found)
///Converting system to basis with a priori diagonal directions and blocks. The basis will be composed first by the "eigen-block" vectors and then the a priori eigen-vectors
vector<double>TestMag(d2V[0][0].size(),0);// Auxiliary vector to test matrix elements