runhenon.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// @file runhenon.cpp
00004 ///
00005 /// The main computations for the Henon attractor.
00006 /// This program runs rigorous numerical computations aimed at proving
00007 /// that an attractor for the given dynamical system is mixing
00008 /// at some finite resolution.
00009 /// This program accompanies the paper "Finite resolution dynamics"
00010 /// by S. Luzzatto and P. Pilarczyk, and follows the algorithms
00011 /// introduced there.
00012 ///
00013 /// @author Pawel Pilarczyk
00014 ///
00015 /////////////////////////////////////////////////////////////////////////////
00016 ///
00017 /// @mainpage The Finite Resolution Dynamics Software
00018 ///
00019 /// \section intro Introduction
00020 ///
00021 /// This website contains the documentation of software designed and
00022 /// programmed by Pawel Pilarczyk which accompanies the paper
00023 /// <em>Finite resolution dynamics</em> by S. Luzzatto and P. Pilarczyk.
00024 ///
00025 /// \section License
00026 ///
00027 /// In order to make this software freely available for wide audience,
00028 /// it is provided here under the terms of the GNU General Public License,
00029 /// version 2 or any later version. Please, see the
00030 /// <a href="http://www.gnu.org/copyleft/gpl.html">GNU website</a>
00031 /// for details.
00032 ///
00033 /// \section browsing Browsing
00034 ///
00035 /// Although a lot of effort was put into making this software as transparent
00036 /// and clear as possible, and to keep this documentation complete,
00037 /// I am sure that there is a lot of important information
00038 /// that might have been included here but was not.
00039 /// Therefore, this documentation was generated in such a way
00040 /// that it contains the source code which can be browsed and checked
00041 /// in case of any doubt.
00042 ///
00043 /// So, what are you waiting for? Dive and read. Have a happy browsing!
00044 ///
00045 /// Pawel Pilarczyk
00046 ///
00047 /////////////////////////////////////////////////////////////////////////////
00048 
00049 // Copyright (C) 1997-2010 by Pawel Pilarczyk.
00050 //
00051 // This file is part of my research software package.  This is free software;
00052 // you can redistribute it and/or modify it under the terms of the GNU
00053 // General Public License as published by the Free Software Foundation;
00054 // either version 2 of the License, or (at your option) any later version.
00055 //
00056 // This software is distributed in the hope that it will be useful,
00057 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00058 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00059 // GNU General Public License for more details.
00060 //
00061 // You should have received a copy of the GNU General Public License along
00062 // with this software; see the file "license.txt".  If not, write to the
00063 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00064 // MA 02111-1307, USA.
00065 
00066 // Started on December 22, 2008. Last revision: April 12, 2010.
00067 
00068 
00069 // BOOST (this header must be included first)
00070 #include "boost/numeric/interval.hpp"
00071 
00072 // include some standard C++ header files
00073 #include <iomanip>
00074 
00075 // include some headers from the CHomP library
00076 #include "chomp/system/config.h"
00077 #include "chomp/system/textfile.h"
00078 #include "chomp/system/timeused.h"
00079 #include "chomp/system/arg.h"
00080 
00081 // include local header files
00082 #include "maphenon.h"
00083 #include "covboxes.h"
00084 #include "attractor.h"
00085 #include "graph.h"
00086 #include "streams.h"
00087 #include "plotcover.h"
00088 #include "savecover.h"
00089 
00090 
00091 // --------------------------------------------------
00092 // -------------------- OVERTURE --------------------
00093 // --------------------------------------------------
00094 
00095 /// The title of the program with brief licensing information.
00096 const char *title = "\
00097 Finite Resolution Dynamics - computations for the Henon attractor.\n\
00098 Ver. 0.01, April 12, 2010. Copyright (C) 1997-2010 by Pawel Pilarczyk.\n\
00099 This is free software. No warranty. Consult 'license.txt' for details.";
00100 
00101 /// Short help information about the program's usage.
00102 const char *helpinfo = "\
00103 This program accompanies the paper \"Finite resolution dynamics\"\n\
00104 by S. Luzzatto and P. Pilarczyk. It runs computations aiming at proving\n\
00105 that the Henon attractor is mixing at all resolutions > some epsilon.\n\
00106 Call this program with the following arguments:\n\
00107 -p N - the number of cover parts in each direction (must be given),\n\
00108 -b filename.bmp - a file to save a plot of the cover to (default: none),\n\
00109 -w N - the width of the BMP file (default: 1000 pixels),\n\
00110 -s filename.txt - a text file to save the actual cover to (def: none),\n\
00111 -h - to display this brief help information only and exit.\n\
00112 For more information consult the accompanying documentation (if available)\n\
00113 or ask the program's author at http://www.PawelPilarczyk.com/.";
00114 
00115 
00116 // --------------------------------------------------
00117 // ---------------- HENON ATTRACTOR -----------------
00118 // --------------------------------------------------
00119 
00120 /// Runs the computations for the Henon attractor.
00121 template <class NumType>
00122 void henonAttractor (int parts, const char *bitmapFilename,
00123         int bitmapWidth, const char *saveFilename)
00124 {
00125         using chomp::homology::timeused;
00126 
00127         sout << "--- Running computations for the Henon map. ---\n";
00128         sout << std::setprecision (12);
00129 
00130         // define the type of the map to be used for the computations
00131         typedef tMapHenon<NumType> theMapType;
00132 
00133         // define the type of the map to be used for the computations
00134         typedef tCoverBoxes<NumType> theCoverType;
00135 
00136         // set the dimension of the phase space
00137         const int dim = 2;
00138 
00139         // prepare the parameters of the Henon map
00140         NumType aNumerator = 14;
00141         NumType aDenominator = 10;
00142         NumType bNumerator = 3;
00143         NumType bDenominator = 10;
00144         sout << "Parameters of the Henon map: a = " <<
00145                 aNumerator / aDenominator <<
00146                 ", b = " << bNumerator / bDenominator << ".\n";
00147 
00148         // create a dynamical system generator
00149         tMapHenon<NumType> function (aNumerator, aDenominator,
00150                 bNumerator, bDenominator);
00151 
00152         // prepare the phase space box to cover
00153         NumType leftCorner [dim] = {-1.4, -0.5}; //{-1.3, -0.4};
00154         NumType boxWidths [dim] = {2.8, 1.0}; //{2.6, 0.8};
00155         for (int i = 0; i < dim; ++ i)
00156         {
00157                 sout << (i ? ") x (" : "Phase space box: (") <<
00158                         leftCorner [i] << "," <<
00159                         (leftCorner [i] + boxWidths [i]);
00160         }
00161         sout << ").\n";
00162 
00163         // prepare the number of elements in each direction
00164         int partCounts [dim];
00165         partCounts [0] = parts;
00166         for (int i = 1; i < dim; ++ i)
00167         {
00168                 partCounts [i] = static_cast<int>
00169                         (parts * boxWidths [i] / boxWidths [0] + 0.5);
00170         }
00171         NumType *overlap = 0;
00172         double partsCount = 1;
00173         for (int i = 0; i < dim; ++ i)
00174         {
00175                 sout << (i ? " x " : "Number of cover elements: ") <<
00176                         partCounts [i];
00177                 partsCount *= partCounts [i];
00178         }
00179         sout << " = " << partsCount << ".\n";
00180         double area1 = 1;
00181         for (int i = 0; i < dim; ++ i)
00182         {
00183                 double size = static_cast<double> (boxWidths [i]) /
00184                         partCounts [i];
00185                 sout << (i ? " x " : "Size of each box: ") << size;
00186                 area1 *= size;
00187         }
00188         sout << ".\n";
00189         sout << "Area of each box: " << area1 << ".\n";
00190 
00191         // create an initially empty cover
00192         tCoverBoxes<NumType> cover (dim, leftCorner, boxWidths,
00193                 partCounts, overlap);
00194 
00195         // prepare an empty directed graph to store the map on the attractor
00196         Graph graph;
00197 
00198         // set up an initial point that is supposedly in the attraction
00199         // basin of the expected attractor
00200         NumType initialPoint [dim] = {0.61989426930989, 0.17586130934794};
00201 
00202         // set the number of iterations that need to be done
00203         // until the point gets close enough to the attractor
00204         int iterCount = 1000;
00205 
00206         // define the maximal allowed cover size
00207         int maxCoverSize = 0;
00208 
00209         // construct a cover of the attractor
00210         sout << "Computing a cover of the attractor...\n";
00211         timeused coverTime;
00212         double maxDiameter2 = constructAttractor (function, cover, graph,
00213                 initialPoint, iterCount, maxCoverSize);
00214         double percentage = static_cast<double> (cover. size ()) * 100 /
00215                 partsCount;
00216         sout << "A cover consisting of " << cover. size () <<
00217                 " elements (" << percentage << "%) constructed.\n";
00218         sout << "Computed in " << coverTime << ".\n";
00219         double area = 1;
00220         for (int i = 0; i < dim; ++ i)
00221                 area *= boxWidths [i] / partCounts [i];
00222         area *= cover. size ();
00223         sout << "Approximate area of the cover: " << area << ".\n";
00224         sout << "Max square of the diameter of map images: " <<
00225                 maxDiameter2 << ".\n";
00226         sout << "Approx. max diameter of map images: " <<
00227                 std::sqrt (maxDiameter2) << ".\n";
00228         sout << "The map graph has " << graph. countEdges () <<
00229                 " edges.\n";
00230 
00231         // plot the resulting cover in a bitmap image file
00232         if (bitmapFilename)
00233         {
00234                 sout << "Plotting the computed cover in a "
00235                         "black-and-white bitmap image...\n";
00236                 plotCover (cover, bitmapFilename, bitmapWidth);
00237         }
00238 
00239         // save the computed cover to a text file
00240         if (saveFilename)
00241         {
00242                 sout << "Saving the computed cover to a text file...\n";
00243                 saveCover (cover, saveFilename);
00244         }
00245 
00246         // clean up the cover and cubical sets from the memory
00247         sout << "Releasing the cover from the memory...\n";
00248         timeused forgetTime;
00249         cover. forget ();
00250         chomp::homology::PointBase::forget ();
00251         sout << "Memory released in " << forgetTime << ".\n";
00252 
00253         // verify if the constructed graph is strongly connected
00254         sout << "Checking if the graph is strongly connected...\n";
00255         timeused strConnTime;
00256         if (graph. checkStronglyConnected ())
00257                 sout << "Yes! The graph is strongly connected.\n";
00258         else
00259                 throw "The constructed graph is not strongly connected.\n";
00260         sout << "Verified in " << strConnTime << ".\n";
00261 
00262         // verify if the constructed graph is aperiodic
00263         sout << "Checking if the graph is aperiodic...\n";
00264         timeused aperTime;
00265         if (graph. checkAperiodic ())
00266                 sout << "Good! The graph is aperiodic.\n";
00267         else
00268                 throw "The constructed graph is not aperiodic.\n";
00269         sout << "Verified in " << aperTime << ".\n";
00270 
00271         sout << "--- The computations completed successfully. ---\n";
00272         return;
00273 } /* henonAttractor */
00274 
00275 
00276 // --------------------------------------------------
00277 // ---------------------- MAIN ----------------------
00278 // --------------------------------------------------
00279 
00280 /// The main function of the program.
00281 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
00282 int main (int argc, char *argv [])
00283 {
00284         using namespace chomp::homology;
00285 
00286         // turn on a message that will appear if the program does not finish
00287         program_time = "Aborted after";
00288 
00289         // prepare user-configurable data
00290         int parts = 0;
00291         char *bitmapFilename = 0;
00292         int bitmapWidth = 1000;
00293         char *saveFilename = 0;
00294 
00295         // analyze the command line
00296         arguments a;
00297         arg (a, "p", parts);
00298         arg (a, "b", bitmapFilename);
00299         arg (a, "w", bitmapWidth);
00300         arg (a, "s", saveFilename);
00301         arghelp (a);
00302 
00303         argstreamprepare (a);
00304         int argresult = a. analyze (argc, argv);
00305         argstreamset ();
00306 
00307         // show the program's title
00308         if (argresult >= 0)
00309                 sout << title << '\n';
00310 
00311         // if something was incorrect, show an additional message and exit
00312         if (argresult < 0)
00313         {
00314                 sout << "Call with '--help' for help.\n";
00315                 return 2;
00316         }
00317 
00318         // if help requested or no part number defined, show help information
00319         if ((argresult > 0) || (parts <= 0))
00320         {
00321                 sout << helpinfo << '\n';
00322                 return 1;
00323         }
00324 
00325         // try running the main function and catch an error message if thrown
00326         try
00327         {
00328                 // set an appropriate program time message
00329                 program_time = "Aborted after:";
00330 
00331                 // run the main procedure
00332                 henonAttractor<double> (parts, bitmapFilename, bitmapWidth,
00333                         saveFilename);
00334 
00335                 // set an appropriate program time message
00336                 program_time = "Total time used:";
00337                 program_time = 1;
00338 
00339                 // finalize
00340                 return 0;
00341         }
00342         catch (const char *msg)
00343         {
00344                 sout << "ERROR: " << msg << '\n';
00345                 return -1;
00346         }
00347         catch (const std::exception &e)
00348         {
00349                 sout << "ERROR: " << e. what () << '\n';
00350                 return -1;
00351         }
00352         catch (...)
00353         {
00354                 sout << "ABORT: An unknown error occurred.\n";
00355                 return -1;
00356         }
00357         return 0;
00358 } /* main */
00359 

Generated on Mon Apr 12 15:09:57 2010 for The Finite Resolution Dynamics Software by  doxygen 1.5.3