eigenval.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// @file eigenval.h
00004 ///
00005 /// Eigenvalues of the Conley index map.
00006 /// This file contains the definition of a simple class which can be used
00007 /// to store the eigenvalues of the Conley index map,
00008 /// gathered by their level.
00009 ///
00010 /// @author Pawel Pilarczyk
00011 ///
00012 /////////////////////////////////////////////////////////////////////////////
00013 
00014 // Copyright (C) 1997-2008 by Pawel Pilarczyk.
00015 //
00016 // This file is part of my research software package.  This is free software;
00017 // you can redistribute it and/or modify it under the terms of the GNU
00018 // General Public License as published by the Free Software Foundation;
00019 // either version 2 of the License, or (at your option) any later version.
00020 //
00021 // This software is distributed in the hope that it will be useful,
00022 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 // GNU General Public License for more details.
00025 //
00026 // You should have received a copy of the GNU General Public License along
00027 // with this software; see the file "license.txt".  If not, write to the
00028 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00029 // MA 02111-1307, USA.
00030 
00031 // Started on February 16, 2008. Last revision: February 21, 2008.
00032 
00033 
00034 #ifndef _CMGRAPHS_EIGENVAL_H_
00035 #define _CMGRAPHS_EIGENVAL_H_
00036 
00037 
00038 // include some standard C++ header files
00039 #include <string>
00040 #include <sstream>
00041 #include <fstream>
00042 #include <cmath>
00043 #include <algorithm>
00044 #include <vector>
00045 
00046 // include selected header files from the CHomP library
00047 #include "chomp/system/config.h"
00048 #include "chomp/system/textfile.h"
00049 #include "chomp/cubes/cube.h"
00050 #include "chomp/multiwork/mw.h"
00051 
00052 // include local header files
00053 #include "config.h"
00054 #include "typedefs.h"
00055 
00056 
00057 // --------------------------------------------------
00058 // -------- eigenvalues of the Conley index ---------
00059 // --------------------------------------------------
00060 
00061 /// Eigenvalues of the Conley index map gathered by levels.
00062 class IndexEigenValues
00063 {
00064 public:
00065         /// The constructor of an empty object.
00066         IndexEigenValues ();
00067 
00068         /// The constructor of an object based on the given Conley index.
00069         /// Calls the computation of nonzero eigenvalues of the given
00070         /// Conley index and acquires the computed eigenvalues.
00071         IndexEigenValues (const theConleyIndexType &index);
00072 
00073         // The default copy constructor, assignment operator
00074         // and destructor are OK.
00075 
00076         /// Returns the vector of the real parts of the eigenvalues
00077         /// at the given level for appending.
00078         std::vector<double> &re (unsigned int level);
00079 
00080         /// Returns the vector of the real parts of the eigenvalues
00081         /// at the given level for reading only.
00082         const std::vector<double> &re (unsigned int level) const;
00083 
00084         /// Returns the vector of the imaginary parts of the eigenvalues
00085         /// at the given level for appending.
00086         std::vector<double> &im (unsigned int level);
00087 
00088         /// Returns the vector of the imaginary parts of the eigenvalues
00089         /// at the given level for reading only.
00090         const std::vector<double> &im (unsigned int level) const;
00091 
00092         /// Returns the number of levels + 1. To be used in a loop
00093         /// "for (int level = 0; level < this -> maxLevel (); ++ level)".
00094         int maxLevel () const;
00095 
00096         /// Returns "true" if there are no eigenvalues at any level.
00097         /// Otherwise returns "false". Does not verify if the eigenvalues
00098         /// are zero or not.
00099         bool trivial () const;
00100 
00101         /// Writes the eigenvalues in a human-readable format to the output
00102         /// stream. The separator of eigenvalues and line separator can be
00103         /// provided for customized output.
00104         /// Returns the reference of the provided output stream.
00105         std::ostream &write (std::ostream &out,
00106                 const char *valueSep = 0, const char *lineSep = 0) const;
00107 
00108 private:
00109         /// The vector of the real part vectors.
00110         std::vector<std::vector<double> > reVectors;
00111 
00112         /// The vector of the imaginary part vectors.
00113         std::vector<std::vector<double> > imVectors;
00114 
00115         /// Makes sure that the vectors are large enough for the given level.
00116         void addVectors (unsigned int level);
00117 
00118 }; /* class IndexEigenValues */
00119 
00120 // --------------------------------------------------
00121 
00122 inline IndexEigenValues::IndexEigenValues ()
00123 {
00124         return;
00125 } /* IndexEigenValues::IndexEigenValues */
00126 
00127 inline IndexEigenValues::IndexEigenValues (const theConleyIndexType &index)
00128 {
00129         int dim = index. dim ();
00130         for (int level = 0; level <= dim; ++ level)
00131         {
00132                 std::vector<double> reVector, imVector;
00133                 index. eigenvalues (level, reVector, imVector);
00134                 reVectors. push_back (reVector);
00135                 imVectors. push_back (imVector);
00136         }
00137         return;
00138 } /* IndexEigenValues::IndexEigenValues */
00139 
00140 inline void IndexEigenValues::addVectors (unsigned int level)
00141 {
00142         while (reVectors. size () <= level)
00143         {
00144                 std::vector<double> emptyVector;
00145                 reVectors. push_back (emptyVector);
00146                 imVectors. push_back (emptyVector);
00147         }
00148         return;
00149 } /* IndexEigenValues::addVectors */
00150 
00151 inline std::vector<double> &IndexEigenValues::re (unsigned int level)
00152 {
00153         addVectors (level);
00154         return reVectors [level];
00155 } /* IndexEigenValues::re */
00156 
00157 inline const std::vector<double> &IndexEigenValues::re (unsigned int level)
00158         const
00159 {
00160         if (reVectors. size () <= level)
00161                 throw "Undefined level of eigenvalues requested (re).";
00162         return reVectors [level];
00163 } /* IndexEigenValues::re */
00164 
00165 inline std::vector<double> &IndexEigenValues::im (unsigned int level)
00166 {
00167         addVectors (level);
00168         return imVectors [level];
00169 } /* IndexEigenValues::im */
00170 
00171 inline const std::vector<double> &IndexEigenValues::im (unsigned int level)
00172         const
00173 {
00174         if (imVectors. size () <= level)
00175                 throw "Undefined level of eigenvalues requested (im).";
00176         return imVectors [level];
00177 } /* IndexEigenValues::im */
00178 
00179 inline int IndexEigenValues::maxLevel () const
00180 {
00181         return reVectors. size ();
00182 } /* IndexEigenValues::maxLevel */
00183 
00184 inline bool IndexEigenValues::trivial () const
00185 {
00186         int maxLevel = reVectors. size ();
00187         for (int level = 0; level < maxLevel; ++ level)
00188         {
00189                 if (!reVectors [level]. empty ())
00190                         return false;
00191         }
00192         return true;
00193 } /* IndexEigenValues::trivial */
00194 
00195 // --------------------------------------------------
00196 
00197 inline std::ostream &IndexEigenValues::write (std::ostream &out,
00198         const char *valueSep, const char *lineSep) const
00199 {
00200         // set the default separators if necessary
00201         if (!valueSep)
00202                 valueSep = ", ";
00203         if (!lineSep)
00204                 lineSep = "\n";
00205 
00206         // output the eigenvalues at each nontrivial level
00207         int maxLevel = reVectors. size ();
00208         for (int level = 0; level < maxLevel; ++ level)
00209         {
00210                 const std::vector<double> &re = reVectors [level];
00211                 int nValues = re. size ();
00212                 if (!nValues)
00213                         continue;
00214                 const std::vector<double> &im = imVectors [level];
00215                 out << "Eigenvalues " << level << ":" << lineSep << "(";
00216                 for (int i = 0; i < nValues; ++ i)
00217                 {
00218                         if (i)
00219                                 out << valueSep;
00220                         if (re [i])
00221                         {
00222                                 out << re [i];
00223                                 if (im [i] > 0)
00224                                         out << "+";
00225                         }
00226                         if (im [i])
00227                                 out << im [i] << "i";
00228                 }
00229                 out << ")." << lineSep;
00230         }
00231         return out;
00232 } /* IndexEigenValues::write */
00233 
00234 
00235 #endif // _CMGRAPHS_EIGENVAL_H_
00236 

Generated on Sun Mar 28 17:47:57 2010 for The Conley-Morse Graphs Software by  doxygen 1.5.3