v2DM-DOCI  1.0
EIG.cpp
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Copyright (C) 2014-2015 Ward Poelmans
5  *
6  * This file is part of v2DM-DOCI.
7  *
8  * v2DM-DOCI is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Foobar is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * @END LICENSE
22  */
23 
24 #include <assert.h>
25 
26 #include "EIG.h"
27 
28 using namespace doci2DM;
29 
30 EIG::EIG(BlockMatrix &mat): BlockVector(mat.gnr())
31 {
32  for(int i=0;i<mat.gnr();i++)
33  {
34  setDim(i,mat.gdim(i),mat.gdeg(i));
35 
36  (*this)[i].diagonalize(mat[i]);
37  }
38 }
39 
40 EIG::EIG(Container &cont): BlockVector(cont.gnr())
41 {
42  for(int i=0;i<cont.gnMatrix();i++)
43  {
44  setDim(i,cont.gdimMatrix(i),cont.gdegMatrix(i));
45 
46  (*this)[i].diagonalize(cont.getMatrix(i));
47  }
48 
49  for(int i=0;i<cont.gnVector();i++)
50  {
51  setDim(i+cont.gnMatrix(), cont.gdimVector(i), cont.gdegVector(i));
52  (*this)[i+cont.gnMatrix()] = cont.getVector(i);
53  }
54 }
55 
56 EIG::EIG(SUP &sup): BlockVector(sup.gnr())
57 {
58  int tel = 0;
59 
60  for(int i=0;i<sup.getI().gnMatrix();i++)
61  {
62  setDim(tel,sup.getI().gdimMatrix(i),sup.getI().gdegMatrix(i));
63  (*this)[tel++].diagonalize(sup.getI().getMatrix(i));
64  }
65 
66  for(int i=0;i<sup.getI().gnVector();i++)
67  {
68  setDim(tel, sup.getI().gdimVector(i), sup.getI().gdegVector(i));
69  (*this)[tel++] = sup.getI().getVector(i);
70  }
71 
72 #ifdef __Q_CON
73  for(int i=0;i<sup.getQ().gnMatrix();i++)
74  {
75  setDim(tel,sup.getQ().gdimMatrix(i),sup.getQ().gdegMatrix(i));
76  (*this)[tel++].diagonalize(sup.getQ().getMatrix(i));
77  }
78 
79  for(int i=0;i<sup.getQ().gnVector();i++)
80  {
81  setDim(tel, sup.getQ().gdimVector(i), sup.getQ().gdegVector(i));
82  (*this)[tel++] = sup.getQ().getVector(i);
83  }
84 #endif
85 
86 #ifdef __G_CON
87  for(int i=0;i<sup.getG().gnr();i++)
88  {
89  setDim(tel, sup.getG().gdim(i), sup.getG().gdeg(i));
90  (*this)[tel++].diagonalize(sup.getG()[i]);
91  }
92 #endif
93 }
94 
95 double EIG::min() const
96 {
97  double min = (*this)[0].min();
98 
99  for(int i=1;i<gnr();i++)
100  if(min > (*this)[i].min())
101  min = (*this)[i].min();
102 
103  return min;
104 }
105 
106 double EIG::max() const
107 {
108  double max = (*this)[0].max();
109 
110  for(int i=1;i<gnr();i++)
111  if(max < (*this)[i].max())
112  max = (*this)[i].max();
113 
114  return max;
115 }
116 
117 double EIG::lsfunc(double a) const
118 {
119  double res = 0;
120 
121  for(int i=0;i<gnr();i++)
122  for(int j=0;j<gdim(i);j++)
123  res += gdeg(i) * (*this)(i,j)/(1+a*(*this)(i,j));
124 
125  return res;
126 }
127 
128 /* vim: set ts=3 sw=3 expandtab :*/
Matrix & getMatrix(int)
Definition: Container.cpp:174
int gnVector() const
Definition: Container.cpp:225
Vector & getVector(int)
Definition: Container.cpp:184
EIG(BlockMatrix &)
Definition: EIG.cpp:30
double max() const
Definition: EIG.cpp:106
PHM const & getG() const
Definition: SUP.cpp:204
TPM const & getI() const
Definition: SUP.cpp:184
int gdimVector(int) const
Definition: Container.cpp:235
double lsfunc(double) const
Definition: EIG.cpp:117
void setDim(int, int, int)
int gdegMatrix(int) const
Definition: Container.cpp:240
int gdegVector(int) const
Definition: Container.cpp:245
int gdimMatrix(int) const
Definition: Container.cpp:230
double min() const
Definition: EIG.cpp:95
int gnMatrix() const
Definition: Container.cpp:220
TPM const & getQ() const
Definition: SUP.cpp:194