The Conley-Morse Graphs Software
eigenval.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file eigenval.h
4///
5/// Eigenvalues of the Conley index map.
6/// This file contains the definition of a simple class which can be used
7/// to store the eigenvalues of the Conley index map,
8/// gathered by their level.
9///
10/// @author Pawel Pilarczyk
11///
12/////////////////////////////////////////////////////////////////////////////
13
14// Copyright (C) 1997-2014 by Pawel Pilarczyk.
15//
16// This file is part of my research software package. This is free software:
17// you can redistribute it and/or modify it under the terms of the GNU
18// General Public License as published by the Free Software Foundation,
19// either version 3 of the License, or (at your option) any later version.
20//
21// This software is distributed in the hope that it will be useful,
22// but WITHOUT ANY WARRANTY; without even the implied warranty of
23// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24// GNU General Public License for more details.
25//
26// You should have received a copy of the GNU General Public License
27// along with this software; see the file "license.txt". If not,
28// please, see <https://www.gnu.org/licenses/>.
29
30// Started on February 16, 2008. Last revision: February 21, 2008.
31
32
33#ifndef _CMGRAPHS_EIGENVAL_H_
34#define _CMGRAPHS_EIGENVAL_H_
35
36
37// include some standard C++ header files
38#include <string>
39#include <sstream>
40#include <fstream>
41#include <cmath>
42#include <algorithm>
43#include <vector>
44
45// include selected header files from the CHomP library
46#include "chomp/system/config.h"
47#include "chomp/system/textfile.h"
48#include "chomp/cubes/cube.h"
49#include "chomp/multiwork/mw.h"
50
51// include local header files
52#include "config.h"
53#include "typedefs.h"
54#include "typedyns.h"
55
56
57// --------------------------------------------------
58// -------- eigenvalues of the Conley index ---------
59// --------------------------------------------------
60
61/// Eigenvalues of the Conley index map gathered by levels.
63{
64public:
65 /// The constructor of an empty object.
67
68 /// The constructor of an object based on the given Conley index.
69 /// Calls the computation of nonzero eigenvalues of the given
70 /// Conley index and acquires the computed eigenvalues.
71 template <class ConleyIndexType>
72 IndexEigenValues (const ConleyIndexType &index);
73
74 // The default copy constructor, assignment operator
75 // and destructor are OK.
76
77 /// Returns the vector of the real parts of the eigenvalues
78 /// at the given level for appending.
79 std::vector<double> &re (unsigned int level);
80
81 /// Returns the vector of the real parts of the eigenvalues
82 /// at the given level for reading only.
83 const std::vector<double> &re (unsigned int level) const;
84
85 /// Returns the vector of the imaginary parts of the eigenvalues
86 /// at the given level for appending.
87 std::vector<double> &im (unsigned int level);
88
89 /// Returns the vector of the imaginary parts of the eigenvalues
90 /// at the given level for reading only.
91 const std::vector<double> &im (unsigned int level) const;
92
93 /// Returns the number of levels + 1. To be used in a loop
94 /// "for (int level = 0; level < this -> maxLevel (); ++ level)".
95 int maxLevel () const;
96
97 /// Returns "true" if there are no eigenvalues at any level.
98 /// Otherwise returns "false". Does not verify if the eigenvalues
99 /// are zero or not.
100 bool trivial () const;
101
102 /// Writes the eigenvalues in a human-readable format to the output
103 /// stream. The separator of eigenvalues and line separator can be
104 /// provided for customized output.
105 /// Returns the reference of the provided output stream.
106 std::ostream &write (std::ostream &out,
107 const char *valueSep = 0, const char *lineSep = 0) const;
108
109private:
110 /// The vector of the real part vectors.
111 std::vector<std::vector<double> > reVectors;
112
113 /// The vector of the imaginary part vectors.
114 std::vector<std::vector<double> > imVectors;
115
116 /// Makes sure that the vectors are large enough for the given level.
117 void addVectors (unsigned int level);
118
119}; /* class IndexEigenValues */
120
121// --------------------------------------------------
122
124{
125 return;
126} /* IndexEigenValues::IndexEigenValues */
127
128template <class ConleyIndexType>
129inline IndexEigenValues::IndexEigenValues (const ConleyIndexType &index)
130{
131 int dim = index. dim ();
132 for (int level = 0; level <= dim; ++ level)
133 {
134 std::vector<double> reVector, imVector;
135 index. eigenvalues (level, reVector, imVector);
136 reVectors. push_back (reVector);
137 imVectors. push_back (imVector);
138 }
139 return;
140} /* IndexEigenValues::IndexEigenValues */
141
142inline void IndexEigenValues::addVectors (unsigned int level)
143{
144 while (reVectors. size () <= level)
145 {
146 std::vector<double> emptyVector;
147 reVectors. push_back (emptyVector);
148 imVectors. push_back (emptyVector);
149 }
150 return;
151} /* IndexEigenValues::addVectors */
152
153inline std::vector<double> &IndexEigenValues::re (unsigned int level)
154{
155 addVectors (level);
156 return reVectors [level];
157} /* IndexEigenValues::re */
158
159inline const std::vector<double> &IndexEigenValues::re (unsigned int level)
160 const
161{
162 if (reVectors. size () <= level)
163 throw "Undefined level of eigenvalues requested (re).";
164 return reVectors [level];
165} /* IndexEigenValues::re */
166
167inline std::vector<double> &IndexEigenValues::im (unsigned int level)
168{
169 addVectors (level);
170 return imVectors [level];
171} /* IndexEigenValues::im */
172
173inline const std::vector<double> &IndexEigenValues::im (unsigned int level)
174 const
175{
176 if (imVectors. size () <= level)
177 throw "Undefined level of eigenvalues requested (im).";
178 return imVectors [level];
179} /* IndexEigenValues::im */
180
181inline int IndexEigenValues::maxLevel () const
182{
183 return reVectors. size ();
184} /* IndexEigenValues::maxLevel */
185
186inline bool IndexEigenValues::trivial () const
187{
188 int maxLevel = reVectors. size ();
189 for (int level = 0; level < maxLevel; ++ level)
190 {
191 if (!reVectors [level]. empty ())
192 return false;
193 }
194 return true;
195} /* IndexEigenValues::trivial */
196
197// --------------------------------------------------
198
199inline std::ostream &IndexEigenValues::write (std::ostream &out,
200 const char *valueSep, const char *lineSep) const
201{
202 // set the default separators if necessary
203 if (!valueSep)
204 valueSep = ", ";
205 if (!lineSep)
206 lineSep = "\n";
207
208 // output the eigenvalues at each nontrivial level
209 int maxLevel = reVectors. size ();
210 for (int level = 0; level < maxLevel; ++ level)
211 {
212 const std::vector<double> &re = reVectors [level];
213 int nValues = re. size ();
214 if (!nValues)
215 continue;
216 const std::vector<double> &im = imVectors [level];
217 out << "Eigenvalues " << level << ":" << lineSep << "(";
218 for (int i = 0; i < nValues; ++ i)
219 {
220 if (i)
221 out << valueSep;
222 if (re [i])
223 {
224 out << re [i];
225 if (im [i] > 0)
226 out << "+";
227 }
228 if (im [i])
229 out << im [i] << "i";
230 }
231 out << ")." << lineSep;
232 }
233 return out;
234} /* IndexEigenValues::write */
235
236
237#endif // _CMGRAPHS_EIGENVAL_H_
238
Eigenvalues of the Conley index map gathered by levels.
Definition: eigenval.h:63
std::vector< std::vector< double > > reVectors
The vector of the real part vectors.
Definition: eigenval.h:111
int maxLevel() const
Returns the number of levels + 1.
Definition: eigenval.h:181
IndexEigenValues()
The constructor of an empty object.
Definition: eigenval.h:123
std::vector< std::vector< double > > imVectors
The vector of the imaginary part vectors.
Definition: eigenval.h:114
void addVectors(unsigned int level)
Makes sure that the vectors are large enough for the given level.
Definition: eigenval.h:142
bool trivial() const
Returns "true" if there are no eigenvalues at any level.
Definition: eigenval.h:186
std::vector< double > & im(unsigned int level)
Returns the vector of the imaginary parts of the eigenvalues at the given level for appending.
Definition: eigenval.h:167
std::ostream & write(std::ostream &out, const char *valueSep=0, const char *lineSep=0) const
Writes the eigenvalues in a human-readable format to the output stream.
Definition: eigenval.h:199
std::vector< double > & re(unsigned int level)
Returns the vector of the real parts of the eigenvalues at the given level for appending.
Definition: eigenval.h:153
Choice of configuration settings.
Customizable data types for the Conley-Morse graphs computation program.
Data types for the dynamical systems data structures.