CppNoddy  0.92
Loading...
Searching...
No Matches
LinearEigenSystem_base.cpp
Go to the documentation of this file.
1/// \file LinearEigenSystem_base.cpp
2/// Implementation for the LinearEigenSystem_base class.
3/// The specific eigesolvers inherit from here.
4
5#include <vector>
6#include <set>
7
9#include <Exceptions.h>
10#include <Types.h>
11
12namespace CppNoddy {
13
15 m_shift(D_complex(0., 0.)),
16 m_calc_eigenvectors(true) {
17 }
18
19
21 {}
22
23
25 m_shift = z;
26 }
27
28
29 std::complex<double> LinearEigenSystem_base::get_shift() const {
30 return m_shift;
31 }
32
33
35 std::string problem;
36 problem = "The LinearEigenSystem_base::eigensolve method has been called\n";
37 problem += "but the method has not been implemented ... this should be \n";
38 problem += "implemented in the sub-class.";
39 throw ExceptionExternal(problem);
40 }
41
42
45 }
46
47
49 if(m_tagged_indices.size() == 0) {
50 std::string problem;
51 problem = "In LinearEigenSystem_base.get_tagged_eigenvalues() : there are\n";
52 problem += "no eigenvalues that have been tagged. This set is empty.\n";
53 throw ExceptionRuntime(problem);
54 }
55 // storage for the eigenvalues
57 // loop through the tagged set
58 for(iter p = m_tagged_indices.begin(); p != m_tagged_indices.end(); ++p) {
59 // get the index of the relevant eigenvalue from the set
60 std::size_t j = *p;
61 std::cout << " number " << j << " is a tagged ev.\n";
62 // work out the complex eigenvalue associated with this index
63 // and add it to the vector
64 evals.push_back(m_all_eigenvalues[ j ]);
65 }
66 // return the complex vector of eigenvalues
67 return evals;
68 }
69
70
72 if(m_tagged_indices.size() == 0) {
73 std::string problem;
74 problem = "In LinearEigenSystem_base.get_tagged_eigenvectors() : there are\n";
75 problem += "no eigenvalues that have been tagged. This set is empty.\n";
76 throw ExceptionRuntime(problem);
77 }
78 // number of degrees of freedom in each eigenvector
79 std::size_t n = m_all_eigenvectors[0].size();
80 // eigenvector storage : size() eigenvectors each of length n
81 DenseMatrix<D_complex> evecs(m_tagged_indices.size(), n, 0.0);
82 std::size_t row = 0;
83 // loop through the tagged set
84 for(iter p = m_tagged_indices.begin(); p != m_tagged_indices.end(); ++p) {
85 // get the index of the relevant eigenvalue from the set
86 std::size_t j = *p;
87 // put the eigenvector in the matrix
88 evecs[ row ] = m_all_eigenvectors[ j ];
89 // next row/eigenvector
90 ++row;
91 }
92 return evecs;
93 }
94
95 // EIGENVALUE/VECTOR TAGGING
96
97
99 for(unsigned i = 0; i < m_all_eigenvalues.size(); ++i) {
100 m_tagged_indices.insert(m_tagged_indices.end(), i);
101 }
102 std::cout << "** I have tagged " << m_all_eigenvalues.size() << " eigenvalues.\n";
103 }
104
105
106 void LinearEigenSystem_base::tag_eigenvalues_disc(const int &val, const double& radius) {
107 // loop through all the eigenvalues
108 for(std::size_t i = 0; i < m_all_eigenvalues.size(); ++i) {
109 // if the eigenvalue is in the disc centred at shift then include it
110 if(std::abs(m_all_eigenvalues[ i ] - m_shift) < radius) {
111 if(val > 0) {
112 // add it to our set of tagged eigenvalues
113 m_tagged_indices.insert(m_tagged_indices.end(), i);
114 } else {
115 // remove it from the set if it exists
116 m_tagged_indices.erase(i);
117 }
118 }
119 }
120 }
121
122
124 // loop through all the eigenvalues
125 for(std::size_t i = 0; i < m_all_eigenvalues.size(); ++i) {
126 // if the eigenvalue is in the disc centred at m_shift then include it
127 if((m_all_eigenvalues[ i ] - m_shift).real() > 0.0) {
128 if(val > 0) {
129 // add it to our set of tagged eigenvalues
130 m_tagged_indices.insert(m_tagged_indices.end(), i);
131 } else {
132 // remove it from the set if it exists
133 m_tagged_indices.erase(i);
134 }
135 }
136 }
137 }
138
139
141 // loop through all the eigenvalues
142 for(std::size_t i = 0; i < m_all_eigenvalues.size(); ++i) {
143 // if the eigenvalue is in the disc centred at m_shift then include it
144 if((m_all_eigenvalues[ i ] - m_shift).real() < 0.0) {
145 if(val > 0) {
146 // add it to our set of tagged eigenvalues
147 m_tagged_indices.insert(m_tagged_indices.end(), i);
148 } else {
149 // remove it from the set if it exists
150 m_tagged_indices.erase(i);
151 }
152 }
153 }
154 }
155
156
158 // loop through all the eigenvalues
159 for(std::size_t i = 0; i < m_all_eigenvalues.size(); ++i) {
160 // if the eigenvalue is in the disc centred at m_shift then include it
161 if((m_all_eigenvalues[ i ] - m_shift).imag() > 0.0) {
162 if(val > 0) {
163 // add it to our set of tagged eigenvalues
164 m_tagged_indices.insert(m_tagged_indices.end(), i);
165 } else {
166 // remove it from the set if it exists
167 m_tagged_indices.erase(i);
168 }
169 }
170 }
171 }
172
174 // loop through all the eigenvalues
175 for(std::size_t i = 0; i < m_all_eigenvalues.size(); ++i) {
176 // if the eigenvalue is in the disc centred at m_shift then include it
177 if((m_all_eigenvalues[ i ] - m_shift).imag() < 0.0) {
178 if(val > 0) {
179 // add it to our set of tagged eigenvalues
180 m_tagged_indices.insert(m_tagged_indices.end(), i);
181 } else {
182 // remove it from the set if it exists
183 m_tagged_indices.erase(i);
184 }
185 }
186 }
187 }
188
189
191
192} // end namespace
The collection of CppNoddy exceptions.
Specification of the linear eigensystem base class.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
Definition: DenseMatrix.h:25
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
void push_back(const _Type &fill)
A pass-thru definition of push_back.
Definition: DenseVector.h:310
std::size_t size() const
A pass-thru definition to get the size of the vector.
Definition: DenseVector.h:330
An exception to indicate that an error has been detected in an external (LAPACK) routine.
Definition: Exceptions.h:20
A generic runtime exception.
Definition: Exceptions.h:158
A linear Nth-order generalised eigensystem base class.
virtual DenseMatrix< D_complex > get_tagged_eigenvectors() const
Get the the tagged eigenvectors.
virtual void tag_eigenvalues_right(const int &val)
Tag those eigenvalues that are to the right of a specified shft point.
virtual void tag_eigenvalues_all()
Tag all the eigenvalues returned from the ARPACK routine.
virtual void tag_eigenvalues_lower(const int &val)
Tag those eigenvalues that are in the lower half-plane below a specified point.
D_complex m_shift
The complex shift value.
virtual void tag_eigenvalues_disc(const int &val, const double &radius)
Tag those eigenvalues that are within a disc centred at a point in the complex plane.
std::set< unsigned, std::less< unsigned > >::iterator iter
DenseVector< D_complex > m_all_eigenvalues
storage for eigenvectors and eigenvalues
virtual void tag_eigenvalues_left(const int &val)
Tag those eigenvalues that are to the left of a specified point.
std::set< unsigned, std::less< unsigned > > m_tagged_indices
a set of tagged eigenvalue indices
virtual void eigensolve()
Solve the matrix linear eigensystem.
D_complex get_shift() const
Get the shift value associated with this class (used for tagging) and eigenvalue tagging.
bool m_calc_eigenvectors
calculate the eigenvectors in any eigenvalue computation
virtual ~LinearEigenSystem_base()
Destructor for a linear system object.
LinearEigenSystem_base()
Constructor for a linear system object.
void set_shift(const D_complex &z)
Set the shift value to be used in tagging.
void set_calc_eigenvectors(bool flag)
Compute the eigenvectors in any eigenvalue computation.
DenseMatrix< D_complex > m_all_eigenvectors
virtual DenseVector< D_complex > get_tagged_eigenvalues() const
Get the the tagged eigenvalues.
virtual void tag_eigenvalues_upper(const int &val)
Tag those eigenvalues that are in the upper half-plane above a specified point.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...
std::complex< double > D_complex
A complex double precision number using std::complex.
Definition: Types.h:98

© 2012

R.E. Hewitt